/* Apnea Log app. Colours are roles (CSS variables) with light and dark values. */

/* ---- theme --------------------------------------------------------------------------- */
.viz-root {
  color-scheme: light;
  --surface-0: #f3f2ef;
  --surface-1: #fcfcfb;
  --border: #e2e1dc;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #7a7974;
  --grid: #e9e8e4;
  --series-1: #2a78d6;
  --series-1-soft: rgba(42, 120, 214, .14);
  --series-2: #eb6834;
  --series-2-soft: rgba(235, 104, 52, .12);
  --series-3: #1baf7a;
  --series-4: #eda100;
  --good: #008300;
  --warning: #b86e00;
  --critical: #d03b3b;
  --neutral: #a3a29c;
  --good-soft: rgba(0, 131, 0, .08);
  --swim: var(--series-3);
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .viz-root {
    color-scheme: dark;
    --surface-0: #111110;
    --surface-1: #1a1a19;
    --border: #2e2e2c;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #8f8e86;
    --grid: #2a2a28;
    --series-1: #3987e5;
    --series-1-soft: rgba(57, 135, 229, .20);
    --series-2: #d95926;
    --series-2-soft: rgba(217, 89, 38, .16);
    --series-3: #199e70;
    --series-4: #c98500;
    --good: #0ca30c;
    --warning: #d9952a;
    --critical: #e66767;
    --neutral: #6b6a64;
    --good-soft: rgba(12, 163, 12, .12);
  }
}
:root[data-theme="dark"] .viz-root {
  color-scheme: dark;
  --surface-0: #111110;
  --surface-1: #1a1a19;
  --border: #2e2e2c;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #8f8e86;
  --grid: #2a2a28;
  --series-1: #3987e5;
  --series-1-soft: rgba(57, 135, 229, .20);
  --series-2: #d95926;
  --series-2-soft: rgba(217, 89, 38, .16);
  --series-3: #199e70;
  --series-4: #c98500;
  --good: #0ca30c;
  --warning: #d9952a;
  --critical: #e66767;
  --neutral: #6b6a64;
  --good-soft: rgba(12, 163, 12, .12);
}

/* ---- base ---------------------------------------------------------------------------- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.viz-root { min-height: 100vh; background: var(--surface-0); color: var(--text-primary); }
h2 { margin: 0 0 2px; font-size: 15px; }
ol { margin: 6px 0; padding-left: 20px; }
li { margin: 4px 0; }

/* ---- header and navigation ----------------------------------------------------------- */
header { display: flex; flex-wrap: wrap; align-items: baseline; gap: 12px; padding: 14px 18px; }
header h1 { margin: 0; font-size: 20px; }
header .sub { color: var(--text-secondary); font-size: 13px; }
nav { display: flex; flex-wrap: wrap; gap: 4px; margin-left: auto; }
nav a { padding: 6px 10px; border-radius: 8px; color: var(--text-secondary); font-size: 14px; text-decoration: none; }
nav a[aria-current="page"] { background: var(--series-1-soft); color: var(--text-primary); }

/* ---- layout -------------------------------------------------------------------------- */
main { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 16px; padding: 0 18px 24px; }
main > * { min-width: 0; }
.page { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; max-width: 760px; padding: 0 18px 24px; }
.page > *, .card { min-width: 0; }
.card { padding: 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-1); }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.note { margin: 0 0 8px; color: var(--text-muted); font-size: 12.5px; }
.empty { padding: 30px 0; color: var(--text-secondary); text-align: center; }
@media (max-width: 760px) {
  main { grid-template-columns: minmax(0, 1fr); }
  .list { max-height: 30vh; }
}
/* phones: narrower margins, text in tables and verdicts may wrap, wide tables scroll inside their card */
@media (max-width: 520px) {
  header { padding: 10px 12px; }
  main, .page { padding: 0 10px 20px; }
  .card { padding: 12px; }
  .page th, .page td { white-space: normal; padding: 6px 5px; }
  .verdict b { white-space: normal; }
  table.trend td.delta { white-space: nowrap; }
}

/* ---- training list ------------------------------------------------------------------- */
.owner { width: 100%; margin-bottom: 8px; }
.list { display: flex; flex-direction: column; gap: 6px; max-height: 80vh; overflow: auto; }
.list button { all: unset; padding: 8px 10px; border: 1px solid transparent; border-radius: 8px; cursor: pointer; }
.list button:hover, .list button:focus-visible { border-color: var(--border); }
.list button[aria-current="true"] { background: var(--series-1-soft); }
.list .date { font-weight: 600; }
.list .meta { color: var(--text-secondary); font-size: 13px; }

/* ---- training detail ----------------------------------------------------------------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 14px; }
.tile .value { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; }
.tile .label { color: var(--text-secondary); font-size: 13px; }
.charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
.charts > * { min-width: 0; }
@media (max-width: 1100px) { .charts { grid-template-columns: minmax(0, 1fr); } }
.charts > .wide { grid-column: 1 / -1; }
#map { height: 360px; border-radius: 8px; }
.dive-pin span {
  display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid #fff; color: #fff; font: 600 11px system-ui, sans-serif; box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
}
.map-error { padding: 20px 0; }

/* ---- charts and tooltip -------------------------------------------------------------- */
svg.chart { display: block; width: 100%; height: auto; overflow: visible; }
svg.chart text { fill: var(--text-muted); font-size: 11px; }
svg.chart text.mark-label { fill: var(--text-secondary); }
svg.chart text.badge-label { fill: var(--text-primary); font-weight: 600; }
svg.chart text.mark-warning { fill: var(--warning); font-weight: 700; font-size: 12px; }
.legend b.mark { color: var(--warning); font-weight: 700; }
.legend i.tick { width: 12px; height: 2px; border-radius: 0; background: var(--text-primary); }
.legend i.kick { width: 3px; height: 14px; border-radius: 1.5px; }
.legend i.glide { width: 14px; height: 0; border-top: 2px dotted var(--neutral); border-radius: 0; }
.verdict { display: flex; align-items: baseline; gap: 6px; margin: 0 0 8px; font-size: 14px; }
.verdict b { flex: none; white-space: nowrap; }
.verdict i { flex: none; display: inline-block; width: 9px; height: 9px; border-radius: 50%; transform: translateY(-1px); }
.facts { display: grid; grid-template-columns: 1fr auto; gap: 6px 14px; margin: 4px 0 0; font-size: 14px; }
.facts dt { color: var(--text-secondary); }
.facts dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 2px 0 6px; color: var(--text-secondary); font-size: 12.5px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.legend i { flex: none; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; }
.tip {
  position: fixed; z-index: 10; display: none; pointer-events: none;
  padding: 6px 9px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-1); color: var(--text-primary); font-size: 13px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .15);
}
.tip b { font-variant-numeric: tabular-nums; }
.tip span { color: var(--text-secondary); }

/* ---- table --------------------------------------------------------------------------- */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
th { color: var(--text-secondary); font-weight: 500; }
th:first-child, td:first-child { text-align: left; }
tbody tr { cursor: pointer; }
tbody tr:hover, tbody tr[aria-selected="true"] { background: var(--series-1-soft); }
.badge { display: inline-flex; align-items: center; gap: 4px; }
.badge i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }

/* ---- forms --------------------------------------------------------------------------- */
input.text, select {
  padding: 9px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-1); color: var(--text-primary); font: inherit;
}
button.primary { padding: 9px 14px; border: 0; border-radius: 8px; background: var(--series-1); color: #fff; font: inherit; cursor: pointer; }
button.link { all: unset; color: var(--series-1); font-size: 14px; cursor: pointer; }
.code { font: 600 22px ui-monospace, monospace; letter-spacing: 2px; }
.error { color: var(--critical); font-size: 14px; }
.ok { color: var(--good); font-size: 14px; }
.download { display: block; margin: 6px 0; color: var(--series-1); }

/* ---- theme switch, progress page ------------------------------------------------------ */
select.theme { padding: 5px 8px; font-size: 13px; }
h2.page-title, .page-title { margin: 0 0 4px; font-size: 18px; }
h3.section { margin: 18px 0 8px; font-size: 15px; color: var(--text-secondary); font-weight: 600; }
.tile.link { cursor: pointer; }
.tile.link:hover { border-color: var(--series-1); }
.tile .when { color: var(--text-muted); font-size: 12px; }
.verdict.big { font-size: 16px; font-weight: 600; margin: 4px 0 10px; }
table.trend td { text-align: left; }
table.trend td.delta { text-align: right; }
.page .charts { grid-template-columns: minmax(0, 1fr); }
.page.wide { max-width: 1180px; }
.page.wide .charts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 1000px) { .page.wide .charts { grid-template-columns: minmax(0, 1fr); } }

/* ---- upload from files ----------------------------------------------------------------- */
dl.how { display: grid; grid-template-columns: max-content 1fr; gap: 6px 12px; margin: 10px 0 14px; font-size: 14px; }
dl.how dt { font-weight: 600; }
dl.how dd { margin: 0; color: var(--text-secondary); }
.dropzone { display: grid; gap: 4px; place-items: center; padding: 26px 12px; border: 2px dashed var(--border); border-radius: 10px; cursor: pointer; text-align: center; }
.dropzone span { color: var(--text-muted); font-size: 13px; }
.dropzone:hover, .dropzone:focus-visible, .dropzone.over { border-color: var(--series-1); background: var(--series-1-soft); }
.imports { display: grid; gap: 10px; margin: 12px 0; }
.import { display: grid; gap: 6px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; }
.import .file { font-weight: 600; word-break: break-all; }
.import .found { color: var(--text-secondary); font-size: 14px; }
.import button[disabled] { opacity: .5; cursor: default; }

/* ---- certifications (progress page) ---------------------------------------------------- */
table.certs { width: 100%; margin: 12px 0 4px; table-layout: fixed; }
table.certs th:first-child { width: 22%; }
table.certs td.none { color: var(--text-muted); }
table.certs th, table.certs td { text-align: left; vertical-align: top; }
table.certs th:first-child { color: var(--text-primary); }
table.certs td:first-child { white-space: nowrap; }
table.certs .badge.passed { margin-left: 8px; color: var(--text-secondary); font-size: 12px; }
.cert-value { font-variant-numeric: tabular-nums; }
.cert-value span { color: var(--text-muted); font-size: 12px; }
.meter { height: 5px; margin-top: 4px; border-radius: 3px; background: var(--border); overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: 3px; }
.card.insights { margin-bottom: 12px; }
.card.insights .verdict { font-size: 15px; flex-wrap: wrap; }
.card.insights .verdict b { white-space: normal; }

/* ---- goal (progress page) ---------------------------------------------------------------- */
.goal-title { font-weight: 600; margin-bottom: 6px; }
.meter.goal { height: 8px; margin: 6px 0 10px; }
.goal-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.goal-form .error { flex-basis: 100%; margin: 0; }

/* ---- training note ------------------------------------------------------------------------ */
.note-card { margin-bottom: 12px; }
.note-text { margin: 4px 0 8px; white-space: pre-wrap; }
.note-form { display: grid; gap: 8px; }
.note-form textarea { font: inherit; padding: 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-1); color: inherit; }

/* ---- plan (progress page) ------------------------------------------------------------------ */
table.plan { width: auto; margin: 6px 0 8px; }
table.plan td, table.plan th { text-align: left; }
.presets { display: grid; gap: 10px; }
.preset { display: grid; gap: 6px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; }
.preset button.primary { justify-self: start; }
input.num { width: 4em; }
.goal-by { flex-basis: 100%; font-size: 14px; }
.goal-by summary { cursor: pointer; color: var(--series-1); }
.goal-by .note { margin: 6px 0; }

/* ---- goal suggestions --------------------------------------------------------------------- */
.ideas { display: grid; gap: 8px; }
.advice { display: grid; gap: 6px; padding: 10px 12px; border: 1px solid var(--series-1); border-radius: 8px; background: var(--series-1-soft); font-size: 14px; }
.advice .note { margin: 0; }
ul.goal-ideas { margin: 0; padding-left: 18px; display: grid; gap: 4px; font-size: 14px; }
ul.goal-ideas button.link { margin-left: 8px; }
.goal-own { font-size: 14px; margin-top: 8px; }
.goal-own summary { cursor: pointer; color: var(--series-1); margin-bottom: 6px; }

/* ---- plan steps ---------------------------------------------------------------------------- */
ol.steps { margin: 4px 0 8px; padding-left: 20px; display: grid; gap: 4px; font-size: 14px; }
.preset details summary { cursor: pointer; color: var(--series-1); font-size: 14px; }
table.tech { margin-top: 10px; }
table.tech th { white-space: normal; vertical-align: bottom; }
.card:has(table.tech) { overflow-x: auto; }
