/* CSS for WhatsApp Gateway Dashboard */
:root {
    --primary: #25D366;
    --secondary: #075E54;
    --bg: #f0f2f5;
    --card-bg: #ffffff;
    --text: #111b21;
    --sidebar: #ffffff;
    --nav-text: #54656f;
    --border: #e9edef;
    --sb-collapsed: 70px;
    --sb-expanded: 250px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    margin: 0;
    display: flex;
    min-height: 100vh;
}

#login-page {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--secondary), var(--primary));
    position: absolute;
    width: 100%;
    height: 100%;
    z-index: 2000;
}

.login-card {
    background: white;
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    width: 350px;
}

#dashboard {
    display: none;
    flex: 1;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar Navigation */
.sidebar {
    width: var(--sb-expanded);
    background: var(--sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease;
    height: 100vh;
    overflow: hidden;
}

.sidebar.collapsed {
    width: var(--sb-collapsed);
}

.sidebar-header {
    height: 55px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0;
}

.logo {
    display: flex;
    align-items: center;
    width: 100%;
    color: var(--secondary);
    font-size: 1.2em;
    font-weight: bold;
    white-space: nowrap;
}

.menu-toggle {
    width: var(--sb-collapsed);
    height: 55px;
    cursor: pointer;
    background: none;
    border: none;
    color: var(--nav-text);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: color 0.2s;
}

.logo-text {
    transition: opacity 0.2s;
}

.sidebar.collapsed .logo-text {
    opacity: 0;
    pointer-events: none;
}

.menu-items {
    flex: 1;
    padding: 10px 0;
    display: flex;
    flex-direction: column;
}

.menu-item {
    height: 50px;
    margin: 4px 0;
    cursor: pointer;
    color: var(--nav-text);
    font-weight: 500;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 0;
    overflow: hidden;
    white-space: nowrap;
}

.menu-item svg {
    width: var(--sb-collapsed);
    height: 24px;
    padding: 0 23px;
    box-sizing: border-box;
    fill: currentColor;
    flex-shrink: 0;
}

.menu-item .text {
    transition: opacity 0.2s;
}

.sidebar.collapsed .text {
    opacity: 0;
    pointer-events: none;
}

.menu-item:hover {
    background: var(--bg);
}

.menu-item.active {
    background: #dcf8c6;
    color: var(--secondary);
}

.user-profile {
    height: 60px;
    border-top: 1px solid var(--border);
    font-size: 0.9em;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 15px;
    background: var(--sidebar);
    margin-top: auto;
    overflow: hidden;
}

#user-display {
    font-weight: bold;
    color: var(--secondary);
    transition: opacity 0.2s;
}

.sidebar.collapsed #user-display {
    opacity: 0;
    pointer-events: none;
    width: 0;
}

.sidebar.collapsed .user-profile {
    justify-content: center;
    padding: 0;
}

.user-profile button {
    border-radius: 4px;
    background: #e9edef;
    color: #111b21;
    font-weight: normal;
    padding: 6px 12px;
    width: auto;
    margin: 0;
}

.sidebar.collapsed .user-profile button {
    padding: 4px 8px;
    font-size: 0.8em;
}

/* Main Content Area */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.tab-content {
    display: none;
    flex: 1;
    overflow: hidden;
    /* Changed from auto, container manages scroll */
    padding: 0;
    /* Removed default padding */
    height: 100%;
}

.tab-content.active {
    display: flex;
    flex-direction: column;
}

.page-header {
    height: 55px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    flex-shrink: 0;
}

.page-title {
    color: var(--secondary);
    font-size: 1.1em;
    font-weight: bold;
    margin: 0;
    display: flex;
    align-items: center;
}

.page-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.page-content {
    flex: 1;
    overflow-y: auto;
    padding: 0 20px 30px 20px;
    /* Zero top padding */
}

.page-content> :first-child {
    margin-top: 0;
}

/* Monitor specific layout fixing */
#tab-monitor .page-content {
    overflow: hidden;
    /* Prevent page scrolling, use pane scrolling */
    display: flex;
    flex-direction: column;
    padding: 0;
    /* Important: remove common padding */
}

.monitor-split-top {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0 20px;
    /* Leave room for registrations but no bottom gap */
}

.monitor-split-bottom {
    flex-shrink: 0;
    border-top: 1px solid var(--border);
    overflow: hidden;
    position: relative;
    background: #1e1e1e;
    /* Ensure background covers everything */
}

.monitor-table-container {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Stats specific styles */
.stats-filter-bar {
    display: flex;
    gap: 15px;
    align-items: center;
    background: var(--bg);
    /* Same as header */
    padding: 0 20px 10px 20px;
    /* Reduced top padding since it follows header */
    border-bottom: 1px solid var(--border);
}

.stats-filter-bar label {
    font-size: 0.8em;
    font-weight: bold;
    color: #666;
    margin-right: -10px;
}

.stats-filter-bar input[type="date"] {
    width: auto;
    margin-bottom: 0;
    padding: 5px;
}

.stats-filter-bar select {
    width: auto;
    margin-bottom: 0;
    padding: 5px;
}

/* Common Components */
.card {
    background: var(--card-bg);
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    margin-bottom: 20px;
}

h3 {
    margin-top: 0;
    color: var(--secondary);
    border-bottom: 1px solid var(--border);
    padding-bottom: 10px;
}

.sub-nav {
    display: flex;
    gap: 5px;
    background: #e9edef;
    padding: 3px;
    border-radius: 8px;
}

.sub-nav button {
    padding: 6px 15px;
    font-size: 0.85em;
    background: transparent;
    color: var(--nav-text);
    border: none;
    margin: 0;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
    width: auto;
}

.sub-nav button:hover {
    background: rgba(255, 255, 255, 0.5);
}

.sub-nav button.active {
    background: white;
    color: var(--secondary);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

input,
button,
select,
textarea {
    padding: 10px;
    border-radius: 6px;
    border: 1px solid #ddd;
    width: 100%;
    box-sizing: border-box;
    margin-bottom: 10px;
    font-family: inherit;
}

.password-input-wrapper {
    position: relative;
    width: 100%;
    margin-bottom: 10px;
}

.password-input-wrapper input {
    margin-bottom: 0 !important;
    padding-right: 40px;
}

.password-toggle {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    color: #bbb;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    height: 24px;
    width: 24px;
}

.password-toggle:hover {
    color: #888;
}

.password-toggle svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}


button {
    background: var(--primary);
    color: white;
    border: none;
    cursor: pointer;
    font-weight: bold;
    transition: opacity 0.2s;
}

button:hover {
    opacity: 0.9;
}

button.secondary {
    background: #eee;
    color: #333;
}

button.delete {
    background: #f44336;
}

button.small {
    width: auto;
    padding: 5px 10px;
    font-size: 0.85em;
}

.w-100 {
    width: 100% !important;
}

/* Monitor Layout with Right Sidebar */
.monitor-layout {
    display: flex;
    height: 100%;
    overflow: hidden;
    background: var(--bg);
}

.monitor-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 15px;
    height: 100%;
    overflow: hidden;
}

.monitor-sidebar {
    width: 320px;
    background: #f8f9fa;
    border-left: 1px solid var(--border);
    padding: 15px;
    height: 100%;
    overflow-y: auto;
    transition: width 0.3s ease, padding 0.3s ease, opacity 0.3s ease;
}

.monitor-sidebar.collapsed {
    width: 0;
    padding: 0;
    opacity: 0;
    pointer-events: none;
    border-left: none;
}

/* New Monitor Styles */
.phone-card {
    transition: transform 0.2s;
}

.phone-card:hover {
    transform: translateY(-2px);
}

.collapsed-bar {
    /* Base styles for collapsed bar are inline in HTML structure mostly, but we can refine transition here */
    overflow: hidden;
}

/* Grid Layouts */
.grid-2 {
    display: grid;
    grid-template-columns: 350px 1fr;
    gap: 20px;
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9em;
}

th,
td {
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

tr:hover {
    background: #f9f9f9;
    cursor: pointer;
}

.status-badge {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.8em;
    font-weight: bold;
}

.status-connected {
    background: #dcf8c6;
    color: #128c7e;
}

.status-disconnected {
    background: #ffebee;
    color: #c62828;
}

/* Modals */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
}

.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 25px;
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    z-index: 1001;
    display: none;
}

/* Detail View Styles */
.log-detail-row {
    margin-bottom: 15px;
    border-bottom: 1px solid #eee;
    padding-bottom: 10px;
}

.log-detail-label {
    font-weight: bold;
    color: #666;
    font-size: 0.85em;
}

.log-json {
    background: #f4f4f4;
    padding: 10px;
    border-radius: 5px;
    font-family: monospace;
    white-space: pre-wrap;
    font-size: 0.85em;
    max-height: 200px;
    overflow: auto;
}

/* Mobile Responsive - Complete Overhaul */
@media (max-width: 768px) {
    * {
        -webkit-tap-highlight-color: transparent;
    }

    body {
        overflow-x: hidden;
        flex-direction: column;
    }

    #dashboard {
        flex-direction: column;
        height: 100vh;
        width: 100vw;
    }

    /* Sidebar - Full overlay style */
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 280px;
        z-index: 2500;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: 5px 0 15px rgba(0, 0, 0, 0.3);
        overflow-y: auto;
    }

    .sidebar:not(.collapsed) {
        transform: translateX(0);
    }

    .sidebar.collapsed {
        width: 280px;
        /* keep width but translated away */
    }

    /* Mobile top bar */
    .mobile-top-bar {
        display: flex !important;
        width: 100%;
        height: 55px;
        background: white;
        border-bottom: 1px solid #e0e0e0;
        align-items: center;
        padding: 0 15px;
        z-index: 1000;
        position: relative;
    }

    /* Main content area */
    .main-content {
        flex: 1;
        width: 100%;
        padding: 0;
        margin: 0 !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        position: relative;
    }

    /* Tab content padding */
    .tab-content {
        padding: 10px !important;
    }

    /* Monitor Layout - Stack everything */
    .monitor-layout {
        display: flex;
        flex-direction: column;
        gap: 12px;
        width: 100%;
    }

    .monitor-main {
        width: 100%;
        padding: 0;
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    /* Cards - Auto height, proper spacing */
    .monitor-main .card {
        height: auto !important;
        min-height: 200px;
        max-height: none !important;
        margin: 0 !important;
        padding: 12px;
    }

    /* Transaction Monitor Card */
    .monitor-main .card:first-child {
        min-height: 300px;
        max-height: 400px;
    }

    /* System Logs Card */
    .monitor-main .card:last-child {
        min-height: 250px;
        max-height: 350px;
    }

    /* Tables - Horizontal scroll */
    .logs-table {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }

    .logs-table thead,
    .logs-table tbody,
    .logs-table tr {
        display: table;
        width: 100%;
        table-layout: fixed;
    }

    .logs-table th,
    .logs-table td {
        padding: 8px 4px;
        font-size: 0.85em;
    }

    /* Ensure minimum widths for table columns */
    .logs-table th:nth-child(1),
    .logs-table td:nth-child(1) {
        min-width: 70px;
    }

    /* Time */
    .logs-table th:nth-child(2),
    .logs-table td:nth-child(2) {
        min-width: 90px;
    }

    /* Session */
    .logs-table th:nth-child(3),
    .logs-table td:nth-child(3) {
        min-width: 60px;
    }

    /* Dir */
    .logs-table th:nth-child(4),
    .logs-table td:nth-child(4) {
        min-width: 90px;
    }

    /* Peer */
    .logs-table th:nth-child(5),
    .logs-table td:nth-child(5) {
        min-width: 150px;
    }

    /* Content */
    .logs-table th:nth-child(6),
    .logs-table td:nth-child(6) {
        min-width: 70px;
    }

    /* Status */

    /* Monitor sidebar (Quick Send) */
    .monitor-sidebar {
        width: 100%;
        border-left: none;
        border-top: 1px solid var(--border);
        padding: 12px;
        margin: 0;
    }

    .monitor-sidebar.collapsed {
        display: none !important;
    }

    .monitor-sidebar .card {
        margin-bottom: 12px;
    }

    /* Admin Grid */
    .grid-2 {
        display: block;
        padding: 0;
    }

    .col-left,
    .col-right {
        width: 100%;
        margin-bottom: 12px;
    }

    /* Cards general */
    .card {
        padding: 16px;
        margin-bottom: 12px;
    }

    /* Buttons */
    button {
        font-size: 14px;
        padding: 10px 16px;
    }

    button.small {
        font-size: 12px;
        padding: 6px 12px;
    }

    /* Inputs */
    input,
    select,
    textarea {
        font-size: 16px;
        /* Prevents zoom on iOS */
        padding: 10px;
    }

    /* Modals */
    .modal {
        position: fixed !important;
        left: 50% !important;
        top: 50% !important;
        transform: translate(-50%, -50%) !important;
        width: 90% !important;
        max-width: 400px !important;
        max-height: 85vh !important;
        overflow-y: auto;
        padding: 20px;
        border-radius: 12px;
    }

    /* Login card */
    .login-card {
        width: 90%;
        max-width: 360px;
        padding: 24px;
    }

    /* Admin sub-tab buttons */
    #tab-admin>div:first-child {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
        padding-bottom: 8px;
        margin-bottom: 12px;
    }

    #tab-admin>div:first-child button {
        margin-right: 8px;
        margin-bottom: 0;
    }

    /* API Documentation Styling */
    .doc-container {
        max-width: 800px;
        margin: 0 auto;
        font-size: 1.05em;
    }

    .doc-container h1 {
        color: var(--secondary);
        border-bottom: 2px solid var(--primary);
        padding-bottom: 10px;
    }

    .doc-container h2 {
        margin-top: 30px;
        color: var(--secondary);
    }

    .doc-container pre {
        background: #f8f9fa;
        padding: 15px;
        border-radius: 8px;
        border: 1px solid #e9edef;
        overflow-x: auto;
    }

    .doc-container code {
        font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
        background: #f1f3f5;
        padding: 2px 4px;
        border-radius: 4px;
        font-size: 0.9em;
    }

    .doc-container pre code {
        background: transparent;
        padding: 0;
    }

    .doc-container hr {
        border: 0;
        border-top: 1px solid var(--border);
        margin: 30px 0;
    }

    .doc-container ul {
        padding-left: 20px;
    }

    .doc-container li {
        margin-bottom: 10px;
    }

    /* Sidebar overlay */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 2000;
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .sidebar-overlay.active {
        display: block;
        opacity: 1;
    }

    /* User profile in sidebar */
    .user-profile {
        padding: 12px;
    }

    /* Hide desktop-only elements */
    .monitor-main>.card>div:first-child {
        flex-wrap: wrap;
        gap: 8px;
    }

    /* System logs specific */
    #system-logs-container {
        font-size: 0.75em !important;
        line-height: 1.3 !important;
    }

    /* Table wrapper scrolling hint */
    .logs-table::after {
        content: '← Scroll →';
        position: absolute;
        bottom: 4px;
        right: 4px;
        font-size: 0.7em;
        color: #999;
        pointer-events: none;
    }
}

/* Hide mobile elements on desktop */
.mobile-top-bar {
    display: none;
}

.sidebar-overlay {
    display: none;
}

/* Toggle Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 20px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 20px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--primary);
}

input:focus+.slider {
    box-shadow: 0 0 1px var(--primary);
}

input:checked+.slider:before {
    transform: translateX(20px);
}