/* Stride — editorial athletic journal.
   Warm paper, Fraunces display, Hanken Grotesk UI, coral (run) + teal (gym). */

:root {
  /* palette */
  --paper:    #f4efe6;
  --paper-2:  #fbf8f2;
  --card:     #fffdf9;
  --ink:      #1d1a15;
  --ink-2:    #4a453c;
  --ink-3:    #857d70;
  --line:     rgba(29,26,21,.10);
  --line-2:   rgba(29,26,21,.06);

  --run:   #e8543a;  /* running / coral */
  --gym:   #2f7d6e;  /* gym / teal */
  --cycle: #d38b1f;  /* amber */
  --yoga:  #7d64c0;  /* violet */
  --swim:  #2e83b8;  /* blue */
  --walk:  #7f8b4a;  /* olive */

  --accent: var(--run);
  --accent-ink: #b83a24;

  /* chart theming */
  --chart-text: #857d70;
  --chart-grid: rgba(29,26,21,.09);
  --chart-tooltip-bg: #201d18;
  --chart-tooltip-text: #fbf8f2;
  --chart-center-text: var(--ink);
  --chart-c1: #e8543a;
  --chart-c2: #2f7d6e;
  --chart-c3: #d38b1f;
  --chart-c4: #7d64c0;
  --chart-c5: #2e83b8;
  --chart-c6: #7f8b4a;

  /* type scale */
  --f-display: "Fraunces", Georgia, serif;
  --f-ui: "Hanken Grotesk", system-ui, sans-serif;

  --sp: 8px;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(29,26,21,.04), 0 6px 22px -12px rgba(29,26,21,.14);
  --shadow-lg: 0 2px 4px rgba(29,26,21,.05), 0 22px 48px -20px rgba(29,26,21,.28);
  --sidebar-w: 244px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--f-ui);
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1,h2,h3 { margin: 0; font-family: var(--f-display); font-weight: 600; letter-spacing: -.01em; line-height: 1.1; }
p { margin: 0; }
button { font-family: inherit; }
.num, .tnum { font-variant-numeric: tabular-nums; }
.sr-only { position:absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip:rect(0,0,0,0); border:0; }

/* ---------- layout ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--paper-2);
  border-right: 1px solid var(--line);
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 26px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px; }
.brand-mark {
  display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--ink); color: var(--paper-2);
}
.brand-name { font-family: var(--f-display); font-size: 22px; font-weight: 600; letter-spacing: -.02em; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-link {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px; border-radius: 10px;
  color: var(--ink-2); text-decoration: none;
  font-size: 14.5px; font-weight: 500;
  transition: background .16s, color .16s;
}
.nav-ico { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; opacity: .8; }
.nav-ico rect { fill: currentColor; stroke: none; opacity: .85; }
.nav-link:hover { background: rgba(29,26,21,.05); color: var(--ink); }
.nav-link.is-active { background: var(--ink); color: var(--paper-2); }
.nav-link.is-active .nav-ico { opacity: 1; }

.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 16px; }
.unit-pref { display: flex; align-items: center; justify-content: space-between; padding: 0 6px; }
.unit-label { font-size: 13px; color: var(--ink-3); font-weight: 500; }
.colophon { font-size: 11.5px; color: var(--ink-3); line-height: 1.45; padding: 0 6px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 18px 32px;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(10px);
}
.topbar-head { margin-right: auto; }
.page-title { font-size: 26px; }
.page-sub { font-size: 13.5px; color: var(--ink-3); margin-top: 2px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.menu-btn { display: none; background: none; border: 0; color: var(--ink); padding: 4px; cursor: pointer; border-radius: 8px; }

.content { padding: 26px 32px 40px; display: flex; flex-direction: column; gap: 22px; max-width: 1240px; width: 100%; }

/* ---------- segmented control ---------- */
.seg { display: inline-flex; background: rgba(29,26,21,.055); border-radius: 10px; padding: 3px; gap: 2px; }
.seg-btn {
  border: 0; background: none; cursor: pointer;
  padding: 6px 13px; border-radius: 8px;
  font-size: 13px; font-weight: 600; color: var(--ink-3);
  transition: background .16s, color .16s, box-shadow .16s;
}
.seg-btn:hover { color: var(--ink); }
.seg-btn.is-on { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(29,26,21,.12); }
.seg-sm .seg-btn { padding: 4px 10px; font-size: 12px; }
.seg-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  border: 0; cursor: pointer; border-radius: 10px;
  padding: 9px 15px; font-size: 14px; font-weight: 600;
  transition: transform .12s, background .16s, box-shadow .16s, border-color .16s;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 2px 10px -3px rgba(232,84,58,.6); }
.btn-primary:hover { background: var(--accent-ink); }
.btn-ghost { background: transparent; color: var(--ink-2); border: 1px solid var(--line); }
.btn-ghost:hover { background: rgba(29,26,21,.045); color: var(--ink); }

/* ---------- cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- banner ---------- */
.banner {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-radius: 12px;
  background: color-mix(in srgb, var(--cycle) 12%, var(--card));
  border: 1px solid color-mix(in srgb, var(--cycle) 30%, transparent);
  color: #7a5310; font-size: 13.5px;
}
.banner svg { flex-shrink: 0; }
.banner strong { color: #5e3f08; }

/* ---------- entry form ---------- */
.entry { padding: 22px 24px 24px; }
.entry-head h2 { font-size: 21px; }
.entry-head p { color: var(--ink-3); font-size: 13.5px; margin-top: 3px; }
.entry-form { margin-top: 18px; display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.field > label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); letter-spacing: .01em; }
.field .hint { color: var(--ink-3); font-weight: 500; }
.field-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }

input[type=date], input[type=number], input[type=text] {
  width: 100%; font-family: inherit; font-size: 14.5px; color: var(--ink);
  background: var(--paper-2);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; transition: border-color .16s, box-shadow .16s, background .16s;
}
input::placeholder { color: #b3aa9b; }
input:hover { border-color: rgba(29,26,21,.2); }
input:focus { outline: none; border-color: var(--accent); background: var(--card); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
input[type=number] { font-variant-numeric: tabular-nums; }

.type-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.type-chip {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 11px 6px 9px; border-radius: 12px; cursor: pointer;
  background: var(--paper-2); border: 1.5px solid var(--line);
  color: var(--ink-2); font-size: 12px; font-weight: 600;
  transition: border-color .16s, background .16s, color .16s, transform .12s;
}
.type-chip svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.type-chip:hover { transform: translateY(-1px); border-color: rgba(29,26,21,.25); }
.type-chip.is-on { color: #fff; border-color: transparent; }
.type-chip.is-on { background: var(--tc, var(--accent)); }
.type-chip:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.feel { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; max-width: 460px; }
.feel-btn {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 9px 4px; border-radius: 11px; cursor: pointer;
  background: var(--paper-2); border: 1.5px solid var(--line);
  color: var(--ink-2); font-size: 11px; font-weight: 600;
  transition: border-color .16s, background .16s, transform .12s;
}
.feel-face { width: 24px; height: 24px; }
.feel-btn:hover { transform: translateY(-1px); border-color: rgba(29,26,21,.25); }
.feel-btn.is-on { border-color: var(--ink); background: var(--card); box-shadow: 0 1px 2px rgba(29,26,21,.12); }
.feel-btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.entry-actions { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.entry-btns { display: flex; gap: 10px; margin-left: auto; }
.form-msg { font-size: 13px; font-weight: 500; }
.form-msg.err { color: var(--accent-ink); }
.form-msg.ok { color: var(--gym); }

.dist-hidden { display: none !important; }

/* ---------- stat cards ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.stat { padding: 18px 18px 16px; display: flex; flex-direction: column; gap: 4px; position: relative; overflow: hidden; }
.stat-label { font-size: 12.5px; color: var(--ink-3); font-weight: 600; display: flex; align-items: center; gap: 7px; }
.stat-ico { width: 15px; height: 15px; opacity: .7; }
.stat-value { font-family: var(--f-display); font-size: 34px; font-weight: 600; line-height: 1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; margin-top: 3px; }
.stat-value .unit { font-size: 15px; color: var(--ink-3); font-weight: 500; margin-left: 3px; letter-spacing: 0; }
.stat-delta { font-size: 12.5px; font-weight: 600; display: inline-flex; align-items: center; gap: 4px; margin-top: 5px; }
.stat-delta.up { color: var(--gym); }
.stat-delta.down { color: var(--accent-ink); }
.stat-delta.flat { color: var(--ink-3); }
.stat-delta svg { width: 13px; height: 13px; }

/* ---------- charts ---------- */
.charts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.chart-card { padding: 18px 20px 16px; min-width: 0; }
.chart-wide { grid-column: 1 / -1; }
.chart-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 12px; gap: 12px; }
.chart-head h3 { font-size: 16px; font-weight: 600; }
.chart-sub { font-size: 12.5px; color: var(--ink-3); margin-top: 2px; }
.chart-host { width: 100%; min-height: 240px; }
.chart-host--donut { display: flex; align-items: center; justify-content: center; }
.chart-empty { display: grid; place-items: center; min-height: 220px; color: var(--ink-3); font-size: 13.5px; text-align: center; padding: 20px; }

/* ---------- history ---------- */
.history { padding: 20px 4px 8px; }
.history-head { display: flex; align-items: center; gap: 10px; padding: 0 20px 14px; }
.history-head h2 { font-size: 20px; }
.pill-count { font-size: 12px; font-weight: 600; color: var(--ink-3); background: rgba(29,26,21,.06); padding: 3px 9px; border-radius: 999px; }
.table-wrap { overflow-x: auto; }
.log-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.log-table th {
  text-align: left; font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--ink-3); padding: 8px 14px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.log-table th.num { text-align: right; }
.log-table th.th-actions { width: 84px; }
.log-table th.sortable { cursor: pointer; user-select: none; }
.log-table th.sortable:hover { color: var(--ink); }
.sort-caret { display: inline-block; width: 8px; margin-left: 3px; opacity: .5; }
.log-table th[aria-sort="ascending"] .sort-caret::after { content: "▲"; font-size: 8px; }
.log-table th[aria-sort="descending"] .sort-caret::after { content: "▼"; font-size: 8px; }
.log-table th[aria-sort] { color: var(--ink); }
.log-table td { padding: 11px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.log-table tbody tr { transition: background .12s; }
.log-table tbody tr:hover { background: color-mix(in srgb, var(--accent) 5%, transparent); }
.log-table td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.td-date { white-space: nowrap; color: var(--ink-2); font-weight: 500; }
.td-notes { color: var(--ink-3); max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.type-tag { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 12.5px; white-space: nowrap; }
.type-dot { width: 9px; height: 9px; border-radius: 3px; flex-shrink: 0; }
.feel-tag { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--ink-2); }
.feel-tag svg { width: 17px; height: 17px; }

.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.icon-btn {
  display: grid; place-items: center; width: 28px; height: 28px;
  border: 0; background: none; border-radius: 8px; cursor: pointer; color: var(--ink-3);
  transition: background .14s, color .14s;
}
.icon-btn svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover { background: rgba(29,26,21,.07); color: var(--ink); }
.icon-btn.del:hover { background: color-mix(in srgb, var(--run) 14%, transparent); color: var(--accent-ink); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.empty { padding: 34px 20px; text-align: center; color: var(--ink-3); font-size: 14px; }

/* ---------- footer ---------- */
.foot {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 20px 4px 0; margin-top: 6px;
  font-size: 12.5px; color: var(--ink-3);
}
.foot-mark { font-family: var(--f-display); font-weight: 600; color: var(--ink-2); }
.foot-sep { opacity: .5; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(12px);
  background: var(--ink); color: var(--paper-2);
  padding: 11px 18px; border-radius: 12px; font-size: 13.5px; font-weight: 500;
  box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none;
  transition: opacity .22s, transform .22s; z-index: 100; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast .t-accent { color: color-mix(in srgb, var(--run) 60%, #fff); font-weight: 600; }

.scrim { position: fixed; inset: 0; background: rgba(29,26,21,.4); z-index: 30; }

/* ---------- responsive ---------- */
@media (max-width: 1080px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 880px) {
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 40;
    transform: translateX(-100%); transition: transform .24s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .menu-btn { display: block; }
  .topbar { padding: 14px 18px; }
  .content { padding: 18px 18px 34px; }
  .page-title { font-size: 22px; }
  .charts { grid-template-columns: 1fr; }
  .chart-wide { grid-column: auto; }
}
@media (max-width: 560px) {
  .topbar { flex-wrap: wrap; }
  .topbar-actions { width: 100%; justify-content: space-between; }
  .topbar-head { margin-right: 0; }
  .field-row { grid-template-columns: 1fr 1fr; }
  .field-row #distField { grid-column: 1 / -1; }
  .type-grid { grid-template-columns: repeat(3, 1fr); }
  .feel { grid-template-columns: repeat(5, 1fr); gap: 6px; }
  .feel-btn { font-size: 10px; padding: 8px 2px; }
  .stats { gap: 12px; }
  .stat-value { font-size: 29px; }
  .entry-btns { width: 100%; }
  .entry-btns .btn-primary { flex: 1; justify-content: center; }
  .page-sub { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
