/* File Sync Admin dashboard. No build step, no framework — plain CSS with
   variables; dark theme follows the OS. */

:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #fafbfc;
  --border: #e2e5ea;
  --text: #1c2330;
  --muted: #68738a;
  --accent: #2563eb;
  --accent-soft: #2563eb1a;
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --shadow: 0 10px 30px rgb(15 23 42 / 0.08);
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10141c;
    --panel: #171d28;
    --panel-2: #1c2432;
    --border: #2a3345;
    --text: #e6eaf2;
    --muted: #8b96ad;
    --accent: #5b8def;
    --accent-soft: #5b8def26;
    --ok: #34d399;
    --warn: #fbbf24;
    --bad: #f87171;
    --shadow: 0 10px 30px rgb(0 0 0 / 0.35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; }
input, select { font: inherit; color: inherit; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

/* ---------- Login ---------- */
.login {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card {
  width: 360px; max-width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 32px;
  display: flex; flex-direction: column; gap: 14px;
}
.login-mark { font-size: 34px; text-align: center; }
.login-card h1 { margin: 0; font-size: 20px; text-align: center; }
.login-sub { margin: 0 0 6px; text-align: center; color: var(--muted); font-size: 13px; }
.login-card label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.login-card input {
  padding: 9px 11px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel-2);
}
.login-card input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.login-card button[type="submit"] {
  margin-top: 6px; padding: 10px;
  background: var(--accent); color: #fff; border: 0; border-radius: 8px; font-weight: 600;
}
.login-card button[disabled] { opacity: 0.6; cursor: default; }
.login-error { margin: 0; min-height: 1em; color: var(--bad); font-size: 13px; text-align: center; }

/* ---------- Shell ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 216px; flex: 0 0 auto;
  display: flex; flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--border);
  position: sticky; top: 0; height: 100vh;
}
.brand { padding: 18px 16px 12px; font-weight: 700; font-size: 15px; }
.brand span { margin-left: 2px; }
#nav { display: flex; flex-direction: column; padding: 6px 8px; gap: 2px; }
#nav a {
  padding: 8px 10px; border-radius: 8px;
  color: var(--muted); text-decoration: none; font-weight: 500;
}
#nav a:hover { background: var(--panel-2); color: var(--text); }
#nav a.active { background: var(--accent-soft); color: var(--accent); }
.sidebar-foot { margin-top: auto; padding: 12px 16px; border-top: 1px solid var(--border); }
.whoami { font-size: 12px; color: var(--muted); margin-bottom: 8px; overflow-wrap: anywhere; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px; border-bottom: 1px solid var(--border);
  background: var(--panel); position: sticky; top: 0; z-index: 5;
}
.topbar h2 { margin: 0; font-size: 17px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.health-dots { display: inline-flex; gap: 5px; }
.health-dots i {
  width: 9px; height: 9px; border-radius: 50%; display: inline-block;
  background: var(--muted);
}
.health-dots i.ok { background: var(--ok); }
.health-dots i.bad { background: var(--bad); }
.view { padding: 20px 22px 40px; }

.ghost {
  background: transparent; border: 1px solid var(--border); color: var(--muted);
  padding: 6px 10px; border-radius: 8px;
}
.ghost:hover { color: var(--text); border-color: var(--muted); }
.primary {
  background: var(--accent); border: 0; color: #fff;
  padding: 7px 12px; border-radius: 8px; font-weight: 600;
}
.primary[disabled], .danger[disabled] { opacity: 0.55; cursor: default; }
.danger {
  background: var(--bad); border: 0; color: #fff;
  padding: 7px 12px; border-radius: 8px; font-weight: 600;
}

/* ---------- Cards / stats ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 12px; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px;
}
.card .stat-label { font-size: 12px; color: var(--muted); }
.card .stat-value { font-size: 24px; font-weight: 700; margin-top: 2px; }
.card .stat-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-top: 16px;
}
.panel h3 { margin: 0 0 10px; font-size: 14px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.panel-head h3 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 980px) { .grid-2 { grid-template-columns: 1fr; } }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* ---------- Tables ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; align-items: center; }
.toolbar input[type="search"], .toolbar input[type="text"] {
  padding: 7px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel); min-width: 220px;
}
.toolbar select {
  padding: 7px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel);
}
.toolbar .spacer { flex: 1; }
.count-note { color: var(--muted); font-size: 12px; }

.tablewrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); background: var(--panel-2);
  position: sticky; top: 0;
}
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--accent-soft); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td .path { overflow-wrap: anywhere; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 10px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; border: 1px solid transparent;
  white-space: nowrap;
}
.badge.ok      { color: var(--ok);   background: color-mix(in srgb, var(--ok) 12%, transparent); }
.badge.warn    { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }
.badge.bad     { color: var(--bad);  background: color-mix(in srgb, var(--bad) 12%, transparent); }
.badge.muted   { color: var(--muted); background: var(--panel-2); border-color: var(--border); }
.badge.accent  { color: var(--accent); background: var(--accent-soft); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }

/* ---------- Chart ---------- */
.chart-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 8px; }
.chart-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 5px; vertical-align: -1px; }
svg.chart { width: 100%; height: auto; display: block; }
svg.chart text { fill: var(--muted); font-size: 10px; }

/* ---------- Drawer ---------- */
.drawer-backdrop, .modal-backdrop {
  position: fixed; inset: 0; background: rgb(0 0 0 / 0.35); z-index: 20;
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 560px; max-width: 92vw;
  background: var(--panel); border-left: 1px solid var(--border);
  box-shadow: var(--shadow); z-index: 21; overflow-y: auto; padding: 20px 22px;
}
.drawer h3 { margin: 0 0 2px; font-size: 15px; overflow-wrap: anywhere; }
.drawer .drawer-close { position: absolute; top: 14px; right: 14px; }
.drawer .actions { display: flex; gap: 8px; margin: 14px 0; }
.drawer h4 { margin: 18px 0 8px; font-size: 13px; color: var(--muted); }
.timeline { list-style: none; margin: 0; padding: 0; font-size: 12.5px; }
.timeline li { padding: 7px 0; border-bottom: 1px solid var(--border); display: flex; gap: 8px; align-items: baseline; }
.timeline li:last-child { border-bottom: 0; }
.timeline .when { color: var(--muted); white-space: nowrap; }

/* ---------- Modal / toasts ---------- */
.modal-backdrop { display: flex; align-items: center; justify-content: center; z-index: 30; }
.modal {
  width: 420px; max-width: 92vw; background: var(--panel);
  border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
  padding: 20px;
}
.modal h3 { margin: 0 0 8px; }
.modal p { margin: 0 0 16px; color: var(--muted); overflow-wrap: anywhere; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.modal-input { display: flex; flex-direction: column; gap: 5px; margin: 0 0 16px; font-size: 13px; color: var(--muted); }
.modal-input input {
  padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel-2); font: inherit; color: inherit;
}
.modal-input select {
  padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel-2); font: inherit; color: inherit;
}
.modal-error { margin: 0 0 12px; min-height: 1em; color: var(--bad); font-size: 13px; }
.modal-error:empty { margin: 0; min-height: 0; }
/* An enrollment code, shown once: big enough to read out over the phone. */
.modal-code { display: flex; align-items: center; gap: 10px; margin: 0 0 16px; }
.modal-code code {
  flex: 1; padding: 12px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel-2); font-size: 22px; letter-spacing: 0.08em; text-align: center;
  user-select: all;
}

/* Inline "add admin" form */
.form-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.form-row input {
  padding: 7px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel-2); min-width: 200px;
}

.toasts { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 40; }
.toast {
  background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 8px; box-shadow: var(--shadow);
  padding: 10px 14px; font-size: 13px; max-width: 360px;
}
.toast.ok { border-left-color: var(--ok); }
.toast.bad { border-left-color: var(--bad); }

details.json { margin-top: 4px; }
details.json pre {
  margin: 6px 0 0; padding: 8px; background: var(--panel-2); border-radius: 6px;
  font-size: 11px; overflow-x: auto; max-height: 240px;
}
details.json summary { cursor: pointer; color: var(--muted); font-size: 12px; }

/* ---------- Users & devices ---------- */
.user-panel { margin-top: 12px; }
.user-head { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 10px 18px; }
.user-id { min-width: 200px; }
.user-name { font-weight: 600; font-size: 14px; }
.user-actions { margin-left: auto; text-align: right; }
.user-actions .chips { justify-content: flex-end; }
details.nest { margin-top: 10px; }
details.nest > summary { cursor: pointer; color: var(--muted); font-size: 12px; user-select: none; }
details.nest > summary:hover { color: var(--text); }
details.nest > .tablewrap { margin-top: 8px; }

/* ---------- Settings sections (buckets, admin access) ---------- */
.section-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; margin: 28px 0 4px; padding-top: 18px; border-top: 1px solid var(--border); }
.section-head h2 { margin: 0; font-size: 16px; }
.section-head.first { margin-top: 0; padding-top: 0; border-top: 0; }
