/* ── Reset & Tokens ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:           #080d14;
    --surface:      #0d1117;
    --surface-2:    #161b22;
    --surface-3:    #1c2330;
    --border:       #21262d;
    --border-2:     #30363d;
    --text:         #e6edf3;
    --text-muted:   #7d8590;
    --text-subtle:  #484f58;
    --green:        #2ea043;
    --green-light:  #3fb950;
    --yellow:       #d29922;
    --yellow-light: #e3b341;
    --red:          #da3633;
    --red-light:    #f85149;
    --blue:         #1f6feb;
    --blue-light:   #388bfd;
    --blue-muted:   #58a6ff;
    --radius:       6px;
    --radius-lg:    10px;
    --shadow:       0 8px 24px rgba(0,0,0,.4);
    --font-mono:    ui-monospace, 'Cascadia Code', 'Fira Code', Menlo, Consolas, monospace;
}

html, body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

a { color: var(--blue-muted); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Auth / Setup pages ──────────────────────────────────────────────────── */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}

.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 36px 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow);
}

.setup-card { max-width: 480px; }

.auth-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 24px;
    font-weight: 600;
    font-size: 16px;
    color: var(--text);
}

.auth-card h1 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
}

.auth-subtitle {
    color: var(--text-muted);
    margin-bottom: 24px;
    font-size: 13px;
}

.auth-footer {
    margin-top: 20px;
    font-size: 12px;
    color: var(--text-subtle);
    display: flex;
    align-items: center;
    gap: 5px;
    justify-content: center;
}

/* Setup steps */
.setup-steps {
    display: flex;
    align-items: center;
    margin-bottom: 28px;
}
.setup-step {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid var(--border-2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    flex-shrink: 0;
    transition: all .2s;
}
.setup-step.active { border-color: var(--blue); color: var(--blue-light); }
.setup-step.done   { background: var(--green); border-color: var(--green); color: #fff; }
.setup-line {
    flex: 1;
    height: 2px;
    background: var(--border);
    transition: background .2s;
}
.setup-line.done { background: var(--green); }
.setup-info { margin-top: 20px; }
.setup-info h3 { font-size: 14px; font-weight: 600; margin-bottom: 8px; }

/* ── Form fields ─────────────────────────────────────────────────────────── */
.field { margin-bottom: 16px; }

label {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 6px;
}

.label-hint {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 400;
}

input[type="password"],
input[type="text"] {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border-2);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    padding: 8px 12px;
    outline: none;
    transition: border-color .15s;
    font-family: inherit;
}
input[type="text"][inputmode="numeric"] {
    font-family: var(--font-mono);
    letter-spacing: 4px;
    font-size: 18px;
    text-align: center;
}
input:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(31,111,235,.15);
}
input:disabled {
    opacity: .5;
    cursor: not-allowed;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all .15s;
    white-space: nowrap;
    text-decoration: none;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
    background: var(--blue);
    color: #fff;
    border-color: rgba(255,255,255,.1);
}
.btn-primary:hover:not(:disabled) {
    background: #1a5cc8;
    text-decoration: none;
    color: #fff;
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border-color: var(--border-2);
}
.btn-ghost:hover:not(:disabled) {
    background: var(--surface-2);
    color: var(--text);
    text-decoration: none;
}

.btn-danger {
    background: var(--red);
    color: #fff;
    border-color: transparent;
}
.btn-danger:hover:not(:disabled) { background: #b92825; }

.btn-sm    { padding: 4px 10px; font-size: 12px; }
.btn-full  { width: 100%; justify-content: center; }
.btn-icon  { padding: 4px 8px; color: var(--text-muted); }
.btn-icon:hover { color: var(--red-light); border-color: var(--red); }

.btn-copy {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px;
    border-radius: 4px;
    transition: color .15s;
    display: flex;
    align-items: center;
}
.btn-copy:hover { color: var(--blue-muted); }

/* ── Alerts ──────────────────────────────────────────────────────────────── */
.alert {
    border-radius: var(--radius);
    padding: 10px 14px;
    font-size: 13px;
    margin-bottom: 16px;
    border: 1px solid;
}
.alert-error   { background: rgba(218,54,51,.1);  border-color: rgba(218,54,51,.3);  color: #f97583; }
.alert-success { background: rgba(46,160,67,.1);  border-color: rgba(46,160,67,.3);  color: var(--green-light); }

/* ── TOTP key display ────────────────────────────────────────────────────── */
.totp-setup { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.totp-key {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg);
    border: 1px solid var(--border-2);
    border-radius: var(--radius);
    padding: 10px 12px;
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--blue-muted);
    letter-spacing: 1px;
    word-break: break-all;
}

/* ── Dashboard layout ────────────────────────────────────────────────────── */
.dash-page {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Top bar */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 52px;
    padding: 0 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}
.topbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
}
.topbar-title {
    font-weight: 600;
    font-size: 15px;
}
.topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}
.topbar-reg-key {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    transition: all .15s;
}
.topbar-reg-key:hover {
    color: var(--blue-muted);
    border-color: var(--blue);
    background: rgba(31,111,235,.08);
}

/* Stats bar */
.stats-bar {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    gap: 0;
}
.stat {
    display: flex;
    flex-direction: column;
    padding: 0 20px 0 0;
}
.stat-num {
    font-size: 22px;
    font-weight: 700;
    line-height: 1.1;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}
.stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }
.stat-warn  .stat-num { color: var(--yellow-light); }
.stat-danger .stat-num { color: var(--red-light); }
.stat-divider {
    width: 1px;
    height: 32px;
    background: var(--border);
    margin: 0 20px 0 0;
}
.stats-right { margin-left: auto; }

/* Filter tabs */
.filter-tabs { display: flex; gap: 4px; }
.filter-tab {
    background: none;
    border: 1px solid transparent;
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
    padding: 4px 10px;
    cursor: pointer;
    transition: all .15s;
    font-family: inherit;
}
.filter-tab:hover   { color: var(--text); background: var(--surface-2); }
.filter-tab.active  { color: var(--text); background: var(--surface-2); border-color: var(--border-2); }

/* Main */
.main-content {
    flex: 1;
    padding: 20px;
}

/* Table */
.table-wrap {
    overflow-x: auto;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
}
.sites-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
}
.sites-table thead th {
    background: var(--surface-2);
    padding: 10px 14px;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .6px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.sites-table thead th.sortable {
    cursor: pointer;
    user-select: none;
}
.sites-table thead th.sortable:hover { color: var(--text); }
.sites-table thead th.sort-asc::after  { content: ' ↑'; color: var(--blue-muted); }
.sites-table thead th.sort-desc::after { content: ' ↓'; color: var(--blue-muted); }

.sites-table tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background .1s;
}
.sites-table tbody tr:last-child { border-bottom: none; }
.sites-table tbody tr:hover { background: var(--surface-2); }
.sites-table tbody tr.hidden { display: none; }

.sites-table td {
    padding: 12px 14px;
    vertical-align: middle;
}

/* Status dot */
.col-status { width: 28px; padding-right: 0; }
.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.status-online  { background: var(--green-light); box-shadow: 0 0 6px var(--green); animation: pulse 2s infinite; }
.status-stale   { background: var(--yellow-light); }
.status-offline { background: var(--red-light); }
.status-never   { background: var(--text-subtle); }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: .6; }
}

/* Site name */
.col-name { min-width: 200px; }
.site-link {
    font-weight: 500;
    color: var(--text);
    display: block;
    line-height: 1.3;
}
.site-link:hover { color: var(--blue-muted); text-decoration: none; }
.site-domain {
    font-size: 12px;
    color: var(--text-muted);
    display: block;
}

/* Versions */
.version {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-muted);
}

/* Badges */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}
.badge-ok   { background: rgba(46,160,67,.12); color: var(--green-light); border: 1px solid rgba(46,160,67,.25); }
.badge-warn { background: rgba(210,153,34,.12); color: var(--yellow-light); border: 1px solid rgba(210,153,34,.25); }

/* Last seen */
.age { font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* Actions */
.col-actions { width: 120px; white-space: nowrap; }
.col-actions .btn + .btn { margin-left: 4px; }

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 80px 20px;
    color: var(--text-muted);
}
.empty-state h2 { font-size: 18px; color: var(--text); margin: 16px 0 8px; }
.empty-state p  { font-size: 14px; margin-bottom: 6px; }

/* ── Modals ──────────────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}
.modal-overlay[hidden] { display: none; }

.modal {
    background: var(--surface);
    border: 1px solid var(--border-2);
    border-radius: var(--radius-lg);
    padding: 28px 32px;
    max-width: 440px;
    width: 100%;
    box-shadow: var(--shadow);
}
.modal h3   { font-size: 17px; margin-bottom: 10px; }
.modal p    { color: var(--text-muted); font-size: 13px; line-height: 1.6; }
.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 24px;
}

/* ── Login spinner ───────────────────────────────────────────────────────── */
.login-btn.loading {
    opacity: .7;
    pointer-events: none;
}
.login-btn.loading::after {
    content: '';
    display: inline-block;
    width: 10px;
    height: 10px;
    border: 2px solid rgba(255,255,255,.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .6s linear infinite;
    margin-left: 4px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .auth-card { padding: 24px 20px; }
    .col-php, .col-themes { display: none; }
    .stats-bar { flex-wrap: wrap; gap: 12px; }
    .stats-right { order: -1; width: 100%; }
}
