/* ============================================================================
   mycal — visual design system
   ----------------------------------------------------------------------------
   DIRECTION:  "Instrument"
   A personal command center styled like a precision measuring instrument — an
   oscilloscope / vitals monitor — rather than a frosted-glass SaaS dashboard.

   IDENTITY (the recognizable hook):
   - Near-monochrome graphite UI carrying ONE electric "live signal" accent: a
     sharp chartreuse-lime (#c9f24d) — the color of a heart-rate trace. Used
     surgically: the active nav, the data line, focus rings, the today marker.
   - Structural motif: the MEASUREMENT GRID. Hairline 1px rules, tick marks,
     and a thin "instrument rule" across the top of every panel. Panels are
     matte, not glass — text always sits on near-solid surfaces (legibility).
   - Typography: prose in a humanist system sans; every NUMBER and micro-label
     in a system MONOSPACE, tracked out and uppercased, so figures read like
     instrument readouts (protein g, kcal band, dates, chart).

   PALETTE:   ink #e9edf4 on graphite #0c0e12 / panel #14171f / raised #1b1f29
              hairline #262b37, signal #c9f24d, with restrained category hues
              (strength indigo, cardio aqua, injection coral, calendar blue).
   TYPE:      fluid clamp() display scale, 12px tracked mono labels, mono nums.
   MOTION:    "signal sweep" — accent line draws/pulses like a live trace;
              count-ups; staggered panel rise; hover lift. All disabled under
              prefers-reduced-motion. Targets 60fps (transform/opacity only).
   ========================================================================== */

:root {
  /* surfaces */
  --bg: #0c0e12;
  --bg-2: #0a0c10;
  --panel: #14171f;
  --panel-2: #1b1f29;
  --raised: #20252f;
  --line: #262b37;
  --line-soft: #1d222c;

  /* ink */
  --ink: #e9edf4;
  --ink-2: #c2c9d6;
  --muted: #828b9c;
  --faint: #5a6273;

  /* signal accent (single confident identity color) */
  --signal: #c9f24d;
  --signal-dim: #9bbe33;
  --signal-glow: rgba(201, 242, 77, .14);
  --signal-ink: #0c0e12;     /* text on signal fills */

  /* category hues (used sparingly, mostly as 1px markers) */
  --strength: #8a7dff;
  --cardio: #34d4b4;
  --inject: #ff7a59;
  --gcal: #4aa3ff;
  --upstream: #7c869a;
  --rest: #39414f;

  /* legacy aliases kept so any stray reference still resolves */
  --accent: var(--signal);
  --accent-2: var(--cardio);
  --injection: var(--inject);

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 0 rgba(255,255,255,.02) inset,
            0 18px 40px -24px rgba(0,0,0,.9);

  --mono: "SFMono-Regular", ui-monospace, "Cascadia Code", "JetBrains Mono",
          "Roboto Mono", Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;

  --ease: cubic-bezier(.2, .7, .2, 1);
}

* { box-sizing: border-box; }

/* The `hidden` attribute must win over author display rules (e.g. .stat is a
   flex/grid container, which would otherwise override [hidden]'s display:none). */
[hidden] { display: none !important; }

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

body {
  margin: 0;
  color: var(--ink);
  font: 15px/1.55 var(--sans);
  background-color: var(--bg);
  /* faint measurement grid + a single soft light from top-left */
  background-image:
    radial-gradient(900px 480px at 8% -8%, rgba(201,242,77,.05), transparent 60%),
    linear-gradient(var(--line-soft) 1px, transparent 1px),
    linear-gradient(90deg, var(--line-soft) 1px, transparent 1px);
  background-size: 100% 100%, 64px 64px, 64px 64px;
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.muted { color: var(--muted); }
a { color: inherit; text-decoration: none; }

/* shared micro-label: the "instrument readout" label style */
.stat-label, .hero-date, .up-day, .wp-day, .day-cat, .legend, .cell-date,
.grid .head, .stat-sub, .more {
  font-family: var(--mono);
  font-feature-settings: "tnum" 1;
}

/* ============================== LOGIN ============================== */
.login-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  position: relative;
  width: min(380px, 92vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 34px 30px 30px;
  display: flex;
  flex-direction: column;
  gap: 13px;
  box-shadow: var(--shadow), 0 40px 90px -50px #000;
  overflow: hidden;
}
/* the "instrument rule": a hairline with a moving signal pip across the top */
.login-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--signal), transparent);
  background-size: 40% 100%;
  background-repeat: no-repeat;
  opacity: .9;
  animation: sweep 3.2s var(--ease) infinite;
}
@keyframes sweep {
  0%   { background-position: -40% 0; }
  100% { background-position: 140% 0; }
}
.login-card h1 {
  margin: 4px 0 0;
  font-size: 30px;
  letter-spacing: -.5px;
  font-weight: 700;
}
.login-card > p { margin: 0 0 6px; font-size: 13px; }
.login-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  position: relative;
  display: grid;
  place-items: center;
}
/* a pulsing vitals dot inside the mark — real motion, no image */
.login-mark::after {
  content: "";
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--signal);
  box-shadow: 0 0 0 0 var(--signal-glow);
  animation: pulse 2s var(--ease) infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(201,242,77,.5); }
  70%  { box-shadow: 0 0 0 12px rgba(201,242,77,0); }
  100% { box-shadow: 0 0 0 0 rgba(201,242,77,0); }
}
.login-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}
.login-card input {
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: 12px 13px;
  font: 15px/1.2 var(--sans);
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease);
}
.login-card input:focus {
  outline: none;
  border-color: var(--signal);
  box-shadow: 0 0 0 3px var(--signal-glow);
}
button {
  background: var(--signal);
  color: var(--signal-ink);
  border: 0;
  border-radius: var(--radius-sm);
  padding: 12px 15px;
  font: 600 14px/1 var(--sans);
  letter-spacing: .01em;
  cursor: pointer;
  transition: transform .15s var(--ease), filter .15s var(--ease),
              box-shadow .15s var(--ease);
}
button:hover { filter: brightness(1.06); box-shadow: 0 8px 22px -10px var(--signal); }
button:active { transform: translateY(1px); }
button:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }
.alert {
  background: #2a1517;
  border: 1px solid #5b2a2a;
  color: #ffb1a3;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}

/* ============================== APP SHELL ============================== */
.app { min-height: 100vh; min-height: 100dvh; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 22px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(12,14,18,.82);
  backdrop-filter: blur(10px) saturate(1.2);
  -webkit-backdrop-filter: blur(10px) saturate(1.2);
}
.brand {
  font-weight: 800;
  letter-spacing: -.3px;
  font-size: 17px;
  display: flex;
  align-items: center;
  gap: 9px;
}
.brand::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--signal);
  box-shadow: 0 0 10px var(--signal);
  animation: pulse 2.4s var(--ease) infinite;
}
.topbar nav { display: flex; gap: 6px; align-items: center; }
.topbar nav a {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 7px 12px;
  border-radius: 8px;
  transition: color .15s var(--ease), background .15s var(--ease);
}
.topbar nav a:hover { color: var(--ink); background: var(--panel); }
.topbar nav a.active {
  color: var(--signal);
  background: var(--signal-glow);
}

.layout {
  display: grid;
  grid-template-columns: 1fr 330px;
  gap: 18px;
  max-width: 1200px;
  margin: 24px auto;
  padding: 0 20px;
}
.layout .full, .content.full { grid-column: 1 / -1; }
.content { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.sidebar { display: flex; flex-direction: column; gap: 18px; min-width: 0; }

/* matte instrument panel */
.card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  transition: transform .25s var(--ease), border-color .25s var(--ease);
}
/* thin instrument rule along the top edge of every panel */
.card::before {
  content: "";
  position: absolute;
  top: -1px; left: 14px; right: 14px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--line) 12%,
              var(--line) 88%, transparent);
}
.card.subtle { background: var(--panel-2); }
.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.card-head h2 {
  margin: 0;
  font-size: 12px;
  font-family: var(--mono);
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-2);
  display: flex;
  align-items: center;
  gap: 8px;
}
/* tick mark before each section title */
.card-head h2::before {
  content: "";
  width: 6px; height: 6px;
  background: var(--signal);
  border-radius: 1px;
}
.card-head .muted { font-family: var(--mono); font-size: 12px; }

/* ============================== HERO / TODAY ============================== */
.hero {
  overflow: hidden;
  background:
    radial-gradient(600px 220px at 100% -40%, var(--signal-glow), transparent 70%),
    var(--panel);
}
.hero-date {
  font-size: 12px;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--signal-dim);
  display: flex;
  align-items: center;
  gap: 8px;
}
.hero-date::before {
  content: "● LIVE";
  font-size: 9px;
  letter-spacing: .15em;
  color: var(--signal);
  padding: 2px 6px;
  border: 1px solid var(--signal-dim);
  border-radius: 4px;
  line-height: 1;
}
.hero-headline {
  margin: 10px 0 20px;
  font-size: clamp(26px, 4.2vw, 38px);
  line-height: 1.08;
  letter-spacing: -.6px;
  font-weight: 700;
  max-width: 22ch;
}
.hero-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}
.stat {
  position: relative;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow: hidden;
  transition: transform .2s var(--ease), border-color .2s var(--ease),
              background .2s var(--ease);
}
.stat::after {            /* left tick rail */
  content: "";
  position: absolute;
  left: 0; top: 14px; bottom: 14px;
  width: 2px;
  background: var(--line);
  border-radius: 2px;
  transition: background .2s var(--ease);
}
.stat:hover {
  transform: translateY(-2px);
  border-color: #313846;
  background: var(--raised);
}
.stat:hover::after { background: var(--signal); }
.stat-label {
  font-size: 10.5px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
}
.stat-value {
  font-family: var(--mono);
  font-size: 25px;
  font-weight: 600;
  letter-spacing: -.5px;
  font-feature-settings: "tnum" 1;
  color: var(--ink);
}
.stat-value b { font-weight: 700; }
.stat-sub { font-size: 11px; color: var(--muted); letter-spacing: .02em; }
.badge-inject { color: var(--inject); }
.disclaimer {
  margin: 16px 0 0;
  font-size: 11.5px;
  color: var(--muted);
  border-top: 1px dashed var(--line);
  padding-top: 12px;
}

/* progress chart panel — bound the canvas so the responsive chart can't
   grow unbounded (Chart.js maintainAspectRatio:false needs a sized box). */
#progressChart {
  margin-top: 4px;
  width: 100% !important;
  max-height: 280px;
  display: block;
}

/* ============================== SIDEBAR LISTS ============================== */
.upcoming, .weekplan {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.up-item {
  display: grid;
  grid-template-columns: 58px 1fr auto;
  gap: 10px;
  align-items: center;
  font-size: 14px;
  padding: 8px 8px;
  border-radius: 8px;
  border-left: 2px solid var(--line);
  transition: background .15s var(--ease), border-color .15s var(--ease);
}
.up-item:hover { background: var(--panel-2); border-left-color: var(--signal); }
.up-day {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .04em;
}
.up-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lock { opacity: .65; font-size: 12px; }
.wp-item {
  display: grid;
  grid-template-columns: 46px 1fr;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  transition: background .15s var(--ease);
}
.wp-item:hover { background: var(--panel); }
.wp-item.is-today {
  background: var(--signal-glow);
  border-color: var(--signal-dim);
}
.wp-item.is-today .wp-day { color: var(--signal); }
.wp-day {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.wp-focus { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ============================== CALENDAR ============================== */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  font-size: 11px;
  letter-spacing: .04em;
  color: var(--muted);
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.dot {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 2px;
  margin-right: 6px;
  vertical-align: -1px;
}
.c-strength { background: var(--strength); }
.c-cardio   { background: var(--cardio); }
.c-injection{ background: var(--inject); }
.c-gcal     { background: var(--gcal); }
.c-upstream { background: var(--upstream); }
.c-rest     { background: var(--rest); }

.cal-head { flex-wrap: wrap; gap: 14px; align-items: center; }
.cal-nav { display: flex; align-items: center; gap: 8px; }
.cal-nav h2 {
  min-width: 200px;
  text-transform: none;
  letter-spacing: -.2px;
  font-family: var(--sans);
  font-size: 17px;
  color: var(--ink);
}
.cal-nav h2::before { display: none; }
.cal-nav button, .cal-views button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--ink-2);
  padding: 7px 13px;
  border-radius: 8px;
  font: 600 13px/1 var(--sans);
  cursor: pointer;
  transition: background .15s var(--ease), color .15s var(--ease),
              border-color .15s var(--ease), transform .1s var(--ease);
}
.cal-nav button:hover, .cal-views button:hover {
  background: var(--raised);
  border-color: #313846;
}
.cal-nav button:active, .cal-views button:active { transform: translateY(1px); }
.cal-views { display: flex; gap: 6px; }
.cal-views button {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.cal-views button.active {
  background: var(--signal);
  border-color: transparent;
  color: var(--signal-ink);
}
.ghost { opacity: .9; }
button:focus-visible, .cal-nav button:focus-visible,
.cal-views button:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }

.grid { display: grid; gap: 6px; }
/* minmax(0,1fr) lets columns shrink below their content's intrinsic width so
   the 7-col grid never overflows; chips ellipsis inside the clamped cell. */
.grid.month, .grid.week { grid-template-columns: repeat(7, minmax(0, 1fr)); }
.grid .head {
  text-align: center;
  font-size: 10.5px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 6px 0 8px;
}
.cell {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  min-height: 96px;
  min-width: 0;
  padding: 7px;
  transition: border-color .15s var(--ease), background .15s var(--ease),
              transform .12s var(--ease);
}
.cell:hover { border-color: #353d4c; background: var(--raised); }
.grid.week .cell { min-height: 230px; }
.cell.dim { opacity: .4; }
.cell.is-today {
  border-color: var(--signal-dim);
  background:
    radial-gradient(120px 80px at 50% 0%, var(--signal-glow), transparent 70%),
    var(--panel-2);
}
.cell.is-today .cell-date { color: var(--signal); font-weight: 700; }
.cell-date {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
  font-feature-settings: "tnum" 1;
}
.cell-items { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cell-items .chip { max-width: 100%; }
.chip {
  font-family: var(--sans);
  font-size: 11px;
  padding: 3px 7px;
  border-radius: 5px;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-left: 2px solid rgba(255,255,255,.35);
  background: var(--panel);
  transition: transform .12s var(--ease);
}
.chip:hover { transform: translateX(2px); }
/* category chips: tinted surface + solid left rule (instrument look) */
.chip.c-strength { background: rgba(138,125,255,.16); color: #cdc6ff; border-left-color: var(--strength); }
.chip.c-cardio   { background: rgba(52,212,180,.15); color: #a8efe0; border-left-color: var(--cardio); }
.chip.c-injection{ background: rgba(255,122,89,.16); color: #ffc4b3; border-left-color: var(--inject); }
.chip.c-gcal     { background: rgba(74,163,255,.15); color: #bcdcff; border-left-color: var(--gcal); }
.chip.c-upstream { background: rgba(124,134,154,.16); color: #cbd2de; border-left-color: var(--upstream); }
.chip.c-rest     { background: var(--panel); color: var(--muted); border-left-color: var(--rest); }
.chip.masked { font-style: italic; opacity: .85; }
.more {
  font-size: 10.5px;
  color: var(--muted);
  letter-spacing: .05em;
  padding: 1px 3px;
}

.dayview { display: flex; flex-direction: column; gap: 9px; }
.day-row {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 12px;
  padding: 13px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left-width: 3px;
  border-radius: var(--radius-sm);
  transition: transform .15s var(--ease), background .15s var(--ease);
}
.day-row:hover { transform: translateX(3px); background: var(--raised); }
.day-row.c-strength { border-left-color: var(--strength); }
.day-row.c-cardio   { border-left-color: var(--cardio); }
.day-row.c-injection{ border-left-color: var(--inject); }
.day-row.c-gcal     { border-left-color: var(--gcal); }
.day-row.c-upstream { border-left-color: var(--upstream); }
.day-cat {
  font-size: 10.5px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}
.day-title { font-weight: 600; }
.day-detail { font-size: 13px; color: var(--muted); margin-top: 2px; }

/* ============================== ENTRANCE MOTION ============================== */
/* .reveal is animated via WAAPI in common.js; provide a CSS fallback start
   state so cards aren't visible-then-jump if JS is slow. JS clears this. */
.reveal { will-change: transform, opacity; }

/* ============================== RESPONSIVE ============================== */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; gap: 14px; margin: 16px auto; }
}
@media (max-width: 600px) {
  body { background-size: 100% 100%, 44px 44px, 44px 44px; }
  .topbar { padding: 11px 14px; }
  .topbar nav { gap: 2px; }
  .topbar nav a { padding: 6px 9px; font-size: 11px; }
  .layout { padding: 0 12px; }
  .card { padding: 16px; border-radius: 12px; }
  .hero-headline { font-size: clamp(22px, 7vw, 28px); margin-bottom: 16px; }
  .hero-grid { grid-template-columns: repeat(2, 1fr); gap: 9px; }
  .stat { padding: 12px; }
  .stat-value { font-size: 21px; }
  .cell { min-height: 62px; padding: 5px; }
  .cell-date { margin-bottom: 3px; }
  .chip { font-size: 10px; padding: 2px 5px; }
  .grid { gap: 4px; }
  /* Month/week grids stay 7-wide but become horizontally scrollable so
     columns never clip off-screen on a phone. Day view & lists are unaffected. */
  #calendar-root { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .grid.month, .grid.week { min-width: 640px; }
  .grid.week .cell { min-height: 180px; }
  .cal-nav h2 { min-width: 0; font-size: 15px; }
  .cal-head { gap: 10px; }
  .day-row { grid-template-columns: 90px 1fr; gap: 9px; padding: 11px; }
}
@media (max-width: 380px) {
  .hero-grid { grid-template-columns: 1fr; }
}

/* ============================== REDUCED MOTION ============================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
  .reveal { will-change: auto; }
}
