@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600&family=Sora:wght@300;400;600;700&display=swap');

/* ── Variables ── */
:root {
    --bg: #0a0c10;
    --surface: #111318;
    --surface2: #181c24;
    --border: #1e2330;
    --accent: #00e5a0;
    --accent2: #0070f3;
    --danger: #ff4d6d;
    --text: #e2e8f0;
    --muted: #64748b;
    --working: #00e5a0;
    --idle: #ff4d6d;
    --sidebar-w: 220px;
    --radius: 10px;
}

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

/* ── Custom scrollbars ── */
::-webkit-scrollbar {
    width: 5px;
    height: 5px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #2d3748;
    border-radius: 99px;
}

    ::-webkit-scrollbar-thumb:hover {
        background: #4a5568;
    }

::-webkit-scrollbar-corner {
    background: transparent;
}

body {
    font-family: 'Sora', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
}

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
}

.sidebar-brand {
    padding: 1.5rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    border-bottom: 1px solid var(--border);
}

.brand-icon {
    font-size: 1.4rem;
    color: var(--accent);
}

    .brand-icon.large {
        font-size: 2.5rem;
        display: block;
        margin-bottom: 0.5rem;
    }

.brand-name {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.nav-links {
    list-style: none;
    padding: 1rem 0;
    flex: 1;
}

    .nav-links li a {
        display: block;
        padding: 0.7rem 1.25rem;
        color: var(--muted);
        text-decoration: none;
        font-size: 0.875rem;
        border-left: 3px solid transparent;
        transition: all 0.15s;
    }

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

.sidebar-version {
    font-size: 0.65rem;
    color: #334155;
    margin-top: 0.4rem;
    letter-spacing: 0.04em;
}

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

.logout-btn {
    display: block;
    color: var(--danger);
    text-decoration: none;
    font-size: 0.8rem;
    padding: 0.5rem 0;
    transition: opacity 0.15s;
}

    .logout-btn:hover {
        opacity: 0.7;
    }

/* ── Main content ── */
.main-content {
    margin-left: var(--sidebar-w);
    min-width: 0;
    padding: 2rem 2.5rem;
    flex: 1;
    min-height: 100vh;
}

/* ── Page header ── */
.page-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

    .page-header h1 {
        font-size: 1.75rem;
        font-weight: 700;
        letter-spacing: -0.03em;
        background: linear-gradient(135deg, var(--accent), var(--accent2));
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;
    }

.page-date {
    font-size: 0.8rem;
    color: var(--muted);
}

/* ── Stat cards ── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    position: relative;
    overflow: hidden;
}

    .stat-card::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        height: 2px;
        background: linear-gradient(90deg, var(--accent), transparent);
    }

    .stat-card.accent-green::before {
        background: linear-gradient(90deg, var(--working), transparent);
    }

    .stat-card.accent-red::before {
        background: linear-gradient(90deg, var(--idle), transparent);
    }

.stat-label {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--muted);
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
    color: var(--accent);
}

.stat-card.accent-red .stat-value {
    color: var(--idle);
}

.stat-sub {
    font-size: 0.72rem;
    color: var(--muted);
    margin-top: 0.25rem;
}

/* ── Progress bar ── */
.progress-wrap {
    margin-bottom: 2rem;
}

.progress-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--muted);
    margin-bottom: 0.4rem;
}

.progress-track {
    height: 6px;
    background: var(--surface2);
    border-radius: 99px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent2), var(--accent));
    border-radius: 99px;
}

/* ── Section header ── */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

    .section-header h2 {
        font-size: 1rem;
        font-weight: 600;
    }

/* ── Table ── */
.records-table-wrap {
    overflow-x: auto;
}

.records-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

    .records-table th {
        text-align: left;
        padding: 0.6rem 1rem;
        font-size: 0.68rem;
        text-transform: uppercase;
        letter-spacing: 0.08em;
        color: var(--muted);
        border-bottom: 1px solid var(--border);
    }

    .records-table td {
        padding: 0.75rem 1rem;
        border-bottom: 1px solid var(--border);
        vertical-align: middle;
    }

    .records-table tr:hover td {
        background: var(--surface2);
    }

/* Action button groups inside table cells */
.table-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
}

.analysis-cell {
    max-width: 300px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--muted);
}

/* ── Inline confidence bar ── */
.inline-bar {
    display: inline-block;
    width: 60px;
    height: 4px;
    background: var(--surface2);
    border-radius: 99px;
    vertical-align: middle;
    margin-right: 4px;
    overflow: hidden;
}

.inline-fill {
    height: 100%;
    border-radius: 99px;
}

    .inline-fill.working {
        background: var(--working);
    }

    .inline-fill.idle {
        background: var(--idle);
    }

/* ── Filter bar ── */
.filter-bar {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
    align-items: center;
}

.filter-input {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    padding: 0.5rem 0.85rem;
    font-size: 0.82rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
}

    .filter-input:focus {
        border-color: var(--accent2);
    }

/* ── Record cards (Activity page) ── */
.records-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
    min-width: 0;
}

.record-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: grid;
    grid-template-columns: 280px 1fr;
    overflow: hidden;
    transition: border-color 0.2s, transform 0.15s;
    width: 100%;
    min-width: 0;
}

    .record-card:hover {
        border-color: #2a3040;
        transform: translateY(-1px);
    }

.card-image {
    position: relative;
    background: #000;
    cursor: zoom-in;
    overflow: hidden;
    min-height: 160px;
    border-right: 1px solid var(--border);
}

    .card-image img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        display: block;
        transition: transform 0.3s;
    }

    .card-image:hover img {
        transform: scale(1.03);
    }

.card-image-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 0.85rem;
    opacity: 0;
    transition: opacity 0.2s;
}

.card-image:hover .card-image-overlay {
    opacity: 1;
}

.card-body {
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    min-width: 0; /* allow flex children to shrink below content size */
    overflow: hidden;
}

.card-meta-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.confidence-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.confidence-track {
    flex: 1;
    height: 4px;
    background: var(--surface2);
    border-radius: 99px;
    overflow: hidden;
}

.confidence-fill {
    height: 100%;
    border-radius: 99px;
}

    .confidence-fill.working {
        background: var(--working);
    }

    .confidence-fill.idle {
        background: var(--idle);
    }

.analysis-text {
    font-size: 0.82rem;
    line-height: 1.6;
    color: var(--text);
    flex: 1;
}

.card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    min-width: 0;
}

.tag {
    font-size: 0.68rem;
    font-family: 'JetBrains Mono', monospace;
    background: var(--surface2);
    color: var(--muted);
    padding: 0.2rem 0.55rem;
    border-radius: 4px;
}

/* ── Badges ── */
.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 99px;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

    .badge.working {
        background: rgba(0,229,160,0.12);
        color: var(--working);
        border: 1px solid rgba(0,229,160,0.25);
    }

    .badge.superadmin {
        background: rgba(168,85,247,0.12);
        color: #a855f7;
        border: 1px solid rgba(168,85,247,0.25);
        font-weight: 700;
    }

    .badge.pending {
        background: rgba(251,191,36,0.12);
        color: #f59e0b;
        border: 1px solid rgba(251,191,36,0.25);
    }

.stat-card.accent-yellow::before {
    background: linear-gradient(90deg, #f59e0b, transparent);
}

.stat-card.accent-yellow .stat-value {
    color: #f59e0b;
}

.badge.idle {
    background: rgba(255,77,109,0.12);
    color: var(--idle);
    border: 1px solid rgba(255,77,109,0.25);
}

/* ── Pagination ── */
.pagination {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
    margin-top: 1.5rem;
}

.page-btn {
    padding: 0.4rem 0.75rem;
    border-radius: 6px;
    font-size: 0.8rem;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--muted);
    text-decoration: none;
    transition: all 0.15s;
}

    .page-btn:hover, .page-btn.active {
        background: var(--accent2);
        border-color: var(--accent2);
        color: #fff;
    }

/* ── Map ── */
#map {
    height: calc(100vh - 200px);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow: hidden;
}

.map-legend {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 1rem;
    font-size: 0.8rem;
    color: var(--muted);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

    .dot.working {
        background: var(--working);
    }

    .dot.idle {
        background: var(--idle);
    }

.map-pin {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.5);
    box-shadow: 0 0 6px rgba(0,0,0,0.4);
}

    .map-pin.working {
        background: var(--working);
    }

    .map-pin.idle {
        background: var(--idle);
    }

.map-popup {
    font-family: 'Sora', sans-serif;
    min-width: 220px;
}

.popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.popup-meta {
    font-size: 0.75rem;
    color: #555;
    margin-bottom: 0.2rem;
}

.popup-analysis {
    font-size: 0.78rem;
    margin: 0.5rem 0;
    color: #333;
    line-height: 1.5;
}

.popup-link {
    font-size: 0.75rem;
    color: var(--accent2);
    text-decoration: none;
}

    .popup-link:hover {
        text-decoration: underline;
    }

/* ── Settings ── */
.settings-group {
    margin-bottom: 2.5rem;
}

.settings-group-title {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--muted);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.setting-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    padding: 1rem 0;
    border-bottom: 1px solid var(--border);
    align-items: start;
}

.setting-key {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.82rem;
    margin-bottom: 0.3rem;
}

.setting-desc {
    font-size: 0.75rem;
    margin-bottom: 0.25rem;
}

.setting-updated {
    font-size: 0.68rem;
}

.setting-form {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.setting-input, .setting-textarea {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    padding: 0.5rem 0.75rem;
    font-size: 0.82rem;
    font-family: inherit;
    width: 100%;
    outline: none;
    transition: border-color 0.15s;
}

.setting-textarea {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    resize: vertical;
}

    .setting-input:focus, .setting-textarea:focus {
        border-color: var(--accent2);
    }

/* ── Buttons ── */
.btn-primary {
    background: var(--accent2);
    color: #fff;
    border: none;
    padding: 0.5rem 1.1rem;
    border-radius: 6px;
    font-size: 0.82rem;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    transition: opacity 0.15s;
}

    .btn-primary:hover {
        opacity: 0.85;
    }

    .btn-primary.btn-full {
        width: 100%;
        text-align: center;
        padding: 0.7rem;
    }

    .btn-primary.btn-sm {
        padding: 0.35rem 0.75rem;
        font-size: 0.75rem;
        align-self: flex-start;
    }

.btn-secondary {
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 0.5rem 1.1rem;
    border-radius: 6px;
    font-size: 0.82rem;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    transition: border-color 0.15s;
}

    .btn-secondary:hover {
        border-color: var(--accent2);
    }

/* ── Alerts ── */
.alert {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    font-size: 0.82rem;
    margin-bottom: 1.25rem;
    border-left: 3px solid;
}

.alert-error {
    background: rgba(255,77,109,0.1);
    border-color: var(--idle);
    color: var(--idle);
}

.alert-success {
    background: rgba(0,229,160,0.1);
    border-color: var(--working);
    color: var(--working);
}

/* ── Utilities ── */
.mono {
    font-family: 'JetBrains Mono', monospace;
}

.muted {
    color: var(--muted);
    font-size: 0.8rem;
}

.map-link {
    color: var(--accent2);
    text-decoration: none;
}

    .map-link:hover {
        text-decoration: underline;
    }

.empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--muted);
    font-size: 0.85rem;
}

/* ── Lightbox ── */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.92);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
    cursor: zoom-out;
}

    .modal.open {
        display: flex;
    }

    .modal img {
        max-width: 92vw;
        max-height: 92vh;
        object-fit: contain;
        border-radius: 8px;
        box-shadow: 0 0 80px rgba(0,0,0,0.8);
    }

.modal-close {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 1.1rem;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

    .modal-close:hover {
        background: var(--surface2);
    }

/* ── Login page ── */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
}

.login-wrap {
    width: 100%;
    max-width: 380px;
    padding: 2.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
}

.login-brand {
    text-align: center;
    margin-bottom: 2rem;
}

    .login-brand h1 {
        font-size: 1.5rem;
        font-weight: 700;
        letter-spacing: -0.03em;
    }

    .login-brand p {
        color: var(--muted);
        font-size: 0.8rem;
        margin-top: 0.25rem;
    }

.login-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

    .form-group label {
        font-size: 0.78rem;
        color: var(--muted);
    }

    .form-group input {
        background: var(--surface2);
        border: 1px solid var(--border);
        border-radius: 6px;
        color: var(--text);
        padding: 0.6rem 0.85rem;
        font-size: 0.9rem;
        font-family: inherit;
        outline: none;
        transition: border-color 0.15s;
    }

        .form-group input:focus {
            border-color: var(--accent2);
        }



/* ── Modal dialogs ── */
.modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    z-index: 200;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

    .modal-backdrop.open {
        display: flex;
    }

.modal-dialog {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
    margin: 1rem;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

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

    .modal-header button {
        background: none;
        border: none;
        color: var(--muted);
        font-size: 1rem;
        cursor: pointer;
        padding: 0.25rem;
    }

        .modal-header button:hover {
            color: var(--text);
        }

.modal-body {
    padding: 1.25rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
}

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

.role-checkboxes {
    display: flex;
    gap: 1.5rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    cursor: pointer;
}

    .checkbox-label input {
        accent-color: var(--accent2);
    }


/* ── Dashboard activity cards ─────────────────────────────────── */
.activity-cards {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    width: 100%;
    min-width: 0;
}

.activity-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: border-color 0.15s;
    width: 100%;
    min-width: 0;
}

    .activity-card:hover {
        border-color: var(--accent);
    }

.activity-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.65rem 1rem;
    border-bottom: 1px solid var(--border);
    gap: 0.5rem;
    flex-wrap: wrap;
    min-width: 0;
}

    .activity-card-header .mono {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        min-width: 0;
        flex-shrink: 1;
    }

.activity-card-body {
    padding: 0.65rem 1rem;
    min-width: 0;
}

.activity-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    min-width: 0;
}

.analysis-summary {
    font-size: 0.82rem;
    color: #94a3b8;
    line-height: 1.5;
    margin: 0;
}

/* ── Field groups (forms / modals) ── */
.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    align-items: start;
}

.field-group {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

    .field-group label {
        font-size: 0.72rem;
        text-transform: uppercase;
        letter-spacing: 0.08em;
        color: #64748b;
    }

    .field-group input,
    .field-group select {
        background: #181c24;
        border: 1px solid #1e2330;
        border-radius: 6px;
        color: #e2e8f0;
        padding: 0.55rem 0.85rem;
        font-size: 0.85rem;
        font-family: inherit;
        width: 100%;
        height: 2.4rem;
        outline: none;
        transition: border-color 0.15s;
        box-sizing: border-box;
    }

    .field-group textarea {
        background: #181c24;
        border: 1px solid #1e2330;
        border-radius: 6px;
        color: #e2e8f0;
        padding: 0.55rem 0.85rem;
        font-size: 0.85rem;
        font-family: inherit;
        width: 100%;
        outline: none;
        resize: vertical;
        transition: border-color 0.15s;
        box-sizing: border-box;
    }

        .field-group input:focus,
        .field-group select:focus,
        .field-group textarea:focus {
            border-color: var(--accent);
        }

/* ── Role checkboxes ── */
.role-row {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.role-check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: #e2e8f0;
    cursor: pointer;
}

    .role-check input {
        accent-color: var(--accent);
        width: 16px;
        height: 16px;
    }

/* ══════════════════════════════════════════════════════════════
   RESPONSIVE — mobile sidebar drawer + layout
   ══════════════════════════════════════════════════════════════ */

/* ── Mobile top bar — hidden on desktop ─────────────────────── */
.mobile-topbar {
    display: none;
}

/* ── Sidebar close button — hidden on desktop ───────────────── */
.sidebar-close {
    display: none;
    background: none;
    border: none;
    color: var(--muted);
    font-size: 1rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    margin-left: auto;
    transition: color 0.15s;
    flex-shrink: 0;
}

    .sidebar-close:hover {
        color: var(--text);
    }

/* ── Overlay — hidden until sidebar opens on mobile ─────────── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.65);
    z-index: 198;
    backdrop-filter: blur(2px);
}

/* ══════════════════════════════════════════════════════════════
   Tablet (≤ 900px)
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {

    /* ── Mobile top bar ── */
    .mobile-topbar {
        display: flex;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 54px;
        background: var(--surface);
        border-bottom: 1px solid var(--border);
        align-items: center;
        justify-content: space-between;
        padding: 0 1rem;
        z-index: 200;
        gap: 0.75rem;
    }

    .mobile-brand {
        font-weight: 600;
        font-size: 0.9rem;
        color: var(--text);
        display: flex;
        align-items: center;
        gap: 0.4rem;
        flex: 1;
    }

    .mobile-signout {
        color: var(--danger);
        font-size: 0.85rem;
        text-decoration: none;
        padding: 0.4rem 0.6rem;
        border-radius: 6px;
        transition: color 0.15s, background 0.15s;
    }

        .mobile-signout:hover {
            color: var(--text);
            background: var(--surface2);
        }

    /* ── Hamburger button ── */
    .hamburger {
        display: flex;
        flex-direction: column;
        justify-content: center;
        gap: 5px;
        width: 36px;
        height: 36px;
        background: none;
        border: none;
        cursor: pointer;
        padding: 6px;
        border-radius: 6px;
        flex-shrink: 0;
        transition: background 0.15s;
    }

        .hamburger:hover {
            background: var(--surface2);
        }

        .hamburger span {
            display: block;
            width: 100%;
            height: 2px;
            background: var(--text);
            border-radius: 2px;
        }

    /* ── Sidebar becomes off-screen drawer ── */
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        z-index: 199;
        box-shadow: 4px 0 24px rgba(0,0,0,0.5);
    }

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

    /* ── Show close button inside sidebar ── */
    .sidebar-close {
        display: block;
    }

    /* ── Overlay visible when sidebar open ── */
    .sidebar-overlay.is-open {
        display: block;
    }

    /* ── Main content shifts down for top bar, no left margin ── */
    .main-content {
        margin-left: 0;
        padding: 1rem;
        padding-top: calc(54px + 1rem);
    }

    /* ── Responsive tables ── */
    .records-table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .records-table {
        min-width: 560px;
    }

    /* ── Stat cards 2-col ── */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    /* ── Filter bar wraps ── */
    .filter-bar {
        flex-wrap: wrap;
    }

    .filter-input {
        flex: 1 1 150px;
    }

    /* ── Record cards stack to single column ── */
    .record-card {
        grid-template-columns: 1fr;
        flex-direction: column;
    }

    .card-image {
        width: 100%;
        height: 200px;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    /* ── Settings rows stack ── */
    .setting-row {
        grid-template-columns: 1fr;
    }

    /* ── Pagination wraps ── */
    .pagination {
        flex-wrap: wrap;
        gap: 0.25rem;
    }
}

/* ══════════════════════════════════════════════════════════════
   Tablet portrait / large phone (≤ 768px)
   record-card already handled by ≤ 900px
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .field-row {
        grid-template-columns: 1fr;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .modal-box {
        margin: 0.5rem;
    }

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

    .card-image {
        height: 160px;
    }

    .card-body {
        padding: 0.75rem;
    }

    .card-meta-row {
        flex-wrap: wrap;
        gap: 0.35rem;
    }

    .card-tags {
        gap: 0.3rem;
    }

    .tag {
        font-size: 0.65rem;
        padding: 0.15rem 0.4rem;
    }
}

/* ══════════════════════════════════════════════════════════════
   Small phones (≤ 512px)
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 512px) {
    .record-card {
        grid-template-columns: 1fr;
        border-radius: 6px;
    }

    .card-image {
        height: 140px;
    }

    .card-body {
        padding: 0.6rem 0.75rem;
        gap: 0.4rem;
    }

    .card-meta-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.3rem;
    }

    .confidence-row {
        gap: 0.4rem;
    }

    .card-tags {
        gap: 0.25rem;
    }

    .tag {
        font-size: 0.62rem;
        padding: 0.12rem 0.35rem;
    }

    .analysis-section-title {
        font-size: 0.62rem;
    }

    .tab-item {
        font-size: 0.72rem;
    }
    /* Dashboard activity cards */
    .activity-card-header {
        flex-wrap: wrap;
        gap: 0.35rem;
    }

    .activity-card-body {
        padding: 0.5rem 0.75rem;
    }

    .activity-card-meta {
        gap: 0.25rem;
    }
    /* Stats */
    .stat-value {
        font-size: 2rem;
    }

    .page-header h1 {
        font-size: 1.4rem;
    }
}

/* ── Modal overlay (global) ── */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.85);
    z-index: 9999;
    align-items: center;
    justify-content: center;
}

    .modal-overlay.is-open {
        display: flex;
    }

/* ── Modal box ── */
.modal-box {
    background: #111318;
    border: 1px solid #1e2330;
    border-radius: 12px;
    width: 100%;
    max-width: 540px;
    max-height: 90vh;
    margin: 1rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.4), 0 8px 20px rgba(0,0,0,0.35);
    /* Flex column — header + scrollable body + pinned footer */
    display: flex;
    flex-direction: column;
    overflow: hidden; /* clip children, each section scrolls independently */
}

    /* Scrollable middle section */
    .modal-box > div:not(.modal-hd):not(.modal-ft) {
        flex: 1;
        overflow-y: auto;
        display: flex;
        flex-direction: column;
    }

/* Footer always pinned at bottom */
.modal-ft {
    flex-shrink: 0;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    background: var(--surface); /* ensure it's visible over scrollable content */
}

/* Email body fills all remaining vertical space in the dialog */
#emailBody {
    flex: 1 1 auto;
    min-height: 120px;
    max-height: unset !important;
    overflow-y: auto;
}

.modal-box.modal-sm {
    max-width: 420px;
}

.modal-hd {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid #1e2330;
}

    .modal-hd h3 {
        font-size: 1rem;
        font-weight: 600;
        color: #e2e8f0;
        margin: 0;
    }

.modal-close-btn {
    background: none;
    border: none;
    color: #64748b;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    transition: color 0.15s, background 0.15s;
}

    .modal-close-btn:hover {
        color: #e2e8f0;
        background: #181c24;
    }

.modal-bd {
    padding: 1.25rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0; /* required for flex overflow to work */
}

.modal-ft {
    padding: 1rem 1.5rem;
    border-top: 1px solid #1e2330;
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
}

/* ── Email compose modal sizing ── */
.email-modal-box {
    max-width: 80vw;
    width: 80vw;
    height: 80vh;
    max-height: 80vh;
}

@media (max-width: 900px) {
    /* All modal boxes — full width minus margin, contained within viewport */

    .modal-box {
        width: calc(100vw - 1rem) !important;
        max-width: calc(100vw - 1rem) !important;
        max-height: calc(100dvh - 54px - 2rem);
        margin: 0.5rem;
        border-radius: 8px;
    }

    /* Collapse all grid form rows to single column */
    .field-row {
        grid-template-columns: 1fr !important;
        gap: 0.5rem;
    }

    .modal-bd {
        padding: 0.75rem 1rem;
        gap: 0.5rem;
    }

    /* Email modal keeps its set height on mobile */
    /* Shrink toolbar buttons on mobile */
    #editorToolbar {
        gap: 0.2rem;
        padding: 0.5rem 0.75rem;
    }

    .editor-btn {
        padding: 0.2rem 0.4rem;
        font-size: 0.75rem;
        min-width: 26px;
    }

    /* Email field font size */
    #editorToolbar select {
        font-size: 0.72rem;
    }

    #emailBody {
        font-size: 0.82rem;
        padding: 0.75rem;
    }
}

/* ── WYSIWYG email editor ── */
.editor-btn {
    background: #181c24;
    border: 1px solid #1e2330;
    color: #e2e8f0;
    border-radius: 5px;
    padding: 0.25rem 0.55rem;
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.15s;
    min-width: 30px;
}

    .editor-btn:hover {
        background: #1e2330;
    }

#emailBody:empty:before {
    content: attr(placeholder);
    color: #475569;
    pointer-events: none;
}

#emailBody h1, #emailBody h2, #emailBody h3,
#emailBody h4, #emailBody h5 {
    margin: 0.5rem 0;
}

#emailBody ul, #emailBody ol {
    padding-left: 1.5rem;
    margin: 0.3rem 0;
}

/* ── Field groups (forms / modals) ── */
/* field-row/field-group defined earlier in file */

/* ── Role checkboxes ── */
.role-row {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.role-check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: #e2e8f0;
    cursor: pointer;
}

    .role-check input {
        accent-color: var(--accent);
        width: 16px;
        height: 16px;
    }

/* ══════════════════════════════════════════════════════════════
   Mobile card view — Users & Employees tables
   Hides the table, shows a card stack instead at ≤ 900px
   ══════════════════════════════════════════════════════════════ */

/* Mobile card layout — hidden on desktop */
.mobile-card-list {
    display: none;
}

@media (max-width: 900px) {
    /* Hide the table, show the card list */
    .desktop-table-wrap {
        display: none;
    }

    .mobile-card-list {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
        margin-top: 0.75rem;
    }

    /* Individual mobile card */
    .mobile-card {
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        padding: 0.9rem 1rem;
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        transition: border-color 0.15s;
    }

        .mobile-card:hover {
            border-color: var(--accent);
        }

    .mobile-card-header {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 0.5rem;
    }

    .mobile-card-title {
        font-weight: 600;
        font-size: 0.9rem;
        color: var(--text);
    }

    .mobile-card-subtitle {
        font-size: 0.75rem;
        color: var(--muted);
        margin-top: 0.1rem;
    }

    .mobile-card-badges {
        display: flex;
        flex-wrap: wrap;
        gap: 0.3rem;
        flex-shrink: 0;
    }

    .mobile-card-row {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        font-size: 0.78rem;
        color: var(--muted);
    }

    .mobile-card-row-label {
        font-size: 0.65rem;
        text-transform: uppercase;
        letter-spacing: 0.06em;
        color: #475569;
        min-width: 72px;
    }

    .mobile-card-row-value {
        color: #94a3b8;
        flex: 1;
    }

    .mobile-card-divider {
        height: 1px;
        background: var(--border);
    }

    .mobile-card-footer {
        display: flex;
        gap: 0.4rem;
        flex-wrap: wrap;
        padding-top: 0.25rem;
    }
}
