:root {
  --bg: #fbfbfc; --panel: #ffffff; --fg: #18181b; --muted: #71717a;
  --rule: #e4e4e7; --accent: #2563eb; --accent-soft: #eff6ff;
  --warn: #b45309; --warn-soft: #fffbeb;
  --danger: #b91c1c; --danger-soft: #fef2f2;
  --ok: #15803d;
  --dir: #2563eb; --radius: 8px; --shadow: 0 1px 2px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0e11; --panel: #16171b; --fg: #e9e9ec; --muted: #8b8b94;
    --rule: #26272d; --accent: #7aa2f7; --accent-soft: #1a2030;
    --warn: #d4a017; --warn-soft: #2a2416;
    --danger: #f87171; --danger-soft: #2a1a1a;
    --ok: #4ade80;
    --dir: #7aa2f7; --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  --bg: #0d0e11; --panel: #16171b; --fg: #e9e9ec; --muted: #8b8b94;
  --rule: #26272d; --accent: #7aa2f7; --accent-soft: #1a2030;
  --warn: #d4a017; --warn-soft: #2a2416;
  --danger: #f87171; --danger-soft: #2a1a1a;
  --ok: #4ade80; --dir: #7aa2f7;
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; }

/* ---------------------------------------------------------------- header */
header {
  position: sticky; top: 0; z-index: 20;
  background: var(--panel); border-bottom: 1px solid var(--rule); padding: 0 16px;
}
.hwrap {
  max-width: 72rem; margin: 0 auto; display: flex; align-items: center;
  gap: 10px; height: 54px;
}
.logo { font-weight: 650; letter-spacing: -.01em; white-space: nowrap; }
.logo span { color: var(--accent); }
#search {
  flex: 1; min-width: 0; padding: 7px 11px; border: 1px solid var(--rule);
  border-radius: var(--radius); background: var(--bg); color: var(--fg);
}
#search:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

nav.tabs { display: flex; gap: 2px; }
nav.tabs button {
  background: none; border: 0; color: var(--muted); cursor: pointer;
  padding: 6px 10px; border-radius: 6px; white-space: nowrap;
}
nav.tabs button:hover { background: var(--accent-soft); color: var(--accent); }
nav.tabs button[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
nav.tabs .badge {
  display: inline-block; min-width: 16px; padding: 0 4px; margin-left: 5px;
  background: var(--danger); color: #fff; border-radius: 9px;
  font-size: .7rem; font-weight: 700; text-align: center;
}

main { max-width: 72rem; margin: 0 auto; padding: 16px; }

/* ---------------------------------------------------------------- cards */
.quota { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
.card {
  background: var(--panel); border: 1px solid var(--rule);
  border-radius: var(--radius); padding: 12px 14px; flex: 1 1 15rem;
  box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 2px; font-size: .82rem; font-weight: 600; color: var(--muted); }
.card .big { font-size: 1.3rem; font-weight: 600; letter-spacing: -.02em; }
.card .sub { color: var(--muted); font-size: .82rem; }
.bar { height: 5px; background: var(--rule); border-radius: 3px; margin-top: 8px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }

/* ---------------------------------------------------------------- lists */
nav.crumbs {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px;
  margin-bottom: 10px; font-size: .9rem; min-height: 24px;
}
nav.crumbs button {
  background: none; border: 0; color: var(--accent); cursor: pointer;
  padding: 2px 4px; border-radius: 4px;
}
nav.crumbs button:hover { background: var(--accent-soft); }
nav.crumbs .sep { color: var(--muted); }

.list {
  background: var(--panel); border: 1px solid var(--rule);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
.row {
  display: grid; grid-template-columns: 34px 1fr auto auto auto;
  gap: 10px; align-items: center; padding: 8px 14px;
  border-bottom: 1px solid var(--rule);
}
.row:last-child { border-bottom: 0; }
.row.clickable { cursor: pointer; }
.row.clickable:hover { background: var(--accent-soft); }
.row.result { align-items: start; padding: 10px 14px; }
.row.result .nm { white-space: normal; }

.thumb {
  width: 34px; height: 34px; border-radius: 4px; object-fit: cover;
  background: var(--rule); display: block;
}
.ico { width: 20px; height: 20px; margin: 7px; display: block; color: var(--muted); }
.row.dir .ico, .row.shortcut .ico { color: var(--dir); }

.nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.path {
  color: var(--muted); font-size: .78rem; margin-top: 1px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sz { color: var(--muted); font-variant-numeric: tabular-nums; font-size: .86rem; white-space: nowrap; }
.when { color: var(--muted); font-size: .8rem; white-space: nowrap; }

.tag {
  font-size: .72rem; padding: 1px 6px; border-radius: 10px; white-space: nowrap;
  border: 1px solid var(--rule); color: var(--muted);
}
.tag.export { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.tag.unavail { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.tag.readonly { background: transparent; }
.tag.ok { background: transparent; border-color: var(--ok); color: var(--ok); }
.tag.bad { background: var(--danger-soft); border-color: transparent; color: var(--danger); }

mark { background: var(--accent-soft); color: var(--accent); padding: 0 1px; border-radius: 2px; font-weight: 600; }

.act {
  background: none; border: 1px solid var(--rule); color: var(--muted);
  cursor: pointer; padding: 3px 9px; border-radius: 6px; font-size: .8rem;
}
.act:hover { border-color: var(--accent); color: var(--accent); }
.act.danger:hover { border-color: var(--danger); color: var(--danger); }

.notice {
  border: 1px solid transparent; padding: 9px 12px; border-radius: var(--radius);
  margin-bottom: 12px; font-size: .88rem;
}
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.info { background: var(--accent-soft); color: var(--accent); }
.notice.danger { background: var(--danger-soft); color: var(--danger); }

.empty, .loading { color: var(--muted); padding: 28px 14px; text-align: center; }
.err { color: var(--danger); padding: 14px; }
footer { max-width: 72rem; margin: 0 auto; padding: 8px 16px 32px; color: var(--muted); font-size: .8rem; }

/* ---------------------------------------------------------------- preview */
.sheet {
  position: fixed; inset: 0; z-index: 50; display: flex;
  align-items: center; justify-content: center; padding: 20px;
  background: rgba(0,0,0,.55); backdrop-filter: blur(2px);
}
.sheet[hidden] { display: none; }
.sheet-inner {
  background: var(--panel); border-radius: 12px; max-width: 60rem; width: 100%;
  max-height: 88vh; display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 12px 40px rgba(0,0,0,.3);
}
.sheet-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-bottom: 1px solid var(--rule);
}
.sheet-head .nm { font-weight: 600; }
.sheet-head .close {
  margin-left: auto; background: none; border: 0; color: var(--muted);
  cursor: pointer; font-size: 1.3rem; line-height: 1; padding: 2px 8px; border-radius: 6px;
}
.sheet-head .close:hover { background: var(--rule); color: var(--fg); }
.sheet-body { padding: 14px; overflow: auto; }
.sheet-body img, .sheet-body video { max-width: 100%; max-height: 70vh; display: block; margin: 0 auto; border-radius: 6px; }
.sheet-body pre {
  margin: 0; padding: 12px; background: var(--bg); border: 1px solid var(--rule);
  border-radius: 6px; overflow: auto; max-height: 70vh;
  font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap; word-break: break-word;
}
.sheet-body iframe { width: 100%; height: 70vh; border: 1px solid var(--rule); border-radius: 6px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: .86rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }
.ext {
  display: inline-block; margin-top: 10px; padding: 7px 13px;
  background: var(--accent); color: #fff; border-radius: 6px;
  text-decoration: none; font-weight: 600;
}

@media (max-width: 640px) {
  .hwrap { flex-wrap: wrap; height: auto; padding: 8px 0; }
  nav.tabs { order: 3; width: 100%; overflow-x: auto; }
  .row { grid-template-columns: 34px 1fr auto; }
  .row .when, .row .tag { display: none; }
}

/* ------------------------------------------------------------ sign-in gate */
/* A full-cover overlay rather than a separate page: the app shell is already
   loaded, and a passkey prompt is quick enough that a navigation would feel
   heavier than the thing it guards. */
.gate {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center; padding: 24px;
  background: var(--bg);
}
/* `display: grid` above would otherwise beat the browser's `[hidden] {
   display: none }`, which lives in the user-agent stylesheet and loses to any
   author rule. Without this the overlay never goes away: setting
   `gate.hidden = true` has no visible effect, so a successful sign-in leaves
   the app loaded underneath a sign-in screen that will not move. */
.gate[hidden] { display: none; }
.gate-card {
  width: 100%; max-width: 22rem;
  background: var(--panel); border: 1px solid var(--rule);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 28px 24px; text-align: center;
}
.gate-card .logo { justify-content: center; margin-bottom: 18px; }
.gate-lead { color: var(--muted); margin: 0 0 18px; line-height: 1.5; }
.gate-field { display: block; text-align: left; margin-bottom: 12px; }
.gate-field span {
  display: block; font-size: .8rem; color: var(--muted); margin-bottom: 4px;
}
.gate-field input {
  width: 100%; font: inherit; color: var(--fg);
  background: var(--bg); border: 1px solid var(--rule);
  border-radius: 6px; padding: 9px 10px;
}
.gate-field input:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent);
}
button.primary {
  width: 100%; cursor: pointer;
  background: var(--accent); color: #fff; border: 0;
  border-radius: 6px; padding: 11px 16px; font-weight: 500;
}
button.primary:hover { filter: brightness(1.06); }
button.primary:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
.gate-msg { min-height: 1.4em; margin: 14px 0 0; font-size: .875rem; color: var(--muted); }
.gate-msg.err { color: var(--danger); }
.gate-alt { margin: 14px 0 0; }
button.link {
  background: none; border: 0; padding: 0; cursor: pointer;
  color: var(--accent); font-size: .875rem; text-decoration: underline;
}
button.link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --------------------------------------------------------- connect storage */
/* Shown when no backend exists yet. The empty state used to be a sentence of
   text with nothing to click, which is a dead end on a fresh install: every
   endpoint works and there is no way to reach any of them. */
.connect { max-width: 34rem; }
.connect h2 { font-size: 1.1rem; margin: 0 0 6px; font-weight: 600; }
.connect > .sub { margin: 0 0 18px; line-height: 1.55; }
.connect-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 10px;
}
.connect-row h3 { margin: 0 0 2px; font-size: .95rem; font-weight: 600; }
.connect-row button.primary { width: auto; flex: 0 0 auto; padding: 9px 18px; }
.sub.err { color: var(--danger); }
