/*
 * theme.css — Duet's design-system values.
 * Swiss grid discipline (square corners, hairline borders, no shadow) carrying
 * loose, hand-picked colour (each habit's own colour is drawn at runtime as an
 * inline style, never a token — this file only sets the system's own palette).
 */

:root {
  --canvas: #fbf8f3;
  --surface: #fdfcfa;
  --surface-2: #f2ede2;
  --border: #ddd6c6;
  --border-strong: #b9b099;
  --ink: #22242b;
  --muted: #666668;
  --accent: #3d5a80;
  --accent-hover: #32496a;
  --accent-ink: #ffffff;
  --accent-text: #3d5a80;
  --accent-strong: #3d5a80;
  --accent-soft: #e4ebf2;
  --accent-border: #a9bdd2;
  --success: #3f7d54;
  --success-ink: #ffffff;
  --success-soft: #e2ede4;
  --success-strong: #2e5c3e;
  --warning: #a2661c;
  --warning-ink: #ffffff;
  --warning-soft: #f3e7d5;
  --warning-strong: #825115;
  --danger: #a33d3d;
  --danger-ink: #ffffff;
  --danger-soft: #f2e0df;
  --danger-strong: #832f2f;
  --chart-1: #3d5a80;
  --chart-2: #c1666b;
  --chart-3: #9c8f4e;
  --chart-4: #598c74;
  --chart-5: #8a5a9e;
  --chart-6: #c98a3d;

  --font-display: "Fraunces", ui-serif, Georgia, serif;
  --font-body: "Inter", ui-sans-serif, system-ui, sans-serif;
  --font-sans: "Inter", ui-sans-serif, system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --display-weight: 600;
  --display-tracking: -0.01em;
  --eyebrow-tracking: 0.06em;

  --radius-btn: 2px;
  --radius-card: 0px;
  --radius-input: 2px;
  --border-w: 1px;
  --border-strong-w: 1.5px;
  --shadow-card: none;
  --shadow-raised: 0 10px 30px -12px color-mix(in srgb, var(--ink) 22%, transparent);
  --shadow-btn: none;
  --card-pad: 1.5rem;
  --caps: none;
  --caps-tracking: 0.03em;
  --btn-weight: 600;
  --measure: 62ch;

  /* A habit's own colour fills the day cell (set inline, per row); this is
     the checkmark drawn on top of it — white reads on every colour in the
     palette, in both modes, since the cell's ground is never the page's. */
  --x-tick-ink: #ffffff;
}

html[data-theme="dark"] {
  --canvas: #1c1c20;
  --surface: #232327;
  --surface-2: #2b2b30;
  --border: #3a3a40;
  --border-strong: #55555c;
  --ink: #f2efe9;
  --muted: #a3a2a0;
  --accent: #7fa1c7;
  --accent-hover: #93b1d2;
  --accent-ink: #16202c;
  --accent-text: #93b1d2;
  --accent-strong: #b7cee3;
  --accent-soft: #2a3a4b;
  --accent-border: #3f5872;
  --success: #6bab80;
  --success-ink: #10241a;
  --success-soft: #203028;
  --success-strong: #93cca5;
  --warning: #cf9c56;
  --warning-ink: #241a0c;
  --warning-soft: #362b18;
  --warning-strong: #e0b579;
  --danger: #c17b7b;
  --danger-ink: #260f0f;
  --danger-soft: #362323;
  --danger-strong: #daa1a1;
  --chart-1: #7fa1c7;
  --chart-2: #d89195;
  --chart-3: #bdae73;
  --chart-4: #83b49b;
  --chart-5: #ae87c2;
  --chart-6: #e0ab6b;

  --x-tick-ink: #ffffff;
}

/*
 * app.css — Duet's own screen: the week grid, the day cells, the colour and
 * icon pickers, the sliding add/edit panel, and the past-weeks dot grids.
 * Tokens only.
 */

/* A faint grid paper behind the whole page — the "visible grid" the brief
   asks for, doing quiet work under everything rather than one band. */
body {
  background-image:
    linear-gradient(color-mix(in srgb, var(--ink) 5%, transparent) 1px, transparent 1px),
    linear-gradient(90deg, color-mix(in srgb, var(--ink) 5%, transparent) 1px, transparent 1px);
  background-size: 2.5rem 2.5rem;
  background-position: -1px -1px;
}

/* ---- Week header ------------------------------------------------------ */
.week-header {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding-top: 0.5rem;
}
@media (min-width: 48rem) {
  .week-header { flex-direction: row; align-items: flex-end; justify-content: space-between; }
}
.week-header-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.85rem;
}
@media (min-width: 40rem) {
  .week-header-actions { flex-direction: row; align-items: center; gap: 1.5rem; }
}
.owner-filter { display: flex; gap: 0.5rem; }

/* ---- The grid ----------------------------------------------------------- */
.hgrid { border-collapse: separate; border-spacing: 0; min-width: 44rem; }
.hgrid-habit {
  position: sticky;
  left: 0;
  z-index: 2;
  min-width: 14.5rem;
  max-width: 14.5rem;
  background: var(--surface);
}
.hgrid thead .hgrid-habit { z-index: 3; background: var(--surface-2); }
.hgrid-cell { min-width: 3.25rem; text-align: center; }
.hgrid-cell.is-today { background: color-mix(in srgb, var(--accent) 9%, transparent); }
.hgrid thead .hgrid-cell.is-today { background: color-mix(in srgb, var(--accent) 16%, var(--surface-2)); }
.hgrid-streak { min-width: 4.5rem; text-align: right; }

.day-cell {
  display: inline-grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 10px;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  color: transparent;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.1s var(--ease-out, ease);
}
.day-cell:hover { border-color: var(--ink); transform: translateY(-1px); }
.day-cell:active { transform: translateY(0) scale(0.92); }
.day-cell:focus-visible { outline: none; box-shadow: var(--ring); }
.day-cell.is-done {
  background: var(--habit-color);
  border-color: var(--habit-color);
  color: var(--x-tick-ink);
  box-shadow: 0 6px 14px -7px color-mix(in srgb, var(--habit-color) 70%, transparent);
}
.day-cell.is-future {
  border-style: dashed;
  border-color: var(--border);
  opacity: 0.4;
  cursor: default;
}
.day-cell.htmx-request { opacity: 0.6; }

/* Row entrance — the one grid that moves. Pure CSS so it plays on first
   paint and replays whenever htmx drops in fresh rows (a new habit, an
   expanded week) without any script. */
@keyframes row-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.hgrid tbody tr { animation: row-in 0.45s var(--ease-out, ease) both; }
.hgrid tbody tr:nth-child(1) { animation-delay: 0ms; }
.hgrid tbody tr:nth-child(2) { animation-delay: 55ms; }
.hgrid tbody tr:nth-child(3) { animation-delay: 110ms; }
.hgrid tbody tr:nth-child(4) { animation-delay: 165ms; }
.hgrid tbody tr:nth-child(5) { animation-delay: 220ms; }
.hgrid tbody tr:nth-child(6) { animation-delay: 275ms; }
.hgrid tbody tr:nth-child(7) { animation-delay: 330ms; }
.hgrid tbody tr:nth-child(8) { animation-delay: 385ms; }
html.reduced-motion .hgrid tbody tr { animation: none; }

/* ---- Colour swatches ---------------------------------------------------- */
.swatch-row { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.swatch {
  position: relative;
  display: inline-block;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 999px;
  background: var(--swatch-color);
  cursor: pointer;
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1.5px color-mix(in srgb, var(--ink) 15%, transparent);
  transition: transform 0.15s, box-shadow 0.15s;
}
.swatch:hover { transform: translateY(-2px); }
.swatch.is-selected, .swatch:has(input:checked) {
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--swatch-color);
}

/* Icon chips reuse .chip; the input is visually hidden, :has() keeps the
   selected one lit without any script. */
.icon-chip:has(input:checked) { border-color: var(--accent-border); background: var(--accent-soft); color: var(--accent-strong); }
.swatch:has(input:focus-visible), .icon-chip:has(input:focus-visible) {
  outline: 2px solid var(--accent-border);
  outline-offset: 2px;
}

/* ---- Add/edit panel — a CSS-grid accordion, no JS height math ---------- */
.habit-panel-collapse {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.35s var(--ease, ease);
}
.habit-panel-collapse.open { grid-template-rows: 1fr; margin-top: 1.5rem; }
.habit-panel-collapse > .habit-panel-inner { overflow: hidden; min-height: 0; }
#habit-panel-body:empty { padding: 0; border: 0; }

/* ---- Past weeks ---------------------------------------------------------- */
.week-tiles-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(11.5rem, 1fr)); gap: 1rem; }
.week-tile { border: var(--border-w, 1px) solid var(--border); background: var(--surface); padding: 1.1rem; }
.week-tile.is-open { grid-column: 1 / -1; }
.week-tile-head {
  display: flex;
  width: 100%;
  min-height: 2.25rem;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: var(--ink);
  text-align: left;
}
.week-dots { margin-top: 0.85rem; display: flex; flex-direction: column; gap: 0.4rem; }
.week-dots-row { display: flex; gap: 0.3rem; }
.week-dots-empty { margin-top: 0.85rem; font-size: 0.8rem; color: var(--muted); }
.dot { width: 0.5rem; height: 0.5rem; border-radius: 999px; background: color-mix(in srgb, var(--ink) 14%, transparent); }
.dot.is-filled { background: var(--ink); }

@media (width < 40rem) {
  .week-tiles-grid { grid-template-columns: repeat(2, 1fr); }
}
