/* =========================================================
   Energy and Recovery Planner — styles.css

   HOW TO CHANGE COLOURS
   All colours live in the two blocks just below:
   - ":root" is the light theme
   - "@media (prefers-color-scheme: dark)" is the dark theme
   Change a hex value once and it updates everywhere.
   If you change a text or background colour, check the contrast
   (aim for at least 4.5:1) with a free checker such as
   https://webaim.org/resources/contrastchecker/
   ========================================================= */

:root {
  /* Core palette */
  --bg: #F6F3EE;            /* page background */
  --card: #FFFFFF;          /* cards */
  --ink: #1F2A2E;           /* main text */
  --muted: #5B6567;         /* secondary text */
  --primary: #2F6F6A;       /* teal: buttons, selected states */
  --on-primary: #FFFFFF;    /* text on teal buttons */
  --teal-tint: #E3EFEC;     /* soft teal backgrounds */
  --deep-teal: #1F5550;     /* teal text on light backgrounds */
  --amber: #C98A2B;         /* low-energy bars */
  --border: #DCD6CC;        /* card and input borders */
  --danger: #9A3324;        /* delete buttons */
  --on-danger: #FFFFFF;
  --note-bg: #FBF1DE;       /* gentle note background */
  --bar-track: #EFEBE4;     /* empty part of chart bars */

  /* Demand pills */
  --pill-demanding-bg: #F5E3C3; --pill-demanding-fg: #6B4A0E;
  --pill-moderate-bg:  #E6E9EC; --pill-moderate-fg:  #3B4650;
  --pill-restoring-bg: #D6E9E4; --pill-restoring-fg: #1F5550;

  /* Shape and type */
  --radius: 16px;
  --radius-lg: 18px;
  --radius-sm: 10px;
  --font-head: "Fraunces", Georgia, "Times New Roman", serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --tap: 44px;              /* minimum touch target */
  --focus: #2F6F6A;
  --shadow: 0 1px 2px rgba(31, 42, 46, 0.06);

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141A1C;
    --card: #1E2629;
    --ink: #E9EDEB;
    --muted: #A8B2B3;
    --primary: #7CC2B8;
    --on-primary: #10201E;
    --teal-tint: #1D3633;
    --deep-teal: #A9DCD3;
    --amber: #E0A64A;
    --border: #34403F;
    --danger: #F0A493;
    --on-danger: #2A0E08;
    --note-bg: #33291A;
    --bar-track: #2A3436;

    --pill-demanding-bg: #4A3610; --pill-demanding-fg: #F5E3C3;
    --pill-moderate-bg:  #333C44; --pill-moderate-fg:  #E6E9EC;
    --pill-restoring-bg: #1F3A37; --pill-restoring-fg: #D6E9E4;

    --focus: #7CC2B8;
    --shadow: none;
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

/* Anything marked "hidden" stays hidden, even if another rule sets display */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.5;
  /* room for the bottom tab bar */
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
}

h1, h2, h3 {
  font-family: var(--font-head);
  font-weight: 600;
  line-height: 1.2;
  margin: 0 0 0.5rem;
  color: var(--ink);
}
h1 { font-size: 1.75rem; }
h2 { font-size: 1.25rem; }
h3, .h3 { font-size: 1.1rem; font-family: var(--font-head); font-weight: 600; }
h1:focus, h3:focus { outline: none; } /* headings receive focus only for screen readers on screen change */

p { margin: 0 0 0.75rem; }
a { color: var(--deep-teal); text-underline-offset: 2px; }

.muted { color: var(--muted); }
.muted-inline { color: var(--muted); font-family: var(--font-body); font-weight: 400; font-size: 0.9em; }
.small { font-size: 0.875rem; }
.center { text-align: center; }
.lead { font-size: 1.05rem; color: var(--muted); }
.eyebrow { color: var(--muted); font-size: 0.9rem; margin: 0 0 0.25rem; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* Visible focus for keyboard users */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 6px;
}

.skip-link {
  position: absolute; left: 8px; top: -60px;
  background: var(--card); color: var(--ink);
  padding: 10px 14px; border-radius: var(--radius-sm);
  z-index: 100;
}
.skip-link:focus { top: 8px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 720px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 16px;
}
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  min-height: var(--tap);
  font-family: var(--font-head); font-weight: 600; font-size: 1.05rem;
  color: var(--ink); text-decoration: none;
}
.icon-button {
  display: inline-flex; align-items: center; justify-content: center;
  width: var(--tap); height: var(--tap);
  border-radius: 50%;
  color: var(--ink);
}
.icon-button[aria-current="page"] { background: var(--teal-tint); color: var(--deep-teal); }

/* ---------- Layout ---------- */
main {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 16px 24px;
}
.screen > * + * { margin-top: 0; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  margin: 0 0 16px;
  box-shadow: var(--shadow);
}
.card-tint { background: var(--teal-tint); border-color: transparent; }
.card-tint, .card-tint p, .card-tint h2 { color: var(--deep-teal); }
.card-note { background: var(--note-bg); border-color: transparent; }
.card-locked { border-style: dashed; }
.card-danger { border-color: var(--danger); }

.section-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin: 24px 0 10px;
}
.section-head h2 { margin: 0; }

.badge {
  display: inline-block; vertical-align: middle;
  font-family: var(--font-body); font-size: 0.75rem; font-weight: 600;
  letter-spacing: 0.02em;
  padding: 2px 8px; border-radius: 999px;
  background: var(--teal-tint); color: var(--deep-teal);
}

.disclaimer {
  margin-top: 28px; padding-top: 14px;
  border-top: 1px solid var(--border);
  color: var(--muted); font-size: 0.875rem; text-align: center;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--tap);
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid transparent;
  font: 600 0.95rem/1.2 var(--font-body);
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-secondary { background: var(--card); color: var(--deep-teal); border-color: var(--primary); }
.btn-secondary:hover { background: var(--teal-tint); }
.btn-ghost { background: transparent; color: var(--deep-teal); }
.btn-ghost:hover { background: var(--teal-tint); }
.btn-danger { background: var(--danger); color: var(--on-danger); }
.btn-small { min-height: var(--tap); padding: 6px 12px; font-size: 0.875rem; }
.btn-block { width: 100%; }
.btn[aria-disabled="true"] { opacity: 0.6; cursor: not-allowed; }

.button-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
.button-stack { display: grid; gap: 10px; justify-items: start; }
.file-btn { position: relative; }
.file-btn:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---------- Energy buttons ---------- */
.energy-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-bottom: 18px;
}
.energy-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  min-height: 72px;
  padding: 8px 2px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  cursor: pointer;
}
.energy-num { font-family: var(--font-head); font-weight: 600; font-size: 1.4rem; line-height: 1; }
.energy-label { font-size: 0.8rem; }
.energy-btn:hover { border-color: var(--primary); }
.energy-btn[aria-pressed="true"] {
  background: var(--primary); color: var(--on-primary); border-color: var(--primary);
}

/* ---------- Chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.chip {
  min-height: var(--tap);
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--ink);
  font: 500 0.9rem/1.2 var(--font-body);
  cursor: pointer;
}
.chip[aria-pressed="true"] {
  background: var(--teal-tint); color: var(--deep-teal); border-color: var(--primary);
}
/* A tick so "selected" is not shown by colour alone */
.chip[aria-pressed="true"]::before { content: "\2713\00a0"; }

/* ---------- Pills ---------- */
.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.8rem; font-weight: 600;
  white-space: nowrap;
}
.pill-demanding { background: var(--pill-demanding-bg); color: var(--pill-demanding-fg); }
.pill-moderate  { background: var(--pill-moderate-bg);  color: var(--pill-moderate-fg); }
.pill-restoring { background: var(--pill-restoring-bg); color: var(--pill-restoring-fg); }
.pill-demo { background: var(--bar-track); color: var(--ink); }

/* Radio buttons shown as pills */
.demand-choice { border: 0; padding: 0; margin: 12px 0; display: flex; flex-wrap: wrap; gap: 8px; }
.demand-choice legend { padding: 0; margin-bottom: 6px; }
.pill-radio {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: var(--tap);
  padding: 4px 12px 4px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
}
.pill-radio input { width: 20px; height: 20px; margin: 0; accent-color: var(--primary); }
.pill-radio:has(input:checked) { border-color: var(--primary); background: var(--teal-tint); }
.pill-radio:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---------- Forms ---------- */
.field-label { display: block; font-weight: 600; font-size: 0.9rem; margin: 12px 0 4px; }
input[type="text"], input[type="number"], input[type="date"], input[type="time"], select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--ink);
  font: 400 1rem/1.4 var(--font-body);
}
input:focus-visible, select:focus-visible, textarea:focus-visible { border-color: var(--primary); }
textarea { resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }

.inline-form { display: flex; gap: 8px; margin-bottom: 4px; }
.inline-form input { flex: 1; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; }
.field-row .grow { grid-column: span 2; }
@media (max-width: 380px) { .field-row .grow { grid-column: auto; } }

.check-row { display: flex; align-items: center; gap: 10px; min-height: var(--tap); }
.check-row input[type="checkbox"] { width: 22px; height: 22px; margin: 0; accent-color: var(--primary); flex: none; }

.form-message { color: var(--danger); font-weight: 500; margin: 8px 0 0; min-height: 0; }
.form-message:empty { display: none; }

/* ---------- Lists ---------- */
.list { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 8px; }
.list-item {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 10px 10px 14px;
}
.list-compact .list-item { background: transparent; border: 0; padding: 4px 0; }
.card-tint .list-compact .list-item { color: var(--deep-teal); }
.list-main { min-width: 0; flex: 1 1 170px; }
.list-title { font-weight: 600; overflow-wrap: anywhere; }
.list-meta { color: var(--muted); font-size: 0.875rem; overflow-wrap: anywhere; }
.card-tint .list-meta { color: var(--deep-teal); }
.list-actions { display: flex; gap: 6px; flex: none; align-items: center; }
.empty { color: var(--muted); font-size: 0.95rem; padding: 4px 2px; }
.summary-line { font-weight: 500; margin: 0 0 8px; }

/* Edit-in-place row on the recovery menu */
.edit-row { display: grid; gap: 8px; width: 100%; }

/* ---------- Week chart ---------- */
.chart {
  list-style: none; margin: 8px 0 0; padding: 0;
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px;
}
.chart-col { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.chart-value { font-weight: 600; font-size: 0.9rem; min-height: 1.4em; }
.chart-track {
  width: 100%; max-width: 44px; height: 150px;
  background: var(--bar-track);
  border-radius: 10px;
  display: flex; align-items: flex-end;
  overflow: hidden;
}
.chart-bar { width: 100%; background: var(--primary); border-radius: 10px 10px 0 0; }
/* Low bars: amber plus a dark outline, so they stand out from the track (not colour alone) */
.chart-bar.is-low { background: var(--amber); box-shadow: inset 0 0 0 2px var(--pill-demanding-fg); }
.chart-day { font-size: 0.8rem; color: var(--muted); text-align: center; line-height: 1.2; }
.chart-day strong { color: var(--ink); font-weight: 600; display: block; }

.week-nav { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 12px; margin-bottom: 4px; }
.stat-grid .card { margin: 0 0 12px; padding: 14px; }
.stat-label { color: var(--muted); font-size: 0.875rem; margin: 0 0 4px; }
.stat-value { font-family: var(--font-head); font-weight: 600; font-size: 1.6rem; margin: 0; }

/* ---------- Patterns ---------- */
.pattern-list { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 10px; }
.pattern-list li { padding: 12px 14px; border-radius: var(--radius); background: var(--bg); }
.progress { height: 10px; background: var(--bar-track); border-radius: 999px; overflow: hidden; margin: 8px 0 12px; }
.progress > span { display: block; height: 100%; background: var(--primary); }

.feature-list { padding-left: 1.2rem; margin: 0 0 12px; }
.feature-list li { margin-bottom: 6px; }

/* ---------- Banners ---------- */
.banner {
  max-width: 720px; margin: 12px auto 0;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--teal-tint); color: var(--deep-teal);
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
}
.banner[hidden] { display: none; }
.banner-warn { background: var(--note-bg); color: var(--ink); }
@media (max-width: 752px) { .banner { margin-left: 16px; margin-right: 16px; } }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center; gap: 4px;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.tab {
  flex: 1; max-width: 160px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  min-height: 56px;
  border-radius: var(--radius);
  color: var(--muted);
  text-decoration: none;
  font-size: 0.8rem; font-weight: 600;
}
.tab[aria-current="page"] { color: var(--deep-teal); background: var(--teal-tint); }

/* ---------- Dialog ---------- */
dialog {
  border: 0; border-radius: var(--radius-lg);
  padding: 22px; max-width: min(420px, calc(100vw - 32px));
  background: var(--card); color: var(--ink);
}
dialog::backdrop { background: rgba(20, 26, 28, 0.55); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 999px;
  font-weight: 500; font-size: 0.95rem;
  z-index: 50;
}
.toast:empty { display: none; }

.dev-panel summary { cursor: pointer; font-weight: 600; min-height: var(--tap); display: flex; align-items: center; }

/* ---------- Respect reduced-motion preference ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto !important;
  }
}
