/* Dashboard de trail running - mobile first.
   Paleta de series validada para daltonismo (orden de slots fijo). */

:root {
  color-scheme: light;
  --plane: #f9f9f7;
  --surface: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6;   /* azul   - metrica principal */
  --series-2: #eb6834;   /* naranja- metrica secundaria */
  --series-3: #1baf7a;   /* aqua   */
  --series-4: #eda100;   /* amarillo */
  --series-5: #e87ba4;   /* magenta */
  --zone-1: #86b6ef;     /* rampa ordinal azul (zonas de FC: categorias ordenadas) */
  --zone-2: #5598e7;
  --zone-3: #2a78d6;
  --zone-4: #1c5cab;
  --zone-5: #104281;
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --up: #006300;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --plane: #0d0d0d;
    --surface: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --zone-1: #9ec5f4;
    --zone-2: #6da7ec;
    --zone-3: #3987e5;
    --zone-4: #256abf;
    --zone-5: #184f95;
    --up: #0ca30c;
    --shadow: none;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --plane: #0d0d0d;
  --surface: #1a1a19;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --zone-1: #9ec5f4;
  --zone-2: #6da7ec;
  --zone-3: #3987e5;
  --zone-4: #256abf;
  --zone-5: #184f95;
  --up: #0ca30c;
  --shadow: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
  background: var(--plane);
  color: var(--text-primary);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

h1, h2 { margin: 0; font-weight: 600; }
h1 { font-size: 1.1rem; letter-spacing: -0.01em; }
h2 { font-size: 0.95rem; }

.app-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px calc(12px);
  padding-top: calc(14px + env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.sync-info { margin: 2px 0 0; font-size: 0.75rem; color: var(--text-muted); }

.icon-btn {
  background: none; border: 1px solid var(--border); border-radius: 8px;
  color: var(--text-secondary); font-size: 1rem; width: 36px; height: 36px;
  cursor: pointer; flex: 0 0 auto;
}

.banner {
  margin: 12px 16px 0; padding: 10px 12px; border-radius: 10px;
  font-size: 0.82rem; line-height: 1.4;
  background: color-mix(in srgb, var(--warning) 14%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--warning) 45%, var(--border));
  color: var(--text-primary);
}
.banner.is-error {
  background: color-mix(in srgb, var(--critical) 12%, var(--surface));
  border-color: color-mix(in srgb, var(--critical) 45%, var(--border));
}

main { padding: 12px 16px 24px; max-width: 780px; margin: 0 auto; }

/* --- tiles --- */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
@media (min-width: 620px) { .tiles { grid-template-columns: repeat(4, 1fr); } }

.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px; box-shadow: var(--shadow);
}
.tile-label { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.tile-value { font-size: 1.55rem; font-weight: 600; line-height: 1.15; margin-top: 4px; }
.tile-value small { font-size: 0.8rem; font-weight: 500; color: var(--text-secondary); margin-left: 2px; }
.tile-delta { font-size: 0.75rem; margin-top: 3px; color: var(--text-secondary); }
.tile-delta.up { color: var(--up); }
.tile-delta.down { color: var(--critical); }

/* --- cards & charts --- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.card-sub { margin: 2px 0 0; font-size: 0.76rem; color: var(--text-muted); }

.ghost-btn {
  background: none; border: 1px solid var(--border); border-radius: 999px;
  color: var(--text-secondary); font-size: 0.74rem; padding: 4px 10px; cursor: pointer;
  min-height: 28px; flex: 0 0 auto;
}
.ghost-btn[aria-pressed="true"] { background: var(--grid); color: var(--text-primary); }

.chart-box { position: relative; height: 220px; }
.chart-box--auto { height: 200px; }

.table-view { margin-top: 10px; max-height: 260px; overflow: auto; }
.table-view table { width: 100%; border-collapse: collapse; font-size: 0.78rem; font-variant-numeric: tabular-nums; }
.table-view th, .table-view td { text-align: right; padding: 5px 6px; border-bottom: 1px solid var(--grid); }
.table-view th:first-child, .table-view td:first-child { text-align: left; }
.table-view th { color: var(--text-muted); font-weight: 500; position: sticky; top: 0; background: var(--surface); }

/* --- filtros --- */
.filter-row { display: flex; gap: 10px; margin-bottom: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; flex: 1; font-size: 0.72rem; color: var(--text-muted); }
.field select {
  font: inherit; font-size: 0.88rem; color: var(--text-primary);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 9px; padding: 9px 10px; min-height: 40px;
}
.filter-summary { margin: 0 0 12px; font-size: 0.78rem; color: var(--text-secondary); }

/* --- lista de actividades --- */
.activity-list { display: flex; flex-direction: column; gap: 8px; }
.activity {
  display: grid; grid-template-columns: 4px 1fr auto; gap: 10px; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 12px; cursor: pointer; text-align: left; font: inherit; color: inherit;
  width: 100%; box-shadow: var(--shadow);
}
.activity:hover { border-color: var(--axis); }
.activity-accent { width: 4px; height: 34px; border-radius: 2px; background: var(--series-1); }
.activity-name { display: block; font-weight: 600; font-size: 0.9rem; }
.activity-meta { display: block; font-size: 0.76rem; color: var(--text-muted); margin-top: 2px; }
.activity-main { text-align: right; font-variant-numeric: tabular-nums; }
.activity-km { display: block; font-weight: 600; font-size: 0.95rem; }
.activity-sub { display: block; font-size: 0.74rem; color: var(--text-muted); margin-top: 2px; }
.empty { color: var(--text-muted); font-size: 0.85rem; padding: 24px 0; text-align: center; }

/* --- records --- */
.records-list { display: flex; flex-direction: column; }
.record-row {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--grid);
}
.record-row:last-child { border-bottom: none; }
.record-label { font-size: 0.88rem; }
.record-date { font-size: 0.72rem; color: var(--text-muted); }
.record-value { font-weight: 600; font-variant-numeric: tabular-nums; }

/* --- tabbar --- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  background: none; border: none; cursor: pointer; padding: 9px 2px 10px;
  font: inherit; font-size: 0.66rem; color: var(--text-muted);
  display: flex; flex-direction: column; align-items: center; gap: 3px; min-height: 56px;
}
.tab span { font-size: 1.05rem; line-height: 1; }
.tab.is-active { color: var(--series-1); }

/* --- detalle --- */
.detail {
  position: fixed; inset: 0; z-index: 40; background: var(--plane);
  overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.detail-head {
  display: flex; gap: 12px; align-items: center;
  padding: 14px 16px; padding-top: calc(14px + env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.detail-body { padding: 12px 16px 32px; max-width: 780px; margin: 0 auto; }
.map { height: 260px; border-radius: 12px; overflow: hidden; margin-bottom: 14px; border: 1px solid var(--border); }
.leaflet-container { background: var(--grid); font: inherit; }
