/* Where did my month go — habit dashboard
 * Concept: time as a filling grid. The month grid is the signature; big
 * Space Grotesk streak numbers are the emotional hook. Everything else stays
 * quiet so those two carry the page.
 * Type: Space Grotesk (display/numbers) + Inter (body/UI).
 * Habit colors come from the validated dataviz categorical palette (fixed
 * hue per habit — color follows the entity, never its rank).
 */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --ink: #14161a;
  --ink-2: #565b64;
  --ink-3: #8b909a;
  --line: #e4e6ea;
  --line-2: #eef0f3;
  --accent: #2a78d6;
  --shadow: 0 1px 2px rgba(20,22,26,.06), 0 12px 28px -16px rgba(20,22,26,.22);

  /* categorical habit hues (light) — dataviz palette, fixed slot order */
  --slot-0:#2a78d6; --slot-1:#eb6834; --slot-2:#1baf7a; --slot-3:#eda100;
  --slot-4:#e87ba4; --slot-5:#008300; --slot-6:#4a3aa7; --slot-7:#e34948;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0e11;
    --surface: #16191e;
    --ink: #eceef1;
    --ink-2: #a3a9b3;
    --ink-3: #6c727c;
    --line: #262a30;
    --line-2: #1e2126;
    --accent: #3987e5;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 12px 28px -16px rgba(0,0,0,.7);
    --slot-0:#3987e5; --slot-1:#d95926; --slot-2:#199e70; --slot-3:#c98500;
    --slot-4:#d55181; --slot-5:#008300; --slot-6:#9085e9; --slot-7:#e66767;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0 auto;
  max-width: 980px;
  padding: 3rem 1.1rem 5rem;
  font-family: "Inter", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ---------- masthead ---------- */
.masthead { margin-bottom: 2.4rem; }
.masthead h1 {
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  font-size: clamp(2.4rem, 8vw, 4.2rem);
  line-height: .96;
  letter-spacing: -.02em;
  margin: 0 0 .8rem;
}
.lede { max-width: 34rem; font-size: 1.05rem; color: var(--ink-2); margin: 0 0 .6rem; }
.fineprint { font-size: .82rem; color: var(--ink-3); margin: 0; }
.fineprint a { color: var(--accent); }

/* ---------- overview strip ---------- */
.overview {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .9rem;
  margin-bottom: 2rem;
}
.ov-tile {
  background: var(--surface);
  box-shadow: var(--shadow);
  border-radius: 14px;
  padding: 1rem 1.2rem;
  display: flex;
  flex-direction: column;
}
.ov-label { font-size: .76rem; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-3); }
.ov-value {
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  font-size: 2.2rem;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.ov-unit { font-size: .8rem; color: var(--ink-2); }

/* ---------- habit cards ---------- */
.card {
  background: var(--surface);
  box-shadow: var(--shadow);
  border-radius: 16px;
  padding: 1.3rem 1.4rem;
  margin-bottom: 1.1rem;
  border-left: 4px solid var(--habit, var(--accent));
}
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.title-wrap { display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; }
.swatch { width: 12px; height: 12px; border-radius: 3px; background: var(--habit, var(--accent)); flex: none; }
.habit-name { font-family: "Space Grotesk", sans-serif; font-weight: 500; font-size: 1.3rem; margin: 0; }
.habit-goal { font-size: .82rem; color: var(--ink-3); }
.card-tools { display: flex; gap: .2rem; }

.metrics { display: flex; flex-wrap: wrap; gap: 1.6rem; margin: 1.1rem 0 1.3rem; align-items: baseline; }
.metric { display: flex; flex-direction: column; }
.metric-value {
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  font-size: 1.5rem;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.metric.big .metric-value {
  font-size: 2.9rem;
  color: var(--habit, var(--accent));
}
.metric.big .metric-value::before { content: "🔥 "; font-size: .7em; }
.metric.big .metric-value.zero { color: var(--ink-3); }
.metric.big .metric-value.zero::before { content: ""; }
.metric-label { font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); margin-top: .2rem; }

/* ---------- month grid (the signature) ---------- */
.grid-wrap { --cell: 30px; --gap: 5px; }
.weekday-row, .month-grid {
  display: grid;
  grid-template-columns: repeat(7, var(--cell));
  gap: var(--gap);
}
.weekday-row { margin-bottom: 4px; }
.weekday-row span { font-size: .64rem; text-align: center; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; }
.cell {
  width: var(--cell); height: var(--cell);
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--line-2);
  cursor: pointer;
  padding: 0;
  position: relative;
  transition: transform .08s ease, box-shadow .08s ease;
  font: inherit;
  font-size: .62rem;
  color: var(--ink-3);
}
.cell:hover { transform: scale(1.12); box-shadow: 0 2px 8px rgba(20,22,26,.18); z-index: 2; }
.cell:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.cell.pad { visibility: hidden; cursor: default; }
.cell.future { opacity: .35; cursor: not-allowed; }
.cell.today { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--habit, var(--accent)); }
/* met: filled with the habit hue. logged-but-missed: faint tint + dot. */
.cell.met { background: var(--habit, var(--accent)); border-color: var(--habit, var(--accent)); color: #fff; }
.cell.missed { background: color-mix(in srgb, var(--habit, var(--accent)) 14%, var(--surface)); border-color: color-mix(in srgb, var(--habit, var(--accent)) 30%, var(--line)); }
.cell.missed::after { content: ""; position: absolute; inset: 0; margin: auto; width: 5px; height: 5px; border-radius: 50%; background: var(--ink-3); }
.cell .daynum { position: absolute; top: 2px; left: 4px; }

.cell-editor { width: var(--cell); }
.cell-input {
  width: 3.4rem; padding: .3rem .4rem; font: inherit; font-size: .85rem;
  border: 1px solid var(--accent); border-radius: 6px; background: var(--surface); color: var(--ink);
}

/* ---------- trend chart ---------- */
.trend { margin-top: 1.2rem; }
.trend-caption { font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); margin-bottom: .4rem; }
.trend svg { display: block; width: 100%; height: 130px; }
.trend .goal-line { stroke: var(--ink-3); stroke-width: 1; stroke-dasharray: 3 3; }
.trend .baseline { stroke: var(--line); stroke-width: 1; }
.trend .series-line { fill: none; stroke: var(--habit, var(--accent)); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.trend .dot { fill: var(--habit, var(--accent)); }
.trend text { font-size: 10px; fill: var(--ink-3); font-family: "Inter", sans-serif; }
.trend text.goal-label { fill: var(--ink-2); }

/* ---------- composer ---------- */
.composer {
  background: var(--surface);
  box-shadow: var(--shadow);
  border-radius: 16px;
  padding: 1.3rem 1.4rem 1.5rem;
  margin-top: 2rem;
}
.composer h2 { font-family: "Space Grotesk", sans-serif; font-weight: 500; font-size: 1.2rem; margin: 0 0 1rem; }
.row { display: flex; flex-wrap: wrap; gap: .9rem; align-items: flex-end; margin-bottom: .9rem; }
.row label { display: flex; flex-direction: column; gap: .3rem; font-size: .78rem; color: var(--ink-2); }
.row label.grow { flex: 1 1 12rem; }
.actions-row { align-items: center; margin-bottom: 0; }
input, select, button {
  font: inherit; font-size: .92rem; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: .5rem .7rem;
}
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.row label input, .row label select { min-width: 0; }
button { cursor: pointer; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
button.icon { border: none; background: none; padding: .2rem .4rem; font-size: .95rem; color: var(--ink-3); }
button.icon:hover { color: var(--accent); }
button.icon.delete:hover { color: var(--slot-7); }
#form-msg { font-size: .84rem; }
#form-msg.err { color: var(--slot-7); }
#form-msg.ok { color: var(--slot-5); }

#empty-state { color: var(--ink-2); background: var(--surface); box-shadow: var(--shadow); border-radius: 16px; padding: 1.6rem 1.4rem; }
#empty-state p { margin: 0 0 .6rem; }
#empty-state .empty-demo { margin: 0; font-size: .92rem; }
.linkish { border: none; background: none; padding: 0; color: var(--accent); font: inherit; text-decoration: underline; cursor: pointer; }

#tooltip {
  position: fixed; z-index: 20;
  background: var(--ink); color: var(--bg);
  font-size: .76rem; padding: .35rem .55rem; border-radius: 6px;
  pointer-events: none; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 560px) {
  .overview { grid-template-columns: 1fr; }
  .grid-wrap { --cell: 34px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
