:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #f59e0b;
    --bg: #f8fafc;
    --card: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --radius: 12px;
    --navbar-h: 64px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-text-size-adjust: 100%;
}

/* ── Login Screen ── */
.login-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 1rem;
}

.login-card {
    background: var(--card);
    border-radius: 16px;
    padding: 2.5rem;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.login-logo {
    font-size: 3rem;
    text-align: center;
    margin-bottom: 0.5rem;
}

.captcha-box {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    padding: 0.75rem;
    background: #f8fafc;
    border-radius: 8px;
    border: 1px solid var(--border);
    flex-wrap: wrap;
}

.captcha-question {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
    min-width: 100px;
    text-align: center;
}

.captcha-input {
    width: 80px;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 1rem;
    text-align: center;
}

.captcha-input:focus { outline: none; border-color: var(--primary); }

.btn-captcha-refresh {
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.35rem 0.5rem;
    font-size: 1.1rem;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.2s;
}

.btn-captcha-refresh:hover { background: #f1f5f9; color: var(--primary); }

.login-error {
    background: #fee2e2;
    color: var(--danger);
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

.btn-block {
    width: 100%;
    justify-content: center;
    padding: 0.75rem;
    font-size: 1rem;
}

/* ── Navigation ── */
.navbar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    height: var(--navbar-h);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    gap: 0.5rem;
}

.navbar-brand {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 0.4rem;
    white-space: nowrap;
    flex-shrink: 0;
}

/* Hamburger */
.nav-toggle {
    display: none;
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.35rem 0.5rem;
    font-size: 1.3rem;
    cursor: pointer;
    color: var(--text);
    line-height: 1;
    flex-shrink: 0;
}

.nav-links {
    display: flex;
    gap: 0.15rem;
    margin-left: 1rem;
    list-style: none;
    overflow: visible;
    flex: 1;
    min-width: 0;
}

.nav-links a {
    text-decoration: none;
    color: var(--text-muted);
    padding: 0.4rem 0.65rem;
    border-radius: 8px;
    font-weight: 500;
    font-size: 0.82rem;
    transition: all 0.2s;
    white-space: nowrap;
}

.nav-links a:hover,
.nav-links a.active {
    color: var(--primary);
    background: #eef2ff;
}

.nav-separator {
    width: 1px;
    background: var(--border);
    margin: 0 0.35rem;
    align-self: stretch;
}

.nav-group-label {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 0 0.3rem;
    align-self: center;
    white-space: nowrap;
    opacity: 0.7;
}

/* ── Dropdown submenu ── */
.nav-dropdown {
    position: relative;
}

.nav-dropdown-toggle {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0.4rem 0.65rem;
    border-radius: 8px;
    font-weight: 500;
    font-size: 0.82rem;
    white-space: nowrap;
    transition: all 0.2s;
}
.nav-dropdown-toggle:hover,
.nav-dropdown.open .nav-dropdown-toggle,
.nav-dropdown-toggle.active {
    color: var(--primary);
    background: #eef2ff;
}

.nav-caret {
    font-size: 0.55rem;
    transition: transform 0.2s;
    opacity: 0.6;
}
.nav-dropdown.open .nav-caret { transform: rotate(180deg); }

/* Desktop dropdown panel */
.nav-submenu {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    min-width: 180px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.10);
    padding: 0.35rem;
    list-style: none;
    z-index: 1100;
}
.nav-dropdown.open .nav-submenu { display: block; }

.nav-submenu li a {
    display: block;
    padding: 0.45rem 0.75rem;
    border-radius: 6px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.82rem;
    font-weight: 500;
    white-space: nowrap;
    transition: all 0.15s;
}
.nav-submenu li a:hover,
.nav-submenu li a.active {
    color: var(--primary);
    background: #eef2ff;
}

.navbar-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.user-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-logout {
    background: #fee2e2;
    color: var(--danger);
    font-size: 0.75rem;
}

.btn-logout:hover { background: #fecaca; }

.health-badge {
    padding: 0.3rem 0.6rem;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    white-space: nowrap;
}

.health-badge.online { background: #dcfce7; color: var(--success); }
.health-badge.offline { background: #fee2e2; color: var(--danger); }

.health-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ── Layout ── */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem;
}

.page { display: none; }
.page.active { display: block; }

/* ── Full-viewport pages (no scroll) ── */
.container:has(> .page-fill.active) {
    padding: 0;
    max-width: 100%;
}
.page-fill {
    height: calc(100vh - var(--navbar-h));
    overflow: hidden;
}

/* ── Register fullscreen layout ── */
.reg-fs-layout {
    display: grid;
    grid-template-columns: 396px 1fr;
    height: 100%;
    overflow: hidden;
}
.reg-aside {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    padding: 0.75rem;
    overflow-y: auto;
    border-right: 1px solid var(--border);
}
.reg-aside .card { margin-bottom: 0; }
.reg-aside .reg-photo-card {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.reg-aside .reg-photo-card .file-drop { flex: 1; min-height: 0; }
.reg-form-panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.reg-form-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.6rem 1.25rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    background: var(--card);
}
.reg-form-header h2 { font-size: 1rem; font-weight: 700; margin: 0; flex: 1; }
.reg-form-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 0.85rem 1.25rem;
}
.reg-submit-bar {
    padding: 0.6rem 1.25rem;
    border-top: 1px solid var(--border);
    background: var(--card);
    flex-shrink: 0;
}

/* ── Scan fullscreen layout ── */
.scan-fs-layout {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    height: 100%;
    overflow: hidden;
}
.scan-fs-left {
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    overflow: hidden;
}
.scan-fs-left .card {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    margin-bottom: 0;
}
.scan-fs-left .camera-container {
    flex: 1;
    aspect-ratio: unset;
    min-height: 0;
}
.scan-fs-right {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0.75rem;
    gap: 0.65rem;
}
.scan-fs-right .card { margin-bottom: 0; flex-shrink: 0; }
.scan-fs-right .scan-history-card {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.scan-fs-right .scan-history-card .scan-history-wrap {
    flex: 1;
    max-height: none;
    overflow-y: auto;
}

/* ── Cards ── */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.card-title {
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* ── Stats Grid ── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    text-align: center;
}

.stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* ── Forms ── */
.form-group { margin-bottom: 1rem; }

.form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.4rem;
    font-size: 0.9rem;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 0.6rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 16px; /* prevents iOS zoom */
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.form-file-input {
    padding: 0.4rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.85rem;
    width: 100%;
}

/* ── File Drop ── */
.file-drop {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
}

.file-drop:hover,
.file-drop.dragover {
    border-color: var(--primary);
    background: #f5f3ff;
}

.file-drop input[type="file"] {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    opacity: 0;
    cursor: pointer;
}

.file-drop-icon { font-size: 2.5rem; margin-bottom: 0.5rem; }
.file-drop-text { color: var(--text-muted); font-size: 0.9rem; }

.preview-img {
    max-width: 200px;
    max-height: 200px;
    border-radius: 8px;
    margin-top: 0.75rem;
    display: none;
}

/* ── Buttons ── */
.btn {
    padding: 0.6rem 1.25rem;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    touch-action: manipulation;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Register form 3-col grid ── */
.reg-grid3 {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 0;
}
.reg-grid3 .form-group {
    flex: 1;
    min-width: 150px;
}

/* ── Two-column layout ── */
.split-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

/* ── Table ── */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 500px;
}

th, td {
    padding: 0.65rem 0.7rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
}

th {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
}

tr:hover td { background: #f8fafc; }

.face-thumb {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

/* ── Badge ── */
.badge {
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge-success { background: #dcfce7; color: var(--success); }
.badge-danger { background: #fee2e2; color: var(--danger); }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-admin { background: #ede9fe; color: #7c3aed; }
.badge-user { background: #e0e7ff; color: var(--primary); }

.badge-action-login { background: #dbeafe; color: #1e40af; }
.badge-action-create { background: #dcfce7; color: #166534; }
.badge-action-delete { background: #fee2e2; color: #991b1b; }
.badge-action-update { background: #fef3c7; color: #92400e; }
.badge-action-other { background: #f1f5f9; color: #475569; }

/* ── Match Result ── */
.match-result {
    text-align: center;
    padding: 2rem 1rem;
    display: none;
}

.match-result.show { display: block; }

.match-icon { font-size: 3.5rem; margin-bottom: 0.5rem; }
.match-name { font-size: 1.4rem; font-weight: 700; }
.match-confidence { font-size: 1rem; color: var(--text-muted); margin-top: 0.25rem; }

/* ── Toast ── */
.toast-container {
    position: fixed;
    top: calc(var(--navbar-h) + 12px);
    right: 1rem;
    left: 1rem;
    z-index: 999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
    align-items: flex-end;
}

.toast {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    animation: slideIn 0.3s ease;
    max-width: 420px;
    width: 100%;
    word-break: break-word;
    pointer-events: auto;
}

.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }

@keyframes slideIn {
    from { transform: translateX(30px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Logs table */
.log-table td { font-size: 0.82rem; }

/* Spinner */
.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* System Info */
.sys-info {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.sys-item {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
}

.sys-item-label { color: var(--text-muted); }
.sys-item-value { font-weight: 600; }

/* ── Modal ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.modal-card {
    background: var(--card);
    border-radius: 16px;
    padding: 1.5rem;
    width: 100%;
    max-width: 480px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.modal-header h3 { font-size: 1.2rem; font-weight: 700; }

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
    line-height: 1;
    padding: 0.25rem;
}

.modal-close:hover { color: var(--danger); }

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1.5rem;
}

/* ── API Key display ── */
.api-key-display {
    background: #f1f5f9;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-family: 'Consolas', monospace;
    font-size: 0.78rem;
    color: var(--text);
    word-break: break-all;
}

.btn-copy-inline {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 0.1rem;
    vertical-align: middle;
}

.btn-copy-inline:hover { opacity: 0.7; }

/* ── API Docs ── */
.api-overview p {
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.6;
    margin-bottom: 1rem;
}

.api-flow {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.flow-step {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.88rem;
}

.flow-num {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.78rem;
    font-weight: 700;
    flex-shrink: 0;
}

.inline-code {
    background: #f1f5f9;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.82rem;
    color: var(--primary);
    word-break: break-all;
}

.api-endpoint { position: relative; }

/* API docs — grouped endpoint index */
.api-index-group { margin-bottom: 0.9rem; }
.api-index-group:last-child { margin-bottom: 0; }
.api-index-label {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: none;
    letter-spacing: 0.02em;
    margin-bottom: 0.5rem;
    padding-bottom: 0.35rem;
    border-bottom: 1px solid var(--border);
}
.api-index-links { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.api-index-links a {
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.55rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    transition: background 0.12s, border-color 0.12s;
}
.api-index-links a:hover { background: #eef2ff; border-color: var(--primary); }

.api-desc {
    color: var(--text-muted);
    font-size: 0.88rem;
    line-height: 1.6;
    margin-bottom: 1.25rem;
}

.api-section { margin-bottom: 1.25rem; }

.api-section h4 {
    font-size: 0.88rem;
    font-weight: 600;
    margin-bottom: 0.6rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.param-type {
    font-weight: 400;
    font-size: 0.75rem;
    color: var(--text-muted);
    background: #f1f5f9;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
}

/* Method badges */
.method-badge {
    padding: 0.25rem 0.6rem;
    border-radius: 6px;
    font-size: 0.72rem;
    font-weight: 700;
    font-family: 'Consolas', monospace;
    letter-spacing: 0.03em;
}

.method-get { background: #dcfce7; color: #166534; }
.method-post { background: #dbeafe; color: #1e40af; }
.method-put { background: #fef3c7; color: #92400e; }
.method-delete { background: #fee2e2; color: #991b1b; }

.endpoint-path {
    font-family: 'Consolas', monospace;
    font-size: 0.92rem;
    color: var(--text);
    word-break: break-all;
}

/* Param table */
.param-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

.param-table th {
    background: #f8fafc;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    padding: 0.5rem 0.6rem;
    text-align: left;
    border-bottom: 2px solid var(--border);
}

.param-table td {
    padding: 0.5rem 0.6rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.param-table code {
    background: #f1f5f9;
    padding: 0.1rem 0.35rem;
    border-radius: 3px;
    font-size: 0.8rem;
    color: var(--primary);
}

/* Code blocks */
.code-block {
    background: #1e293b;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 0.75rem;
}

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 0.8rem;
    background: #334155;
    font-size: 0.72rem;
    color: #94a3b8;
}

.btn-copy {
    background: none;
    border: 1px solid #475569;
    color: #94a3b8;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.72rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-copy:hover { background: #475569; color: #e2e8f0; }
.btn-copy.copied { background: var(--success); color: #fff; border-color: var(--success); }

.code-block pre {
    padding: 0.75rem 1rem;
    overflow-x: auto;
    margin: 0;
    -webkit-overflow-scrolling: touch;
}

.code-block code {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.78rem;
    color: #e2e8f0;
    line-height: 1.6;
    white-space: pre;
}

/* Code tabs */
.code-tabs {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}

.code-tab {
    background: none;
    border: 1px solid var(--border);
    padding: 0.3rem 0.7rem;
    border-radius: 6px;
    font-size: 0.76rem;
    cursor: pointer;
    color: var(--text-muted);
    font-weight: 500;
    transition: all 0.2s;
}

.code-tab:hover { border-color: var(--primary); color: var(--primary); }
.code-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Try it */
.api-tryit {
    border-top: 1px solid var(--border);
    padding-top: 1rem;
    margin-top: 0.5rem;
}

.tryit-result {
    background: #1e293b;
    color: #e2e8f0;
    border-radius: 8px;
    padding: 0.75rem;
    font-family: 'Consolas', monospace;
    font-size: 0.78rem;
    margin-top: 0.75rem;
    overflow-x: auto;
    white-space: pre;
    max-height: 300px;
    overflow-y: auto;
    line-height: 1.5;
    -webkit-overflow-scrolling: touch;
}

/* ── Register Camera ── */
.photo-source-tabs {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1rem;
}

.photo-tab {
    flex: 1;
    padding: 0.5rem;
    border: 2px solid var(--border);
    background: var(--bg);
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-muted);
    text-align: center;
}

.photo-tab:hover { border-color: var(--primary); color: var(--primary); }
.photo-tab.active { border-color: var(--primary); background: #eef2ff; color: var(--primary); }

.reg-camera-container {
    position: relative;
    background: #000;
    border-radius: 8px;
    overflow: hidden;
    aspect-ratio: 4/3;
}

.reg-camera-container video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transform: scaleX(-1);
}

.reg-camera-controls {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
}

/* ── SmartCard ── */
.smartcard-container {
    background: linear-gradient(135deg, #1e293b, #334155);
    border-radius: 8px;
    padding: 2rem;
    text-align: center;
    color: #fff;
    min-height: 200px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.smartcard-status { text-align: center; }

.smartcard-icon {
    font-size: 3rem;
    margin-bottom: 0.75rem;
    animation: smartcard-pulse 2s infinite;
}

@keyframes smartcard-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.smartcard-container.reading .smartcard-icon { animation: smartcard-pulse 0.6s infinite; }
.smartcard-container.success { background: linear-gradient(135deg, #065f46, #047857); }
.smartcard-container.error { background: linear-gradient(135deg, #7f1d1d, #991b1b); }

#smartcard-status-text {
    font-size: 0.95rem;
    opacity: 0.9;
}

.smartcard-progress-bar {
    width: 200px;
    height: 6px;
    background: rgba(255,255,255,0.2);
    border-radius: 3px;
    margin: 0.75rem auto 0.25rem;
    overflow: hidden;
}

.smartcard-progress-fill {
    height: 100%;
    background: #60a5fa;
    border-radius: 3px;
    transition: width 0.3s;
}

.smartcard-info {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    font-size: 0.85rem;
    text-align: left;
    color: var(--text);
}

.smartcard-info .sc-row {
    display: flex;
    gap: 0.5rem;
    padding: 0.2rem 0;
}

.smartcard-info .sc-label {
    font-weight: 600;
    min-width: 100px;
    color: var(--text-muted);
}

.smartcard-agent-error {
    margin-top: 0.75rem;
    padding: 0.75rem 1rem;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    font-size: 0.85rem;
    color: #991b1b;
    text-align: center;
}

/* ── Settings ── */
.settings-page-title {
    margin-bottom: 1.25rem;
    font-size: 1.4rem;
}

.settings-card {
    padding: 0 !important;
    overflow: hidden;
}

.settings-card-header {
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    color: #fff;
    padding: 1.25rem 1.5rem;
    margin-bottom: 0;
    border-radius: 0;
    align-items: flex-start;
}

.settings-header-left {
    display: flex;
    align-items: center;
    gap: 0.85rem;
}

.settings-icon-badge {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: rgba(255,255,255,0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    flex-shrink: 0;
}

.settings-title-text {
    font-size: 1.05rem;
    font-weight: 600;
}

.settings-subtitle {
    font-size: 0.8rem;
    opacity: 0.8;
    margin-top: 2px;
    font-weight: 400;
}

.settings-header-actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

.settings-btn-test {
    background: rgba(255,255,255,0.15) !important;
    color: #fff !important;
    border: 1px solid rgba(255,255,255,0.3) !important;
    backdrop-filter: blur(4px);
}
.settings-btn-test:hover {
    background: rgba(255,255,255,0.25) !important;
}

.settings-btn-save {
    background: #fff !important;
    color: var(--primary) !important;
    font-weight: 600;
}
.settings-btn-save:hover {
    background: #f0f0ff !important;
}

.settings-btn-icon {
    margin-right: 2px;
}

.settings-test-result {
    display: none;
    margin: 0;
    padding: 0.75rem 1.5rem;
    font-size: 0.85rem;
    font-weight: 500;
    border-bottom: 1px solid var(--border);
}
.settings-test-result.success {
    display: block;
    background: #f0fdf4;
    color: #15803d;
}
.settings-test-result.error {
    display: block;
    background: #fef2f2;
    color: #b91c1c;
}

.settings-section {
    padding: 1.25rem 1.5rem;
}

.settings-section-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.settings-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.25rem;
}
.settings-grid-2col {
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.settings-divider {
    height: 1px;
    background: var(--border);
    margin: 0;
}

.settings-field-inline {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.settings-field-inline label {
    margin-bottom: 0 !important;
    white-space: nowrap;
    min-width: 50px;
}

.settings-toggle-wrap {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.settings-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    display: inline-block;
    flex-shrink: 0;
}
.settings-status-dot.off {
    background: var(--text-muted);
}

.settings-auth-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.settings-auth-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: 1rem 0.75rem;
    border: 2px solid var(--border);
    border-radius: 12px;
    background: var(--card);
    cursor: pointer;
    transition: all 0.2s;
}
.settings-auth-tab:hover {
    border-color: #c7d2fe;
    background: #faf5ff;
}
.settings-auth-tab.active {
    border-color: var(--primary);
    background: #eef2ff;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}
.settings-auth-tab-icon {
    font-size: 1.5rem;
}
.settings-auth-tab-label {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text);
}
.settings-auth-tab-desc {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.settings-auth-panel {
    animation: settingsFadeIn 0.2s ease;
}
@keyframes settingsFadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

.settings-password-wrap {
    position: relative;
}
.settings-password-wrap input {
    padding-right: 2.5rem;
}
.settings-eye-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    color: var(--text-muted);
    padding: 4px;
    border-radius: 4px;
    transition: color 0.2s;
}
.settings-eye-btn:hover {
    color: var(--primary);
}

.settings-field-hint {
    margin-top: 0.4rem;
    font-size: 0.78rem;
    color: var(--text-muted);
}
.settings-field-hint code {
    background: #f1f5f9;
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 0.76rem;
}

@media (max-width: 768px) {
    .settings-card-header { flex-direction: column; gap: 1rem; }
    .settings-header-actions { width: 100%; }
    .settings-header-actions .btn { flex: 1; }
    .settings-grid-2col { grid-template-columns: 1fr; }
    .settings-auth-tabs { grid-template-columns: 1fr; }
    .settings-section { padding: 1rem; }
}

/* ── Live Scan ── */
.scan-layout {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 1.5rem;
    align-items: start;
}

.scan-camera-card {
    position: sticky;
    top: calc(var(--navbar-h) + 16px);
}

.camera-container {
    position: relative;
    background: #000;
    border-radius: 8px;
    overflow: hidden;
    aspect-ratio: 4/3;
}

/* ── Face guide overlay (กรอบใบหน้า+หู กันใช้ภาพถ่าย) ── */
.face-guide {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 5;
}
.face-guide svg { width: 100%; height: 100%; display: block; }
.face-guide .fg-ring {
    stroke: #f59e0b;                 /* amber = ยังไม่เข้ากรอบ */
    stroke-width: 0.8;
    stroke-dasharray: 3 2;
    transition: stroke 0.25s;
}
.face-guide.ok .fg-ring {
    stroke: #22c55e;                 /* green = พร้อมสแกน */
    stroke-dasharray: none;
    filter: drop-shadow(0 0 3px rgba(34,197,94,0.8));
}
.face-guide-hint {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.65);
    color: #fbbf24;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0.35rem 0.9rem;
    border-radius: 999px;
    white-space: nowrap;
    transition: color 0.25s;
}
.face-guide.ok .face-guide-hint { color: #4ade80; }

.camera-container video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transform: scaleX(-1);
}

.camera-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #64748b;
    font-size: 0.9rem;
    gap: 0.5rem;
    background: #1e293b;
}

.camera-placeholder.hidden { display: none; }
.camera-placeholder-icon { font-size: 3rem; }

.scan-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    transition: box-shadow 0.3s;
}

.scan-overlay.scanning { box-shadow: inset 0 0 0 4px var(--warning); }
.scan-overlay.matched { box-shadow: inset 0 0 0 4px var(--success); animation: flash-border 0.6s ease; }
.scan-overlay.unmatched { box-shadow: inset 0 0 0 4px var(--danger); animation: flash-border 0.6s ease; }

@keyframes flash-border {
    0% { opacity: 0; }
    30% { opacity: 1; }
    100% { opacity: 1; }
}

.scan-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

.scan-auto-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    cursor: pointer;
    margin-left: auto;
}

.scan-auto-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

.scan-snapshot-wrap { text-align: center; }

.scan-snapshot-wrap canvas {
    width: 100%;
    max-width: 320px;
    border-radius: 8px;
    background: #1e293b;
}

.scan-result-body {
    min-height: 160px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.scan-result-idle { color: var(--text-muted); font-size: 0.9rem; }

.scan-result-content {
    text-align: center;
    width: 100%;
    padding: 0.75rem 0;
}

.scan-result-content .match-icon { font-size: 3rem; margin-bottom: 0.25rem; }
.scan-result-content .match-name { font-size: 1.3rem; }
.scan-result-content .match-confidence { font-size: 0.95rem; }

.scan-result-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    margin-top: 1rem;
    text-align: left;
    font-size: 0.85rem;
}

.scan-result-details .detail-item { display: flex; flex-direction: column; gap: 0.1rem; }
.scan-result-details .detail-label { color: var(--text-muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.03em; }
.scan-result-details .detail-value { font-weight: 600; }

.scan-history-wrap { max-height: 250px; overflow-y: auto; -webkit-overflow-scrolling: touch; }

.scan-matches-list { width: 100%; display: flex; flex-direction: column; gap: 0.4rem; }

.scan-match-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
}

.scan-match-row.scan-match-top {
    background: color-mix(in srgb, var(--success) 12%, var(--bg-secondary));
    border-color: var(--success);
}

.scan-match-rank {
    font-size: 1.1rem;
    min-width: 1.5rem;
    text-align: center;
    color: var(--success);
    font-weight: 700;
}

.scan-match-info { flex: 1; min-width: 0; }
.scan-match-name { font-weight: 600; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scan-match-sub { font-size: 0.8rem; color: var(--text-muted); }

.scan-match-conf { font-size: 1rem; font-weight: 700; white-space: nowrap; }

.scan-processing {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    color: var(--text-muted);
}

.scan-processing .spinner-dark {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

/* ── Admin: Create User Form ── */
.create-user-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr auto;
    gap: 0.75rem;
    align-items: end;
}

/* ===========================================
   RESPONSIVE BREAKPOINTS
   =========================================== */

/* ── Tablet (≤1024px) ── */
@media (max-width: 1024px) {
    .navbar { padding: 0 1rem; }

    .nav-links a {
        padding: 0.35rem 0.5rem;
        font-size: 0.78rem;
    }

    .stats-grid { grid-template-columns: repeat(2, 1fr); }

    .scan-layout { grid-template-columns: 1fr; }
    .scan-camera-card { position: static; }

    .create-user-grid {
        grid-template-columns: 1fr 1fr;
    }
}

/* ── Mobile (≤768px) ── */
/* ── Mobile drawer backdrop ── */
.nav-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 900;
}
.nav-backdrop.open { display: block; }

@media (max-width: 768px) {
    :root { --navbar-h: 56px; }

    .navbar {
        flex-wrap: nowrap;
        height: var(--navbar-h);
        padding: 0 1rem;
        gap: 0;
        position: relative;
        z-index: 950;
    }

    .navbar-brand { font-size: 1.05rem; }

    .nav-toggle { display: block; margin-left: auto; }

    .navbar-right {
        order: unset;
        margin-left: 0.75rem;
        flex-shrink: 0;
    }

    /* Slide-in drawer from the right */
    .nav-links {
        position: fixed;
        top: 0;
        right: -280px;
        width: 260px;
        height: 100vh;
        flex-direction: column;
        margin-left: 0;
        padding: 1rem 0 2rem;
        gap: 0;
        background: var(--card);
        border-left: 1px solid var(--border);
        box-shadow: -4px 0 20px rgba(0,0,0,0.12);
        overflow-y: auto;
        z-index: 1000;
        transition: right 0.25s ease;
        display: flex;
    }

    .nav-links.open { right: 0; }

    .nav-links li { width: 100%; }

    .nav-links a {
        display: block;
        padding: 0.6rem 1rem;
        font-size: 0.92rem;
        border-radius: 6px;
        margin: 0 0.5rem;
    }

    .nav-separator {
        width: calc(100% - 1rem);
        height: 1px;
        margin: 0.4rem 0.5rem;
    }

    .nav-group-label {
        padding: 0.6rem 1rem 0.2rem;
        font-size: 0.65rem;
    }

    /* Mobile dropdown → accordion */
    .nav-dropdown { position: static; }

    .nav-dropdown-toggle {
        width: calc(100% - 1rem);
        margin: 0 0.5rem;
        padding: 0.6rem 0.75rem;
        font-size: 0.92rem;
        justify-content: space-between;
        border-radius: 6px;
    }

    .nav-submenu {
        position: static;
        box-shadow: none;
        border: none;
        border-radius: 0;
        background: transparent;
        padding: 0 0 0.25rem 0.75rem;
        border-left: 2px solid var(--border);
        margin: 0.1rem 1rem 0.25rem 1.5rem;
    }

    .nav-dropdown.open .nav-submenu { display: block; }

    .health-badge { display: none; }
    .user-name { max-width: 80px; }

    .container { padding: 1rem 0.75rem; }

    .split-layout { grid-template-columns: 1fr; gap: 1rem; }

    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 0.75rem; }

    .stat-value { font-size: 1.5rem; }
    .stat-card { padding: 1rem; }

    .card { padding: 1rem; }

    .match-icon { font-size: 3rem; }
    .match-name { font-size: 1.2rem; }

    .sys-info { grid-template-columns: 1fr; }

    .modal-card { padding: 1.25rem; margin: 0.5rem; }

    .toast-container {
        top: auto;
        bottom: 1rem;
        left: 0.75rem;
        right: 0.75rem;
        align-items: stretch;
    }

    .toast { max-width: 100%; min-width: 0; }

    .create-user-grid {
        grid-template-columns: 1fr;
    }

    table { min-width: 420px; }

    .flow-step { font-size: 0.82rem; }

    .scan-controls { gap: 0.4rem; }
    .scan-auto-label { margin-left: 0; width: 100%; margin-top: 0.25rem; }
}

/* ── Small Phone (≤480px) ── */
@media (max-width: 480px) {
    .login-card { padding: 1.5rem; }

    .container { padding: 0.75rem 0.5rem; }

    .stats-grid { grid-template-columns: 1fr 1fr; gap: 0.5rem; }
    .stat-value { font-size: 1.3rem; }
    .stat-label { font-size: 0.75rem; }
    .stat-card { padding: 0.75rem; }

    .card { padding: 0.85rem; border-radius: 10px; }
    .card-title { font-size: 0.95rem; }

    .file-drop { padding: 1.25rem; }
    .file-drop-icon { font-size: 2rem; }
    .file-drop-text { font-size: 0.82rem; }

    .preview-img { max-width: 150px; max-height: 150px; }

    .btn { padding: 0.55rem 1rem; font-size: 0.85rem; }
    .btn-sm { padding: 0.3rem 0.6rem; font-size: 0.75rem; }

    .match-result { padding: 1.25rem 0.5rem; }
    .match-icon { font-size: 2.5rem; }
    .match-name { font-size: 1.1rem; }
    .match-confidence { font-size: 0.88rem; }

    .captcha-box { justify-content: center; }
    .captcha-question { min-width: auto; }

    table { min-width: 360px; }
    th, td { padding: 0.5rem 0.4rem; font-size: 0.78rem; }
    th { font-size: 0.68rem; }

    .face-thumb { width: 32px; height: 32px; }

    .code-block code { font-size: 0.72rem; }
    .code-block pre { padding: 0.5rem 0.6rem; }
    .endpoint-path { font-size: 0.82rem; }

    .photo-tab { font-size: 0.78rem; padding: 0.4rem; }
}

/* ── Landscape phone ── */
@media (max-height: 500px) and (orientation: landscape) {
    .login-screen { align-items: flex-start; padding-top: 1rem; }
    .login-card { padding: 1.5rem; }
}

/* ── Large desktop (≥1400px) ── */
@media (min-width: 1400px) {
    .container { max-width: 1360px; }
    .stats-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ── Compare Test ── */
.compare-layout {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 1rem;
    align-items: start;
    margin-bottom: 1rem;
}
.compare-photo-card { }
.compare-photo-card .file-drop {
    position: relative;
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    overflow: hidden;
}
.compare-drop-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    pointer-events: none;
}
.compare-preview {
    width: 100%;
    height: 200px;
    object-fit: cover;
    border-radius: 6px;
}
.compare-face-badge {
    position: absolute;
    bottom: 6px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.65);
    color: #fff;
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 20px;
    white-space: nowrap;
}
.compare-vs-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 2.5rem;
    gap: 0.5rem;
    min-width: 90px;
}
.compare-vs-circle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
    transition: background 0.3s, color 0.3s;
}
.compare-result-banner {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border-radius: 10px;
    font-size: 0.95rem;
    margin-bottom: 1rem;
}
.compare-result-banner.cmp-match { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.compare-result-banner.cmp-nomatch { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.compare-result-banner.cmp-warn { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.compare-stats-summary {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.75rem;
}
.cmp-stat-box {
    flex: 1;
    min-width: 80px;
    text-align: center;
    padding: 0.5rem;
    background: var(--bg);
    border-radius: 8px;
    border: 1px solid var(--border);
}
.cmp-stat-val { font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.cmp-stat-label { font-size: 0.72rem; color: var(--text-muted); margin-top: 2px; }

@media (max-width: 640px) {
    .compare-layout { grid-template-columns: 1fr; }
    .compare-vs-col { flex-direction: row; padding-top: 0; justify-content: center; }
}

/* ── Ambiguous scan selection ── */
.scan-ambig-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 0.75rem;
    background: #fef3c7;
    color: #92400e;
    border-radius: 8px;
    margin-bottom: 0.6rem;
    font-size: 0.9rem;
}
.scan-ambig-list { display: flex; flex-direction: column; gap: 0.5rem; }
.scan-ambig-card {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.65rem 0.75rem;
    border: 2px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}
.scan-ambig-card:hover { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 5%, transparent); }
.scan-ambig-card.scan-ambig-top { border-color: var(--success); }
.scan-ambig-rank { font-size: 1rem; font-weight: 700; width: 1.4rem; text-align: center; color: var(--text-muted); }
.scan-ambig-card.scan-ambig-top .scan-ambig-rank { color: var(--success); }
.scan-ambig-info { flex: 1; min-width: 0; }
.scan-ambig-name { font-weight: 600; font-size: 0.92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scan-ambig-sub { font-size: 0.78rem; color: var(--text-muted); }
.scan-ambig-conf { font-weight: 700; font-size: 0.9rem; font-variant-numeric: tabular-nums; color: var(--success); }
.scan-ambig-btn { pointer-events: none; }
.scan-ambig-card:hover .scan-ambig-btn { background: var(--primary); color: #fff; }

/* ── Scan Logs ── */
.sl-map-link {
    color: var(--primary);
    text-decoration: none;
    white-space: nowrap;
}
.sl-map-link:hover { text-decoration: underline; }

/* ── SmartCard Agent Navbar Chip ── */
.sc-nav-wrap {
    position: relative;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 4px 9px 4px 7px;
    border: 1px solid var(--border);
    border-radius: 20px;
    cursor: pointer;
    user-select: none;
    font-size: 0.75rem;
    color: var(--text-muted);
    background: var(--card);
    transition: border-color 0.2s, box-shadow 0.2s;
    margin-right: 6px;
}
.sc-nav-wrap:hover { border-color: var(--primary); box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 15%, transparent); }
.sc-nav-icon {
    position: relative;
    display: flex;
    align-items: center;
    color: var(--text-muted);
    line-height: 0;
}
.sc-nav-dot {
    position: absolute;
    top: -3px;
    right: -4px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #94a3b8;
    border: 1.5px solid var(--card);
    transition: background 0.4s;
}
/* online state */
.sc-nav-wrap.sc-online .sc-nav-dot  { background: #22c55e; animation: sc-blink 1.5s infinite; }
.sc-nav-wrap.sc-online .sc-nav-icon { color: #22c55e; }
.sc-nav-wrap.sc-online .sc-nav-label { color: #22c55e; }
.sc-nav-wrap.sc-online { border-color: #22c55e; }
/* reading state */
.sc-nav-wrap.sc-reading .sc-nav-dot  { background: #f59e0b; animation: sc-pulse 0.9s infinite; }
.sc-nav-wrap.sc-reading .sc-nav-icon { color: #f59e0b; }
/* offline state */
.sc-nav-wrap.sc-offline .sc-nav-dot  { background: #94a3b8; }

@keyframes sc-pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.3; }
}
@keyframes sc-blink {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.6); }
    50%      { opacity: 0.4; box-shadow: 0 0 6px 2px rgba(34, 197, 94, 0.4); }
}

.sc-nav-label { font-size: 0.73rem; white-space: nowrap; }

/* Tooltip dropdown */
.sc-nav-tooltip {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 14px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.18);
    font-size: 0.82rem;
    min-width: 210px;
    z-index: 2000;
    color: var(--text);
}
.sc-nav-tooltip.visible { display: block; }
.sc-tooltip-row {
    display: flex;
    align-items: center;
    gap: 7px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text);
}
.sc-tooltip-detail { color: var(--text-muted); line-height: 1.5; }
.sc-tooltip-dl {
    display: inline-block;
    margin-top: 8px;
    font-size: 0.78rem;
    color: var(--primary);
    text-decoration: none;
}
.sc-tooltip-dl:hover { text-decoration: underline; }

/* hide label on very small screens */
@media (max-width: 480px) { .sc-nav-label { display: none; } }
