/* ===== Reset ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

/* ===== Design tokens (locked to ui-preview.html — Deep Space) ===== */
:root {
  color-scheme: dark;

  --bg: #07090E;
  --text: #6080A0;
  --text-bright: #D0E8FF;
  --text-accent: #80B8FF;
  --text-mid: #4080C0;
  --text-dim: #304860;

  --border: rgba(60, 100, 160, 0.15);
  --border-hover: rgba(100, 160, 255, 0.25);
  --surface: rgba(30, 50, 80, 0.3);
  --accent-soft: rgba(100, 160, 255, 0.12);
  --accent-line: rgba(100, 160, 255, 0.3);

  --radius: 12px;
  --radius-pill: 20px;

  --font: 'Inter', system-ui, -apple-system, sans-serif;

  --gutter: 52px;
  --maxw: 880px;
}

/* ===== Base ===== */
html { -webkit-text-size-adjust: 100%; }
body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }

/* ===== Nav ===== */
.nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 22px var(--gutter);
}
.logo {
  font-size: 16px;
  font-weight: 300;
  color: var(--text-accent);
  letter-spacing: 3px;
  text-transform: uppercase;
}
.logo span { font-weight: 700; color: var(--text-bright); }
.nav-right { display: flex; gap: 12px; align-items: center; }
.pill {
  border: 1px solid rgba(100, 160, 255, 0.2);
  color: var(--text-mid);
  border-radius: var(--radius-pill);
  padding: 6px 16px;
  font-size: 12px;
}
.pill-solid {
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  color: var(--text-accent);
  border-radius: var(--radius-pill);
  padding: 6px 16px;
  font-size: 12px;
  font-weight: 600;
  transition: background 0.15s;
}
.pill-solid:hover { background: rgba(100, 160, 255, 0.2); }

/* Month navigator — prev/next arrows flanking the visible-month pill. */
.month-nav { display: flex; align-items: center; gap: 6px; }
.month-nav .pill { min-width: 108px; text-align: center; }
.nav-arrow {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid rgba(100, 160, 255, 0.2);
  color: var(--text-mid);
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: 0.15s;
}
.nav-arrow:hover { border-color: var(--accent-line); color: var(--text-accent); background: var(--accent-soft); }

/* ===== App shell ===== */
.app { max-width: var(--maxw); margin: 0 auto; padding: 0 var(--gutter); }

/* ===== Hero — visible-month spend total (locked to ui-preview.html) ===== */
.hero { text-align: center; padding: 20px 0 36px; }
.hero-month {
  font-size: 13px;
  font-weight: 300;
  color: #406080;
  letter-spacing: 4px;
  text-transform: uppercase;
  margin-bottom: 4px;
}
.hero-total { font-size: 52px; font-weight: 200; color: #B8D8FF; letter-spacing: -2px; }
.hero-total sup {
  font-size: 22px;
  color: #4880C0;
  vertical-align: top;
  margin-top: 10px;
  display: inline-block;
  font-weight: 300;
}
.hero-sub { font-size: 12px; color: var(--text-dim); margin-top: 4px; letter-spacing: 1px; }

/* ===== Calendar grid (locked to ui-preview.html) ===== */
.cal-wrap { padding: 8px 0 28px; }
.cal-row-header {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  margin-bottom: 8px;
}
.ch {
  text-align: center;
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 4px 0;
}
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }

.dc {
  height: 90px;
  border: 1px solid rgba(60, 100, 160, 0.1);
  border-radius: var(--radius);
  padding: 12px 10px;
  position: relative;
  transition: 0.15s;
}
.dc:hover { border-color: var(--border-hover); background: rgba(100, 160, 255, 0.03); }
.dc.empty { border-color: transparent; }
.dc.empty:hover { border-color: transparent; background: none; }
.dc.today { border-color: rgba(100, 160, 255, 0.4); background: rgba(100, 160, 255, 0.05); }
.dc.today::after {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: var(--radius);
  background: radial-gradient(ellipse at 50% 0%, rgba(100, 160, 255, 0.08), transparent 70%);
  pointer-events: none;
}
.dn { font-size: 12px; font-weight: 400; color: #2A4060; }
.dc.today .dn { color: var(--text-accent); }
.dc.has-bill .dn { color: #6090B8; }

/* Billing dots — up to 3 glowing dots pinned to the cell's bottom-left. */
.glow-dots { position: absolute; bottom: 8px; left: 10px; display: flex; align-items: center; gap: 5px; }
.gd { width: 8px; height: 8px; border-radius: 50%; box-shadow: 0 0 6px currentColor, 0 0 12px currentColor; }
.dot-more { font-size: 9px; font-weight: 600; letter-spacing: 0.5px; color: var(--text-mid); }

/* Overflow popover — full subscription list shown on hover for busy days. */
.dc:hover { z-index: 20; }
.day-pop {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 30;
  width: max-content;
  min-width: 180px;
  max-width: 240px;
  background: #0C1119;
  border: 1px solid var(--border-hover);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: 0 12px 32px rgba(3, 6, 12, 0.7);
}
.day-pop.pop-right { left: auto; right: 0; }
.dc:hover .day-pop { display: block; }
.pop-head {
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 10px;
}
.pop-row { display: flex; align-items: center; gap: 10px; padding: 3px 0; }
.pop-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.pop-name {
  font-size: 12px;
  color: var(--text-accent);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pop-amt { font-size: 12px; font-weight: 600; color: var(--text-bright); margin-left: auto; white-space: nowrap; }

/* ===== Subscription list panel ===== */
.panel { padding: 12px 0 60px; }
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 20px;
}
.panel-title { font-size: 10px; letter-spacing: 3px; text-transform: uppercase; color: var(--text-dim); }
.panel-total { font-size: 12px; color: var(--text-mid); white-space: nowrap; }

.sub-list { display: flex; flex-direction: column; gap: 8px; }
.sub-row {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  transition: border-color 0.15s;
}
.sub-row:hover { border-color: var(--border-hover); }
.sub-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.sub-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.sub-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-accent);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sub-when { font-size: 11px; color: var(--text-dim); }
.sub-amt { font-size: 15px; font-weight: 600; color: var(--text-bright); margin-left: auto; white-space: nowrap; }
.sub-actions { display: flex; gap: 6px; flex-shrink: 0; }
.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--border);
  color: var(--text-mid);
  font-size: 13px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: 0.15s;
}
.icon-btn:hover { border-color: var(--border-hover); color: var(--text-accent); background: var(--accent-soft); }

/* ===== Empty state — orbiting "subscriptions" illustration ===== */
.empty { text-align: center; padding: 80px 0 100px; }
.empty-art { display: block; margin: 0 auto 30px; overflow: visible; }
.empty-ring { fill: none; stroke: var(--accent-line); stroke-width: 1; opacity: 0.3; }
/* Two counter-rotating rings of glowing dots orbit a bright core. */
.empty-orbit { transform-box: view-box; transform-origin: 56px 56px; }
.spin-a { animation: orbit-spin 26s linear infinite; }
.spin-b { animation: orbit-spin 34s linear infinite reverse; }
.orbit-dot { fill: currentColor; filter: drop-shadow(0 0 5px currentColor); }
.empty-core { fill: var(--text-accent); filter: drop-shadow(0 0 9px rgba(128, 184, 255, 0.7)); }
.empty-title { font-size: 14px; letter-spacing: 1px; color: var(--text); }
.empty-sub { font-size: 12px; margin-top: 8px; color: var(--text-dim); }

@keyframes orbit-spin { to { transform: rotate(360deg); } }

/* ===== Motion — content settles in on each render (month change, edits) ===== */
@keyframes fade-up { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.hero { animation: fade-up 0.4s ease both; }
.cal-wrap { animation: fade-up 0.4s ease 0.04s both; }
.panel, .empty { animation: fade-up 0.4s ease 0.08s both; }

/* ===== Dialog / form ===== */
.dialog {
  border: 1px solid var(--border-hover);
  background: #0C1119;
  color: var(--text);
  border-radius: var(--radius);
  padding: 0;
  width: min(420px, calc(100vw - 40px));
  margin: auto;
}
.dialog::backdrop { background: rgba(3, 6, 12, 0.7); }
.form { padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.form-title { font-size: 14px; font-weight: 600; color: var(--text-bright); letter-spacing: 1px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; min-width: 0; }
.field-label { font-size: 10px; letter-spacing: 2px; text-transform: uppercase; color: var(--text-dim); }
.input {
  background: rgba(10, 18, 30, 0.6);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--text-bright);
  font-family: inherit;
  font-size: 13px;
  width: 100%;
  transition: border-color 0.15s;
}
.input::placeholder { color: var(--text-dim); }
.input:focus { outline: none; border-color: var(--accent-line); }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  padding: 0;
  transition: 0.15s;
}
.swatch.selected { border-color: var(--text-bright); box-shadow: 0 0 8px currentColor; }

.form-actions { display: flex; align-items: center; gap: 10px; margin-top: 4px; }
.form-actions-right { display: flex; gap: 8px; margin-left: auto; }
.btn-ghost { color: var(--text-mid); font-size: 12px; padding: 8px 14px; border-radius: var(--radius-pill); border: 1px solid transparent; }
.btn-ghost:hover { color: var(--text-accent); }
.btn-primary {
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  color: var(--text-accent);
  border-radius: var(--radius-pill);
  padding: 8px 18px;
  font-size: 12px;
  font-weight: 600;
  transition: background 0.15s;
}
.btn-primary:hover { background: rgba(100, 160, 255, 0.2); }
.btn-danger {
  color: #E0708A;
  font-size: 12px;
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  border: 1px solid rgba(224, 112, 138, 0.3);
  transition: background 0.15s;
}
.btn-danger[hidden] { display: none; }
.btn-danger:hover { background: rgba(224, 112, 138, 0.1); }

/* ===== Responsive ===== */
@media (max-width: 640px) {
  :root { --gutter: 16px; }

  /* Nav stacks: brand on top, month-nav + add button share the next row. */
  .nav { flex-wrap: wrap; gap: 14px; padding: 18px var(--gutter); }
  .nav-right { width: 100%; justify-content: space-between; gap: 10px; }
  .month-nav .pill { min-width: 92px; }

  .hero { padding: 12px 0 28px; }
  .hero-total { font-size: 44px; }

  /* Tighter grid so 7 columns stay legible on a phone. */
  .cal-row-header, .cal-grid { gap: 5px; }
  .cal-row-header { margin-bottom: 5px; }
  .ch { font-size: 9px; letter-spacing: 1px; }
  .dc { height: 66px; padding: 8px 6px; border-radius: 9px; }
  .dn { font-size: 11px; }
  .glow-dots { bottom: 6px; left: 6px; gap: 4px; }
  .gd { width: 7px; height: 7px; }

  /* Keep the popover on-screen no matter how narrow the viewport. */
  .day-pop { min-width: 150px; max-width: calc(100vw - 32px); }

  .empty { padding: 56px 0 72px; }
}

/* Respect users who prefer minimal motion — no orbit spin, no fade-in. */
@media (prefers-reduced-motion: reduce) {
  .spin-a, .spin-b,
  .hero, .cal-wrap, .panel, .empty { animation: none; }
}
