/* Reset + base */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: #0e1117;
  color: #e6e6e6;
  min-height: 100vh;
  padding: 24px;
}

header {
  max-width: 1400px;
  margin: 0 auto 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid #2a2f3a;
}

header h1 {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.5px;
}

#last-updated {
  color: #8b95a7;
  font-size: 13px;
  margin-top: 4px;
}

#last-export {
  color: #8b95a7;
  font-size: 12px;
  margin-top: 2px;
  padding: 4px 8px;
  border-radius: 4px;
  display: inline-block;
}

#last-export.stale-warn {
  background: #3a2e0e;
  color: #f0c060;
  border: 1px solid #5c4a1c;
  font-weight: 500;
}

#last-export.stale-critical {
  background: #3d1416;
  color: #ff7878;
  border: 1px solid #6b1f23;
  font-weight: 600;
}

main {
  max-width: 1400px;
  margin: 0 auto;
}

.section-title {
  font-size: 12px;
  font-weight: 600;
  color: #8b95a7;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin: 28px 0 12px;
}

.section-title:first-child { margin-top: 0; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: 20px;
}

.card {
  background: #161b22;
  border: 1px solid #2a2f3a;
  border-radius: 10px;
  padding: 20px;
}

.card-wide { grid-column: 1 / -1; }

.card h2 {
  font-size: 14px;
  font-weight: 500;
  color: #8b95a7;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.metric {
  font-size: 36px;
  font-weight: 600;
  letter-spacing: -1px;
}

.metric-sub {
  font-size: 13px;
  color: #8b95a7;
  margin-bottom: 16px;
}

.metric-sub.up   { color: #3fb950; }
.metric-sub.down { color: #f85149; }

canvas {
  width: 100% !important;
  height: 240px !important;
}

.placeholder {
  border-style: dashed;
  opacity: 0.7;
}

.placeholder .hint {
  font-size: 12px;
  color: #8b95a7;
  line-height: 1.5;
  margin-top: 8px;
}

.placeholder code {
  background: #0e1117;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 11px;
  color: #e6e6e6;
}

/* ===== SCHEDULE ===== */
.schedule-card { padding: 16px; }

.schedule-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  padding: 0 4px;
}

.week-nav, .week-today, .week-export {
  background: #21262d;
  border: 1px solid #2a2f3a;
  color: #e6e6e6;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
}
.week-nav:hover, .week-today:hover, .week-export:hover { background: #2a2f3a; }
.week-export { margin-left: auto; }

.week-label {
  font-size: 15px;
  font-weight: 500;
  color: #e6e6e6;
  min-width: 220px;
}

.schedule-scroll {
  overflow-x: auto;
}

.schedule-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.schedule-table th,
.schedule-table td {
  border: 1px solid #2a2f3a;
  padding: 6px 8px;
  text-align: center;
  vertical-align: middle;
  min-width: 90px;
}

.schedule-table th {
  background: #0e1117;
  color: #8b95a7;
  font-weight: 500;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.5px;
}

.schedule-table th.row-label,
.schedule-table td.row-label {
  text-align: left;
  background: #0e1117;
  color: #e6e6e6;
  font-weight: 500;
  min-width: 160px;
  position: sticky;
  left: 0;
  z-index: 1;
}

.schedule-table tr.section-divider td {
  background: #161b22;
  color: #8b95a7;
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 1px;
  text-align: left;
  font-weight: 600;
  padding: 8px;
}

.schedule-table input[type="text"],
.schedule-table input[type="number"] {
  width: 100%;
  background: transparent;
  border: none;
  color: #e6e6e6;
  text-align: center;
  font-family: inherit;
  font-size: 13px;
  padding: 2px;
}

.schedule-table input[type="text"]:focus,
.schedule-table input[type="number"]:focus {
  outline: 1px solid #58a6ff;
  border-radius: 3px;
  background: #0e1117;
}

/* Hide number input spinners */
.schedule-table input[type="number"]::-webkit-outer-spin-button,
.schedule-table input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.schedule-table input[type="number"] { -moz-appearance: textfield; }

/* Peptide checkbox cell — clickable whole cell */
.schedule-table td.peptide-cell {
  cursor: pointer;
  user-select: none;
  font-size: 18px;
}
.schedule-table td.peptide-cell.taken {
  background: #0e2818;
  color: #3fb950;
}
.schedule-table td.peptide-cell:not(.taken) {
  color: #4a525e;
}

/* Today highlight */
.schedule-table th.today,
.schedule-table td.today { background: #0e1d2e; }
.schedule-table td.today.peptide-cell.taken { background: #133326; }

/* ===== AVERAGES STRIP (horizontal row of small summary cards) ===== */
.section-title-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin: 28px 0 12px;
}
.section-title-row .section-title { margin: 0; }
.week-edit.small { padding: 4px 10px; font-size: 12px; }

.strip {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 8px;
}
.strip-card { padding: 11px 12px; }
.strip-card h2 { font-size: 10px; margin-bottom: 4px; letter-spacing: 0.4px; }
.strip-card .metric { font-size: 22px; }
.strip-card .metric-sub { font-size: 10px; margin-bottom: 0; }

/* On narrower screens, wrap to fewer columns */
@media (max-width: 1500px) {
  .strip { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 1000px) {
  .strip { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 700px) {
  .strip { grid-template-columns: repeat(2, 1fr); }
}

/* Editable target value */
.target-line.editable {
  cursor: pointer;
}
.target-line.editable .target-value {
  background: #21262d;
  border: 1px solid #58a6ff;
  border-radius: 3px;
  padding: 1px 4px;
  color: #58a6ff;
}
.target-line input.target-input {
  background: #0e1117;
  border: 1px solid #58a6ff;
  color: #58a6ff;
  padding: 1px 4px;
  border-radius: 3px;
  width: 60px;
  font-size: 11px;
  font-family: inherit;
}
.target-line input.target-input:focus { outline: none; }

/* ===== SCHEDULE EDIT MODE ===== */
.week-edit {
  background: #21262d;
  border: 1px solid #2a2f3a;
  color: #e6e6e6;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
}
.week-edit:hover { background: #2a2f3a; }
.week-edit.active {
  background: #1f3a5f;
  border-color: #58a6ff;
  color: #58a6ff;
}

/* Delete button on peptide row labels in edit mode */
.peptide-delete {
  background: transparent;
  border: none;
  color: #f85149;
  cursor: pointer;
  font-size: 16px;
  margin-right: 6px;
  padding: 0 4px;
  vertical-align: middle;
}
.peptide-delete:hover { color: #ff6b6b; }

/* Label input shown in edit mode for renaming peptides */
.peptide-label-input {
  background: #0e1117;
  border: 1px solid #2a2f3a;
  color: #e6e6e6;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 13px;
  font-family: inherit;
  width: calc(100% - 30px);
}
.peptide-label-input:focus {
  outline: 1px solid #58a6ff;
  border-color: #58a6ff;
}

/* Add-peptide row */
.add-peptide-row td {
  text-align: left;
  padding: 8px;
  background: #0e1117;
}
.add-peptide-input {
  background: #161b22;
  border: 1px solid #2a2f3a;
  color: #e6e6e6;
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
  width: 220px;
  margin-right: 8px;
}
.add-peptide-input:focus {
  outline: 1px solid #58a6ff;
  border-color: #58a6ff;
}
.add-peptide-btn {
  background: #1f6f4a;
  border: 1px solid #2ea043;
  color: #fff;
  padding: 5px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
}
.add-peptide-btn:hover { background: #2ea043; }

/* ===== PEPTIDE DAY SCHEDULING ===== */
.schedule-table td.peptide-cell.unscheduled {
  color: #2a2f3a;
  background: #0e1117;
  cursor: default;
}
.schedule-table td.peptide-cell.unscheduled.taken {
  /* Extra dose on an unscheduled day — different color so it's clearly outside protocol */
  background: #2c1a3f;
  color: #d2a8ff;
}
.schedule-table td.peptide-cell.unscheduled.today { background: #0e1d2e; }
.schedule-table td.peptide-cell.unscheduled.today.taken { background: #2c2244; }

/* Day-toggle row (shown only in edit mode under each peptide) */
.peptide-days-row td {
  padding: 4px;
  background: #0b0e13;
  border-top: none;
}
.peptide-days-row .peptide-days-label {
  font-size: 11px;
  color: #8b95a7;
  font-weight: 400;
  font-style: italic;
}
.day-toggle {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid #2a2f3a;
  background: #161b22;
  color: #4a525e;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.day-toggle:hover { border-color: #58a6ff; }
.day-toggle.on {
  background: #1f3a5f;
  border-color: #58a6ff;
  color: #58a6ff;
}

/* Strict mode toggle */
.strict-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #8b95a7;
  cursor: pointer;
  user-select: none;
  margin-left: 4px;
}
.strict-toggle input { cursor: pointer; accent-color: #58a6ff; }

/* ===== MACROS BREAKDOWN ===== */
.macros-breakdown {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin: 8px 0 12px;
  font-size: 13px;
}
@media (max-width: 800px) {
  .macros-breakdown { grid-template-columns: repeat(2, 1fr); }
}
.bd-row {
  background: #0e1117;
  border: 1px solid #2a2f3a;
  border-radius: 6px;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.bd-label {
  font-size: 10px;
  text-transform: uppercase;
  color: #8b95a7;
  letter-spacing: 0.5px;
  font-weight: 600;
}
.bd-grams {
  font-size: 16px;
  font-weight: 600;
  color: #e6e6e6;
}
.bd-pct {
  font-size: 12px;
  color: #8b95a7;
}
.bd-delta {
  font-size: 11px;
  margin-left: 4px;
}
.bd-delta.bd-ok    { color: #3fb950; }
.bd-delta.bd-over  { color: #f0883e; }
.bd-delta.bd-under { color: #f85149; }
.bd-target {
  font-size: 10px;
  color: #6b7280;
  margin-top: 2px;
}
.bd-empty { color: #4a525e; }

/* Forces two equal columns, ignoring auto-fit minmax */
.card-grid.two-up {
  grid-template-columns: 1fr 1fr;
  margin-top: 20px;
}
@media (max-width: 900px) {
  .card-grid.two-up { grid-template-columns: 1fr; }
}

/* ===== PRIVACY MODE: hide peptide rows + adherence card ===== */
body.privacy-on tr[data-kind="peptide"],
body.privacy-on #peptide-adh-card {
  display: none !important;
}

/* ===== GLOBAL RANGE SELECTOR ===== */
.range-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  padding: 10px 14px;
  background: #0e1117;
  border: 1px solid #2a2f3a;
  border-radius: 8px;
}
.range-label {
  color: #8b95a7;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
  margin-right: 8px;
}
.range-btn {
  background: transparent;
  border: 1px solid #2a2f3a;
  color: #8b95a7;
  padding: 6px 14px;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.15s;
}
.range-btn:hover {
  background: #1a1f2a;
  color: #e6e6e6;
}
.range-btn.active {
  background: #1f6feb;
  border-color: #1f6feb;
  color: #ffffff;
}

/* ===== AUTO-SAVE STATUS INDICATOR ===== */
#autosave-status {
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 3px;
  margin-left: 4px;
}
#autosave-status.off       { background: #3d1416; color: #ff7878; }
#autosave-status.on        { background: #0d2e1a; color: #3fb950; }
#autosave-status.needs-perm{ background: #3a2e0e; color: #f0c060; }
#autosave-status.saving    { background: #14253d; color: #58a6ff; }
#autosave-status.error     { background: #3d1416; color: #ff7878; }

/* ===== Running card header: weekly (left) + TTM (right) ===== */
.run-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}
.run-header-right { text-align: right; }
.run-header-right .metric { color: #f0883e; }
