:root {
  /* Avanza-inspired palette: deep dark with brand green accent */
  --bg: #0a0d0c;
  --bg-grad-1: rgba(0, 200, 150, 0.18);
  --bg-grad-2: rgba(31, 227, 168, 0.10);
  --surface: rgba(255, 255, 255, 0.035);
  --surface-2: rgba(255, 255, 255, 0.06);
  --surface-hi: rgba(255, 255, 255, 0.09);
  --border: rgba(255, 255, 255, 0.08);
  --border-hi: rgba(255, 255, 255, 0.16);
  --text: #e8eee9;
  --text-soft: #b3bdb5;
  --muted: #7c8780;
  --accent: #00c896;
  --accent-2: #1fe3a8;
  --accent-grad: linear-gradient(135deg, #00c896 0%, #1fe3a8 100%);
  --green: #34d399;
  --red: #f87171;
  --amber: #fbbf24;
  --shadow: 0 1px 0 rgba(255,255,255,0.04) inset, 0 8px 24px rgba(0,0,0,0.35);
  --glow: 0 0 0 1px rgba(0,200,150,0.35), 0 0 24px rgba(0,200,150,0.25);

  --row-h: 20px;
  /* Hour / notes / side widths scale with viewport so the layout shrinks
     to fit instead of pushing the topbar (and the Account button) off the
     right edge. At ≥1900px these hit their max; at ≤900px the mobile
     breakpoint takes over. */
  --hour-w: clamp(22px, 1.8vw, 34px);
  --date-w: 64px;
  --day-w: 44px;
  --notes-w: clamp(150px, 14vw, 280px);
  --side-w: clamp(200px, 16vw, 260px);
  --top-h: 56px;
  --life-h: 22px;
  --hours-h: 26px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI Variable", "Segoe UI",
               Inter, Roboto, system-ui, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  background-image:
    radial-gradient(1000px 600px at 85% -10%, var(--bg-grad-1), transparent 60%),
    radial-gradient(900px 500px at -10% 10%, var(--bg-grad-2), transparent 60%),
    radial-gradient(700px 500px at 50% 110%, rgba(0,200,150,0.10), transparent 60%);
  background-attachment: fixed;
  font-size: 13px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;

  display: grid;
  grid-template-columns: 1fr var(--side-w);
  grid-template-rows: var(--top-h) var(--life-h) var(--hours-h) 1fr;
  grid-template-areas:
    "topbar  topbar"
    "lifebar lifebar"
    "hours   palette"
    "years   palette";
  height: 100vh;
}
::selection { background: rgba(0,200,150,0.35); color: #fff; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.16); }

button { font: inherit; color: inherit; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }

/* ---- topbar ---- */
.topbar {
  grid-area: topbar;
  background: rgba(10, 12, 18, 0.55);
  backdrop-filter: saturate(150%) blur(14px);
  -webkit-backdrop-filter: saturate(150%) blur(14px);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  min-width: 0;
}
.topbar > .brand,
.topbar > .datebar,
.topbar > .actions { flex-shrink: 0; }

.brand {
  margin: 0;
  display: inline-flex;
  align-items: baseline;
  gap: 10px;
  line-height: 1;
}
.brand .word {
  font-family: "Archivo Black", "Impact", "Helvetica Neue", sans-serif;
  font-size: 24px;
  font-weight: 900;
  letter-spacing: -0.025em;
  background: linear-gradient(115deg, #00c896 0%, #1fe3a8 35%, #9ff5d1 60%, #ffd27a 100%);
  background-size: 220% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: titleShimmer 7s ease-in-out infinite;
  filter: drop-shadow(0 2px 12px rgba(0,200,150,0.25));
  user-select: none;
}
body.demo-mode .brand .word {
  background: linear-gradient(115deg, #ff6b9d 0%, #ff9f4d 50%, #ffd27a 100%);
  background-size: 220% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  filter: drop-shadow(0 2px 12px rgba(255,107,157,0.35));
}
@keyframes titleShimmer {
  0%, 100% { background-position: 0% 50%; }
  50%      { background-position: 100% 50%; }
}
.brand .tagline {
  font-family: "Archivo Black", "Impact", sans-serif;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 4px;
  color: var(--muted);
  text-transform: uppercase;
  transform: translateY(-2px);
}
.brand .version {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 10px;
  font-weight: 500;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  letter-spacing: 0.02em;
  transform: translateY(-2px);
  user-select: text;
}
.brand .dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--accent-2);
  box-shadow: 0 0 10px var(--accent-2);
  transform: translateY(-3px);
}

.datebar { display: flex; gap: 6px; align-items: center; }
.datebar input[type="date"] {
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  color: var(--text);
  transition: all 0.15s;
}
.datebar input[type="date"]:hover { border-color: var(--border-hi); }
.datebar input[type="date"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,200,150,0.2);
}
.datebar input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(1) opacity(0.6); cursor: pointer;
}

.btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  font-weight: 500;
  transition: all 0.15s;
}
.btn:hover { background: var(--surface-hi); border-color: var(--border-hi); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--accent-grad);
  color: #0a0a0f;
  border: 0;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(0,200,150,0.35);
}

.actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.save-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-soft);
  font-size: 11px;
  padding: 0 4px;
}
.save-indicator[hidden] { display: none; }
.save-indicator .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 10px var(--green);
}
.save-indicator.saving .dot,
.save-indicator.uploading .dot {
  background: var(--amber);
  box-shadow: 0 0 10px var(--amber);
  animation: savePulse 1s infinite;
}
.save-indicator.error .dot { background: var(--red); box-shadow: 0 0 10px var(--red); }
.save-indicator.ok-cloud .dot { background: var(--accent-2); box-shadow: 0 0 10px var(--accent-2); }
@keyframes savePulse { 50% { opacity: 0.45; } }
/* "saved ✓" flash — brief confirmation after a successful cloud push,
   before the indicator settles into "synced HH:MM". */
.save-indicator.just-saved .dot { animation: saveFlashDot 1.6s ease-out; }
.save-indicator.just-saved .lbl { color: var(--accent-2); font-weight: 600; animation: saveFlashLbl 1.6s ease-out; }
@keyframes saveFlashDot {
  0%   { transform: scale(1);   box-shadow: 0 0 10px var(--accent-2); }
  20%  { transform: scale(1.6); box-shadow: 0 0 18px var(--accent-2); }
  100% { transform: scale(1);   box-shadow: 0 0 10px var(--accent-2); }
}
@keyframes saveFlashLbl {
  0%   { opacity: 0; transform: translateY(2px); }
  25%  { opacity: 1; transform: translateY(0); }
  100% { opacity: 1; }
}

/* ---- life-progress bar (4000 weeks) ---- */
.life-bar {
  grid-area: lifebar;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 18px;
  background: rgba(10, 12, 18, 0.45);
  backdrop-filter: saturate(150%) blur(10px);
  -webkit-backdrop-filter: saturate(150%) blur(10px);
  border-bottom: 1px solid var(--border);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.4px;
  color: var(--muted);
  text-transform: uppercase;
}
.life-bar-label {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  color: var(--text-soft);
}
.life-bar-track {
  position: relative;
  flex: 1;
  height: 4px;
  min-width: 80px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  overflow: hidden;
}
.life-bar-tick {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: rgba(232, 238, 233, 0.45);
  pointer-events: none;
}
.life-bar-fill {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent-grad);
  border-radius: 999px;
  box-shadow: 0 0 10px rgba(0, 200, 150, 0.45);
  transition: width 0.6s ease;
}
.life-bar-end {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  color: var(--text-soft);
}

/* ---- hour column header ---- */
.hour-header {
  --col-gap: 3px;
  grid-area: hours;
  display: grid;
  grid-template-columns:
    var(--date-w) var(--day-w) repeat(24, minmax(var(--hour-w), 1fr)) var(--notes-w);
  column-gap: var(--col-gap);
  align-items: center;
  background: rgba(10, 12, 18, 0.55);
  backdrop-filter: saturate(150%) blur(10px);
  -webkit-backdrop-filter: saturate(150%) blur(10px);
  border-bottom: 1px solid var(--border);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.4px;
  color: var(--muted);
  text-transform: uppercase;
  position: sticky; top: 0; z-index: 4;
}
.hour-header .h-date,
.hour-header .h-day { padding-left: 10px; }
.hour-header .h-hour {
  text-align: center;
  font-variant-numeric: tabular-nums;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-soft);
  font-weight: 600;
}
.hour-header .h-notes { padding-left: 12px; }

/* ---- years scroller ---- */
.years {
  grid-area: years;
  overflow: auto;
  padding: 6px 0 30vh;
}

.year-section { margin-bottom: 4px; }
.year-section > h2 { display: none; }
.year-section:not(.is-active) { display: none; }

.year-select {
  appearance: none;
  -webkit-appearance: none;
  background: rgba(0,0,0,0.25)
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' stroke='%237c8780' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>")
    no-repeat right 10px center;
  border: 1px solid var(--border);
  color: var(--text);
  color-scheme: dark;
  font: inherit;
  font-family: "Archivo Black", sans-serif;
  font-size: 14px;
  letter-spacing: -0.01em;
  border-radius: 8px;
  padding: 6px 28px 6px 10px;
  cursor: pointer;
  transition: all 0.15s;
}
.year-select:hover { border-color: var(--border-hi); }
.year-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,200,150,0.2);
}
.year-select option { background: #11131a; color: var(--text); font-family: inherit; }

.year-step {
  padding: 6px 9px;
  font-family: "Archivo Black", sans-serif;
  font-size: 14px;
  line-height: 1;
}

/* ---- rows ---- */
.row {
  --col-gap: 3px;
  display: grid;
  grid-template-columns:
    var(--date-w) var(--day-w) repeat(24, minmax(var(--hour-w), 1fr)) var(--notes-w);
  column-gap: var(--col-gap);
  align-items: stretch;
  height: var(--row-h);
  border-bottom: 1px solid rgba(255,255,255,0.03);
  user-select: none;
  transition: background 0.1s;
}
.row.is-today {
  background: rgba(0,200,150,0.06);
  outline: 1px solid rgba(0,200,150,0.45);
  outline-offset: -1px;
  z-index: 1;
}
.row.is-today:hover { background: rgba(0,200,150,0.09); }
.row.is-today .day { color: var(--accent-2); font-weight: 600; }
.row.month-first { border-top: 1px solid var(--border); }

.row .date {
  display: flex; align-items: center;
  padding-left: 10px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 10px;
}
.row .day {
  display: flex; align-items: center;
  padding-left: 4px;
  color: var(--text-soft);
  font-size: 10px;
}
.row.is-weekend .date,
.row.is-weekend .day { color: #cdb78a; }

.cell {
  /* Vertical inset only — horizontal gaps come from the row's column-gap
     so every column transition (including first-hour↔day and
     last-hour↔notes) is the same width and the outer cells don't look
     shaved compared to the middle ones. */
  border-top: 3px solid transparent;
  border-bottom: 3px solid transparent;
  border-radius: 5px;
  background-clip: padding-box;
  cursor: crosshair;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-variant-numeric: tabular-nums;
  font-size: 9px;
  font-weight: 600;
  transition: filter 0.08s, box-shadow 0.08s;
}
.cell.empty { background: transparent; color: transparent; }
.cell.has-icon { font-size: 6px; line-height: 1; font-style: italic; letter-spacing: -0.5px; }

/* Runs of the same category merge into a continuous bar — cells past the
   first one pull left by --col-gap so they meet the previous cell exactly,
   and inner corners square off so the seam is invisible. */
.cell.run-not-first {
  margin-left: calc(-1 * var(--col-gap, 6px));
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}
.cell.run-not-last {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.row .notes {
  display: flex; align-items: center;
  border-left: 1px solid var(--border);
  padding-left: 6px;
}
.row .notes input {
  background: transparent;
  border: none;
  outline: none;
  width: 100%;
  font-size: 12px;
  color: var(--text);
  padding: 2px 8px;
  border-radius: 6px;
  transition: background 0.12s;
}
.row .notes input::placeholder { color: var(--muted); opacity: 0.4; }
.row .notes input:focus { background: rgba(0,0,0,0.25); }

/* ---- palette sidebar ---- */
.palette {
  grid-area: palette;
  background: rgba(10, 13, 12, 0.65);
  backdrop-filter: saturate(150%) blur(10px);
  -webkit-backdrop-filter: saturate(150%) blur(10px);
  border-left: 1px solid var(--border);
  padding: 14px 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
}
.palette > header {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 4px;
}
.palette ul {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 2px;
  overflow: auto;
  flex: 1;
}
.cat {
  position: relative;
  display: grid;
  grid-template-columns: 22px 16px 1fr;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.12s;
}
.cat:hover { background: var(--surface-2); }
.cat[aria-pressed="true"] {
  background: rgba(0, 200, 150, 0.20);
  border-color: rgba(0, 200, 150, 0.65);
  box-shadow:
    0 0 0 1px rgba(0, 200, 150, 0.35),
    0 6px 18px rgba(0, 200, 150, 0.22);
}
/* Left-edge accent stripe makes the selected row read at a glance, even
   when the swatch color happens to be close to the accent green. */
.cat[aria-pressed="true"]::before {
  content: "";
  position: absolute;
  left: 3px;
  top: 6px;
  bottom: 6px;
  width: 3px;
  border-radius: 2px;
  background: var(--accent-grad);
  box-shadow: 0 0 8px rgba(0, 200, 150, 0.55);
}
.cat[aria-pressed="true"] .id { color: var(--text); }
.cat[aria-pressed="true"] .name { color: var(--text); font-weight: 700; }
.cat .id {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: right;
  font-size: 11px;
  font-weight: 600;
}
.cat .swatch { width: 14px; height: 14px; border-radius: 4px; }
.cat .name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-soft);
}
/* Rename input shown only while the palette is in edit mode. Styled to
   feel continuous with the palette, with enough chrome to read as editable. */
.cat .name-edit {
  width: 100%;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 3px 8px;
  color: var(--text);
  font: inherit;
  outline: none;
  box-shadow: 0 0 0 3px rgba(0, 200, 150, 0.18);
}

/* Palette header — "Categories" label and the Edit/Done toggle. */
.palette-edit-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 9px;
  color: var(--text-soft);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  cursor: pointer;
  transition: all 0.12s;
}
.palette-edit-btn:hover { background: var(--surface-hi); border-color: var(--border-hi); color: var(--text); }
body.palette-editing #palette-edit-btn {
  background: var(--accent-grad);
  border-color: transparent;
  color: #0a0a0f;
  box-shadow: 0 0 0 1px rgba(0, 200, 150, 0.35), 0 4px 12px rgba(0, 200, 150, 0.25);
}

.palette-header-actions { display: inline-flex; gap: 6px; }
.palette-reset-btn { display: none; }
body.palette-editing .palette-reset-btn { display: inline-block; }

/* Subtle highlight on the palette while editing so it's obvious that the
   normal click-to-select behaviour is paused. */
body.palette-editing .palette {
  background: rgba(0, 200, 150, 0.05);
}
body.palette-editing .cat { cursor: default; }

/* Native color picker styled as a small swatch so it fits the same slot
   as the read-only .swatch span. The vendor pseudo-elements strip the
   default chrome so just the color shows through a rounded border. */
.cat .swatch-edit {
  width: 14px;
  height: 14px;
  padding: 0;
  border: 1px solid var(--border-hi);
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}
.cat .swatch-edit::-webkit-color-swatch-wrapper { padding: 0; }
.cat .swatch-edit::-webkit-color-swatch { border: none; border-radius: 3px; }
.cat .swatch-edit::-moz-color-swatch { border: none; border-radius: 3px; }
/* ---- dialog ---- */
dialog {
  background: rgba(15, 18, 22, 0.96);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  color: var(--text);
  border: 1px solid var(--border-hi);
  border-radius: 14px;
  padding: 22px 24px;
  max-width: 560px;
  width: calc(100vw - 32px);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0,0,0,0.55); backdrop-filter: blur(4px); }
dialog h2 {
  margin: 0 0 12px;
  font-family: "Archivo Black", sans-serif;
  font-size: 18px;
  letter-spacing: -0.01em;
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
dialog .row { display: flex; gap: 10px; flex-wrap: wrap; height: auto; border: none; }
dialog button {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px;
  color: var(--text);
  font-weight: 500;
}
dialog button:hover { background: var(--surface-hi); border-color: var(--border-hi); }
dialog menu { display: flex; justify-content: flex-end; padding: 0; margin: 14px 0 0; }
dialog h3 {
  margin: 0 0 6px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-soft);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
dialog hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 16px 0 12px;
}
dialog .text-input {
  flex: 1;
  min-width: 180px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  color: var(--text);
  outline: none;
}
dialog .text-input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(0,200,150,0.18); }
/* ---- stats dialog: full-screen ---- */
#stats-dialog {
  max-width: 100vw;
  width: 100vw;
  max-height: 100vh;
  height: 100vh;
  margin: 0;
  border-radius: 0;
  border: none;
  padding: 26px clamp(16px, 4vw, 48px);
  inset: 0;
}
#stats-dialog form.stats {
  height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}
#stats-dialog #stats-body {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}
#stats-dialog menu { margin-top: 16px; }

/* Floating close button — only shown on phones, where the regular Close
   button at the bottom of the form scrolls out of reach. Position:fixed
   pins it to the viewport so it stays visible no matter how far the user
   has scrolled through the stats. */
.dialog-close-fab {
  display: none;
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(15, 18, 22, 0.88);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-hi);
  color: var(--text);
  font-size: 26px;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  z-index: 10;
  box-shadow: 0 6px 18px rgba(0,0,0,0.45);
}
@media (max-width: 760px) {
  .dialog-close-fab {
    display: flex;
    align-items: center;
    justify-content: center;
  }
}
.stats-subtitle {
  margin: 0 2px 14px;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.stats-empty {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 64px 30px;
  text-align: center;
  color: var(--muted);
  box-shadow: var(--shadow);
}

/* KPI cards (lifted from Finances app) */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.kpi::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: var(--accent-grad);
  opacity: 0.9;
}
.kpi.green::before { background: linear-gradient(90deg, #34d399, #10b981); }
.kpi.red::before   { background: linear-gradient(90deg, #f87171, #ef4444); }
.kpi.blue::before  { background: linear-gradient(90deg, #60a5fa, #22d3ee); }
.kpi-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}
.kpi-value {
  font-size: 30px;
  font-weight: 700;
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  letter-spacing: -0.02em;
}
.kpi-sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

/* Chart cards */
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.chart-card h3 {
  margin: 0 0 16px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.4px;
  text-transform: uppercase;
}
.chart-card.collapsible details summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  user-select: none;
  -webkit-user-select: none;
}
.chart-card.collapsible details summary::-webkit-details-marker { display: none; }
.chart-card.collapsible details summary h3 { margin: 0; flex: 1; }
.chart-card.collapsible details summary::after {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--text-soft);
  border-bottom: 2px solid var(--text-soft);
  transform: rotate(-45deg);
  transition: transform 0.18s ease;
  margin-right: 4px;
}
.chart-card.collapsible details[open] summary::after {
  transform: rotate(45deg);
}
.chart-card.collapsible details summary:hover::after {
  border-color: var(--text);
}
.chart-card.collapsible details[open] summary { margin-bottom: 16px; }
.stats-grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}
@media (min-width: 880px) {
  .stats-grid-2 {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
  }
  .stats-grid-2 > .chart-card { margin-bottom: 0; }
}
.stats-controls {
  display: flex;
  gap: 10px;
  align-items: center;
  margin: 0 0 12px;
}
.stats-controls label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-soft);
  font-size: 12px;
}
.stats-controls select {
  background-color: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 28px 5px 10px;
  color: var(--text);
  color-scheme: dark;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' stroke='%237c8780' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
select option {
  background: #14181a;
  color: var(--text);
}
.stats-pie {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 4px 0 6px;
  min-height: 280px;
}
.stats-pie svg {
  filter: drop-shadow(0 6px 22px rgba(0,0,0,0.45));
  border-radius: 50%;
  max-width: 100%;
  height: auto;
}
.stats-pie svg path { transition: filter 0.15s, opacity 0.15s; }
.stats-pie svg:hover path { opacity: 0.55; }
.stats-pie svg:hover path:hover { opacity: 1; filter: brightness(1.1); }

/* Inner wrap is the positioned ancestor for the custom tooltip — needs to
   be relative so .pie-tooltip's absolute coordinates make sense. Sized to
   the svg so hover events outside the chart don't move the tooltip. */
.stats-pie-wrap {
  position: relative;
  display: inline-block;
  line-height: 0;
}
.pie-tooltip {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  column-gap: 8px;
  row-gap: 2px;
  background: rgba(15, 18, 22, 0.96);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-hi);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  line-height: 1.3;
  color: var(--text);
  white-space: nowrap;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transform: translateY(2px);
  transition: opacity 0.12s ease, transform 0.12s ease;
  z-index: 5;
}
.pie-tooltip.visible { opacity: 1; transform: translateY(0); }
.pie-tip-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}
.pie-tip-label {
  font-weight: 600;
  color: var(--text);
}
.pie-tip-value {
  grid-column: 1 / -1;
  color: var(--text-soft);
  font-variant-numeric: tabular-nums;
}
.stats-section-title {
  margin: 14px 2px 6px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-soft);
}
.stats-hl-list {
  list-style: none;
  margin: 0; padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px 24px;
}
.stats-hl-row {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}
.stats-hl-swatch { width: 10px; height: 10px; border-radius: 2px; }
.stats-hl-label { color: var(--text-soft); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stats-hl-value { font-variant-numeric: tabular-nums; font-weight: 600; }
.stats-year-progress { margin: 8px 2px 0; }
.stats-list {
  list-style: none;
  padding: 0;
  margin: 6px 0 0;
}
.stats-row {
  display: grid;
  grid-template-columns: 14px 1fr 90px 70px 46px;
  align-items: center;
  gap: 10px;
  padding: 4px 2px;
}
.stats-swatch { width: 14px; height: 14px; border-radius: 3px; }
.stats-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stats-bar-wrap {
  height: 6px;
  background: rgba(255,255,255,0.06);
  border-radius: 3px;
  overflow: hidden;
}
.stats-bar { display: block; height: 100%; border-radius: 3px; }
.stats-num { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-soft); font-size: 12px; }
.stats-pct { text-align: right; font-variant-numeric: tabular-nums; font-size: 12px; }

@media (max-width: 540px) {
  .stats-row {
    grid-template-columns: 14px 1fr 60px 44px;
    gap: 8px;
  }
  .stats-bar-wrap { display: none; }
  .stats-hl-list { grid-template-columns: 1fr; }
}

.btn.is-signed-in::before {
  content: "";
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent-2);
  box-shadow: 0 0 8px var(--accent-2);
  margin-right: 6px;
  transform: translateY(-1px);
}

/* OAuth provider buttons in the sign-in dialog */
.oauth-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 12px 0 6px;
}
.oauth-btn {
  display: flex !important;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 11px 16px !important;
  font-size: 14px !important;
  font-weight: 600 !important;
  border-radius: 10px !important;
  background: var(--surface-hi) !important;
  border: 1px solid var(--border-hi) !important;
  cursor: pointer;
  transition: all 0.15s;
}
.oauth-btn:hover {
  background: rgba(255,255,255,0.13) !important;
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(0,0,0,0.3);
}
.oauth-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* Advanced/manual backup collapsible */
dialog details.advanced {
  margin-top: 18px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
dialog details.advanced summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  list-style: none;
  padding: 4px 0;
  user-select: none;
}
dialog details.advanced summary::-webkit-details-marker { display: none; }
dialog details.advanced summary::before {
  content: "▸ ";
  display: inline-block;
  transition: transform 0.15s;
}
dialog details.advanced[open] summary::before { content: "▾ "; }
dialog details.advanced summary:hover { color: var(--text-soft); }
dialog details.advanced > p,
dialog details.advanced > .row { margin-top: 8px; }
.muted { color: var(--muted); font-size: 12px; }

/* ---- signed-out empty state ---- */
.signin-overlay {
  position: fixed;
  inset: var(--top-h) 0 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 13, 12, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 6;
  padding: 24px;
}
.signin-overlay[hidden] { display: none; }
.signin-overlay-card {
  background: rgba(15, 18, 22, 0.96);
  border: 1px solid var(--border-hi);
  border-radius: 16px;
  padding: 36px clamp(28px, 5vw, 48px) 32px;
  text-align: center;
  max-width: 380px;
  width: 100%;
  box-shadow: var(--shadow);
}
.signin-overlay-card h2 {
  margin: 0 0 10px;
  font-family: "Archivo Black", sans-serif;
  font-size: 22px;
  letter-spacing: -0.01em;
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.signin-overlay-card > p {
  margin: 0 0 22px;
  color: var(--text-soft);
  font-size: 13px;
  line-height: 1.5;
}
.signin-overlay-card .oauth-btn {
  width: 100%;
  margin-bottom: 18px;
}
.signin-overlay-card .overlay-hint {
  margin: 0;
  font-size: 11px;
}
.signin-overlay-card .link {
  background: none;
  border: none;
  color: var(--accent-2);
  padding: 0;
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.signin-overlay-card .link:hover { color: var(--accent); }

/* ---- tablet / narrow desktop: keep topbar legible without overflow ---- */
@media (max-width: 900px) {
  .topbar .brand .tagline { display: none; }
  .save-indicator .lbl { display: none; }
}

/* ---- mobile ----
   Categories palette and the active-cat picker are hidden — editing is
   desktop-only; mobile is a read-only view of the grid + life bar. The
   topbar shrinks to fit a phone screen without horizontal scroll. */
@media (max-width: 760px) {
  :root { --row-h: 22px; --side-w: 0; }
  body {
    grid-template-columns: 1fr;
    /* topbar row is auto so it can grow when contents wrap to a 2nd line */
    grid-template-rows: auto var(--life-h) var(--hours-h) 1fr;
    grid-template-areas:
      "topbar"
      "lifebar"
      "hours"
      "years";
  }
  .palette { display: none; }
  .life-bar { padding: 0 10px; gap: 8px; }
  /* Topbar wraps instead of clipping — Stats / Sign-in roll under to a 2nd
     line on narrow screens instead of getting cut off at the right edge. */
  .topbar {
    gap: 6px;
    padding: 6px 8px;
    overflow: visible;
    flex-wrap: wrap;
    align-content: center;
    height: auto;
    min-height: var(--top-h);
  }
  .topbar .brand .word { font-size: 18px; }
  .topbar .brand .tagline,
  .topbar .brand .version { display: none; }
  .save-indicator .lbl { display: none; }
  .actions { gap: 4px; }
  .actions .btn { padding: 6px 10px; font-size: 12px; }
  .year-select { font-size: 13px; padding: 5px 22px 5px 8px; }
  .datebar { gap: 4px; }
  /* Squish the grid: drop date + notes columns and let all 24 hour cells
     flex to share the remaining width so the full day is always visible
     without horizontal scrolling. */
  .hour-header,
  .row {
    grid-template-columns: var(--day-w) repeat(24, 1fr);
    /* Tighter on mobile — cells are only ~14px wide so we can't afford a
       big gap between each one. --col-gap drives both column-gap and the
       run-merge offset. */
    --col-gap: 1px;
  }
  .hour-header .h-date,
  .hour-header .h-notes,
  .row .date,
  .row .notes { display: none; }
  .hour-header .h-hour { font-size: 9px; }
  .cell { font-size: 7px; }
}
@media (max-width: 420px) {
  /* Give the brand its own row so the title stays legible on phones
     instead of getting clipped. The topbar grows vertically rather
     than fighting for horizontal space. */
  .topbar { row-gap: 4px; padding-top: 8px; padding-bottom: 8px; }
  .topbar .brand { flex-basis: 100%; }
  /* On very narrow screens, even the day-of-week label takes too much
     width — shrink it so each hour cell still gets a few pixels. */
  :root { --day-w: 28px; }
  .row .day { font-size: 9px; padding-left: 2px; }
}
