:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1a1d21;
  --muted: #6b7280;
  --line: #e3e6ea;
  --accent: #2563eb;
  --nit: #6b7280;
  --suggestion: #2563eb;
  --must: #dc2626;
  --ok: #16a34a;
  --warn-bg: #fff7ed;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,0.05), 0 4px 12px rgba(0,0,0,0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --panel: #171a20;
    --ink: #e7eaee;
    --muted: #9aa4b2;
    --line: #2a2f38;
    --accent: #5b8cff;
    --nit: #9aa4b2;
    --suggestion: #5b8cff;
    --must: #f87171;
    --ok: #4ade80;
    --warn-bg: #2a2118;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

h1, h2, h3 { line-height: 1.25; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--must); margin: 6px 0 0; }

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  padding: 8px 14px;
  border-radius: 8px;
}
button:hover { filter: brightness(1.05); }
button.link {
  background: none;
  border: none;
  color: var(--accent);
  padding: 4px 6px;
}
button.ghost {
  background: none;
  color: var(--ink);
  border: 1px solid var(--line);
}

input, select, textarea {
  font: inherit;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
}
label { display: block; font-size: 13px; color: var(--muted); margin-top: 8px; }
label input, label select, label textarea { margin-top: 4px; }

/* Gate */
.gate {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background: var(--bg);
  padding: 20px;
  z-index: 50;
}
.gate-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  width: 100%; max-width: 380px;
}
.gate-card h1 { margin: 0 0 6px; font-size: 20px; }
.gate-card button { width: 100%; margin-top: 14px; }
.admin-toggle { margin-top: 12px; }
.admin-toggle summary { cursor: pointer; color: var(--muted); font-size: 13px; }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-left select { width: auto; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.badge {
  font-size: 12px; padding: 2px 8px; border-radius: 999px;
  background: var(--line); color: var(--ink);
}

/* Layout */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 20px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { order: -1; }
}

/* Program */
.block-header {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 16px;
}
.block-header h1 { margin: 0 0 4px; font-size: 20px; }
.meta-grid {
  display: flex; flex-wrap: wrap; gap: 8px 18px;
  margin: 10px 0 0; font-size: 13px; color: var(--muted);
}
.week {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 14px;
  overflow: hidden;
}
.week > summary {
  list-style: none;
  cursor: pointer;
  padding: 12px 16px;
  display: flex; align-items: center; gap: 10px;
  font-weight: 600;
}
.week > summary::-webkit-details-marker { display: none; }
.week-intent { color: var(--muted); font-weight: 400; font-size: 13px; }
.tag {
  font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  padding: 2px 7px; border-radius: 6px; background: var(--line);
}
.tag.deload { background: var(--warn-bg); color: #b45309; }
.week-body { padding: 0 16px 12px; }
.progression {
  font-size: 13px; color: var(--muted);
  background: var(--bg); border-radius: 8px; padding: 8px 10px; margin: 6px 0 12px;
}

.day { border-top: 1px solid var(--line); padding: 12px 0; }
.day:first-child { border-top: none; }
.day-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.day-head h3 { margin: 0; font-size: 16px; }
.day-focus { font-size: 12px; color: var(--muted); }

.exercise { padding: 8px 0; border-top: 1px dashed var(--line); }
.exercise-head { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.exercise-name { font-weight: 600; }
.superset { font-size: 11px; color: var(--accent); border: 1px solid var(--accent); border-radius: 6px; padding: 0 5px; }
.sets { width: 100%; border-collapse: collapse; margin: 6px 0 4px; font-size: 13px; }
.sets th, .sets td { text-align: left; padding: 3px 8px 3px 0; }
.sets th { color: var(--muted); font-weight: 500; }
.sets tr.warmup td { color: var(--muted); }
.cues { font-size: 12px; color: var(--muted); }
.sub { font-size: 12px; color: var(--muted); }

/* Actuals (planned vs logged) */
.sets.actual { background: var(--bg); border-radius: 6px; margin: 2px 0 6px; }
.sets.actual th { color: var(--accent); }
.sets.actual tr.actual-under td:nth-child(2) { color: var(--must); font-weight: 700; }
.sets.actual tr.actual-hit td:nth-child(2) { color: var(--ok); font-weight: 700; }
.banner {
  background: var(--warn-bg); color: #b45309;
  border-radius: 8px; padding: 8px 10px; margin-bottom: 12px; font-size: 13px;
}
.topbar .toggle { display: inline-flex; align-items: center; gap: 6px; width: auto; margin: 0; font-size: 13px; color: var(--ink); }
.topbar .toggle input { width: auto; }

/* Comment affordance */
.comment-btn {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
}
.comment-btn .n { color: var(--must); font-weight: 700; }
.comment-btn.has .n { margin-left: 4px; }

/* Sidebar */
.sidebar {
  align-self: start;
  position: sticky; top: 64px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  max-height: calc(100vh - 84px);
  display: flex; flex-direction: column;
}
.sidebar-head { padding: 14px 14px 8px; border-bottom: 1px solid var(--line); }
.sidebar-head h2 { margin: 0 0 8px; font-size: 15px; }
.count { color: var(--muted); font-weight: 400; }
.filters { display: flex; gap: 8px; }
.filters label { flex: 1; margin: 0; }
.comment-list { list-style: none; margin: 0; padding: 8px; overflow-y: auto; }
.comment-list.compact { max-height: 240px; }

.comment {
  border: 1px solid var(--line);
  border-left-width: 3px;
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 8px;
  background: var(--panel);
}
.comment.level-nit { border-left-color: var(--nit); }
.comment.level-suggestion { border-left-color: var(--suggestion); }
.comment.level-must { border-left-color: var(--must); }
.comment.resolved { opacity: .55; }
.comment .c-top { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.chip {
  font-size: 10px; text-transform: uppercase; letter-spacing: .03em;
  padding: 1px 6px; border-radius: 5px; color: #fff;
}
.chip.nit { background: var(--nit); }
.chip.suggestion { background: var(--suggestion); }
.chip.must { background: var(--must); }
.comment .c-label { font-size: 12px; color: var(--accent); cursor: pointer; }
.comment .c-text { margin: 4px 0 0; white-space: pre-wrap; }
.comment .c-suggestion { margin: 4px 0 0; font-size: 13px; color: var(--muted); border-left: 2px solid var(--line); padding-left: 8px; }
.comment .c-meta { font-size: 11px; color: var(--muted); margin-top: 4px; display: flex; gap: 8px; align-items: center; }
.comment .c-actions { display: flex; gap: 4px; }

.empty { color: var(--muted); font-size: 13px; padding: 12px; text-align: center; }

/* Modal */
.modal {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0,0,0,0.4);
  display: grid; place-items: center; padding: 16px;
}
.modal-card {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%; max-width: 520px;
  max-height: 90vh; overflow-y: auto;
  padding: 18px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { margin: 0; font-size: 17px; }
.comment-form .row { display: flex; gap: 10px; }
.comment-form .row label { flex: 1; }
.comment-form button { margin-top: 12px; }

.flash { animation: flash 1.4s ease; }
@keyframes flash {
  0% { background: var(--warn-bg); }
  100% { background: transparent; }
}
