/* Palette & tokens — validated categorical palette from the dataviz skill.
   Light is the default (:root); dark applies via prefers-color-scheme AND
   a [data-theme] override so an explicit toggle always wins over the OS setting. */
:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --panel: #ffffff;
  --border: rgba(11, 11, 11, 0.10);
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --good: #006300;

  --series-1: #2a78d6; /* blue */
  --series-2: #eb6834; /* orange */
  --series-3: #1baf7a; /* aqua */
  --series-4: #eda100; /* yellow */
  --series-5: #e87ba4; /* magenta */
  --series-6: #008300; /* green */
  --series-7: #4a3aa7; /* violet */
  --series-8: #e34948; /* red */
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --panel: #17181c;
    --border: rgba(255, 255, 255, 0.10);
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --good: #0ca30c;

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --panel: #17181c;
  --border: rgba(255, 255, 255, 0.10);
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --baseline: #383835;
  --good: #0ca30c;

  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

code, .mono, .tabular { font-variant-numeric: tabular-nums; }

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

.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.login-card h1 { margin: 0 0 0.5rem; font-size: 1.4rem; text-align: center; }
.login-card label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; color: var(--text-secondary); }
.login-card input {
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.6rem;
  color: var(--text-primary);
  font: inherit;
}
.login-card button {
  background: var(--series-1);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0.6rem;
  font-weight: 600;
  cursor: pointer;
  font: inherit;
}
.login-error { color: var(--series-8); font-size: 0.85rem; margin: 0; }

/* ---------- Dashboard shell ---------- */

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

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.brand { font-size: 1.1rem; font-weight: 700; padding: 0 0.5rem; }
.brand span { color: var(--series-1); }

.nav { display: flex; flex-direction: column; gap: 0.15rem; }
.nav a {
  color: var(--text-secondary);
  text-decoration: none;
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  font-size: 0.9rem;
}
.nav a:hover { background: var(--page); color: var(--text-primary); }
.nav a.active { background: var(--series-1); color: #fff; }

.sidebar-footer { margin-top: auto; }
.logout-form button {
  width: 100%;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 6px;
  padding: 0.5rem;
  cursor: pointer;
  font: inherit;
  font-size: 0.85rem;
}
.logout-form button:hover { color: var(--text-primary); border-color: var(--text-muted); }

.main { flex: 1; padding: 1.75rem 2rem; max-width: 1200px; }
.page-title { font-size: 1.3rem; font-weight: 700; margin: 0 0 1.25rem; }

/* ---------- Stat tiles ---------- */

.tile-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.tile {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.1rem;
}
.tile .label { font-size: 0.78rem; color: var(--text-secondary); margin-bottom: 0.35rem; }
.tile .value { font-size: 1.6rem; font-weight: 600; }
.tile .sub { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.25rem; }

/* ---------- Chart cards ---------- */

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: 1.25rem;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.1rem 1.25rem;
  overflow-x: auto;
}
.card h2 { font-size: 0.95rem; font-weight: 600; margin: 0 0 0.9rem; }
.card .chart-wrap { position: relative; height: 260px; }
.card .chart-wrap.tall { height: 340px; }
.card .empty { color: var(--text-muted); font-size: 0.85rem; padding: 2rem 0; text-align: center; }

.bucket-toggle { display: inline-flex; gap: 0.25rem; margin-bottom: 1rem; }
.bucket-toggle button {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 6px;
  padding: 0.3rem 0.7rem;
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}
.bucket-toggle button.active { background: var(--series-1); color: #fff; border-color: var(--series-1); }

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

table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { text-align: left; padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--grid); }
th { color: var(--text-secondary); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.02em; }
tbody tr:hover { background: var(--page); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
a.row-link { color: inherit; text-decoration: none; display: block; }
a.row-link:hover { color: var(--series-1); }

.pagination { display: flex; gap: 0.5rem; margin-top: 1rem; align-items: center; font-size: 0.85rem; }
.pagination button {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: 6px;
  padding: 0.3rem 0.7rem;
  cursor: pointer;
  font: inherit;
}
.pagination button:disabled { opacity: 0.4; cursor: default; }

/* ---------- Calendar heatmap ---------- */

.calendar-year-picker { display: flex; gap: 0.4rem; margin-bottom: 1.25rem; }
.calendar-year-picker button {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 6px;
  padding: 0.3rem 0.7rem;
  font: inherit;
  cursor: pointer;
}
.calendar-year-picker button.active { background: var(--series-1); color: #fff; border-color: var(--series-1); }

.heatmap-grid {
  display: grid;
  grid-template-rows: repeat(7, 12px);
  grid-auto-flow: column;
  grid-auto-columns: 12px;
  gap: 3px;
  overflow-x: auto;
  padding-bottom: 0.5rem;
}
.heatmap-cell {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  background: var(--grid);
}
.heatmap-legend { display: flex; align-items: center; gap: 0.3rem; margin-top: 0.75rem; font-size: 0.75rem; color: var(--text-muted); }
.heatmap-legend .heatmap-cell { width: 10px; height: 10px; }

/* ---------- Records ---------- */

.record-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}
.record-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.1rem 1.25rem;
}
.record-card .label { font-size: 0.78rem; color: var(--text-secondary); margin-bottom: 0.4rem; }
.record-card .value { font-size: 1.4rem; font-weight: 600; }
.record-card .meta { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.3rem; }
.record-card a { color: inherit; text-decoration: none; }
.record-card a:hover .value { color: var(--series-1); }

/* ---------- Recent sessions ---------- */

.session-list { display: flex; flex-direction: column; gap: 1rem; }

.session-card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--pool-accent, var(--series-1));
  border-radius: 12px;
  padding: 1.1rem 1.35rem 1.25rem;
  display: block;
  color: inherit;
  text-decoration: none;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.session-card:hover {
  transform: translateY(-2px);
  border-color: var(--pool-accent, var(--series-1));
  box-shadow: 0 10px 24px -12px rgba(0, 0, 0, 0.5);
}

.session-card .session-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 1rem;
}
.session-card .session-date-block { display: flex; align-items: baseline; gap: 0.5rem; }
.session-card .session-date { font-weight: 700; font-size: 1.05rem; }
.session-card .session-relative { font-size: 0.78rem; color: var(--text-muted); }
.session-card .session-badge {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--pool-accent, var(--series-1));
  background: color-mix(in srgb, var(--pool-accent, var(--series-1)) 14%, transparent);
  border-radius: 999px;
  padding: 0.25rem 0.75rem;
  white-space: nowrap;
}

.session-hero {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 1.1rem;
  padding-bottom: 1rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--grid);
}
.session-hero .stat .label { font-size: 0.74rem; color: var(--text-secondary); margin-bottom: 0.3rem; }
.session-hero .stat .value { font-size: 1.55rem; font-weight: 700; line-height: 1.1; }

.session-secondary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 0.85rem;
}
.session-secondary .stat .label { font-size: 0.7rem; color: var(--text-secondary); margin-bottom: 0.2rem; }
.session-secondary .stat .value { font-size: 0.92rem; font-weight: 600; color: var(--text-secondary); }

.delta-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.72rem;
  font-weight: 600;
  border-radius: 999px;
  padding: 0.12rem 0.5rem;
  margin-top: 0.35rem;
}
.delta-good { color: var(--good); background: color-mix(in srgb, var(--good) 15%, transparent); }
.delta-bad { color: var(--series-8); background: color-mix(in srgb, var(--series-8) 15%, transparent); }
.delta-neutral { color: var(--text-muted); background: var(--page); }

/* ---------- Workout detail ---------- */

.detail-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 1.25rem; flex-wrap: wrap; gap: 0.5rem; }
.detail-header .back { font-size: 0.85rem; color: var(--text-secondary); text-decoration: none; }
.detail-header .back:hover { color: var(--text-primary); }

/* ---------- IA Manodou assistant widget ---------- */

.assistant-fab {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: linear-gradient(145deg, var(--series-1), var(--series-7));
  box-shadow: 0 8px 24px -6px rgba(0, 0, 0, 0.5);
  font-size: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.assistant-fab:hover { transform: scale(1.07); box-shadow: 0 10px 28px -6px rgba(0, 0, 0, 0.6); }
.assistant-fab .assistant-fab-dot {
  position: absolute;
  top: 2px; right: 2px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--good);
  border: 2px solid var(--page);
}

.assistant-panel {
  position: fixed;
  right: 1.5rem;
  bottom: 5.75rem;
  width: 380px;
  max-width: calc(100vw - 2.5rem);
  height: 560px;
  max-height: calc(100vh - 8rem);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 20px 48px -12px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 1000;
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.assistant-panel.open { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }

.assistant-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(145deg, color-mix(in srgb, var(--series-1) 16%, var(--panel)), var(--panel));
}
.assistant-header .avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--series-1), var(--series-7));
  display: flex; align-items: center; justify-content: center;
  font-size: 17px;
  flex-shrink: 0;
}
.assistant-header .titles { flex: 1; min-width: 0; }
.assistant-header .name { font-weight: 700; font-size: 0.9rem; }
.assistant-header .status { font-size: 0.72rem; color: var(--text-muted); }
.assistant-header .status.online::before { content: "● "; color: var(--good); }
.assistant-header .status.standby::before { content: "● "; color: var(--series-4); }
.assistant-header .status.offline::before { content: "● "; color: var(--series-8); }
.assistant-close {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  font-size: 1.1rem; padding: 0.2rem 0.4rem; border-radius: 6px;
}
.assistant-close:hover { color: var(--text-primary); background: var(--page); }

.assistant-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
.assistant-msg { max-width: 85%; font-size: 0.85rem; line-height: 1.45; padding: 0.55rem 0.8rem; border-radius: 12px; white-space: pre-wrap; }
.assistant-msg.user { align-self: flex-end; background: var(--series-1); color: #fff; border-bottom-right-radius: 3px; }
.assistant-msg.assistant { align-self: flex-start; background: var(--page); color: var(--text-primary); border: 1px solid var(--border); border-bottom-left-radius: 3px; }
.assistant-msg.thinking { align-self: flex-start; color: var(--text-muted); font-style: italic; }
.assistant-msg.error { align-self: center; color: var(--series-8); font-size: 0.78rem; text-align: center; }

.assistant-suggestion {
  align-self: flex-start;
  background: none;
  border: 1px solid var(--series-1);
  color: var(--series-1);
  border-radius: 999px;
  padding: 0.4rem 0.9rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}
.assistant-suggestion:hover { background: color-mix(in srgb, var(--series-1) 12%, transparent); }

.assistant-input-row {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid var(--border);
}
.assistant-input-row input {
  flex: 1;
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.55rem 0.9rem;
  color: var(--text-primary);
  font: inherit;
  font-size: 0.85rem;
}
.assistant-input-row button {
  background: var(--series-1);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 38px; height: 38px;
  flex-shrink: 0;
  cursor: pointer;
  font-size: 1rem;
}
.assistant-input-row button:disabled { opacity: 0.5; cursor: default; }
