:root {
  --bg: #0a0a0a;
  --panel: #111113;
  --panel-2: #17171a;
  --border: #232328;
  --fg: #f5f5f5;
  --muted: #8a8a8a;
  --faint: #5a5a5a;
  --accent: #ff2d6f;
  --accent-dim: rgba(255, 45, 111, 0.12);
  --ok: #3ecf8e;
  --warn: #f5a623;
}

body.light {
  --bg: #f6f6f7;
  --panel: #ffffff;
  --panel-2: #efeff1;
  --border: #e0e0e4;
  --fg: #17171a;
  --muted: #6b6b74;
  --faint: #9b9ba3;
  --accent: #e40058;
  --accent-dim: rgba(228, 0, 88, 0.08);
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--fg);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
}

button {
  font: inherit;
  color: var(--fg);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 0.45rem 0.85rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { filter: brightness(1.1); }
button.danger:hover { border-color: #ff4d4d; color: #ff6b6b; }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); padding: 0.3rem 0.5rem; }
button.ghost:hover { color: var(--fg); border-color: var(--border); }

input, textarea {
  font: inherit;
  color: var(--fg);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 0.5rem 0.7rem;
  outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); }

/* ---- login ---- */
.login-wrap {
  height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
}
.login-card {
  width: 100%;
  max-width: 30rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 2.25rem;
}
.eyebrow {
  margin: 0 0 1rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
}
.login-card h1 { margin: 0 0 0.5rem; font-size: 1.6rem; letter-spacing: -0.02em; }
.login-card p.sub { margin: 0 0 1.5rem; color: var(--muted); line-height: 1.55; }
.login-card textarea { width: 100%; min-height: 6.5rem; resize: vertical; font-family: ui-monospace, monospace; font-size: 12px; }
.login-card .row { margin-top: 1rem; display: flex; gap: 0.75rem; align-items: center; }
.login-card .hint { margin-top: 1.25rem; font-size: 0.78rem; color: var(--faint); line-height: 1.5; }
.login-card code { color: var(--muted); }

/* ---- app layout ---- */
.shell { display: flex; height: 100vh; }

.sidebar {
  width: 240px;
  flex: none;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.sidebar .brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 0.8rem 0.75rem 1.1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  border-bottom: 1px solid var(--border);
}
.theme-toggle { font-size: 1rem; line-height: 1; }
.sidebar .brand .dot { color: var(--accent); }
.sidebar .drives { flex: 1; overflow-y: auto; padding: 0.6rem; }
.sidebar .drives .label {
  padding: 0.4rem 0.5rem;
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
}
.drive-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  text-align: left;
  background: none;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 0.45rem 0.55rem;
  color: var(--fg);
  margin-bottom: 2px;
}
.drive-item:hover { background: var(--panel-2); border-color: transparent; }
.drive-item.active { background: var(--accent-dim); color: var(--fg); }
.drive-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: 4px;
  padding: 0.14rem 0.36rem;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--border);
}
.badge.owner { color: var(--accent); border-color: rgba(255, 45, 111, 0.4); background: var(--accent-dim); }
.badge.write { color: var(--ok); border-color: rgba(62, 207, 142, 0.35); background: rgba(62, 207, 142, 0.08); }
.new-drive {
  width: 100%;
  margin-top: 0.4rem;
  color: var(--muted);
  border-style: dashed;
  background: transparent;
}
.new-drive:hover { color: var(--accent); }
.empty-drives { padding: 0.4rem 0.55rem; color: var(--faint); font-size: 0.85rem; }

.sidebar .foot {
  border-top: 1px solid var(--border);
  padding: 0.85rem 1.1rem;
  font-size: 0.8rem;
  color: var(--muted);
}
.sidebar .foot .who { color: var(--fg); font-weight: 600; }
.sidebar .foot .exp { font-size: 0.72rem; color: var(--faint); margin-top: 2px; }
.sidebar .foot button { margin-top: 0.6rem; width: 100%; }
.open-by-id { display: flex; gap: 4px; padding: 0.3rem 0.5rem 0.5rem; }
.open-by-id input { flex: 1; min-width: 0; padding: 0.32rem 0.5rem; font-size: 0.8rem; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.8rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.crumbs { flex: 1; display: flex; align-items: center; flex-wrap: wrap; gap: 0.15rem; min-width: 0; font-size: 0.95rem; }
.crumbs a { color: var(--muted); text-decoration: none; padding: 0.15rem 0.3rem; border-radius: 5px; }
.crumbs a:hover { color: var(--fg); background: var(--panel-2); }
.crumbs .sep { color: var(--faint); }
.crumbs .here { color: var(--fg); font-weight: 600; padding: 0.15rem 0.3rem; }
.topbar .meta { font-size: 0.75rem; color: var(--faint); white-space: nowrap; }

.listing { flex: 1; overflow-y: auto; padding: 0.5rem 1.25rem 2rem; }
table.files { width: 100%; border-collapse: collapse; }
table.files th {
  text-align: left;
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--faint);
  font-weight: 600;
  padding: 0.7rem 0.6rem 0.5rem;
  border-bottom: 1px solid var(--border);
}
table.files td { padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--panel-2); }
table.files tr.row:hover td { background: var(--panel); }
td.name { cursor: pointer; max-width: 0; width: 55%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.name .icon { display: inline-block; width: 1.4rem; color: var(--muted); }
tr.dir td.name { color: var(--fg); font-weight: 550; }
td.num { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
td.actions { text-align: right; white-space: nowrap; }
td.actions button { opacity: 0; }
tr.row:hover td.actions button { opacity: 1; }

.empty { padding: 3rem 1rem; text-align: center; color: var(--faint); }
.empty .big { font-size: 2rem; margin-bottom: 0.5rem; }

.drop-hint { outline: 2px dashed var(--accent); outline-offset: -6px; border-radius: 10px; }

/* ---- modal ---- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 2rem;
}
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 56rem;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.8rem 1.1rem;
  border-bottom: 1px solid var(--border);
}
.modal header .title { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal header .sub { font-size: 0.72rem; color: var(--faint); }
.modal .body { flex: 1; overflow: auto; padding: 1.1rem; min-height: 8rem; }
.modal .body textarea {
  width: 100%;
  height: 55vh;
  resize: vertical;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.55;
  tab-size: 2;
}
.modal .body img, .modal .body video { max-width: 100%; max-height: 62vh; display: block; margin: 0 auto; border-radius: 8px; }
.modal .body .binary { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }
.modal footer {
  display: flex;
  gap: 0.6rem;
  justify-content: flex-end;
  padding: 0.8rem 1.1rem;
  border-top: 1px solid var(--border);
}

/* ---- toasts ---- */
#toasts { position: fixed; right: 1.25rem; bottom: 1.25rem; display: flex; flex-direction: column; gap: 0.5rem; z-index: 100; }
.toast {
  color: var(--fg);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--ok);
  border-radius: 8px;
  padding: 0.6rem 0.9rem;
  font-size: 0.85rem;
  max-width: 22rem;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}
.toast.err { border-left-color: #ff4d4d; }

/* ---------- viewers ---------- */
.doc-frame { width: 100%; height: 68vh; border: none; background: #fff; border-radius: 6px; }
.viewer-body { max-height: 68vh; overflow: auto; }
.md { line-height: 1.55; font-size: .95rem; }
.md h1, .md h2, .md h3 { margin: 1.1em 0 .4em; line-height: 1.25; }
.md p { margin: .55em 0; }
.md pre { background: rgba(128,128,128,.12); padding: .7rem .9rem; border-radius: 6px; overflow-x: auto; }
.md code { background: rgba(128,128,128,.14); padding: .1em .35em; border-radius: 4px; font-size: .88em; }
.md pre code { background: none; padding: 0; }
.md blockquote { border-left: 3px solid rgba(128,128,128,.4); margin: .6em 0; padding: .1em 0 .1em .9em; opacity: .85; }
.md img { max-width: 100%; border-radius: 6px; }
.md a { color: inherit; text-decoration: underline; }
.md hr { border: none; border-top: 1px solid rgba(128,128,128,.3); margin: 1.2em 0; }
.raw { white-space: pre-wrap; font-size: .85rem; }
.json-tree { font-family: ui-monospace, monospace; font-size: .85rem; line-height: 1.5; }
.json-tree details { padding-left: 1rem; }
.json-tree summary { cursor: pointer; opacity: .85; }
.json-leaf { padding-left: 1rem; }
.json-string { color: #7aa869; }
.json-number { color: #c08c4a; }
.json-boolean { color: #b07acc; }
.csv-wrap { max-height: 68vh; overflow: auto; }
table.csv { border-collapse: collapse; font-size: .82rem; }
table.csv th, table.csv td { border: 1px solid rgba(128,128,128,.25); padding: .25rem .55rem; text-align: left; white-space: nowrap; }
table.csv th { position: sticky; top: 0; background: var(--bg, #1c1c1e); }

/* ---------- members / shares dialogs ---------- */
.members { display: flex; flex-direction: column; gap: .5rem; min-width: 380px; }
.member-row { display: flex; align-items: center; gap: .6rem; }
.member-row .subject { flex: 1; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; }
.member-row select { padding: .2rem .4rem; }
.member-add { display: flex; gap: .5rem; margin-top: .6rem; }
.member-add input[type=text] { flex: 1; padding: .4rem .6rem; }
.share-url { font-size: .85rem; opacity: .9; }
.hint { font-size: .78rem; opacity: .6; margin-top: .5rem; }

/* ---------- admin console (#/admin) ---------- */
.admin { padding: 1.25rem 1.5rem 4rem; overflow-y: auto; height: 100%; display: flex; flex-direction: column; gap: 1rem; }
.admin-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.admin-top h1 { margin: 0; font-size: 1.35rem; letter-spacing: -0.01em; }
.admin-top .row { display: flex; gap: .5rem; align-items: center; }
.admin .panel-sub { margin: .25rem 0 0; color: var(--muted); font-size: .8rem; max-width: 60ch; }
.admin-link { color: var(--accent); }
.range-select {
  font: inherit; color: var(--fg); background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 7px; padding: .4rem .5rem;
}

.health { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .6rem; }
.health-item {
  display: flex; align-items: center; gap: .6rem; padding: .7rem .85rem;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
}
.health-item .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.health-item.ok .dot { background: var(--ok); }
.health-item.warn .dot { background: var(--warn); }
.health-item.bad .dot { background: var(--accent); }
.health-item .h-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.health-item .h-value { font-size: .9rem; margin-top: .1rem; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .6rem; }
.tile { padding: .8rem .9rem; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; }
.tile-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.tile-value { font-size: 1.4rem; font-weight: 600; margin-top: .25rem; letter-spacing: -0.02em; }
.tile-sub { font-size: .75rem; color: var(--faint); margin-top: .15rem; }

.panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: .8rem; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 1rem 1.1rem; }
.panel.wide { grid-column: 1 / -1; }
.panel-head h2 { margin: 0; font-size: .95rem; font-weight: 600; }
.chart { margin-top: .9rem; }
.chart-svg { width: 100%; height: 130px; display: block; }
.chart-svg .bar { fill: var(--accent); opacity: .85; }
.chart-svg .bar.warn { fill: var(--warn); }
.chart-svg .bar:hover { opacity: 1; }
.chart-axis { display: flex; justify-content: space-between; font-size: .7rem; color: var(--faint); margin-top: .35rem; }
.chart-foot { margin-top: .5rem; }
.chart-data { margin-top: .6rem; max-height: 220px; overflow: auto; }
.chart-data table { width: 100%; border-collapse: collapse; font-size: .78rem; }
.chart-data th, .chart-data td { text-align: left; padding: .2rem .4rem; border-bottom: 1px solid var(--panel-2); }
.chart-tip {
  position: fixed; z-index: 50; pointer-events: none; font-size: .78rem;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; padding: .3rem .5rem;
}
button.sm { padding: .2rem .5rem; font-size: .78rem; }

.table-wrap { margin-top: .8rem; overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: .82rem; white-space: nowrap; }
table.data-table th {
  text-align: left; font-weight: 500; color: var(--muted); font-size: .72rem;
  text-transform: uppercase; letter-spacing: .05em; padding: .35rem .6rem; border-bottom: 1px solid var(--border);
}
table.data-table td { padding: .4rem .6rem; border-bottom: 1px solid var(--panel-2); }
table.data-table th.num, table.data-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data-table .mono { font-family: ui-monospace, monospace; font-size: .8rem; }
table.data-table a { color: inherit; text-decoration: none; border-bottom: 1px dotted var(--border); }
table.data-table a:hover { color: var(--accent); }
.warn-text { color: var(--warn); }
.empty.sm { padding: 1.2rem; font-size: .85rem; }
.footnote { font-size: .75rem; color: var(--faint); margin: .7rem 0 0; line-height: 1.5; }

.feed { margin-top: .8rem; max-height: 340px; overflow-y: auto; display: flex; flex-direction: column; gap: .1rem; }
.feed-row { padding: .5rem .6rem; border-left: 2px solid var(--border); border-radius: 0 6px 6px 0; }
.feed-row.error { border-left-color: var(--accent); }
.feed-row.warn { border-left-color: var(--warn); }
.feed-row:hover { background: var(--panel-2); }
.feed-head { display: flex; justify-content: space-between; gap: .6rem; font-size: .78rem; }
.feed-head .kind { font-family: ui-monospace, monospace; }
.feed-head .when { color: var(--faint); }
.feed-detail { font-size: .78rem; color: var(--muted); margin-top: .15rem; word-break: break-word; white-space: normal; }
.feed-meta { font-size: .72rem; color: var(--faint); margin-top: .15rem; }

.settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1.2rem; margin-top: .9rem; }
.setting-block h3 { margin: 0 0 .6rem; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.setting-block .row { display: flex; gap: .5rem; align-items: center; margin-top: .5rem; flex-wrap: wrap; }
.setting-block input[type=text], .setting-block input[type=email] { padding: .35rem .5rem; border-radius: 6px; }
.setting-block input[type=number] { width: 5.5rem; padding: .35rem .5rem; border-radius: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip {
  display: inline-flex; align-items: center; gap: .35rem; font-size: .78rem;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px; padding: .2rem .5rem .2rem .65rem;
}
.chip-x { background: none; border: none; color: var(--faint); cursor: pointer; padding: 0 .1rem; }
.chip-x:hover { color: var(--accent); }
.rule { display: flex; align-items: center; justify-content: space-between; gap: .6rem; padding: .25rem 0; }
.rule-name { display: flex; align-items: center; gap: .45rem; font-size: .85rem; cursor: pointer; }
.rule-value { display: flex; align-items: center; gap: .35rem; }
.unit { font-size: .75rem; color: var(--faint); }
.cost-split { margin-top: .6rem; display: flex; flex-direction: column; gap: .25rem; font-size: .82rem; }
.cost-split div { display: flex; justify-content: space-between; gap: 1rem; }
.cost-split span { color: var(--muted); }

/* Where extra-auth's org widget mounts. It renders in a shadow root, so the
   only things reachable from here are the box it sits in and the variables it
   reads. Which ID you are acting as decides which drives exist, so it sits
   directly above the drive list. */
.orgslot {
  padding: 0 1rem 0.75rem;
  --xo-line: var(--line, #232328);
  --xo-card: var(--panel, #141417);
  --xo-row: var(--panel-2, #17171a);
  --xo-ink: var(--text, #f5f5f5);
  --xo-dim: var(--muted, #8a8a8a);
  --xo-accent: var(--accent, #ff2d6f);
}
.orgslot > * { max-width: 100%; }
