/* ============================================================================
   Tabucket — shared theme
   Dark by default; light via [data-theme="light"] on <html>.
   Tokens live in :root so any app inheriting this CSS gets the same system.
   ========================================================================== */

:root {
  /* Color tokens — dark (default). Slate greys + a blue accent; every value
     here is a Tailwind slate/blue step, so a page written against these
     tokens matches anything designed to that palette without a lookup. */
  --bg:            #0a0f1a;
  --bg-grad:       radial-gradient(1200px 600px at 80% -10%, #16233b 0%, transparent 60%),
                   radial-gradient(900px 500px at -10% 10%, #111c30 0%, transparent 55%);
  --surface:       #0f172a;  /* slate-900 */
  --surface-2:     #1e293b;  /* slate-800 */
  --elevated:      #1e293b;  /* slate-800 */
  --border:        #334155;  /* slate-700 */
  --border-soft:   #1e293b;  /* slate-800 */
  --text:          #e2e8f0;  /* slate-200 */
  --text-strong:   #f8fafc;  /* slate-50  */
  --muted:         #94a3b8;  /* slate-400 */
  --faint:         #64748b;  /* slate-500 */

  --primary:       #2563eb;  /* blue-600 */
  --primary-2:     #3b82f6;  /* blue-500 */
  --primary-ink:   #ffffff;
  --primary-soft:  rgba(37, 99, 235, 0.16);
  --ring:          rgba(59, 130, 246, 0.45);

  --success:       #22c55e;
  --warn:          #f59e0b;
  --danger:        #ef4444;

  --shadow-sm:     0 1px 2px rgba(0,0,0,0.4);
  --shadow-md:     0 8px 24px rgba(0,0,0,0.35);
  --shadow-lg:     0 20px 50px rgba(0,0,0,0.45);

  /* Geometry */
  --radius:        12px;
  --radius-sm:     8px;
  --radius-pill:   999px;
  --maxw:          1200px;
  --header-h:      60px;

  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               Helvetica, Arial, sans-serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", Consolas, "Liberation Mono",
               Menlo, monospace;

  color-scheme: dark;
}

/* Light theme overrides */
[data-theme="light"] {
  --bg:            #f8fafc;  /* slate-50  */
  --bg-grad:       radial-gradient(1100px 560px at 85% -12%, #dbeafe 0%, transparent 60%),
                   radial-gradient(800px 460px at -8% 8%, #e0e7ff 0%, transparent 55%);
  --surface:       #ffffff;
  --surface-2:     #f1f5f9;  /* slate-100 */
  --elevated:      #ffffff;
  --border:        #e2e8f0;  /* slate-200 */
  --border-soft:   #f1f5f9;  /* slate-100 */
  --text:          #1e293b;  /* slate-800 */
  --text-strong:   #0f172a;  /* slate-900 */
  --muted:         #64748b;  /* slate-500 */
  --faint:         #94a3b8;  /* slate-400 */

  --primary-soft:  rgba(37, 99, 235, 0.10);
  --shadow-sm:     0 1px 2px rgba(16,24,40,0.06);
  --shadow-md:     0 8px 24px rgba(16,24,40,0.08);
  --shadow-lg:     0 20px 50px rgba(16,24,40,0.12);

  color-scheme: light;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color 0.25s ease, color 0.25s ease;
}

/* ── Header ── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border-soft);
}

.nav {
  display: flex;
  align-items: center;
  height: var(--header-h);
  gap: 1.5rem;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 1.25rem;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text-strong);
  text-decoration: none;
  letter-spacing: 0.01em;
}
.nav-brand::before {
  content: "";
  width: 18px; height: 18px;
  border-radius: 6px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: 0 0 0 4px var(--primary-soft);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: auto;
}
.nav-links a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.4rem 0.7rem;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
}
.nav-links a:hover { color: var(--text-strong); background: var(--surface-2); }
.nav-links a.is-active { color: var(--text-strong); background: var(--primary-soft); }

/* Theme toggle + hamburger */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px; height: 38px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.icon-btn:hover { color: var(--text-strong); border-color: var(--primary); }
.icon-btn svg { width: 18px; height: 18px; }

.theme-toggle .icon-moon { display: none; }
.theme-toggle .icon-sun  { display: block; }
[data-theme="light"] .theme-toggle .icon-moon { display: block; }
[data-theme="light"] .theme-toggle .icon-sun  { display: none; }

.nav-toggle { display: none; }

/* ── Main content ── */
.content {
  flex: 1;
  width: 100%;
  max-width: var(--maxw);
  margin: 2.25rem auto;
  padding: 0 1.25rem;
}

.page-header { margin-bottom: 1.5rem; }
.page-header h1 {
  font-size: clamp(1.5rem, 1.1rem + 1.6vw, 2.1rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-strong);
}
.page-header p { color: var(--muted); margin-top: 0.4rem; }

/* ── Card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow-sm);
}
.card h2 {
  font-size: 1.05rem;
  font-weight: 650;
  margin-bottom: 1rem;
  color: var(--text-strong);
  letter-spacing: -0.01em;
}

/* ── Status pill ── */
.status {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.88rem;
  font-weight: 500;
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  margin-bottom: 1rem;
}
.status-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 0 4px transparent;
}
.status--ok   { color: var(--success); border-color: color-mix(in srgb, var(--success) 35%, var(--border)); }
.status--ok   .status-dot { background: var(--success); box-shadow: 0 0 0 4px rgba(34,197,94,0.18); }
.status--warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, var(--border)); }
.status--warn .status-dot { background: var(--warn); box-shadow: 0 0 0 4px rgba(245,158,11,0.18); }

/* ── Actions / Buttons ── */
.actions { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 1.1rem; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1.15rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-strong);
  cursor: pointer;
  transition: transform 0.05s, background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.btn:hover { border-color: var(--primary); background: var(--elevated); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }

.btn--primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: var(--primary-ink);
  border-color: transparent;
  box-shadow: 0 6px 18px rgba(99,102,241,0.28);
}
.btn--primary:hover { filter: brightness(1.07); border-color: transparent; }
.btn--block { width: 100%; }

.btn--danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.btn--danger:hover { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, var(--surface-2)); }

/* ── Forms ── */
.field { margin-bottom: 1.1rem; }
.field label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.4rem;
  letter-spacing: 0.01em;
}
.input {
  width: 100%;
  padding: 0.7rem 0.85rem;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.input::placeholder { color: var(--faint); }
.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--ring);
  background: var(--surface);
}

select.input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239aa4b5' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.25rem;
  cursor: pointer;
}
select.input option { background: var(--surface); color: var(--text); }

.form-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.85rem;
}
.form-row label { display: inline-flex; align-items: center; gap: 0.45rem; color: var(--muted); cursor: pointer; }
.form-aside { margin-top: 1.25rem; font-size: 0.88rem; color: var(--muted); text-align: center; }

/* ── Auth (login/register) ── */
.auth-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 72vh;
  padding: 2.5rem 1.25rem;
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow-lg);
}
.auth-card h1 {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-strong);
  text-align: center;
}
.auth-card .sub {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0.4rem 0 1.6rem;
}

.divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--faint);
  font-size: 0.78rem;
  margin: 1.4rem 0;
}
.divider::before, .divider::after {
  content: ""; flex: 1; height: 1px; background: var(--border);
}

/* ── Help / prose ── */
.help { margin-top: 1.5rem; padding-top: 1.25rem; border-top: 1px solid var(--border-soft); }
.help h3 { font-size: 0.92rem; font-weight: 650; margin-bottom: 0.75rem; color: var(--text-strong); }
.help p, .help ol, .help ul { font-size: 0.88rem; line-height: 1.85; color: var(--muted); }
.help ol, .help ul { padding-left: 1.25rem; }

code {
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: 5px;
  padding: 0.12em 0.45em;
  font-family: var(--font-mono);
  font-size: 0.85em;
  color: var(--text-strong);
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Footer ── */
.site-footer {
  text-align: center;
  padding: 1.4rem;
  font-size: 0.82rem;
  color: var(--faint);
  border-top: 1px solid var(--border-soft);
}
.site-footer a { color: var(--muted); }

/* ── Responsive ── */
@media (max-width: 640px) {
  .nav-toggle { display: inline-flex; margin-left: auto; }
  .nav-links {
    position: absolute;
    top: var(--header-h);
    left: 0; right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0.15rem;
    margin: 0;
    padding: 0.6rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    display: none;
  }
  .nav-links.is-open { display: flex; }
  .nav-links a { padding: 0.65rem 0.8rem; }
  .nav .theme-toggle { margin-left: auto; }
  .content { margin: 1.5rem auto; }
  .card, .auth-card { padding: 1.25rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}

/* ── User menu dropdown ── */
.user-menu-wrap {
  position: relative;
  margin-left: 0.25rem;
}
.user-menu {
  position: absolute;
  top: calc(100% + 0.6rem);
  right: 0;
  width: 270px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 1.1rem 1.25rem 1rem;
  z-index: 300;
  display: none;
}
.user-menu.is-open { display: block; }
.user-menu-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.75rem;
}
.user-menu-aside {
  margin-top: 0.85rem;
  font-size: 0.875rem;
  color: var(--muted);
  text-align: center;
}
.user-menu-aside a { color: var(--primary); }

/* ── Alerts ── */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.alert--success {
  background: color-mix(in srgb, var(--success) 15%, var(--surface));
  border: 1px solid var(--success);
  color: var(--success);
}
.alert--error {
  background: color-mix(in srgb, var(--danger) 15%, var(--surface));
  border: 1px solid var(--danger);
  color: var(--danger);
}

/* ── Tables ──
   .table-wrap scrolls horizontally on its own so a wide table never makes
   the whole page scroll sideways on mobile. */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  white-space: nowrap;
}
.table th {
  text-align: left;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  background: var(--surface-2);
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--border);
}
.table td {
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--border-soft);
  color: var(--text);
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background-color 0.15s ease; }
.table tbody tr:hover { background: var(--surface-2); }
.table .num { font-family: var(--font-mono); }
.table .center { text-align: center; }
.table .strong { font-weight: 600; color: var(--text-strong); }
/* Opt-out of the table's default nowrap for a cell holding prose (a description, a note) rather
   than a short tabular value - without this, one long sentence forces the whole table (and its
   .table-wrap scrollbar) far wider than the rest of the row's actual columns need. */
.table td.wrap { white-space: normal; max-width: 320px; }

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.badge--primary {
  background: var(--primary-soft);
  border-color: color-mix(in srgb, var(--primary) 45%, transparent);
  color: var(--primary-2);
}
.badge--ok {
  background: color-mix(in srgb, var(--success) 14%, transparent);
  border-color: color-mix(in srgb, var(--success) 45%, transparent);
  color: var(--success);
}

/* ── Stat grid ──
   Promoted from tabucket-web's backtest.html, which had its own inline copy -
   any page showing a row of headline numbers wants this. */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.85rem;
}
.stat-cell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}
.stat-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.35rem;
}
.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-strong);
  font-family: var(--font-mono);
  line-height: 1.2;
}

/* ── Field grid ──
   Responsive row of form fields (filter bars, multi-field forms). Distinct
   from .form-row, which is the small space-between row for things like
   "remember me" / "forgot password". */
.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  align-items: end;
}
.field-grid .field { margin-bottom: 0; }

/* ── Checkbox ── */
.check {
  width: 1rem;
  height: 1rem;
  accent-color: var(--primary);
  cursor: pointer;
  vertical-align: middle;
}
.check:disabled { cursor: wait; opacity: 0.5; }

/* ── Muted helper text ── */
.text-muted { color: var(--muted); }
.text-ok { color: var(--success); }
.text-danger { color: var(--danger); }
