:root {
    --bg: #0b1120;
    --surface: #111827;
    --surface-2: #1e293b;
    --border: #263348;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --accent: #10b981;
    --accent-hover: #059669;
    --danger: #ef4444;
    --warning: #f59e0b;
    --radius: 10px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 14px 20px;
    position: sticky;
    top: 0;
    z-index: 20;
}

.topbar-inner {
    max-width: 1280px;
    margin: 0 auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand h1 {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 700;
}

.subtitle {
    margin: 2px 0 0;
    font-size: 0.82rem;
    color: var(--muted);
}

.brand-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--warning);
    box-shadow: 0 0 10px rgba(245, 158, 11, 0.7);
    flex-shrink: 0;
}

.brand-dot.online {
    background: var(--accent);
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.8);
}

.brand-dot.error {
    background: var(--danger);
    box-shadow: 0 0 10px rgba(239, 68, 68, 0.8);
}

.topbar-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.pill {
    font-size: 0.78rem;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.pill-live.connected {
    border-color: rgba(16, 185, 129, 0.5);
    color: #6ee7b7;
}

.container {
    max-width: 1280px;
    margin: 20px auto 48px;
    padding: 0 20px;
}

.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 0.9rem;
    border: 1px solid transparent;
}

.alert.hidden {
    display: none;
}

.alert.error {
    background: rgba(239, 68, 68, 0.12);
    border-color: rgba(239, 68, 68, 0.45);
    color: #fca5a5;
}

.alert.success {
    background: rgba(16, 185, 129, 0.12);
    border-color: rgba(16, 185, 129, 0.45);
    color: #6ee7b7;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.stat-value {
    font-size: 1.9rem;
    font-weight: 700;
    margin: 4px 0;
}

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

.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 10px;
}

.tab {
    background: transparent;
    border: 1px solid transparent;
    color: var(--muted);
    padding: 8px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
}

.tab:hover {
    color: var(--text);
    background: var(--surface);
}

.tab.active {
    background: var(--surface-2);
    border-color: var(--border);
    color: #fff;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

.grid-2-narrow {
    display: grid;
    grid-template-columns: minmax(290px, 360px) 1fr;
    gap: 16px;
}

@media (max-width: 900px) {
    .grid-2-narrow {
        grid-template-columns: 1fr;
    }
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 16px;
}

.card-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}

.card-header h2 {
    margin: 0;
    font-size: 1.02rem;
}

.muted {
    color: var(--muted);
    margin-top: 0;
}

.small {
    font-size: 0.84rem;
}

code {
    background: var(--surface-2);
    padding: 2px 6px;
    border-radius: 5px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.85em;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.82rem;
    color: var(--muted);
}

input[type="text"],
input[type="number"],
select {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 10px;
    border-radius: 7px;
    font-size: 0.9rem;
    outline: none;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.25);
}

.wedge-chips-row {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
}

.chip {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 0.78rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    cursor: pointer;
}

.chip:hover {
    border-color: var(--primary);
    color: #fff;
}

.chip-clear {
    border-color: rgba(239, 68, 68, 0.45);
    color: #fca5a5;
}

.wedge-preview-bar {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    margin-top: 4px;
}

.preview-left {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.keycap-list {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 5px;
}

.keycap {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 5px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.8rem;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: #e2e8f0;
}

.keycap-id {
    background: rgba(59, 130, 246, 0.2);
    border-color: rgba(59, 130, 246, 0.5);
    color: #93c5fd;
    font-weight: 700;
}

.keycap-key {
    background: rgba(16, 185, 129, 0.16);
    border-color: rgba(16, 185, 129, 0.45);
    color: #6ee7b7;
    font-weight: 600;
}

.checkbox-row,
.toggle {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    color: var(--text);
    font-size: 0.85rem;
}

.form-actions {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 4px;
}

.wedge-form,
.scan-field-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 12px 0;
}

.wedge-form input,
.scan-field-group .disabled-id-input {
    flex: 1;
    min-width: 190px;
    font-size: 1.08rem;
    padding: 11px 12px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.disabled-id-input:disabled {
    background: #0f172a;
    color: #94a3b8;
    border: 1px solid var(--border);
    cursor: not-allowed;
    opacity: 1;
}

.disabled-id-input.has-value:disabled {
    color: #6ee7b7;
    font-weight: 700;
    border-color: rgba(16, 185, 129, 0.55);
    background: rgba(16, 185, 129, 0.08);
}

.disabled-id-input.flash-populated {
    animation: flashInput 1.2s ease;
}

@keyframes flashInput {
    0% { box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.55); }
    100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.scan-meta {
    margin: -4px 0 10px;
    padding: 8px 10px;
    border-radius: 7px;
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.35);
    color: #a7f3d0;
    font-size: 0.84rem;
}

.scan-meta.hidden {
    display: none;
}

/* Biometric Scan Popup Modal */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.78);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 1000;
}

.modal-backdrop.hidden {
    display: none;
}

.modal-card {
    width: 100%;
    max-width: 440px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 28px 24px 22px;
    text-align: center;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}

.modal-card h2 {
    margin: 14px 0 8px;
    font-size: 1.2rem;
}

.modal-desc {
    margin: 0 0 14px;
    font-size: 0.92rem;
    color: var(--muted);
}

.modal-status {
    font-size: 0.82rem;
    color: #93c5fd;
    background: rgba(59, 130, 246, 0.12);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: 8px;
    padding: 8px 12px;
    margin-bottom: 18px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.modal-status.success {
    color: #6ee7b7;
    background: rgba(16, 185, 129, 0.14);
    border-color: rgba(16, 185, 129, 0.45);
}

.modal-actions {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
}

.scan-pulse-wrap {
    position: relative;
    width: 84px;
    height: 84px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

.scan-pulse-ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid rgba(59, 130, 246, 0.7);
    animation: scanPulse 1.6s ease-out infinite;
}

.scan-pulse-core {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: rgba(59, 130, 246, 0.18);
    border: 1px solid rgba(59, 130, 246, 0.55);
    color: #60a5fa;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
}

.scan-pulse-wrap.success .scan-pulse-ring {
    border-color: rgba(16, 185, 129, 0.85);
    animation: none;
}

.scan-pulse-wrap.success .scan-pulse-core {
    background: rgba(16, 185, 129, 0.22);
    border-color: rgba(16, 185, 129, 0.8);
    color: #34d399;
}

@keyframes scanPulse {
    0%   { transform: scale(0.85); opacity: 0.9; }
    100% { transform: scale(1.32); opacity: 0; }
}

.wedge-history {
    background: var(--bg);
    border: 1px dashed var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    min-height: 54px;
    font-size: 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.wedge-hit {
    color: #6ee7b7;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.inline-form {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.inline-form input:first-child {
    width: 140px;
}

.inline-form input:nth-child(2) {
    flex: 1;
    min-width: 220px;
}

.btn {
    border: none;
    border-radius: 7px;
    padding: 9px 14px;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    color: #fff;
    transition: background 0.15s ease;
}

.btn-sm {
    padding: 6px 10px;
    font-size: 0.8rem;
}

.btn-primary {
    background: var(--primary);
}
.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-staff {
    background: #8b5cf6;
}
.btn-staff:hover {
    background: #7c3aed;
}

.btn-accent {
    background: var(--accent);
}
.btn-accent:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--surface-2);
    border: 1px solid var(--border);
}
.btn-secondary:hover {
    background: #273549;
}

.btn-danger {
    background: rgba(239, 68, 68, 0.85);
}
.btn-danger:hover {
    background: var(--danger);
}

.btn-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.86rem;
}

th, td {
    text-align: left;
    padding: 9px 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

th {
    color: var(--muted);
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

tbody tr.flash-new {
    animation: flashRow 1.6s ease;
}

@keyframes flashRow {
    0% { background: rgba(16, 185, 129, 0.35); }
    100% { background: transparent; }
}

.empty {
    text-align: center;
    color: var(--muted);
    padding: 22px !important;
}

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-ok {
    background: rgba(16, 185, 129, 0.16);
    color: #6ee7b7;
}

.badge-warn {
    background: rgba(245, 158, 11, 0.16);
    color: #fcd34d;
}

.badge-err {
    background: rgba(239, 68, 68, 0.16);
    color: #fca5a5;
}

.badge-info {
    background: rgba(59, 130, 246, 0.16);
    color: #93c5fd;
}

.badge-student {
    background: rgba(59, 130, 246, 0.18);
    color: #93c5fd;
    border: 1px solid rgba(59, 130, 246, 0.35);
}

.badge-staff {
    background: rgba(139, 92, 246, 0.2);
    color: #c4b5fd;
    border: 1px solid rgba(139, 92, 246, 0.4);
}

.badge-both {
    background: rgba(16, 185, 129, 0.18);
    color: #6ee7b7;
    border: 1px solid rgba(16, 185, 129, 0.4);
}

.user-detail-card {
    margin-top: 8px;
    border-radius: 8px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    background: var(--bg);
}

.user-detail-card.hidden {
    display: none;
}

.user-detail-card.type-student {
    border-color: rgba(59, 130, 246, 0.5);
    background: rgba(59, 130, 246, 0.07);
}

.user-detail-card.type-staff {
    border-color: rgba(139, 92, 246, 0.55);
    background: rgba(139, 92, 246, 0.08);
}

.user-detail-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
    padding-bottom: 7px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.user-detail-name {
    font-size: 0.98rem;
    font-weight: 700;
    color: #fff;
}

.user-detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(125px, 1fr));
    gap: 8px 12px;
    font-size: 0.82rem;
}

.user-detail-item span {
    display: block;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
}

.user-detail-item strong {
    color: var(--text);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.classified-block {
    background: rgba(15, 23, 42, 0.55);
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 12px 12px 10px;
    margin-bottom: 12px;
}

.classified-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 0.9rem;
}

.classified-block .scan-field-group {
    margin: 8px 0 6px;
}

.modal-type-badge-wrap {
    margin-top: 12px;
}

.modal-status.error {
    color: #fca5a5;
    background: rgba(239, 68, 68, 0.15);
    border-color: rgba(239, 68, 68, 0.5);
}

.scan-pulse-wrap.error .scan-pulse-ring {
    border-color: rgba(239, 68, 68, 0.85);
}

.scan-pulse-wrap.error .scan-pulse-core {
    background: rgba(239, 68, 68, 0.22);
    border-color: rgba(239, 68, 68, 0.8);
    color: #f87171;
}

.wedge-reject {
    color: #fca5a5;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.setup-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 18px;
}

.setup-grid h3 {
    margin-top: 0;
    font-size: 0.95rem;
}

.code-block {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    overflow-x: auto;
    font-size: 0.8rem;
    color: #cbd5e1;
}

.checklist {
    padding-left: 18px;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 0.88rem;
}

.mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.82rem;
    word-break: break-all;
}

.raw-pre {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-all;
    max-width: 460px;
    max-height: 120px;
    overflow: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.78rem;
    background: var(--bg);
    padding: 6px 8px;
    border-radius: 6px;
}
