/* ============================================================
   Отчётник — Mini App · «Quiet Ledger»
   Цвет целиком из Telegram themeParams (CSS-переменные пишет app.js).
   Ниже — только структура, типографика, материя и моушн.
   ============================================================ */

:root {
  /* фолбэки на случай, если themeParams ещё не применились (обычный браузер) */
  --bg: #ffffff;
  --text: #1a1a1c;
  --hint: #8a8a8e;
  --subtitle: #8a8a8e;
  --link: #2f7bd6;
  --accent: #2f7bd6;
  --button: #2f7bd6;
  --button-text: #ffffff;
  --secondary-bg: #f2f2f6;
  --section-bg: #ffffff;
  --section-header: #8a8a8e;
  --destructive: #e5484d;

  /* производные */
  --separator: color-mix(in srgb, var(--hint) 24%, transparent);
  --hairline: color-mix(in srgb, var(--hint) 16%, transparent);
  --press: color-mix(in srgb, var(--hint) 12%, transparent);
  --accent-soft: color-mix(in srgb, var(--accent) 12%, transparent);

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 26px;

  --pad: 16px;
  --gap: 12px;

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto,
    system-ui, sans-serif;
  --tap: 44px;

  --ease-spring: cubic-bezier(0.32, 0.72, 0, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}

body {
  min-height: 100dvh;
  padding: 0 0 max(20px, env(safe-area-inset-bottom));
}

.tnum {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1, "cv01" 1;
  letter-spacing: -0.01em;
}

/* ---------- каркас экрана ---------- */
#app { max-width: 520px; margin: 0 auto; }

.screen { padding: 8px var(--pad) 0; }

.appbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 14px var(--pad) 12px;
  padding-top: max(14px, calc(env(safe-area-inset-top) + 6px));
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
}
.appbar > div:first-child { min-width: 0; }
.appbar h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.appbar-actions { flex: 0 0 auto; }
.appbar .eyebrow {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--section-header);
}
.appbar .count {
  font-size: 13px;
  color: var(--hint);
  font-variant-numeric: tabular-nums;
}

/* ---------- нативный grouped-list ---------- */
.section-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--section-header);
  padding: 20px 4px 8px;
}

.list {
  background: var(--section-bg);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: 0 1px 0 var(--hairline), 0 8px 24px -18px rgba(0, 0, 0, 0.28);
}

.row {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 15px 16px;
  background: transparent;
  border: 0;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  position: relative;
  transition: background 0.18s var(--ease-out), transform 0.12s var(--ease-out);
}
.row:not(:last-child)::after {
  content: "";
  position: absolute;
  left: 56px;
  right: 0;
  bottom: 0;
  height: 1px;
  background: var(--hairline);
}
.row:active { background: var(--press); transform: scale(0.99); }

.row .glyph {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border-radius: var(--r-sm);
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
}
.row .glyph svg { width: 18px; height: 18px; }

.row .body { flex: 1 1 auto; min-width: 0; }
.row .title {
  display: block;
  font-size: 16px;
  font-weight: 550;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row .sub {
  display: block;
  font-size: 13px;
  color: var(--hint);
  margin-top: 2px;
}
.row .chev { flex: 0 0 auto; color: var(--hint); opacity: 0.7; }
.row .chev svg { width: 16px; height: 16px; display: block; }

/* stagger появления строк */
.stagger > * {
  opacity: 0;
  transform: translateY(10px);
  animation: rise 0.5s var(--ease-out) forwards;
  animation-delay: calc(var(--i, 0) * 45ms);
}
@keyframes rise { to { opacity: 1; transform: none; } }

/* ============================================================
   Карточка отчёта
   ============================================================ */
.report { padding-bottom: 96px; }

.week-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px 6px 10px;
  border-radius: 999px;
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  margin: 4px 0 18px;
}
.week-pill .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
}

.report-head { margin-bottom: 22px; }
.report-head .proj {
  font-size: 26px;
  font-weight: 720;
  letter-spacing: -0.025em;
  line-height: 1.1;
}
.report-head .sheet {
  margin-top: 5px;
  font-size: 14px;
  color: var(--hint);
  font-weight: 500;
}

/* сегментированный тумблер валюты */
.seg {
  position: relative;
  display: inline-grid;
  grid-auto-flow: column;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  background: var(--secondary-bg);
  margin: 0 0 24px;
  box-shadow: inset 0 1px 1px color-mix(in srgb, var(--hint) 10%, transparent);
}
.seg button {
  position: relative;
  z-index: 1;
  min-width: 58px;
  padding: 8px 16px;
  border: 0;
  background: transparent;
  color: var(--hint);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.28s var(--ease-spring);
}
.seg button[aria-selected="true"] { color: var(--text); }
.seg .thumb {
  position: absolute;
  z-index: 0;
  top: 3px;
  bottom: 3px;
  border-radius: 999px;
  background: var(--section-bg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.16), 0 0 0 0.5px var(--hairline);
  transition: transform 0.34s var(--ease-spring), width 0.34s var(--ease-spring);
  will-change: transform;
}

/* герой: Траты */
.hero {
  padding: 4px 0 24px;
  border-bottom: 1px solid var(--hairline);
}
.metric-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--section-header);
}
.hero-value {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.hero-value .amount {
  font-size: clamp(36px, 13vw, 52px);
  font-weight: 680;
  letter-spacing: -0.035em;
  line-height: 0.98;
}
.hero-value .sym {
  font-size: 26px;
  font-weight: 600;
  color: var(--hint);
}
.conv-note {
  margin-top: 8px;
  font-size: 14px;
  color: var(--hint);
  font-weight: 500;
}
.conv-note.rate-missing { color: var(--destructive); opacity: 0.85; }

/* Подписки — второй по важности блок */
.subs {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 0;
  border-bottom: 1px solid var(--hairline);
}
.subs .left .count {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-top: 6px;
}
.subs .right { text-align: right; }
.subs .right .metric-label { color: var(--section-header); }
.subs .right .price {
  margin-top: 8px;
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -0.02em;
  color: var(--accent);
}
.subs .right .price .sym { font-size: 15px; color: color-mix(in srgb, var(--accent) 70%, var(--hint)); }
.subs .right .price-sub { font-size: 12.5px; color: var(--hint); margin-top: 3px; }

/* сетка прочих метрик — терминальная, hairline-дивайдеры, без карточек */
.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
}
.cell {
  padding: 18px 2px 18px;
  position: relative;
}
.cell:nth-child(odd) { padding-right: 16px; }
.cell:nth-child(even) { padding-left: 16px; }
.cell:nth-child(even)::before {
  content: "";
  position: absolute;
  left: 0; top: 18px; bottom: 18px;
  width: 1px;
  background: var(--hairline);
}
.cell:nth-child(n + 3)::after {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 1px;
  background: var(--hairline);
}
.cell .k {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--section-header);
  text-transform: uppercase;
}
.cell .v {
  margin-top: 9px;
  font-size: 25px;
  font-weight: 640;
  letter-spacing: -0.025em;
}
.cell .v .sym { font-size: 15px; color: var(--hint); font-weight: 550; margin-left: 2px; }
.cell .v2 { margin-top: 4px; font-size: 12.5px; color: var(--hint); }

/* sticky-бар ссылок */
.linkbar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 30;
  display: flex;
  gap: 8px;
  width: min(520px, calc(100% - 24px));
  padding: 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--section-bg) 80%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  box-shadow: 0 10px 30px -12px rgba(0, 0, 0, 0.4), 0 0 0 0.5px var(--hairline);
}
.linkbar button {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.14s var(--ease-out), background 0.2s var(--ease-out);
}
.linkbar button:active { transform: scale(0.97); }
.linkbar .primary { background: var(--button); color: var(--button-text); }
.linkbar .ghost { background: var(--secondary-bg); color: var(--text); }
.linkbar .ico {
  display: grid; place-items: center;
  width: 24px; height: 24px; border-radius: 50%;
  background: color-mix(in srgb, var(--button-text) 18%, transparent);
}
.linkbar .ghost .ico { background: var(--press); }
.linkbar .ico svg { width: 13px; height: 13px; }
.linkbar button[disabled] { opacity: 0.4; pointer-events: none; }

/* ============================================================
   Состояния
   ============================================================ */
/* skeleton */
.sk {
  background: linear-gradient(
    100deg,
    var(--secondary-bg) 30%,
    color-mix(in srgb, var(--secondary-bg) 55%, var(--hint) 10%) 50%,
    var(--secondary-bg) 70%
  );
  background-size: 200% 100%;
  border-radius: 8px;
  animation: shimmer 1.3s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }
.sk.line { height: 14px; }
.sk.big { height: 52px; border-radius: 12px; }

.center-state {
  min-height: 60dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 28px;
  gap: 14px;
}
.center-state .mark {
  width: 72px; height: 72px;
  border-radius: 22px;
  display: grid; place-items: center;
  background: var(--secondary-bg);
  color: var(--hint);
}
.center-state .mark.dash {
  font-size: 40px; font-weight: 300; color: var(--hint);
}
.center-state .mark svg { width: 30px; height: 30px; }
.center-state h2 {
  margin: 4px 0 0;
  font-size: 20px;
  font-weight: 680;
  letter-spacing: -0.02em;
}
.center-state p {
  margin: 0;
  max-width: 30ch;
  color: var(--hint);
  font-size: 15px;
  line-height: 1.5;
}
.center-state.error .mark { color: var(--destructive); background: color-mix(in srgb, var(--destructive) 12%, transparent); }
.center-state button.retry {
  margin-top: 6px;
  padding: 11px 22px;
  border: 0;
  border-radius: 999px;
  background: var(--button);
  color: var(--button-text);
  font: inherit; font-weight: 600; font-size: 15px;
  cursor: pointer;
  transition: transform 0.14s var(--ease-out);
}
.center-state button.retry:active { transform: scale(0.97); }

.dash-value { color: var(--hint); font-weight: 500; }

/* ============================================================
   Админ-компоненты (управление проектами/листами/расписанием)
   ============================================================ */

/* иконки-кнопки в аппбаре */
.appbar-actions { display: flex; align-items: center; gap: 6px; }
.icon-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: var(--secondary-bg);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.14s var(--ease-out), background 0.2s var(--ease-out);
}
.icon-btn:active { transform: scale(0.92); }
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn.accent { background: var(--accent-soft); color: var(--accent); }

/* строка-переключатель (лейбл слева, switch справа) */
.manage-list {
  background: var(--section-bg);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: 0 1px 0 var(--hairline), 0 8px 24px -18px rgba(0, 0, 0, 0.28);
}
.mrow {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  position: relative;
  width: 100%;
  background: transparent;
  border: 0;
  color: inherit;
  font: inherit;
  text-align: left;
}
.mrow.tap { cursor: pointer; transition: background 0.18s var(--ease-out); }
.mrow.tap:active { background: var(--press); }
.mrow:not(:last-child)::after {
  content: ""; position: absolute; left: 16px; right: 0; bottom: 0;
  height: 1px; background: var(--hairline);
}
.mrow .m-body { flex: 1 1 auto; min-width: 0; }
.mrow .m-title {
  display: block; font-size: 16px; font-weight: 550; letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.mrow .m-sub {
  display: block; font-size: 13px; color: var(--hint); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.mrow .check { flex: 0 0 auto; display: grid; place-items: center; transition: opacity 0.2s var(--ease-out); }

/* подвал настроек */
.settings-foot {
  margin-top: 26px;
  padding: 0 4px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--hint);
  text-align: center;
}
.mrow .m-title.dot::before {
  content: ""; display: inline-block;
  width: 8px; height: 8px; border-radius: 50%;
  margin-right: 9px; vertical-align: middle;
  background: var(--hint);
}
.mrow .m-title.dot.on::before { background: #34c759; }
.mrow .m-title.dot.off::before { background: color-mix(in srgb, var(--destructive) 80%, var(--hint)); }
.mrow .chev { color: var(--hint); opacity: 0.6; }
.mrow .chev svg { width: 16px; height: 16px; display: block; }
.mrow .pill-tag {
  font-size: 12px; font-weight: 600;
  color: var(--hint);
  font-variant-numeric: tabular-nums;
  padding: 3px 9px; border-radius: 999px;
  background: var(--secondary-bg);
}

/* switch */
.switch {
  position: relative;
  flex: 0 0 auto;
  width: 51px; height: 31px;
  border-radius: 999px;
  border: 0; padding: 0;
  background: color-mix(in srgb, var(--hint) 32%, transparent);
  cursor: pointer;
  transition: background 0.28s var(--ease-spring);
}
.switch[aria-checked="true"] { background: #34c759; }
.switch .knob {
  position: absolute; top: 2px; left: 2px;
  width: 27px; height: 27px; border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.28);
  transition: transform 0.28s var(--ease-spring);
}
.switch[aria-checked="true"] .knob { transform: translateX(20px); }

/* формы */
.form-field { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.form-field label {
  font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--section-header);
  padding-left: 2px;
}
.text-input {
  width: 100%;
  padding: 14px 16px;
  border: 0;
  border-radius: var(--r-md);
  background: var(--section-bg);
  color: var(--text);
  font: inherit; font-size: 16px;
  box-shadow: inset 0 0 0 1px var(--hairline);
  transition: box-shadow 0.2s var(--ease-out);
}
.text-input::placeholder { color: var(--hint); }
.text-input:focus { outline: none; box-shadow: inset 0 0 0 1.5px var(--accent); }
.text-input.mono { font-variant-numeric: tabular-nums; letter-spacing: 0.04em; }
.form-help { font-size: 13px; color: var(--hint); padding-left: 2px; margin-top: -4px; }
.form-error { font-size: 13px; color: var(--destructive); padding-left: 2px; }

/* кнопки */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: var(--tap);
  padding: 0 20px;
  border: 0;
  border-radius: var(--r-md);
  font: inherit; font-size: 16px; font-weight: 600;
  cursor: pointer;
  transition: transform 0.14s var(--ease-out), opacity 0.2s var(--ease-out);
}
.btn:active { transform: scale(0.98); }
.btn[disabled] { opacity: 0.45; pointer-events: none; }
.btn svg { width: 18px; height: 18px; flex: 0 0 auto; }
.btn.primary { background: var(--button); color: var(--button-text); }
.btn.ghost { background: var(--secondary-bg); color: var(--text); }
.btn.danger { background: color-mix(in srgb, var(--destructive) 14%, transparent); color: var(--destructive); }
.btn.small { width: auto; min-height: 40px; font-size: 14px; border-radius: 999px; padding: 0 16px; }

/* чипы дней */
.chips { display: grid; grid-template-columns: repeat(7, 1fr); gap: 7px; }
.chip {
  min-height: 46px;
  border: 0;
  border-radius: var(--r-md);
  background: var(--section-bg);
  box-shadow: inset 0 0 0 1px var(--hairline);
  color: var(--hint);
  font: inherit; font-size: 14px; font-weight: 600;
  cursor: pointer;
  transition: transform 0.14s var(--ease-out), background 0.2s var(--ease-out), color 0.2s var(--ease-out), box-shadow 0.2s var(--ease-out);
}
.chip:active { transform: scale(0.94); }
.chip[aria-pressed="true"] {
  background: var(--accent);
  color: var(--button-text);
  box-shadow: none;
}

/* степпер часы/минуты */
.stepper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  background: var(--section-bg);
  border-radius: var(--r-md);
  box-shadow: inset 0 0 0 1px var(--hairline);
}
.stepper .st-val {
  flex: 1 1 auto;
  font-size: 28px; font-weight: 680;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  min-width: 40px; text-align: center;
}
.stepper .st-btn {
  flex: 0 0 auto;
  width: 42px; height: 42px;
  border: 0; border-radius: var(--r-sm);
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 24px; font-weight: 500;
  cursor: pointer;
  display: grid; place-items: center;
  transition: transform 0.12s var(--ease-out), background 0.2s var(--ease-out);
}
.stepper .st-btn:active { transform: scale(0.9); background: var(--press); }
.time-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.time-grid .form-field { margin-bottom: 0; }

/* toast */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 22px);
  transform: translate(-50%, 20px);
  z-index: 60;
  max-width: min(440px, calc(100% - 32px));
  padding: 13px 20px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--text) 92%, transparent);
  color: var(--bg);
  font-size: 14.5px; font-weight: 550;
  box-shadow: 0 14px 40px -12px rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.4s var(--ease-spring), opacity 0.3s var(--ease-out);
  text-align: center;
}
#toast.show { transform: translate(-50%, 0); opacity: 1; }
#toast.err { background: var(--destructive); color: #fff; }

/* модалка подтверждения */
#modal {
  position: fixed; inset: 0; z-index: 70;
  display: none;
  align-items: flex-end;
  justify-content: center;
}
#modal.open { display: flex; }
#modal .scrim {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0; transition: opacity 0.3s var(--ease-out);
}
#modal.open .scrim { opacity: 1; }
#modal .card {
  position: relative;
  width: min(520px, 100%);
  margin: 0 12px calc(env(safe-area-inset-bottom) + 12px);
  padding: 24px 22px 20px;
  border-radius: var(--r-xl);
  background: var(--section-bg);
  box-shadow: 0 -10px 40px -10px rgba(0, 0, 0, 0.4);
  transform: translateY(24px);
  transition: transform 0.4s var(--ease-spring);
}
#modal.open .card { transform: none; }
#modal h3 { margin: 0 0 8px; font-size: 19px; font-weight: 700; letter-spacing: -0.02em; }
#modal p { margin: 0 0 20px; color: var(--hint); font-size: 15px; line-height: 1.5; }
#modal .actions { display: grid; gap: 8px; }

/* низовая панель действий (Добавить / Создать) */
.actionbar {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 30;
  width: min(520px, calc(100% - 24px));
  display: flex; gap: 8px;
}
.actionbar .btn {
  box-shadow: 0 10px 30px -12px rgba(0, 0, 0, 0.45);
}
.with-actionbar { padding-bottom: 92px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .stagger > * { opacity: 1; transform: none; }
}
