/* SubManager Dark Theme — Mobile First */
:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-card: #1e293b;
    --bg-input: #0f172a;
    --bg-hover: #334155;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --border: #334155;
    --sidebar-width: 240px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ─── Hamburger toggle (visible = mobile default) ─── */
.menu-toggle {
    display: block;
    position: fixed;
    top: 12px; left: 12px;
    z-index: 200;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 1.4rem;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    line-height: 1;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
}

.sidebar-open .sidebar-overlay { display: block; }

/* ─── Sidebar (off-screen = mobile default) ─── */
.sidebar {
    position: fixed;
    top: 0; left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
}

.sidebar-open .sidebar { transform: translateX(0); }

.sidebar-brand { padding: 20px; border-bottom: 1px solid var(--border); }
.sidebar-brand h2 { color: var(--accent); font-size: 1.3rem; }

.nav-links {
    list-style: none;
    flex: 1;
    padding: 10px 0;
    overflow-y: auto;
}

.nav-links li a {
    display: block;
    padding: 14px 20px;
    color: var(--text-secondary);
    transition: all 0.2s;
    border-left: 3px solid transparent;
    font-size: 0.95rem;
}

.nav-links li a:hover,
.nav-links li a.active {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-left-color: var(--accent);
}

.sidebar-footer {
    border-top: 1px solid var(--border);
}

.sidebar-footer a {
    display: block;
    padding: 14px 20px;
    color: var(--text-muted);
    font-size: 0.95rem;
    transition: all 0.2s;
    border-left: 3px solid transparent;
    text-decoration: none;
}

.sidebar-footer a:hover {
    background: var(--bg-hover);
    color: var(--danger);
    border-left-color: var(--danger);
}

/* ─── Main content (full width = mobile default) ─── */
.content {
    margin-left: 0;
    padding: 60px 16px 24px;
    min-height: 100vh;
}

.content-full {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 16px;
}

/* ─── Page header ─── */
.page-header {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 20px;
}

.page-header h1 { font-size: 1.25rem; font-weight: 600; }

/* ─── Cards ─── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px;
    margin-bottom: 16px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
    gap: 10px;
    flex-wrap: wrap;
}

.card-header h3 { font-size: 1rem; font-weight: 600; }

/* ─── Stat cards ─── */
.stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px;
}

.stat-card .stat-value { font-size: 1.4rem; font-weight: 700; color: var(--accent); }
.stat-card .stat-label { color: var(--text-secondary); font-size: 0.78rem; margin-top: 4px; }

/* ─── Tables (mobile: card layout by default) ─── */
.table-wrap {
    overflow-x: visible;
}

table { width: 100%; border-collapse: collapse; }

/* Mobile: hide thead, make rows into cards */
thead { display: none; }

tr {
    display: block;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 10px;
    padding: 12px;
}

td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 0;
    border: none;
    font-size: 0.88rem;
    white-space: normal;
    word-break: break-word;
}

td::before {
    content: attr(data-label);
    font-weight: 600;
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-right: 12px;
    flex-shrink: 0;
    min-width: 80px;
}

/* Actions cell: full width, no label */
td.cell-actions {
    display: block;
    padding-top: 10px;
    margin-top: 6px;
    border-top: 1px solid var(--border);
}

td.cell-actions::before { display: none; }

/* ─── Badges ─── */
.badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-success { background: rgba(34,197,94,0.15); color: var(--success); }
.badge-danger { background: rgba(239,68,68,0.15); color: var(--danger); }
.badge-warning { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge-secondary { background: rgba(148,163,184,0.15); color: var(--text-secondary); }
.badge-dark { background: rgba(100,116,139,0.15); color: var(--text-muted); }

/* ─── Buttons (touch-friendly by default, min 40px height) ─── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 10px 16px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s;
    text-decoration: none;
    line-height: 1.5;
    white-space: nowrap;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #16a34a; color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; color: #fff; }
.btn-warning { background: var(--warning); color: #000; }
.btn-warning:hover { background: #d97706; color: #000; }
.btn-secondary { background: var(--bg-hover); color: var(--text-primary); }
.btn-secondary:hover { background: var(--border); color: var(--text-primary); }
.btn-sm { min-height: 40px; padding: 8px 12px; font-size: 0.82rem; }

.btn-group {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
}

/* ─── Forms (single column = mobile default) ─── */
.form-group { margin-bottom: 16px; }

.form-group label {
    display: block;
    margin-bottom: 6px;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
}

.form-control {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 16px;
    transition: border-color 0.2s;
}

.form-control:focus { outline: none; border-color: var(--accent); }
select.form-control { appearance: auto; }
textarea.form-control { min-height: 80px; resize: vertical; }

.form-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0;
}

.form-inline { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }

/* ─── Alerts ─── */
.alert {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 0.88rem;
}

.alert-success { background: rgba(34,197,94,0.1); border: 1px solid rgba(34,197,94,0.3); color: var(--success); }
.alert-danger { background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.3); color: var(--danger); }
.alert-warning { background: rgba(245,158,11,0.1); border: 1px solid rgba(245,158,11,0.3); color: var(--warning); }
.alert-info { background: rgba(59,130,246,0.1); border: 1px solid rgba(59,130,246,0.3); color: var(--accent); }

/* ─── Login/Setup box ─── */
.auth-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    width: 100%;
    max-width: 440px;
}

/* ─── Empty state ─── */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: 10px; opacity: 0.5; }
.empty-state p { font-size: 0.95rem; }

/* ─── Form actions row ─── */
.form-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-top: 8px;
}

/* ─── Danger zone ─── */
.danger-zone {
    margin-left: auto;
}

/* ─── Tab content ─── */
.tab-content { display: none; }
.tab-content.active { display: block; }

.auth-box h1 { text-align: center; margin-bottom: 8px; color: var(--accent); }
.auth-box p { text-align: center; color: var(--text-secondary); margin-bottom: 25px; }

/* ─── Modal ─── */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.6);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 12px;
}

.modal-overlay.show { display: flex; }

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal h3 { margin-bottom: 16px; font-size: 1.05rem; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }

/* ─── Copy field ─── */
.copy-field { display: flex; gap: 6px; align-items: center; }
.copy-field input { flex: 1; min-width: 0; }

/* ─── Pagination ─── */
.pagination { display: flex; gap: 4px; margin-top: 15px; justify-content: center; flex-wrap: wrap; }
.pagination a, .pagination span { display: inline-block; padding: 8px 14px; border-radius: 4px; font-size: 0.85rem; }
.pagination a { background: var(--bg-hover); color: var(--text-primary); }
.pagination a:hover { background: var(--border); }
.pagination .current { background: var(--accent); color: #fff; }

/* ─── Search bar ─── */
.search-bar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.search-bar input { flex: 1 1 100%; min-width: 0; }

/* ─── Filter bar ─── */
.filter-bar { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; align-items: stretch; }
.filter-bar .form-group { margin-bottom: 0; }

/* ─── Tabs ─── */
.tabs { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 20px; overflow-x: auto; }
.tab { padding: 10px 16px; color: var(--text-secondary); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all 0.2s; white-space: nowrap; }
.tab:hover, .tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ─── Utility ─── */
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-right { text-align: right; }
.mt-10 { margin-top: 10px; }
.mt-20 { margin-top: 20px; }
.mb-10 { margin-bottom: 10px; }
.mb-20 { margin-bottom: 20px; }
.d-flex { display: flex; }
.gap-10 { gap: 10px; }
.hidden { display: none; }

/* ─── Mobile top bar ─── */
.mobile-topbar {
    display: flex;
    align-items: center;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 52px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 0 16px;
    z-index: 90;
}

.mobile-topbar-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ─── Bottom tab bar ─── */
.bottom-tabs {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 60px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    z-index: 90;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.bottom-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.68rem;
    background: none;
    border: none;
    cursor: pointer;
    transition: color 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.bottom-tab svg {
    width: 22px;
    height: 22px;
}

.bottom-tab.active {
    color: var(--accent);
}

/* ─── More menu ─── */
.more-menu-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    align-items: flex-end;
    justify-content: center;
}

.more-menu-overlay.show { display: flex; }

.more-menu {
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    width: 100%;
    max-width: 500px;
    padding: 8px 0;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0));
}

.more-menu-item {
    display: block;
    padding: 16px 24px;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 1rem;
    transition: background 0.15s;
}

.more-menu-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* ─── Password masking ─── */
.pw-masked {
    font-family: monospace;
    letter-spacing: 2px;
}

.pw-toggle {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    font-size: 0.85rem;
    -webkit-tap-highlight-color: transparent;
}

/* ─── Adjust content for mobile top bar + bottom tabs ─── */
.content {
    padding-top: 64px;
    padding-bottom: 76px;
}

/* Hide hamburger — replaced by bottom tabs */
.menu-toggle { display: none; }

/* ═══════════════════════════════════════════
   Desktop (>= 769px) — restore traditional tables
   ═══════════════════════════════════════════ */
@media (min-width: 769px) {
    .menu-toggle { display: none; }
    .sidebar-overlay { display: none !important; }
    .sidebar { transform: translateX(0); }

    /* Hide mobile-only elements */
    .mobile-topbar { display: none; }
    .bottom-tabs { display: none; }
    .more-menu-overlay { display: none !important; }

    .content { margin-left: var(--sidebar-width); padding: 30px; padding-top: 30px; padding-bottom: 30px; }
    .content-full { padding: 30px; }

    .page-header { flex-direction: row; align-items: center; justify-content: space-between; margin-bottom: 25px; }
    .page-header h1 { font-size: 1.5rem; }

    .card { padding: 20px; margin-bottom: 20px; }
    .card-header h3 { font-size: 1.1rem; }

    .stat-grid { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 15px; margin-bottom: 25px; }
    .stat-card { padding: 20px; }
    .stat-card .stat-value { font-size: 2rem; }
    .stat-card .stat-label { font-size: 0.85rem; }

    /* Restore traditional table layout */
    .table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -20px;
        padding: 0 20px;
    }

    thead { display: table-header-group; }

    tr {
        display: table-row;
        background: none;
        border: none;
        border-radius: 0;
        margin-bottom: 0;
        padding: 0;
    }

    td {
        display: table-cell;
        padding: 10px 12px;
        border-bottom: 1px solid var(--border);
        font-size: 0.9rem;
        white-space: nowrap;
        word-break: normal;
    }

    td::before { display: none; }

    td.cell-actions {
        display: table-cell;
        padding-top: 10px;
        margin-top: 0;
        border-top: none;
    }

    th {
        padding: 10px 12px;
        text-align: left;
        border-bottom: 1px solid var(--border);
        color: var(--text-secondary);
        font-weight: 600;
        font-size: 0.8rem;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        white-space: nowrap;
    }

    tr:hover td { background: var(--bg-hover); }

    .badge { font-size: 0.75rem; padding: 3px 10px; }

    .btn { min-height: unset; padding: 8px 16px; font-size: 0.875rem; }
    .btn-sm { min-height: unset; padding: 5px 10px; font-size: 0.8rem; }
    .btn-group { gap: 8px; }

    .form-row { grid-template-columns: 1fr 1fr; gap: 15px; }

    /* Wider form cards on desktop */
    .card[style*="max-width:600px"] { max-width: 700px !important; }

    .search-bar { flex-wrap: nowrap; }
    .search-bar input { flex: 1; }

    .filter-bar { flex-direction: row; flex-wrap: wrap; align-items: end; }
    .filter-bar .form-group { flex: 1; }

    .modal { padding: 25px; border-radius: 12px; }
    .modal h3 { font-size: 1.15rem; margin-bottom: 20px; }

    .auth-box { padding: 40px; max-width: 460px; }

    /* URLs in tables should look like links */
    td a[href^="http"], td .url-link { color: var(--accent); }
    td a[href^="http"]:hover, td .url-link:hover { text-decoration: underline; }
}
