/* Светлая тема — майская сирень и шампанское, тёмная — вечер с золотом */
:root {
  color-scheme: light dark;

  --bg: #f6f1f9;
  --panel: #fffdfe;
  --ink: #2b1838;
  --ink-2: #6a587a;
  --ink-3: #8f7f9e;
  --line: #e8deef;
  --lilac: #8e4fc8;
  --lilac-wash: rgb(142 79 200 / 0.1);
  --track: #eee4f5;
  --primary: #3d1e5c;
  --on-primary: #fff;
  --gold: #c59a3c;
  --ring-a: #8e4fc8;
  --ring-b: #e58ab6;
  --petal: #e58ab6;
  --petal-deep: #8e4fc8;
  --hero-bg: radial-gradient(120% 90% at 100% 0%, #f3dcef 0%, #fbf6fd 60%);
  --good: #2f7a45;
  --good-bg: #e0f1e4;
  --warn: #8d5304;
  --warn-bg: #f8ead2;
  --danger: #a3313e;

  --display: 'Unbounded', 'Onest', system-ui, sans-serif;
  --text: 'Onest', system-ui, -apple-system, 'Segoe UI', sans-serif;

  @media (prefers-color-scheme: dark) {
    --bg: #15122a;
    --panel: #1f1a3a;
    --ink: #f6f0ff;
    --ink-2: #b9b0cf;
    --ink-3: #8e85a8;
    --line: #342c55;
    --lilac: #a27fd8;
    --lilac-wash: rgb(162 127 216 / 0.12);
    --track: #2e2650;
    --primary: #e7c56f;
    --on-primary: #231a33;
    --gold: #e7c56f;
    --ring-a: #e7c56f;
    --ring-b: #f2a3c4;
    --petal: #f2a3c4;
    --petal-deep: #e7c56f;
    --hero-bg: radial-gradient(120% 90% at 100% 0%, #3d2c62 0%, #1f1a3a 60%);
    --good: #9fdcae;
    --good-bg: #22402d;
    --warn: #f0b86a;
    --warn-bg: #3d2c18;
    --danger: #f59aa6;
  }

  accent-color: var(--lilac);
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.5 var(--text);
  -webkit-font-smoothing: antialiased;
  padding: max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 48px max(16px, env(safe-area-inset-left));
}

h1, h2, p, ul, dl, dd, fieldset { margin: 0; padding: 0; }
ul { list-style: none; }
fieldset { border: 0; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}

.muted { color: var(--ink-2); font-size: 14px; }

:focus-visible {
  outline: 2px solid var(--lilac);
  outline-offset: 2px;
}

/* ---------- Кнопки и поля ---------- */

button, .button {
  font: 500 15px/1 var(--text);
  color: inherit;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 12px 16px;
  background: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.primary {
  background: var(--primary);
  color: var(--on-primary);
}
.primary:hover { filter: brightness(1.12); }

.ghost {
  border-color: var(--line);
  color: var(--ink);
}
.ghost:hover { background: var(--lilac-wash); }
.ghost.danger { color: var(--danger); }
.ghost.icon {
  border-color: transparent;
  padding: 6px 10px;
  font-size: 20px;
  color: var(--ink-3);
}

.field {
  display: grid;
  gap: 6px;
  font-size: 14px;
  color: var(--ink-2);
}
.field input, .field select, .field textarea {
  font: 400 16px/1.4 var(--text);
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
}
.field textarea { resize: vertical; }

.check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 14px;
  color: var(--ink-2);
}
.check input { margin-top: 3px; }

.error {
  color: var(--danger);
  font-size: 14px;
}
.error:empty { display: none; }

/* ---------- Сетка ---------- */

.layout {
  max-width: 1120px;
  margin: 0 auto;
  display: grid;
  gap: 16px;
  grid-template-areas: 'hero' 'chart' 'items';
}
.hero { grid-area: hero; }
.chart-panel { grid-area: chart; }
.items-panel { grid-area: items; }

@media (min-width: 960px) {
  .layout {
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
    grid-template-areas: 'hero hero' 'chart items';
    align-items: start;
    column-gap: 24px;
  }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 20px;
}
.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 12px;
  margin-bottom: 16px;
}
.panel-head h2 {
  font: 600 17px/1.3 var(--display);
  letter-spacing: -0.01em;
}
.panel-head .ghost { margin-left: auto; padding: 8px 12px; font-size: 14px; }

/* ---------- Кольцо ---------- */

.hero {
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-areas: 'head' 'ring' 'body';
  justify-items: center;
  text-align: center;
  gap: 16px;
  padding: 24px 20px;
  border-radius: 28px;
  background: var(--hero-bg);
  border: 1px solid var(--line);
}
.hero > * { position: relative; }
.hero-head { grid-area: head; }
.hero-body { grid-area: body; display: grid; justify-items: center; gap: 12px; }

.petals { position: absolute; right: -12px; top: -10px; width: 160px; pointer-events: none; }
.petal { fill: var(--petal); opacity: 0.55; }
.petal--deep { fill: var(--petal-deep); opacity: 0.35; }
.spark { fill: var(--gold); }

.names { font: 30px/1.1 'Marck Script', cursive; color: var(--lilac); }
.hero-date { font-weight: 600; font-size: 14px; color: var(--ink-2); }

.ring { grid-area: ring; position: relative; width: min(240px, 70vw); aspect-ratio: 1; }
.ring svg { display: block; width: 100%; height: 100%; }
.ring-track, .ring-fill { fill: none; stroke-width: 14; }
.ring-track { stroke: var(--track); }
.ring-fill { stroke: url(#ring-grad); stroke-linecap: round; }
.gem {
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 3px;
  background: var(--gold);
  translate: -50% -50%;
  rotate: 45deg;
  box-shadow: 0 0 0 3px var(--panel), 0 0 14px var(--gold);
}
.ring-mid {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 2px;
  color: var(--ink-2);
  font-size: 14px;
}
.days { font: 700 64px/1 var(--display); letter-spacing: -0.04em; color: var(--ink); }
.days--word { font-size: 30px; letter-spacing: -0.02em; }

.saved { display: grid; }
.saved b { font: 600 22px/1.25 var(--display); letter-spacing: -0.02em; }
.saved span { color: var(--ink-2); font-size: 14px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 15px;
  padding: 5px 14px 5px 6px;
  border-radius: 999px;
  background: var(--track);
}
.badge span {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 12px;
  background: var(--ink);
  color: var(--panel);
}
.badge--good { background: var(--good-bg); color: var(--good); }
.badge--good span { background: var(--good); color: var(--good-bg); }
.badge--warn { background: var(--warn-bg); color: var(--warn); }
.badge--warn span { background: var(--warn); color: var(--warn-bg); }


.figures {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 24px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.figures dt { font-size: 13px; color: var(--ink-2); }
.figures dd { font-weight: 600; font-variant-numeric: tabular-nums; }

.actions { display: grid; gap: 10px; width: 100%; max-width: 420px; }
@media (min-width: 440px) { .actions { grid-template-columns: 1fr 1fr; } }

.start {
  display: grid;
  gap: 12px;
  width: 100%;
  max-width: 420px;
  text-align: left;
}

@media (min-width: 640px) {
  .hero {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas: 'ring head' 'ring body';
    justify-items: start;
    align-items: center;
    text-align: left;
    column-gap: 32px;
    padding: 32px;
  }
  .hero-head { align-self: end; }
  .hero-body { justify-items: start; align-self: start; }
  .figures, .actions { justify-content: start; }
}

/* ---------- График ---------- */

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  font-size: 13px;
  color: var(--ink-2);
}
.legend li { display: flex; align-items: center; gap: 6px; }
.legend li[hidden] { display: none; }
.key--fact, .key--forecast, .key--required { height: 0; width: 16px; border-radius: 0; border-top: 2px solid var(--lilac); }
.key--forecast { border-top-style: dashed; }
.key--required { border-top: 1.5px dashed var(--ink-3); }

.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; touch-action: pan-y; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .tick { fill: var(--ink-3); font-size: 12px; font-variant-numeric: tabular-nums; }
.chart .note { fill: var(--ink-2); font-size: 12px; }
.chart .value { fill: var(--ink); font-size: 13px; font-weight: 600; stroke: var(--panel); stroke-width: 4px; paint-order: stroke; stroke-linejoin: round; }
.chart .budget { stroke: var(--ink-2); stroke-width: 1; }
.chart .marker, .chart .cross { stroke: var(--ink-3); stroke-width: 1; }
.chart .area { fill: var(--lilac-wash); }
.chart .fact { fill: none; stroke: var(--lilac); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .forecast { fill: none; stroke: var(--lilac); stroke-width: 2; stroke-dasharray: 6 5; stroke-linecap: round; }
.chart .required { fill: none; stroke: var(--ink-3); stroke-width: 1.5; stroke-dasharray: 3 4; }
.chart .dot { fill: var(--lilac); stroke: var(--panel); stroke-width: 2; }

.tooltip {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  display: grid;
  grid-template-columns: auto auto;
  gap: 2px 12px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--bg);
  font-size: 13px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.tooltip[hidden] { display: none; }
.tooltip b { grid-column: 1 / -1; font-weight: 600; }
.tooltip span:nth-of-type(even) { text-align: right; font-weight: 500; }

/* ---------- Смета ---------- */

.items { display: grid; }
.items li + li { border-top: 1px solid var(--line); }
.item {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: 'name money' 'meter meter';
  align-items: baseline;
  gap: 8px 16px;
  padding: 12px 4px;
  border-radius: 10px;
  text-align: left;
  font: inherit;
}
.item:hover { background: var(--lilac-wash); }
.item-name { grid-area: name; font-weight: 500; }
.item-money { grid-area: money; display: grid; justify-items: end; color: var(--ink-2); font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.item-money b { color: var(--ink); font-weight: 600; }
.item-money .over { color: var(--warn); font-size: 12px; }
.meter { grid-area: meter; height: 4px; border-radius: 2px; background: var(--track); overflow: hidden; }
.meter span { display: block; height: 100%; background: linear-gradient(90deg, var(--ring-a), var(--ring-b)); border-radius: 2px; }
.item.is-done .item-name { color: var(--ink-2); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 2px;
  font-size: 12px;
  font-weight: 400;
  padding: 1px 8px 1px 6px;
  border-radius: 999px;
  color: var(--ink-2);
  background: var(--bg);
  vertical-align: 1px;
}
.chip span { font-size: 11px; }
.chip--agreed { color: var(--lilac); }
.chip--done { background: var(--good-bg); color: var(--good); }

/* ---------- Вход и синхронизация ---------- */

main[hidden], .lock[hidden], .foot[hidden] { display: none; }

.lock { display: grid; place-items: center; min-height: 80dvh; }
.lock-card {
  display: grid;
  gap: 16px;
  width: min(440px, 100%);
  padding: 28px 24px;
  border-radius: 28px;
  background: var(--hero-bg);
  border: 1px solid var(--line);
}
.lock-card h1 { font: 600 24px/1.2 var(--display); letter-spacing: -0.02em; }

.foot {
  max-width: 1120px;
  margin: 24px auto 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 16px;
  font-size: 13px;
  color: var(--ink-3);
}
.foot [data-status="offline"], .foot [data-status="auth"] { color: var(--warn); }
.link {
  padding: 0;
  font-size: 13px;
  color: var(--ink-2);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ---------- Диалоги ---------- */

dialog {
  width: min(460px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 24px;
  border: 0;
  border-radius: 20px;
  background: var(--panel);
  color: var(--ink);
}
dialog:modal { overscroll-behavior: contain; }
dialog::backdrop {
  background: rgb(23 18 29 / 0.45);
  overflow: hidden;
  overscroll-behavior: contain;
}
dialog form { display: grid; gap: 16px; }
dialog h2 { font: 600 20px/1.25 var(--display); letter-spacing: -0.01em; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: -6px -10px 0 0; }
.hint { margin-top: -8px; font-size: 13px; color: var(--ink-2); }
.hint:empty { display: none; }
.dialog-actions .primary { min-width: 140px; }

/* На телефоне окно прижато к верху: клавиатура не уводит заголовок за край экрана */
@media (max-width: 600px) {
  dialog:modal {
    margin: max(12px, env(safe-area-inset-top)) auto auto;
    max-height: calc(100dvh - 24px);
  }
  .dialog-actions .primary { flex: 1; }
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.dialog-actions .danger { margin-right: auto; }
.file-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.file-actions > * { padding: 9px 12px; font-size: 14px; }

@media (prefers-reduced-motion: no-preference) {
  .meter span { transition: width 0.4s ease; }
}
