/* ============================================================
   ChitraGupta Dashboard — design tokens & layout
   Palette roles follow the project dataviz reference palette.
   ============================================================ */

:root {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232322;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --ink-muted: #898781;
  --hairline: #2c2c2a;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --accent-ink: #ffffff;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --delta-up: #0ca30c;
  --delta-down: #d03b3b;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

:root[data-theme="light"] {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --ink-muted: #898781;
  --hairline: #e1e0d9;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --delta-up: #006300;
  --delta-down: #d03b3b;
  --shadow: 0 8px 24px rgba(11, 11, 11, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--page);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
button { font: inherit; }

/* ---------------- App shell ---------------- */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px 20px;
  border-bottom: 1px solid var(--hairline);
  margin-bottom: 14px;
}
.brand .mark {
  width: 34px; height: 34px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid; place-items: center;
  font-weight: 700; font-size: 16px;
}
.brand .name { font-weight: 700; font-size: 16px; letter-spacing: 0.2px; }
.brand .sub { font-size: 11px; color: var(--ink-muted); }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--ink-2);
  font-weight: 500;
  font-size: 14px;
}
.nav a svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a.active { background: var(--surface-2); color: var(--ink); }
.nav a.active svg { color: var(--accent); }

.sidebar-footer {
  border-top: 1px solid var(--hairline);
  padding-top: 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.user-row { display: flex; align-items: center; gap: 8px; padding: 0 10px; font-size: 13px; color: var(--ink-2); }

.main { flex: 1; min-width: 0; padding: 24px 28px 90px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 20px; flex-wrap: wrap;
}
.topbar h1 { font-size: 20px; font-weight: 700; }
.topbar .meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ---------------- Badges & status ---------------- */

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px; font-weight: 600;
  background: var(--surface-2);
  color: var(--ink-2);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.badge .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-muted); }
.badge.good .dot { background: var(--good); }
.badge.good { color: var(--good); }
.badge.warning .dot { background: var(--warning); }
.badge.warning { color: var(--warning); }
.badge.serious .dot { background: var(--serious); }
.badge.serious { color: var(--serious); }
.badge.critical .dot { background: var(--critical); }
.badge.critical { color: var(--critical); }

/* ---------------- Cards, tiles, grids ---------------- */

.grid { display: grid; gap: 14px; }
.tiles { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: 20px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
}
.card h2 {
  font-size: 13px; font-weight: 600;
  color: var(--ink-muted);
  text-transform: uppercase; letter-spacing: 0.06em;
  margin-bottom: 12px;
}

.tile .label { font-size: 12px; color: var(--ink-muted); font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }
.tile .value { font-size: 26px; font-weight: 700; margin-top: 6px; line-height: 1.15; }
.hint { font-size: 12px; color: var(--ink-2); margin-top: 4px; font-weight: 400; text-transform: none; letter-spacing: normal; }
.card h2 .hint { display: inline; margin-top: 0; margin-left: 4px; }

.pnl-up { color: var(--delta-up); }
.pnl-down { color: var(--delta-down); }
.num { font-variant-numeric: tabular-nums; }

.section { margin-bottom: 20px; }

/* ---------------- Tables ---------------- */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 560px; }
th {
  text-align: left;
  font-size: 11.5px; font-weight: 600;
  color: var(--ink-muted);
  text-transform: uppercase; letter-spacing: 0.05em;
  padding: 8px 10px;
  border-bottom: 1px solid var(--hairline);
  white-space: nowrap;
}
td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--hairline);
  color: var(--ink-2);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
td.strong { color: var(--ink); font-weight: 600; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-2); }
td.right, th.right { text-align: right; }

.empty {
  color: var(--ink-muted);
  padding: 26px 10px;
  text-align: center;
  font-size: 13.5px;
}

/* ---------------- Chips (order status etc.) ---------------- */

.chip {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px; font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink-2);
}
.chip.filled { color: var(--good); }
.chip.pending { color: var(--warning); }
.chip.rejected { color: var(--critical); }
.chip.cancelled { color: var(--ink-muted); }
.chip.partially_filled { color: var(--warning); }
.side-buy { color: var(--delta-up); font-weight: 700; }
.side-sell { color: var(--delta-down); font-weight: 700; }

/* ---------------- Buttons, forms, toggles ---------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-weight: 600; font-size: 14px;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.ghost {
  background: transparent;
  color: var(--ink-2);
  border: 1px solid var(--border);
}
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn.small { padding: 6px 12px; font-size: 12.5px; border-radius: 7px; }

.switch { position: relative; width: 40px; height: 22px; flex-shrink: 0; cursor: pointer; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: background 0.15s;
}
.switch .track::after {
  content: "";
  position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--ink-muted);
  transition: transform 0.15s, background 0.15s;
}
.switch input:checked + .track { background: var(--good); border-color: var(--good); }
.switch input:checked + .track::after { transform: translateX(18px); background: #fff; }

input[type="text"], input[type="password"], select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--ink);
  border-radius: 8px;
  padding: 11px 12px;
  font-size: 14px;
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
select { width: auto; padding: 8px 10px; }

/* ---------------- Strategy cards ---------------- */

.strategy-grid { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.strategy-card .head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.strategy-card .title { font-size: 15.5px; font-weight: 700; color: var(--ink); word-break: break-word; }
.strategy-card .file { font-size: 11.5px; color: var(--ink-muted); margin-top: 2px; word-break: break-all; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 4px 14px; font-size: 13px; margin-top: 10px; }
.kv .k { color: var(--ink-muted); }
.kv .v { color: var(--ink-2); text-align: right; font-variant-numeric: tabular-nums; }
.params-details summary { cursor: pointer; font-size: 12.5px; color: var(--accent); margin-top: 10px; }
.progress {
  height: 6px; border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden; margin-top: 6px;
}
.progress > div { height: 100%; background: var(--accent); border-radius: 999px; }

/* ---------------- Toasts ---------------- */

.toasts {
  position: fixed;
  right: 16px; bottom: 76px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 60;
  max-width: min(360px, calc(100vw - 32px));
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  box-shadow: var(--shadow);
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 13px;
  color: var(--ink-2);
  animation: toast-in 0.18s ease-out;
}
.toast.good { border-left-color: var(--good); }
.toast.warning { border-left-color: var(--warning); }
.toast.critical { border-left-color: var(--critical); }
.toast .t-title { font-weight: 700; color: var(--ink); margin-bottom: 2px; font-size: 12.5px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

/* ---------------- Login page ---------------- */

.login-body {
  display: grid; place-items: center;
  min-height: 100vh;
  padding: 20px;
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
}
.login-card .brand { border: none; padding: 0 0 6px; margin: 0 0 4px; }
.login-card p.lead { color: var(--ink-muted); font-size: 13px; margin-bottom: 22px; }
.login-card label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin: 14px 0 6px; }
.login-error {
  display: none;
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--critical) 12%, transparent);
  border: 1px solid var(--critical);
  color: var(--critical);
  font-size: 13px;
}
.login-card .btn { width: 100%; margin-top: 20px; }

/* ---------------- Markdown viewer (backtests) ---------------- */

.md-view { font-size: 13.5px; line-height: 1.6; color: var(--ink-2); overflow-x: auto; }
.md-view h1, .md-view h2, .md-view h3 { color: var(--ink); margin: 14px 0 6px; }
.md-view table { min-width: 0; margin: 8px 0; }
.md-view code { background: var(--surface-2); border-radius: 4px; padding: 1px 5px; font-size: 12.5px; }
.md-view pre { background: var(--surface-2); border-radius: 8px; padding: 12px; overflow-x: auto; margin: 8px 0; }

/* ---------------- Mobile ---------------- */

.bottom-nav { display: none; }

@media (max-width: 860px) {
  .sidebar { display: none; }
  .main { padding: 16px 14px 92px; }
  .topbar h1 { font-size: 18px; }
  .tiles { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .tile .value { font-size: 21px; }
  .card { padding: 14px; border-radius: 11px; }
  .strategy-grid { grid-template-columns: 1fr; }

  .bottom-nav {
    display: flex;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    background: var(--surface);
    border-top: 1px solid var(--hairline);
    z-index: 50;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bottom-nav a {
    flex: 1;
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    padding: 6px 2px;
    color: var(--ink-muted);
    font-size: 10px; font-weight: 600;
    border-radius: 8px;
  }
  .bottom-nav a svg { width: 20px; height: 20px; }
  .bottom-nav a.active { color: var(--accent); }
}
