/* Metashare Tracker — plain CSS, no framework, mobile-first.
   Color roles follow the studio's validated data-viz palette so charts and
   UI chrome share one system in both themes. */

:root {
  color-scheme: light;
  --bg: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f2f1ee;
  --text: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --border: #e1e0d9;
  --border-strong: #c3c2b7;
  --accent: #2a78d6;
  --accent-wash: rgba(42, 120, 214, 0.10);
  --good: #0ca30c;
  --critical: #d03b3b;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232322;
    --text: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --border: #2c2c2a;
    --border-strong: #383835;
    --accent: #3987e5;
    --accent-wash: rgba(57, 135, 229, 0.14);
    --good: #0ca30c;
    --critical: #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232322;
  --text: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --border: #2c2c2a;
  --border-strong: #383835;
  --accent: #3987e5;
  --accent-wash: rgba(57, 135, 229, 0.14);
  --good: #0ca30c;
  --critical: #e66767;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 68px;
}

a { color: inherit; }

.app-header {
  padding: 20px 16px 8px;
}
.app-header h1 {
  margin: 0 0 2px;
  font-size: 1.4rem;
}
.subtitle {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.88rem;
}

.app-main {
  padding: 8px 16px 24px;
  max-width: 900px;
  margin: 0 auto;
}

/* Bottom nav on phones, top nav on wide screens */
.app-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-around;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
  z-index: 20;
}
.nav-item {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.78rem;
  text-align: center;
  padding: 4px 6px;
}
.nav-item.active { color: var(--accent); font-weight: 600; }

@media (min-width: 768px) {
  body { padding-bottom: 0; }
  .app-nav {
    position: static;
    justify-content: flex-start;
    gap: 4px;
    border-top: none;
    border-bottom: 1px solid var(--border);
    padding: 10px 16px;
  }
  .nav-item { font-size: 0.85rem; padding: 6px 10px; border-radius: 6px; }
  .nav-item.active { background: var(--accent-wash); }
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.card + .card { margin-top: 12px; }
.card h2 { margin: 0 0 10px; font-size: 1.02rem; }
.card h3 { margin: 0 0 8px; font-size: 0.92rem; color: var(--text-secondary); }

/* Buttons & inputs */
button, .btn {
  font: inherit;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
button:disabled { opacity: 0.5; cursor: default; }
button.secondary, .btn.secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
}
button.danger { background: var(--critical); }

input[type="text"], input[type="date"], input[type="number"], input[type="url"], select {
  font: inherit;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
label { font-size: 0.82rem; color: var(--text-secondary); display: block; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

/* Autocomplete / combobox */
.combo { position: relative; }
.combo-list {
  position: absolute;
  left: 0; right: 0; top: calc(100% + 4px);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  max-height: 220px;
  overflow-y: auto;
  z-index: 10;
  box-shadow: 0 6px 20px rgba(0,0,0,0.15);
}
.combo-list button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  color: var(--text);
  border-radius: 0;
  padding: 9px 12px;
}
.combo-list button:hover, .combo-list button.hl { background: var(--accent-wash); }
.combo-list .create-new { color: var(--accent); font-weight: 600; border-top: 1px solid var(--border); }

/* Filter row (date-range presets) */
.filter-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 14px;
}
.filter-row .presets { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  font-size: 0.8rem;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Deck list / metashare bars */
.deck-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
}
.deck-row:last-child { border-bottom: none; }
.deck-thumb {
  width: 44px; height: 44px;
  border-radius: 8px;
  flex-shrink: 0;
  background-size: cover;
  background-position: center;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 1rem;
}
.deck-row-main { flex: 1; min-width: 0; }
.deck-row-name { font-weight: 600; font-size: 0.92rem; }
.deck-row-sub { font-size: 0.76rem; color: var(--text-muted); }
.bar-track {
  height: 8px;
  border-radius: 4px;
  background: var(--surface-2);
  margin-top: 6px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
}
.deck-row-pct {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 1rem;
  width: 56px;
  text-align: right;
  flex-shrink: 0;
}

/* Deck banner (detail page hero image / placeholder gradient) */
.deck-banner {
  height: 140px;
  border-radius: var(--radius);
  background-size: cover;
  background-position: center;
  display: flex; align-items: flex-end;
  color: #fff;
  padding: 14px;
  margin-bottom: 12px;
}
.deck-banner h1 { margin: 0; font-size: 1.3rem; text-shadow: 0 1px 6px rgba(0,0,0,0.4); }

/* Stat tiles */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}
.stat-tile .label { font-size: 0.76rem; color: var(--text-secondary); }
.stat-tile .value { font-size: 1.5rem; font-weight: 700; margin-top: 2px; }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); }
th { color: var(--text-secondary); font-weight: 600; font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.02em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: var(--surface-2); }

/* Charts (SVG, built by js/charts.js) */
.chart-wrap { position: relative; }
.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.78rem;
  box-shadow: 0 6px 20px rgba(0,0,0,0.18);
  white-space: nowrap;
  z-index: 5;
  opacity: 0;
  transition: opacity 0.08s;
}
.chart-tooltip.show { opacity: 1; }
.chart-tooltip .tt-value { font-weight: 700; font-variant-numeric: tabular-nums; }
.chart-tooltip .tt-label { color: var(--text-secondary); }
.empty-note { color: var(--text-muted); font-size: 0.86rem; padding: 10px 0; }

/* Player/pilot chips */
.pilot-list { display: flex; flex-direction: column; gap: 0; }
.pilot-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0; border-bottom: 1px solid var(--border);
}
.pilot-row:last-child { border-bottom: none; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--surface-2); color: var(--text);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.78rem; font-weight: 700; flex-shrink: 0;
}
.pill {
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-secondary);
}
.pill.good { background: color-mix(in srgb, var(--good) 16%, transparent); color: var(--good); }

.section-title {
  display: flex; align-items: center; justify-content: space-between;
  margin: 18px 0 8px;
}
.section-title h2 { margin: 0; font-size: 1rem; }

.standings-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.standings-rank {
  width: 28px; text-align: center; font-weight: 700; color: var(--text-muted);
  flex-shrink: 0;
}
.remove-btn {
  background: none; border: none; color: var(--text-muted); font-size: 1.1rem;
  padding: 4px 8px; cursor: pointer;
}

.toast {
  position: fixed;
  bottom: 78px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 999px;
  font-size: 0.84rem;
  z-index: 30;
  opacity: 0; pointer-events: none;
  transition: opacity 0.15s;
}
.toast.show { opacity: 1; }
@media (min-width: 768px) { .toast { bottom: 20px; } }

