:root {
  --bg: #0f1216;
  --panel: #171c22;
  --panel-2: #1e242c;
  --line: #2a323c;
  --line-soft: #222932;
  --text: #e8edf2;
  --muted: #8b97a6;
  --accent: #f5a524;      /* Guardian gold */
  --accent-ink: #1a1206;
  --danger: #e5484d;
  --ok: #46c26a;
  --radius: 10px;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; }
input { font: inherit; }

/* ---------- Login ---------- */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: radial-gradient(1200px 600px at 50% -10%, #1c2530, var(--bg));
}
.login-card {
  width: min(360px, 92vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-logo { font-weight: 800; letter-spacing: 3px; font-size: 24px; color: var(--accent); }
.login-sub { color: var(--muted); margin-bottom: 10px; font-size: 13px; }
.login-card input {
  padding: 12px 14px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
}
.login-card button {
  padding: 12px 14px; border-radius: var(--radius); border: none;
  background: var(--accent); color: var(--accent-ink); font-weight: 700;
}
.login-error { color: var(--danger); font-size: 13px; min-height: 16px; }

/* ---------- Topbar ---------- */
.app { height: 100vh; overflow: hidden; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 10px 18px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 800; letter-spacing: 2px; color: var(--accent); }
.brand span { color: var(--text); font-weight: 700; }
.tabs { display: flex; gap: 6px; }
.tab {
  padding: 7px 14px; border-radius: 999px; border: 1px solid transparent;
  background: transparent; color: var(--muted); font-weight: 600;
}
.tab.active { background: var(--panel-2); color: var(--text); border-color: var(--line); }
.topbar-right { margin-left: auto; display: flex; gap: 8px; }

.ghost {
  padding: 7px 12px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
}
.ghost:hover { border-color: #3a4552; }
.ghost.small { font-size: 13px; padding: 5px 10px; }
.primary {
  padding: 8px 14px; border-radius: var(--radius); border: none;
  background: var(--accent); color: var(--accent-ink); font-weight: 700;
}
.danger {
  padding: 8px 14px; border-radius: var(--radius); border: 1px solid var(--danger);
  background: transparent; color: var(--danger); font-weight: 600;
}

.view { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 14px 18px; }

/* ---------- Board toolbar ---------- */
.board-toolbar { display: flex; align-items: center; gap: 16px; margin-bottom: 12px; flex: 0 0 auto; }
.week-nav { display: flex; align-items: center; gap: 8px; }
.week-label { font-weight: 700; min-width: 220px; text-align: center; }
.save-state { margin-left: auto; color: var(--muted); font-size: 13px; }
.save-state.saved { color: var(--ok); }

/* ---------- Board grid ---------- */
.board-mount { flex: 1; min-height: 0; overflow: auto; }
.grid {
  display: grid;
  grid-template-columns: minmax(140px, 200px) repeat(6, minmax(110px, 1fr));
  grid-template-rows: auto;
  grid-auto-rows: minmax(96px, 1fr);
  gap: 8px;
  min-width: 700px;
  min-height: 100%;
}
.grid-head, .grid-row { display: contents; }
.col-head {
  align-self: end;
  padding: 8px 8px 10px;
  font-weight: 700; text-align: center; color: var(--muted);
  font-size: 12px; text-transform: uppercase; letter-spacing: 1px;
  border-bottom: 2px solid var(--line);
}
.col-head .date { display: block; color: var(--text); font-size: 16px; letter-spacing: 0; text-transform: none; }
.corner { align-self: end; border-bottom: 2px solid var(--line); min-height: 20px; }

.section-head {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  display: flex; flex-direction: column; gap: 8px;
  min-height: 90px;
}
.section-name {
  background: transparent; border: none; color: var(--text);
  font-weight: 700; font-size: 15px; width: 100%; padding: 2px 0;
  border-bottom: 1px dashed transparent;
}
.section-name:focus { outline: none; border-bottom-color: var(--line); }
.section-tools { display: flex; gap: 6px; margin-top: auto; }
.section-tools button {
  background: transparent; border: 1px solid var(--line-soft); color: var(--muted);
  border-radius: 6px; font-size: 12px; padding: 3px 7px;
}
.section-tools button:hover { color: var(--text); }

.cell {
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 6px;
  min-height: 90px;
  display: flex; flex-direction: column; gap: 6px;
}
.cell.drop-hover { border-color: var(--accent); }
.cell-list { display: flex; flex-direction: column; gap: 6px; min-height: 8px; flex: 1; }

.chip {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 7px 8px;
  cursor: grab;
}
.chip:active { cursor: grabbing; }
.chip .chip-name { font-weight: 700; font-size: 14px; overflow-wrap: anywhere; }
.chip .chip-meta { margin-top: 3px; }
.chip .chip-note { color: #b7c1cd; font-size: 12px; margin-top: 3px; font-style: italic; }

/* labeled meta tokens: value + tiny unit label (sets / reps / time / load) */
.chip-meta, .lc-meta {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 6px;
  font-size: 12.5px;
}
.tok { white-space: nowrap; }
.tok .v { color: var(--text); font-weight: 600; }
.tok .k {
  font-size: 9.5px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--muted); margin-left: 3px;
}
.chip-meta .sep, .lc-meta .sep { color: var(--line); }
.sortable-ghost { opacity: .4; }
.sortable-drag { box-shadow: var(--shadow); }

.add-btn {
  border: 1px dashed var(--line);
  background: transparent; color: var(--muted);
  border-radius: 8px; padding: 6px; font-weight: 600; font-size: 13px;
}
.add-btn:hover { color: var(--accent); border-color: var(--accent); }

.add-section-row {
  flex: 0 0 auto;
  margin-top: 10px;
}
.add-section-btn {
  border: 1px dashed var(--line); background: transparent; color: var(--muted);
  border-radius: var(--radius); padding: 10px 16px; font-weight: 600;
}
.add-section-btn:hover { color: var(--accent); border-color: var(--accent); }

/* ---------- Empty week ---------- */
.empty-week {
  height: 100%;
  display: grid; place-items: center; gap: 14px; padding: 60px 20px; text-align: center;
  border: 1px dashed var(--line); border-radius: 14px; color: var(--muted);
}
.empty-week .ew-actions { display: flex; gap: 10px; }

/* ---------- Library tab ---------- */
.lib-toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex: 0 0 auto; }
.lib-toolbar h2 { margin: 0; font-size: 18px; }
.lib-mount { flex: 1; min-height: 0; overflow-y: auto; align-content: start; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.lib-card {
  background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: var(--radius); padding: 12px;
}
.lib-card .lc-name { font-weight: 700; }
.lib-card .lc-meta { color: var(--muted); font-size: 13px; margin-top: 3px; }
.lib-card .lc-note { color: #b7c1cd; font-size: 12px; font-style: italic; margin-top: 4px; }
.lib-card .lc-actions { display: flex; gap: 8px; margin-top: 10px; }
.lib-card .lc-actions button {
  background: transparent; border: 1px solid var(--line-soft); color: var(--muted);
  border-radius: 6px; font-size: 12px; padding: 4px 9px;
}
.lib-card .lc-actions button:hover { color: var(--text); }
.lib-empty { color: var(--muted); padding: 30px; text-align: center; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: grid; place-items: center; z-index: 50; padding: 16px;
}
.modal {
  width: min(460px, 96vw); background: var(--panel);
  border: 1px solid var(--line); border-radius: 14px; padding: 20px;
  display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow);
}
.modal-title { font-weight: 700; font-size: 17px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 12.5px; color: var(--muted); }
.field input {
  padding: 10px 12px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
}
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.check { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.modal-actions { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.modal-actions .spacer { flex: 1; }

/* ---------- Print ---------- */
@media print {
  :root { --bg:#fff; --panel:#fff; --panel-2:#fff; --text:#000; --muted:#444; --line:#bbb; --line-soft:#ccc; }
  body { background: #fff; color: #000; }
  .topbar, .board-toolbar, .add-btn, .add-section-row, .section-tools,
  .modal-backdrop, #view-workouts { display: none !important; }
  .app { height: auto; overflow: visible; }
  .view, #view-board { display: block; padding: 0; }
  .board-mount { overflow: visible; }
  .grid { min-width: 0; min-height: 0; grid-auto-rows: auto; }
  .print-title { display: block !important; }
  .chip { break-inside: avoid; border-left-width: 3px; }
  .cell, .section-head { min-height: 0; }
  .col-head { position: static; }
}
.print-title { display: none; text-align: center; font-weight: 800; letter-spacing: 2px; margin: 0 0 12px; font-size: 20px; }
