/* WEKA-inspired theme. Dark is the default (set via :root); users can opt
   into light by toggling, which sets data-theme="light" on <html>.
   This ordering means there's no flash of light on first paint. */
:root {
  /* Invariants — brand accent doesn't change between modes */
  --weka-blue:    #00B7E4;
  --weka-blue-2:  #0091B8;
  --danger:       #DC2626;
  --radius:       8px;
  --radius-sm:    6px;
  --font:         -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  /* Dark theme — the default */
  --weka-navy:    #E2E8F0;
  --ink:          #F1F5F9;
  --ink-2:        #94A3B8;
  --ink-3:        #64748B;
  --bg:           #0B1220;
  --bg-alt:       #131C2E;
  --border:       #1E2A3F;
  --border-2:     #2A3A55;
  --shadow-card:  0 1px 2px rgba(0,0,0,0.3), 0 8px 24px rgba(0,0,0,0.35);
  --gate-glow-1:  rgba(0,183,228,0.18);
  --gate-glow-2:  rgba(0,183,228,0.06);
}
html { color-scheme: dark; }

/* Light theme — opt-in via the toggle (sets data-theme="light"). */
:root[data-theme="light"] {
  --weka-navy:    #0B1A2D;
  --ink:          #0F172A;
  --ink-2:        #475569;
  --ink-3:        #94A3B8;
  --bg:           #FFFFFF;
  --bg-alt:       #F6F8FB;
  --border:       #E5E9F0;
  --border-2:     #D6DBE4;
  --shadow-card:  0 1px 2px rgba(15,23,42,0.04), 0 8px 24px rgba(15,23,42,0.06);
  --gate-glow-1:  rgba(0,183,228,0.08);
  --gate-glow-2:  rgba(11,26,45,0.05);
}
html[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }
html, body { height: 100%; }
/* Force the HTML `hidden` attribute to win over our display: flex/grid rules. */
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.9em; }
a { color: var(--weka-blue-2); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.55rem;
  padding: 0.55rem 1rem;
  font: inherit; font-weight: 500; line-height: 1;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  cursor: pointer; transition: background 120ms ease, border-color 120ms ease;
  white-space: nowrap;
}
.btn:focus-visible { outline: 2px solid var(--weka-blue); outline-offset: 2px; }

.btn-primary {
  background: var(--weka-blue); color: #fff; border-color: var(--weka-blue);
  padding: 0.7rem 1.4rem; font-weight: 600;
}
.btn-primary:hover { background: var(--weka-blue-2); border-color: var(--weka-blue-2); }

.btn-secondary {
  background: var(--bg); color: var(--ink); border-color: var(--border-2);
}
.btn-secondary:hover { background: var(--bg-alt); border-color: var(--ink-3); }

.btn-ghost {
  background: transparent; color: var(--ink-2); border-color: transparent;
  padding: 0.4rem 0.7rem;
}
.btn-ghost:hover { color: var(--ink); background: var(--bg-alt); }

.btn-icon { display: inline-block; }

/* Theme toggle: a small circular icon button. */
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px;
  background: transparent; border: 1px solid var(--border-2);
  color: var(--ink-2); border-radius: 50%; padding: 0;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}
.theme-toggle:hover { background: var(--bg-alt); border-color: var(--ink-3); color: var(--ink); }
.theme-toggle svg { width: 16px; height: 16px; }

/* Destructive button (Delete in row actions). */
.btn-danger {
  background: transparent; color: var(--danger); border-color: var(--border-2);
}
.btn-danger:hover { background: rgba(220,38,38,0.08); border-color: var(--danger); }

/* ---------- gate (logged-out) ---------- */
.gate {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 1.5rem;
  background:
    radial-gradient(1100px 600px at 80% -10%, var(--gate-glow-1), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, var(--gate-glow-2), transparent 60%),
    var(--bg);
}
.gate-card {
  width: 100%; max-width: 360px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 2rem 2rem;
  box-shadow: var(--shadow-card);
  text-align: center;
}
.brand {
  font-weight: 800; font-size: 2rem; letter-spacing: 0.18em;
  color: var(--weka-navy);
  position: relative; display: inline-block;
}
.brand::after {
  content: ""; display: block; height: 3px; width: 28px;
  margin: 0.55rem auto 0; background: var(--weka-blue); border-radius: 2px;
}
.brand-sub {
  margin-top: 1rem; margin-bottom: 1.75rem;
  color: var(--ink-2); font-size: 0.95rem; letter-spacing: 0.02em;
}
.gate-card .btn-primary { width: 100%; }
.gate-foot {
  margin-top: 1.25rem; color: var(--ink-3); font-size: 0.8rem;
}
.gate-foot code { color: var(--ink-2); }

/* ---------- app (logged-in) ---------- */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.9rem 1.5rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.app-header-left { display: flex; align-items: center; gap: 0.75rem; }
.app-header-right { display: flex; align-items: center; gap: 0.75rem; }
.brand-mark {
  font-weight: 800; letter-spacing: 0.15em; color: var(--weka-navy);
  font-size: 1rem;
}
.app-divider { color: var(--ink-3); }
.app-title { color: var(--ink-2); }
.user-email { color: var(--ink-2); font-size: 0.9rem; }

.app-main {
  max-width: 1100px; margin: 1.5rem auto; padding: 0 1.5rem 3rem;
}

/* filters */
.filters {
  display: flex; gap: 0.75rem; align-items: end;
  margin-bottom: 1rem;
}
.field { display: flex; flex-direction: column; gap: 0.3rem; }
.field-label { font-size: 0.75rem; color: var(--ink-2); letter-spacing: 0.04em; text-transform: uppercase; }
.input {
  font: inherit; font-size: 0.9rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-2); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--ink);
  width: 220px;
}
.input:focus { outline: 2px solid var(--weka-blue); outline-offset: -1px; border-color: var(--weka-blue); }

/* status */
.status { padding: 0.5rem 0; color: var(--ink-2); }

/* table */
.table-wrap {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.files-table { width: 100%; border-collapse: collapse; }
.files-table th, .files-table td {
  padding: 0.7rem 0.9rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.files-table th {
  background: var(--bg-alt);
  color: var(--ink-2);
  font-weight: 600;
  letter-spacing: 0.02em;
  font-size: 0.78rem; text-transform: uppercase;
}
.files-table tbody tr:last-child td { border-bottom: none; }
.files-table tbody tr:hover { background: var(--bg-alt); }
.files-table .right { text-align: right; }
.files-table td.size { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.files-table td.actions { text-align: right; }

.load-more { display: block; margin: 1rem auto 0; }

/* ---------- docs drawer ---------- */
.docs-overlay {
  position: fixed; inset: 0;
  background: rgba(15,23,42,0.45);
  z-index: 100;
  animation: fade-in 150ms ease;
}
.docs-drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(720px, 95vw);
  background: var(--bg);
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 32px rgba(15,23,42,0.15);
  z-index: 101;
  display: flex; flex-direction: column;
  animation: slide-in 200ms ease;
}
@keyframes fade-in { from { opacity: 0 } to { opacity: 1 } }
@keyframes slide-in { from { transform: translateX(100%) } to { transform: translateX(0) } }

.docs-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.docs-header h2 { margin: 0; font-size: 1rem; color: var(--ink); font-weight: 600; }

.docs-body {
  padding: 1.25rem 1.5rem 2rem;
  overflow-y: auto;
  font-size: 0.92rem;
  color: var(--ink);
  line-height: 1.55;
}
.docs-body section { margin-bottom: 1.75rem; }
.docs-body h3 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem; font-weight: 700;
  color: var(--ink);
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
}
.docs-body h4 { margin: 1rem 0 0.4rem; font-size: 0.85rem; color: var(--ink-2); font-weight: 600; }
.docs-body p { margin: 0 0 0.65rem; color: var(--ink-2); }
.docs-body ol, .docs-body ul { margin: 0 0 0.5rem 1.25rem; padding: 0; color: var(--ink-2); }
.docs-body li { margin-bottom: 0.25rem; }
.docs-body a { color: var(--weka-blue-2); }

.docs-body code {
  background: var(--bg-alt);
  padding: 0.05rem 0.35rem;
  border-radius: 3px;
  font-size: 0.85em;
  color: var(--ink);
  border: 1px solid var(--border);
}
.docs-body pre {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  overflow-x: auto;
  font-size: 0.82rem;
  line-height: 1.45;
  margin: 0 0 0.75rem;
}
.docs-body pre code {
  background: transparent; border: 0; padding: 0; font-size: inherit;
}

.docs-body table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
}
.docs-body table.kv td { padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--border); }
.docs-body table.kv td:first-child { color: var(--ink-2); width: 35%; }
.docs-body table.errors th, .docs-body table.errors td {
  padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top;
}
.docs-body table.errors th {
  background: var(--bg-alt); color: var(--ink-2); font-weight: 600;
  font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em;
}

/* mobile */
@media (max-width: 640px) {
  .app-header { padding: 0.75rem 1rem; }
  .user-email { display: none; }
  .app-main { padding: 0 1rem 2rem; }
  .input { width: 100%; }
  .filters { flex-direction: column; align-items: stretch; }
}
