/* ---------- Design tokens ---------- */
:root {
  --ink: #1B1F23;
  --panel: #262B31;
  --panel-raised: #2E343B;
  --line: #3A414A;
  --paper: #EDE9DF;
  --paper-dim: #A9ACA6;
  --brass: #C89B3C;
  --brass-dim: #8E6C2A;
  --ember: #C1502E;
  --moss: #6E8F5C;

  --font-display: "Oswald", "Arial Narrow", sans-serif;
  --font-body: "Work Sans", -apple-system, BlinkMacSystemFont, sans-serif;

  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

body {
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 0.01em;
  margin: 0;
}

input, select, button {
  font-family: var(--font-body);
  font-size: 16px; /* prevents iOS zoom-on-focus */
}

.num, input[type="number"], .log-set, .chart-wrap {
  font-variant-numeric: tabular-nums;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4em;
  padding: 0.7em 1.3em;
  border-radius: 3px;
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease;
}
.btn-primary {
  background: var(--brass);
  color: #1B1600;
  border-color: var(--brass);
}
.btn-primary:hover { background: #d9ab48; }
.btn-outline {
  background: transparent;
  color: var(--paper);
  border-color: var(--line);
}
.btn-outline:hover { border-color: var(--paper-dim); }
.btn-ghost {
  background: transparent;
  color: var(--paper-dim);
  border-color: transparent;
  padding: 0.7em 0.9em;
}
.btn-ghost:hover { color: var(--paper); }
.btn-small { padding: 0.5em 0.9em; font-size: 0.85rem; }
.btn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
}

.link-btn {
  background: none;
  border: none;
  color: var(--brass);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 4px 0;
  text-align: left;
}
.link-btn:hover { text-decoration: underline; }

/* ---------- Login / denied gate ---------- */
.gate {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 15%, rgba(200,155,60,0.12), transparent 45%),
    var(--ink);
}
.gate[hidden] { display: none; }
.gate-card { max-width: 480px; width: 100%; }
.gate-mark {
  font-family: var(--font-display);
  color: var(--brass);
  letter-spacing: 0.14em;
  font-size: 0.85rem;
  margin: 0 0 1.2em;
}
.gate-card h1 {
  font-size: clamp(1.8rem, 5vw, 2.6rem);
  line-height: 1.15;
  margin-bottom: 0.5em;
}
.gate-sub {
  color: var(--paper-dim);
  line-height: 1.55;
  margin-bottom: 1.8em;
}
.gate-actions { display: flex; flex-wrap: wrap; gap: 0.8em; }

/* ---------- App shell ---------- */
#app { min-height: 100vh; min-height: 100dvh; }

.topbar {
  display: flex;
  align-items: center;
  gap: 1.5em;
  padding: 14px 20px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 5;
  flex-wrap: wrap;
}
.brand-mark {
  font-family: var(--font-display);
  letter-spacing: 0.1em;
  font-size: 1.05rem;
  color: var(--brass);
  white-space: nowrap;
}
.tabs { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.tab {
  background: transparent;
  border: none;
  color: var(--paper-dim);
  font-family: var(--font-display);
  font-size: 0.95rem;
  letter-spacing: 0.03em;
  padding: 0.5em 0.9em;
  border-radius: 3px;
  cursor: pointer;
}
.tab.is-active { color: var(--ink); background: var(--brass); }
.account { display: flex; align-items: center; gap: 1em; margin-left: auto; }
.account-name { color: var(--paper-dim); font-size: 0.9rem; }
.account-logout { color: var(--paper-dim); font-size: 0.9rem; text-decoration: none; border-bottom: 1px solid transparent; }
.account-logout:hover { color: var(--paper); border-color: var(--paper-dim); }

.panel { display: none; padding: 20px; max-width: 900px; margin: 0 auto; }
.panel.is-active { display: block; }

/* ---------- Entry form ---------- */
.entry-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 18px;
  margin-bottom: 24px;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 0.78rem; color: var(--paper-dim); }
.field .optional { font-weight: 400; opacity: 0.7; }
.field input, .field select {
  background: var(--ink);
  border: 1px solid var(--line);
  color: var(--paper);
  border-radius: 3px;
  padding: 0.6em 0.7em;
}
.field input:focus, .field select:focus { border-color: var(--brass); }
.field-hint { color: var(--paper-dim); font-size: 0.82rem; margin: 4px 0; }

.field-exercise select#f-exercise { width: 100%; }

/* Generic category-driven field row (used in the log form, routine rows,
   quick-log rows, and the exercise defaults editor) */
.category-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.category-fields .field { flex: 1; min-width: 110px; }

/* The weight field gets extra room and a larger, more legible number,
   since it's the one people squint at mid-set. */
.category-fields .field-weight { flex: 1.6; min-width: 150px; }
.weight-field {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
  text-align: left;
}

.status { min-height: 1.4em; color: var(--ember); font-size: 0.9rem; margin: -8px 0 16px; }
.status.is-ok { color: var(--brass); }

/* The status line lives in the sticky topbar so it stays visible on
   every tab, not just the one you happened to trigger it from. It only
   takes up space when it actually has something to say. */
.topbar-status {
  flex: 1 0 100%;
  margin: 0;
  min-height: 0;
  padding-top: 4px;
}
.topbar-status:empty { padding-top: 0; }

/* ---------- Log list (ledger style, not cards) ---------- */
.log-day { margin-bottom: 20px; }
.log-day-heading {
  font-family: var(--font-display);
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  color: var(--brass);
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
  margin-bottom: 6px;
}
.log-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  align-items: center;
  gap: 14px;
  padding: 10px 4px;
  border-bottom: 1px solid rgba(58,65,74,0.5);
}
.log-row:last-child { border-bottom: none; }
.log-exercise { font-weight: 500; }
.log-notes { display: block; color: var(--paper-dim); font-size: 0.85rem; margin-top: 2px; }
.log-set { color: var(--paper-dim); white-space: nowrap; }
.log-weight { font-family: var(--font-display); font-weight: 500; white-space: nowrap; }
.log-actions { display: flex; gap: 10px; }
.log-actions button { background: none; border: none; color: var(--paper-dim); cursor: pointer; font-size: 0.85rem; padding: 2px; }
.log-actions button:hover { color: var(--paper); }
.log-actions .delete:hover { color: var(--ember); }

.empty-state { color: var(--paper-dim); line-height: 1.6; max-width: 42ch; margin-top: 12px; }

/* ---------- Exercises page ---------- */
.routines-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.routines-header h2 { font-size: 1.1rem; }

.exercise-groups { display: flex; flex-direction: column; gap: 22px; }
.exercise-group-heading {
  font-family: var(--font-display);
  font-size: 0.9rem;
  letter-spacing: 0.05em;
  color: var(--brass);
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
  margin-bottom: 6px;
}
.exercise-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 4px;
  border-bottom: 1px solid rgba(58,65,74,0.5);
}
.exercise-row:last-child { border-bottom: none; }
.exercise-row-main { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.exercise-name { font-weight: 500; }
.exercise-badge {
  font-size: 0.72rem;
  color: var(--paper-dim);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 1px 6px;
}
.exercise-badge.custom { color: var(--brass); border-color: var(--brass-dim); }

/* ---------- Routines ---------- */
.routine-form {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 18px;
  margin-bottom: 24px;
}
.routine-form .field { margin-bottom: 12px; }
.routine-form .field input, .routine-form .field select { width: 100%; }
.routine-rows { display: flex; flex-direction: column; gap: 10px; margin-bottom: 8px; }
.routine-row-card {
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 10px;
  background: var(--panel-raised);
}
.routine-row-head { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.routine-row-head select { flex: 1; }
.routine-form-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

.routine-list { display: flex; flex-direction: column; gap: 10px; }
.routine-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 14px 16px;
  flex-wrap: wrap;
}
.routine-card h3 { font-size: 1rem; margin-bottom: 2px; }
.routine-summary { color: var(--paper-dim); font-size: 0.85rem; }
.routine-card-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Quick log (start routine) ---------- */
.quick-log {
  background: var(--panel-raised);
  border: 1px solid var(--brass-dim);
  border-radius: 4px;
  padding: 18px;
  margin-bottom: 24px;
}
.quick-log h2 { font-size: 1.05rem; margin-bottom: 10px; }
.quick-log-date { margin-bottom: 12px; max-width: 200px; }
.quick-log-date input {
  width: 100%;
  background: var(--ink);
  border: 1px solid var(--line);
  color: var(--paper);
  border-radius: 3px;
  padding: 0.5em 0.6em;
}
.quick-log-rows { display: flex; flex-direction: column; gap: 10px; }
.quick-log-card { border: 1px solid var(--line); border-radius: 3px; padding: 10px; background: var(--panel); }
.ql-head { margin-bottom: 8px; }
.ql-notes-field { margin-top: 10px; }
.ql-notes-field label { font-size: 0.78rem; color: var(--paper-dim); }
.ql-exercise { font-size: 0.9rem; font-weight: 500; }
.quick-log-actions { display: flex; gap: 8px; margin-top: 14px; }

/* Shared number/select styling inside dynamic field rows */
.category-fields input, .category-fields select,
.routine-row-head select {
  background: var(--ink);
  border: 1px solid var(--line);
  color: var(--paper);
  border-radius: 3px;
  padding: 0.5em 0.6em;
  width: 100%;
}

/* ---------- Calendar ---------- */
.calendar-controls { display: flex; align-items: center; justify-content: center; gap: 18px; margin-bottom: 12px; }
.calendar-label { font-family: var(--font-display); letter-spacing: 0.03em; min-width: 10ch; text-align: center; }
.cal-today { margin-left: 4px; }

.cal-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  justify-content: center;
  margin-bottom: 14px;
  font-size: 0.85rem;
  color: var(--paper-dim);
}
.cal-stat strong { color: var(--brass); font-family: var(--font-display); }
.cal-stat-note { font-style: italic; }

.calendar-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}
.calendar-filters .field { flex: 1; min-width: 140px; margin: 0; }

.cal-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin-bottom: 10px;
  font-size: 0.78rem;
  color: var(--paper-dim);
}
.cal-legend-item { display: inline-flex; align-items: center; gap: 5px; }

.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  color: var(--paper-dim);
  font-size: 0.78rem;
  text-align: center;
  margin-bottom: 4px;
}
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-cell {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 3px;
  color: var(--paper);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 2px;
}
.cal-cell:hover { border-color: var(--paper-dim); }
.cal-cell-empty { background: transparent; border: none; cursor: default; }
.cal-cell.has-entries { background: rgba(200,155,60,0.18); border-color: var(--brass-dim); font-weight: 600; }
.cal-cell.is-today { outline: 1px solid var(--brass); }
.cal-cell-day { line-height: 1; }
.cal-cell-dots {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 6px;
}
.cal-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex: none;
}
.cal-dot-kracht { background: var(--brass); }
.cal-dot-cardio_afstand { background: var(--ember); }
.cal-dot-cardio_duur { background: var(--moss); }
.cal-dot-more {
  width: auto;
  height: auto;
  border-radius: 2px;
  background: none;
  color: var(--paper-dim);
  font-size: 0.6rem;
  line-height: 1;
}
.cal-day-detail { margin-top: 18px; }

/* ---------- Progress tab ---------- */
.progress-controls { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.progress-controls label { color: var(--paper-dim); font-size: 0.9rem; }
.progress-controls select {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--paper);
  border-radius: 3px;
  padding: 0.5em 0.7em;
}
.chart-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 16px; }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .topbar { gap: 0.8em; }
  .account-name { display: none; }
  .log-row { grid-template-columns: 1fr auto; }
  .log-set, .log-weight { grid-column: 2; justify-self: end; }
  .log-actions { grid-column: 2; justify-self: end; }
  .category-fields .field { min-width: 90px; }
  .category-fields .field-weight { min-width: 120px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
