* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    background: var(--background);
    color: var(--text);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
    min-height: 100vh;
}

/* ----------------------------------------
   Topbar
---------------------------------------- */

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
    padding: 20px 28px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.topbar-brand {
    flex-shrink: 0;
}

.navigation {
    display: flex;
    align-items: center;
    gap: 6px;
}

.navigation a {
    padding: 8px 11px;
    border-radius: 7px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 13px;
}

.navigation a:hover {
    background: var(--surface-hover);
    color: var(--text-secondary);
}

.navigation a.active {
    background: var(--surface-hover);
    color: var(--text);
}

.topbar h1 {
    margin: 0;
    font-size: 22px;
    font-weight: 650;
}

#connectionStatus {
    display: inline-block;
    margin-top: 5px;
    font-size: 13px;
    color: var(--text-muted);
}

#connectionStatus.connected {
    color: var(--success);
}

#connectionStatus.disconnected {
    color: var(--error);
}

.stats {
    display: flex;
    gap: 28px;
}

.stats div {
    min-width: 80px;
    text-align: center;
}

.stats strong {
    display: block;
    font-size: 26px;
    font-weight: 650;
}

.stats span {
    display: block;
    margin-top: 3px;
    color: var(--text-muted);
    font-size: 12px;
}

/* ----------------------------------------
   Theme switch
---------------------------------------- */

.theme-toggle {
    display: flex;
    align-items: center;
    gap: 9px;
}

#themeLabel {
    min-width: 34px;
    color: var(--text-muted);
    font-size: 12px;
    text-align: right;
}

.theme-switch {
    padding: 0;
    border: 0;
    background: transparent;
    cursor: pointer;
}

.theme-switch-track {
    position: relative;
    display: block;
    width: 42px;
    height: 24px;
    border-radius: 999px;
    background: var(--toggle-background);
    transition: background 0.15s ease;
}

.theme-switch-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--toggle-thumb);
    transition: transform 0.15s ease;
}

html[data-theme="light"] .theme-switch-thumb {
    transform: translateX(18px);
}

.theme-switch:focus-visible {
    outline: 2px solid var(--text-muted);
    outline-offset: 3px;
}

/* ----------------------------------------
   Main
---------------------------------------- */

main {
    max-width: 1600px;
    margin: 0 auto;
    padding: 24px 28px;
}

.panel {
    margin-bottom: 24px;
    padding: 22px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.panel h2 {
    margin: 0;
    font-size: 18px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 18px;
}

select {
    min-width: 150px;
    padding: 9px 12px;
    border: 1px solid var(--border-input);
    border-radius: 7px;
    background: var(--input-background);
    color: var(--text);
    outline: none;
}

.latest-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
    margin-top: 18px;
    padding: 20px;
    background: var(--surface-hover);
    border: 1px solid var(--border-secondary);
    border-radius: 10px;
}

.latest-main strong {
    display: block;
    font-size: 25px;
    font-weight: 650;
}

.latest-main span {
    display: block;
    margin-top: 6px;
    color: var(--text-muted-strong);
    font-family: monospace;
}

.latest-meta {
    display: flex;
    flex-direction: column;
    gap: 5px;
    text-align: right;
    color: var(--text-muted-strong);
    font-size: 14px;
}

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

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

thead {
    background: var(--surface-secondary);
}

th {
    padding: 11px 12px;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 600;
    text-align: left;
    white-space: nowrap;
}

td {
    padding: 13px 12px;
    border-top: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 14px;
}

tbody tr {
    transition: background 0.15s ease;
}

tbody tr:hover {
    background: var(--surface-hover);
}

td strong {
    color: var(--text-strong);
    font-weight: 600;
}

code {
    padding: 3px 6px;
    border-radius: 5px;
    background: var(--code-background);
    color: var(--text-secondary);
    font-family: monospace;
}


@media (max-width: 900px) {
    .topbar {
        flex-wrap: wrap;
    }

    .navigation {
        order: 3;
        width: 100%;
    }
}

@media (max-width: 700px) {
    .topbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .stats {
        width: 100%;
        justify-content: space-between;
    }

    .navigation {
        width: 100%;
        overflow-x: auto;
    }

    .theme-toggle {
        align-self: flex-end;
    }

    main {
        padding: 16px;
    }

    .latest-card {
        align-items: flex-start;
        flex-direction: column;
    }

    .latest-meta {
        text-align: left;
    }
}

.dashboard-overview {
    margin-bottom: 24px;
}

.scanner-overview {
    display: grid;
    grid-template-columns:
        repeat(
            auto-fit,
            minmax(220px, 1fr)
        );

    gap: 16px;
}

.scanner-summary-card {
    background: var(--panel-background);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 20px;
}

.scanner-summary-name {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 18px;
}

.scanner-summary-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.scanner-summary-stats div {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.scanner-summary-stats span {
    color: var(--muted-text);
    font-size: 0.8rem;
}

.scanner-summary-stats strong {
    font-size: 1.35rem;
}
.group-help { color: var(--text-muted); margin: 0 0 18px; font-size: 14px; }
.group-card { display: flex; flex-direction: column; align-items: flex-start; gap: 7px; color: var(--text); text-align: left; font: inherit; cursor: pointer; }
.group-card span { color: var(--text-muted); font-size: 13px; }
.group-card:hover { border-color: var(--accent); }

.edit-mode-toggle { display: flex; align-items: center; gap: 8px; color: var(--text-muted); font-size: 14px; }
.edit-mode-toggle input { accent-color: var(--accent); width: 18px; height: 18px; }
.scan-actions { white-space: nowrap; }
.scan-actions button, #editScanDialog button { padding: 8px 12px; border: 1px solid var(--border-input); border-radius: 8px; background: var(--surface-hover); color: var(--text); font: inherit; }
.scan-actions .delete-scan { color: var(--error); margin-left: 6px; }
#editScanDialog { width: min(640px, calc(100% - 24px)); max-height: calc(100dvh - 32px); overflow-y: auto; padding: 24px; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--text); }
#editScanDialog::backdrop { background: rgba(5,10,18,.75); backdrop-filter: blur(5px); }
.edit-dialog-header, .edit-dialog-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.edit-dialog-header h2 { margin: 0; }
.edit-help { color: var(--text-muted); font-size: 13px; }
.edit-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.edit-fields label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-muted); }
.edit-fields input, .edit-fields select { min-width: 0; width: 100%; padding: 10px; border: 1px solid var(--border-input); border-radius: 8px; background: var(--input-background); color: var(--text); font: inherit; }
.edit-group { grid-column: 1 / -1; }
#editScanError { color: var(--error); }
#editScanDialog #saveEditScan { background: var(--accent); color: var(--background); border-color: var(--accent); }
@media (max-width: 480px) { .edit-fields { grid-template-columns: 1fr; } }
