:root {
  --bg: #f4f6f5; --card: #fff; --ink: #17201d; --muted: #66716d; --line: #e2e7e5;
  --pri: #0f766e; --pri-ink: #fff; --pri-soft: #e0f2ef; --danger: #b91c1c; --warn: #b45309; --warn-soft: #fef3c7; --ok-soft: #dcfce7;
  --r: 12px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  --c-easy: #16a34a; --c-long: #2563eb; --c-tempo: #ea580c; --c-intervals: #dc2626; --c-hills: #a16207;
  --c-recovery: #0d9488; --c-race: #7c3aed; --c-strength: #475569; --c-crosstrain: #0891b2; --c-rest: #9ca3af;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1413; --card: #182120; --ink: #e7ecea; --muted: #93a09b; --line: #2a3533;
    --pri: #2dd4bf; --pri-ink: #06201c; --pri-soft: #133a35; --warn-soft: #3a2c0c; --ok-soft: #12351f;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); }
a { color: var(--pri); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }
code { background: var(--pri-soft); padding: 1px 5px; border-radius: 4px; }

/* ---------- layout ---------- */
.topbar { display: flex; align-items: center; gap: 1rem; padding: .6rem 1.25rem; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--ink); font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.brand.big { font-size: 1.4rem; justify-content: center; margin-bottom: 1rem; }
.logo { width: 26px; height: 26px; border-radius: 7px; background: var(--pri) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M9 22l5-12 4 8 3-5 3 9' stroke='white' stroke-width='2.6' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/100% no-repeat; }
.topbar nav { display: flex; gap: .25rem; margin-left: auto; flex-wrap: wrap; }
.topbar nav a { padding: .4rem .7rem; border-radius: 8px; color: var(--muted); font-weight: 500; }
.topbar nav a:hover { background: var(--bg); text-decoration: none; color: var(--ink); }
.topbar nav a.active { background: var(--pri-soft); color: var(--pri); }
.menu-btn { display: none; margin-left: auto; background: none; border: 0; font-size: 1.4rem; color: var(--ink); cursor: pointer; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 1.25rem; }
.pagehead { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.1rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 1.1rem 1.2rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.narrow { max-width: 640px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .8rem; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .8rem; }
.grid2 > .card, .grid3 > .card { margin-bottom: 0; }
.grid2 + .card, .grid2 + section, .grid2 + .grid2 { margin-top: 1rem; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: .8rem; }
.grow { flex: 1; min-width: 140px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.scrollx { overflow-x: auto; }
.inline { display: inline; }

/* ---------- forms ---------- */
label { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; font-weight: 600; color: var(--muted); }
label.check, .checks label { flex-direction: row; align-items: center; gap: .4rem; font-weight: 500; color: var(--ink); }
.checks { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .55rem .7rem; width: 100%; min-width: 0; }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--pri); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--pri); outline-offset: -1px; border-color: transparent; }
.pagehead select { width: auto; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .3rem; padding: .5rem .95rem; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { text-decoration: none; border-color: var(--muted); }
.btn.primary { background: var(--pri); color: var(--pri-ink); border-color: var(--pri); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.sm { padding: .3rem .6rem; font-size: .82rem; }
.flash { padding: .7rem 1rem; border-radius: 10px; margin-bottom: 1rem; background: var(--ok-soft); }
.flash.err { background: #fee2e2; color: #7f1d1d; }
.flash.warn { background: var(--warn-soft); }
.pill { display: inline-block; font-size: .75rem; font-weight: 600; padding: .15rem .55rem; border-radius: 99px; background: var(--line); color: var(--ink); vertical-align: middle; }
.pill.ok { background: var(--ok-soft); color: #15803d; }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.race { background: #ede9fe; color: #6d28d9; }
.warn-text { color: var(--warn); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg a, .seg.radio span { padding: .35rem .7rem; color: var(--muted); font-weight: 600; font-size: .85rem; cursor: pointer; display: block; }
.seg a.on { background: var(--pri-soft); color: var(--pri); }
.seg.radio { align-self: flex-start; }
.seg.radio label { display: block; }
.seg.radio input { display: none; }
.seg.radio input:checked + span { background: var(--pri); color: var(--pri-ink); }
.rpe { display: flex; gap: 4px; flex-wrap: wrap; margin-top: .2rem; }
.rpe label { display: block; }
.rpe input { display: none; }
.rpe span { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line); color: var(--ink); font-weight: 600; cursor: pointer; }
.rpe input:checked + span { background: var(--pri); color: var(--pri-ink); border-color: var(--pri); }

/* ---------- tables ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: .5rem; border-bottom: 1px solid var(--line); }
.table td { padding: .55rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr.dim td { opacity: .5; }
.table tr.click { cursor: pointer; }
.table tr.click:hover td { background: var(--bg); }
.table .actions { white-space: nowrap; text-align: right; }

/* ---------- session types ---------- */
.t-easy { --tc: var(--c-easy); } .t-long { --tc: var(--c-long); } .t-tempo { --tc: var(--c-tempo); }
.t-intervals { --tc: var(--c-intervals); } .t-hills { --tc: var(--c-hills); } .t-recovery { --tc: var(--c-recovery); }
.t-race { --tc: var(--c-race); } .t-strength { --tc: var(--c-strength); } .t-crosstrain { --tc: var(--c-crosstrain); } .t-rest { --tc: var(--c-rest); }
.tag { display: inline-block; font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: .1rem .45rem; border-radius: 5px; color: #fff; background: var(--tc, var(--muted)); }

/* ---------- calendar ---------- */
.calnav { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.calrange { margin: 0 .5rem; }
.weekbar { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; font-size: .85rem; color: var(--muted); margin: .9rem 0 .4rem; }
.weekbar strong { color: var(--ink); }
.meter { display: inline-block; width: 140px; height: 7px; border-radius: 9px; background: var(--line); overflow: hidden; vertical-align: middle; }
.meter i { display: block; height: 100%; background: var(--pri); border-radius: 9px; }
.card .meter { width: 100%; margin: .4rem 0; }
.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.day { background: var(--card); border: 1px solid var(--line); border-radius: 10px; min-height: 130px; padding: 6px; display: flex; flex-direction: column; gap: 5px; transition: background .15s; }
.day.today { border-color: var(--pri); box-shadow: 0 0 0 1px var(--pri); }
.day.past { background: color-mix(in srgb, var(--card) 70%, var(--bg)); }
.day.drop { background: var(--pri-soft); }
.dayhead { display: flex; justify-content: space-between; align-items: center; font-size: .8rem; color: var(--muted); padding: 0 2px; }
.dayhead b { color: var(--ink); }
.dayhead .add { width: 22px; height: 22px; display: grid; place-items: center; border-radius: 6px; font-weight: 700; color: var(--muted); }
.dayhead .add:hover { background: var(--pri-soft); color: var(--pri); text-decoration: none; }
.sess { position: relative; display: flex; flex-direction: column; padding: 6px 7px 6px 9px; border-radius: 7px; background: color-mix(in srgb, var(--tc) 11%, var(--card)); border-left: 3px solid var(--tc); color: var(--ink); font-size: .8rem; line-height: 1.3; }
.sess:hover { text-decoration: none; background: color-mix(in srgb, var(--tc) 20%, var(--card)); }
.sess[draggable=true] { cursor: grab; }
.sess.dragging { opacity: .4; }
.stype { font-size: .66rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 700; color: var(--tc); display: flex; justify-content: space-between; }
.stitle { font-weight: 600; }
.smeta { color: var(--muted); font-size: .75rem; }
.st { font-size: .85rem; }
.sess.st-completed { background: color-mix(in srgb, var(--tc) 24%, var(--card)); }
.sess.st-skipped { opacity: .55; }
.sess.st-skipped .stitle { text-decoration: line-through; }
.sess .dot { position: absolute; top: 5px; right: 5px; width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.sess .dot + * {}
.tools { margin-top: 1.25rem; }

/* ---------- library ---------- */
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1rem; }
.chip { padding: .3rem .75rem; border-radius: 99px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font-size: .85rem; font-weight: 500; }
.chip:hover { text-decoration: none; border-color: var(--tc, var(--muted)); }
.chip.on { background: var(--tc, var(--pri)); color: #fff; border-color: transparent; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.tile { background: var(--card); border: 1px solid var(--line); border-top: 4px solid var(--tc); border-radius: var(--r); padding: 1rem; display: flex; flex-direction: column; gap: .3rem; }
.tile h3 { margin: .3rem 0 0; }
.tile p { margin: .2rem 0; flex: 1; }
.tile-head { display: flex; justify-content: space-between; align-items: center; }
.tile-actions { display: flex; gap: .4rem; margin-top: .4rem; }
.tile details summary { list-style: none; display: inline-flex; }
.tile details summary::-webkit-details-marker { display: none; }
.tile details[open] summary { margin-bottom: .6rem; }
.assign { padding: .7rem; background: var(--bg); border-radius: 8px; }

/* ---------- session ---------- */
.plan { border-left: 5px solid var(--tc); }
a.plan { display: block; color: var(--ink); }
a.plan:hover { text-decoration: none; border-color: var(--tc); }
.plan h1, .plan h3 { margin: .4rem 0 .2rem; }
.stats { display: flex; gap: 1.5rem; margin: 1rem 0; flex-wrap: wrap; }
.stats div { display: flex; flex-direction: column; }
.stats b { font-size: 1.2rem; }
.stats span { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.note { background: var(--pri-soft); padding: .7rem .9rem; border-radius: 8px; }
.fb { border-left: 4px solid var(--pri); }

/* ---------- dashboard ---------- */
.acards { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.acards .card { margin: 0; }
.ahead { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.ahead h2 { margin: 0; }
.ahead h2 a { color: var(--ink); }
.big { font-size: 2rem; font-weight: 700; letter-spacing: -.02em; margin-top: .4rem; }
.big small { font-size: .9rem; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.acard p { margin: .3rem 0; }
.line { display: grid; grid-template-columns: 52px auto 1fr auto; gap: .6rem; align-items: center; padding: .5rem .2rem; border-bottom: 1px solid var(--line); color: var(--ink); font-size: .88rem; }
.line:hover { background: var(--bg); text-decoration: none; }
.line .ld { color: var(--muted); font-size: .8rem; }
.line .lm { color: var(--muted); font-size: .8rem; text-align: right; }
.review { padding-bottom: .6rem; margin-bottom: .6rem; }
.review form { margin-top: .4rem; }
.quote { margin: .4rem 0 0; font-style: italic; color: var(--muted); font-size: .88rem; }
.today { margin-bottom: 1rem; }

/* ---------- progress ---------- */
.statgrid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.stat { margin: 0; display: flex; flex-direction: column; }
.stat b { font-size: 1.5rem; letter-spacing: -.02em; }
.stat span { color: var(--muted); font-size: .8rem; }
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .ax { fill: var(--muted); font-size: 11px; }
.chart .ax.now { fill: var(--pri); font-weight: 700; }
.chart .bar-plan { fill: var(--pri-soft); stroke: var(--pri); stroke-width: 1; stroke-dasharray: 3 2; }
.chart .bar-act { fill: var(--pri); }
.chart .pt { fill: var(--tc); fill-opacity: .8; stroke: var(--card); stroke-width: 1.5; }
.legend { display: flex; gap: .8rem; align-items: center; flex-wrap: wrap; font-size: .8rem; color: var(--muted); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; }
.lg-plan { background: var(--pri-soft); border: 1px dashed var(--pri); }
.lg-act { background: var(--pri); }
.dotlg { border-radius: 50% !important; background: var(--tc); }
.mapgrid { margin: .8rem 0; }

/* ---------- auth ---------- */
.auth-page { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.auth-card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 2rem; width: 100%; max-width: 420px; box-shadow: var(--shadow); }
.auth-card h1 { margin-bottom: 1rem; font-size: 1.4rem; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .week { grid-template-columns: 1fr; }
  .day { min-height: 0; flex-direction: column; }
  .day:not(.today) .dayhead { }
  .statgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .menu-btn { display: block; }
  .topbar { flex-wrap: wrap; }
  .topbar nav { display: none; width: 100%; flex-direction: column; margin: 0; }
  body.nav-open .topbar nav { display: flex; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .wrap { padding: 1rem; }
  .table .actions { white-space: normal; }
  .line { grid-template-columns: 44px 1fr auto; }
  .line .tag { display: none; }
  .meter { width: 90px; }
}
