/* ─── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg:        #0F172A;
  --card:      #1E293B;
  --border:    #334155;
  --accent:    #06B6D4;
  --accent-h:  #0891B2;
  --success:   #10B981;
  --danger:    #DC2626;
  --warning:   #F59E0B;
  --text:      #F1F5F9;
  --muted:     #94A3B8;
  --sidebar-w: 220px;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', ui-monospace, monospace;
}
html, body { height: 100%; background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, sans-serif; font-size: 14px; line-height: 1.5; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-h); }
button { cursor: pointer; font-family: inherit; font-size: 14px; }
input, select, textarea { font-family: inherit; font-size: 14px; }
code, .mono { font-family: var(--font-mono); font-size: 12px; }

/* ─── Layout ───────────────────────────────────────────────────────────────── */
#app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; grid-template-rows: 1fr; height: 100vh; overflow: hidden; }
#sidebar { background: var(--bg); border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow-y: auto; }
#main { display: flex; flex-direction: column; overflow: hidden; }
#topbar { display: flex; align-items: center; justify-content: space-between; padding: 0 24px; height: 56px; border-bottom: 1px solid var(--border); background: var(--card); flex-shrink: 0; }
#content { flex: 1; overflow-y: auto; padding: 28px 28px; }

/* ─── Sidebar ──────────────────────────────────────────────────────────────── */
.brand { padding: 20px 16px 16px; border-bottom: 1px solid var(--border); }
.brand-name { font-size: 15px; font-weight: 700; color: var(--text); letter-spacing: .3px; }
.brand-name span { color: var(--accent); }
.brand-ver  { font-size: 10px; color: var(--muted); background: var(--card); padding: 1px 6px; border-radius: 10px; margin-left: 6px; }
.brand-sub  { font-size: 11px; color: var(--muted); margin-top: 3px; }

nav { flex: 1; padding: 12px 8px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 6px; color: var(--muted); font-size: 13px; font-weight: 500; cursor: pointer; transition: background .15s, color .15s; border: none; background: none; width: 100%; text-align: left; border-left: 3px solid transparent; margin-bottom: 2px; }
.nav-item:hover { background: var(--card); color: var(--text); }
.nav-item.active { background: rgba(6,182,212,.1); color: var(--accent); border-left-color: var(--accent); }
.nav-icon { width: 16px; height: 16px; flex-shrink: 0; }

/* ─── Topbar ───────────────────────────────────────────────────────────────── */
.topbar-title { font-size: 16px; font-weight: 600; }
.topbar-user { display: flex; align-items: center; gap: 12px; }
.user-badge { display: flex; align-items: center; gap: 8px; background: var(--card); border: 1px solid var(--border); padding: 5px 12px; border-radius: 6px; font-size: 13px; }
.role-pill { font-size: 10px; padding: 2px 7px; border-radius: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.role-admin    { background: rgba(220,38,38,.2);  color: #FCA5A5; }
.role-operator { background: rgba(245,158,11,.2); color: #FCD34D; }
.role-viewer   { background: rgba(6,182,212,.2);  color: #67E8F9; }

/* ─── Buttons ──────────────────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 6px; font-size: 13px; font-weight: 500; border: none; transition: background .15s, opacity .15s; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary  { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled)  { background: var(--accent-h); }
.btn-danger   { background: rgba(220,38,38,.15); color: #FCA5A5; border: 1px solid rgba(220,38,38,.3); }
.btn-danger:hover:not(:disabled)   { background: rgba(220,38,38,.3); }
.btn-ghost    { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled)    { background: var(--card); color: var(--text); }
.btn-success  { background: rgba(16,185,129,.15); color: #6EE7B7; border: 1px solid rgba(16,185,129,.3); }
.btn-success:hover:not(:disabled)  { background: rgba(16,185,129,.3); }
.btn-warn     { background: rgba(245,158,11,.15); color: #FCD34D; border: 1px solid rgba(245,158,11,.3); }
.btn-warn:hover:not(:disabled)     { background: rgba(245,158,11,.3); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-xs { padding: 2px 8px; font-size: 11px; border-radius: 4px; }

/* ─── Cards ────────────────────────────────────────────────────────────────── */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; }
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-header h3 { font-size: 14px; font-weight: 600; }
.card-body { padding: 20px; }

/* ─── Stats row ────────────────────────────────────────────────────────────── */
.stats-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 18px 20px; }
.stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 8px; }
.stat-value { font-size: 26px; font-weight: 700; }
.stat-sub   { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ─── Progress bar ─────────────────────────────────────────────────────────── */
.progress-wrap { background: var(--bg); border-radius: 99px; height: 8px; overflow: hidden; }
.progress-bar  { height: 100%; border-radius: 99px; transition: width .3s; }
.pb-accent   { background: var(--accent); }
.pb-success  { background: var(--success); }
.pb-danger   { background: var(--danger); }
.pb-warning  { background: var(--warning); }

/* ─── Table ────────────────────────────────────────────────────────────────── */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); }
.tbl td { padding: 11px 14px; border-bottom: 1px solid rgba(51,65,85,.5); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tr.expandable { cursor: pointer; }
.tbl tr.expandable:hover td { background: rgba(255,255,255,.03); }
.tbl tr.row-detail td { background: rgba(15,23,42,.5); padding: 0; }

/* ─── Badges ───────────────────────────────────────────────────────────────── */
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.badge-green  { background: rgba(16,185,129,.2);  color: #6EE7B7; }
.badge-amber  { background: rgba(245,158,11,.2);  color: #FCD34D; }
.badge-red    { background: rgba(220,38,38,.2);   color: #FCA5A5; }
.badge-grey   { background: rgba(148,163,184,.15); color: var(--muted); }
.badge-blue   { background: rgba(6,182,212,.2);   color: #67E8F9; }

/* ─── Forms ────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .4px; }
.form-input { width: 100%; background: var(--bg); border: 1px solid var(--border); color: var(--text); padding: 8px 12px; border-radius: 6px; outline: none; transition: border-color .15s; }
.form-input:focus { border-color: var(--accent); }
.form-select { width: 100%; background: var(--bg); border: 1px solid var(--border); color: var(--text); padding: 8px 12px; border-radius: 6px; outline: none; appearance: none; }

/* ─── Alerts ───────────────────────────────────────────────────────────────── */
.alert { padding: 12px 16px; border-radius: 6px; font-size: 13px; margin-bottom: 16px; }
.alert-danger  { background: rgba(220,38,38,.1);  border: 1px solid rgba(220,38,38,.3);  color: #FCA5A5; }
.alert-success { background: rgba(16,185,129,.1); border: 1px solid rgba(16,185,129,.3); color: #6EE7B7; }
.alert-info    { background: rgba(6,182,212,.1);  border: 1px solid rgba(6,182,212,.3);  color: #67E8F9; }
.alert-warn    { background: rgba(245,158,11,.1); border: 1px solid rgba(245,158,11,.3); color: #FCD34D; }

/* ─── Modal ────────────────────────────────────────────────────────────────── */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 20px; opacity: 0; pointer-events: none; transition: opacity .2s; }
.modal-backdrop.open { opacity: 1; pointer-events: all; }
.modal { background: var(--card); border: 1px solid var(--border); border-radius: 10px; width: 100%; max-width: 900px; max-height: 90vh; display: flex; flex-direction: column; transform: scale(.96); transition: transform .2s; }
.modal-backdrop.open .modal { transform: scale(1); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.modal-header h3 { font-size: 15px; font-weight: 600; }
.modal-close { background: none; border: none; color: var(--muted); font-size: 20px; cursor: pointer; padding: 4px 8px; border-radius: 4px; line-height: 1; }
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-body { flex: 1; overflow-y: auto; padding: 20px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; flex-shrink: 0; }

/* ─── File browser ─────────────────────────────────────────────────────────── */
.fb-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.fb-toolbar label { white-space: nowrap; }
.fb-search { flex: 1; min-width: 200px; background: var(--bg); border: 1px solid var(--border); color: var(--text); padding: 7px 12px; border-radius: 6px; outline: none; }
#fb-modal-title { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.fb-title-account { color: var(--text); font-weight: 600; }
.fb-title-sep { color: var(--muted); font-weight: 300; }
.fb-title-snap { color: var(--accent); font-weight: 500; }
.fb-title-raw { color: var(--muted); font-family: var(--font-mono); font-size: 11px; font-weight: 400; padding: 2px 8px; background: var(--bg); border: 1px solid var(--border); border-radius: 4px; }
.snap-select { background: var(--bg); border: 1px solid var(--border); color: var(--text); padding: 7px 12px; border-radius: 6px; font-size: 12px; font-family: var(--font-mono); min-width: 220px; cursor: pointer; }
.snap-select:hover { border-color: var(--accent); }
#fb-snap-sel { min-width: 260px; }
.fb-search:focus { border-color: var(--accent); }
.file-tree { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; overflow: auto; max-height: 420px; }
.ft-header { display: grid; grid-template-columns: 24px 1fr 80px 100px; gap: 8px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; font-weight: 600; }
.ft-row { display: grid; grid-template-columns: 24px 1fr 80px 100px; gap: 8px; align-items: center; padding: 5px 12px; border-bottom: 1px solid rgba(51,65,85,.3); transition: background .1s; }
.ft-row:last-child { border-bottom: none; }
.ft-row:hover { background: rgba(255,255,255,.03); }
.ft-check { width: 14px; height: 14px; accent-color: var(--accent); cursor: pointer; }
.ft-name { display: flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; user-select: none; }
.ft-name.dir { color: var(--accent); font-weight: 500; }
.ft-name.file { color: var(--text); padding-left: 20px; }
.ft-toggle { font-size: 11px; width: 14px; display: inline-block; text-align: center; color: var(--muted); }
.ft-size { font-size: 12px; color: var(--muted); font-family: var(--font-mono); text-align: right; }
.ft-date { font-size: 12px; color: var(--muted); font-family: var(--font-mono); }
.ft-indent-1 { padding-left: 28px; }
.ft-indent-2 { padding-left: 44px; }
.ft-indent-3 { padding-left: 60px; }
.ft-indent-4 { padding-left: 76px; }
.ft-indent-5 { padding-left: 92px; }
.fb-cat-btn.active { background: var(--accent); color: var(--bg); }

/* ─── Job log ──────────────────────────────────────────────────────────────── */
.job-log { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 12px 14px; font-family: var(--font-mono); font-size: 12px; max-height: 300px; overflow-y: auto; color: #A3E635; white-space: pre-wrap; word-break: break-all; }

/* ─── Login page ───────────────────────────────────────────────────────────── */
#login-screen { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); }
.login-box { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 40px 36px; width: 100%; max-width: 380px; }
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo-name { font-size: 20px; font-weight: 800; color: var(--text); }
.login-logo-name span { color: var(--accent); }
.login-logo-sub  { font-size: 12px; color: var(--muted); margin-top: 4px; }
.login-box h2 { font-size: 18px; font-weight: 700; margin-bottom: 20px; }

/* ─── Misc ─────────────────────────────────────────────────────────────────── */
.page { display: none; }
.page.active { display: block; }
.section-title { font-size: 18px; font-weight: 700; margin-bottom: 20px; }
.flex-row { display: flex; align-items: center; gap: 10px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }
.mb-16 { margin-bottom: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.text-muted { color: var(--muted); }
.text-sm { font-size: 12px; }
.text-accent { color: var(--accent); }
.text-danger { color: #FCA5A5; }
.text-success { color: #6EE7B7; }
.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.2); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty-state-icon { font-size: 40px; margin-bottom: 12px; opacity: .4; }
.coverage-age-green { color: var(--success); }
.coverage-age-amber { color: var(--warning); }
.coverage-age-red   { color: var(--danger); }
.coverage-age-grey  { color: var(--muted); }

/* Quick restore buttons */
.qr-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* Scope picker */
.scope-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.scope-label { font-size: 12px; color: var(--muted); white-space: nowrap; }

/* Snapshot selector */
.snap-select { background: var(--bg); border: 1px solid var(--border); color: var(--text); padding: 5px 10px; border-radius: 5px; font-size: 12px; }

/* User table */
.user-table-wrap { overflow-x: auto; }

/* Audit log */
.audit-line { font-family: var(--font-mono); font-size: 12px; padding: 4px 0; border-bottom: 1px solid rgba(51,65,85,.3); display: grid; grid-template-columns: 140px 100px 110px 120px 1fr; gap: 10px; }
.audit-line:last-child { border-bottom: none; }
.al-time   { color: var(--muted); }
.al-user   { color: var(--accent); }
.al-ip     { color: var(--muted); }
.al-action { color: var(--text); font-weight: 600; }
.al-detail { color: var(--muted); word-break: break-all; }

/* Connection test */
.conn-result { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 10px 14px; font-family: var(--font-mono); font-size: 12px; margin-top: 10px; white-space: pre-wrap; }

/* Snapshot timeline pills */
.snap-pills { display: flex; flex-wrap: wrap; gap: 6px; padding: 12px; }
.snap-pill { background: var(--bg); border: 1px solid var(--border); border-radius: 5px; padding: 4px 10px; font-size: 11px; font-family: var(--font-mono); cursor: pointer; transition: border-color .15s; }
.snap-pill:hover { border-color: var(--accent); color: var(--accent); }
.snap-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 12px 12px; }
