/* Марта: мини-приложение. Цвета берутся из темы Telegram, запасные — для просмотра в браузере. */

:root {
  --fb-bg: #f2f2f7;
  --fb-card: #ffffff;
  --fb-text: #111111;
  --fb-hint: #6d6d72;
  --fb-accent: #1f6fb5;
  --fb-danger: #c0392b;
  --fb-line: #e3e3e8;
  color-scheme: light;
}

:root[data-scheme="dark"] {
  --fb-bg: #0f1821;
  --fb-card: #1c2733;
  --fb-text: #f2f5f8;
  --fb-hint: #8b9bab;
  --fb-accent: #6ab3f3;
  --fb-danger: #ff8a7a;
  --fb-line: #2a3746;
  color-scheme: dark;
}

:root {
  --bg: var(--tg-theme-secondary-bg-color, var(--fb-bg));
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, var(--fb-card)));
  --text: var(--tg-theme-text-color, var(--fb-text));
  --hint: var(--tg-theme-subtitle-text-color, var(--tg-theme-hint-color, var(--fb-hint)));
  --accent: var(--tg-theme-link-color, var(--fb-accent));
  --btn: var(--tg-theme-button-color, var(--fb-accent));
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, var(--fb-danger));
  --line: var(--tg-theme-section-separator-color, var(--fb-line));
  --chip: rgba(127, 127, 127, 0.14);
  --input: rgba(127, 127, 127, 0.08);
  --radius: 14px;
  --tabs-h: 64px;
}

@supports (color: color-mix(in srgb, red, blue)) {
  :root {
    --chip: color-mix(in srgb, var(--btn) 13%, var(--card));
    --input: color-mix(in srgb, var(--text) 5%, var(--card));
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.3 -apple-system, BlinkMacSystemFont, "SF Pro Text", Roboto, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body { max-width: 560px; margin: 0 auto; min-height: 100vh; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 2px;
  padding: 6px 6px 6px 16px; background: var(--bg);
}
.top h1 { flex: 1; margin: 0; font-size: 24px; line-height: 30px; font-weight: 700; }

.icon-btn {
  width: 44px; height: 44px; flex: none; padding: 0;
  border: none; background: transparent; color: var(--accent);
  display: inline-flex; align-items: center; justify-content: center; border-radius: 12px;
}
.icon-btn.quiet { color: var(--hint); }

main {
  padding: 4px 16px calc(var(--tabs-h) + 96px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 20px;
}

.section { display: flex; flex-direction: column; gap: 8px; }
.section > h2 {
  margin: 0; padding: 0 4px; font-size: 13px; line-height: 16px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em; color: var(--hint);
}
.section > h2.danger { color: var(--danger); }
.section > h3 { margin: 4px 0 0; padding: 0 4px; font-size: 14px; font-weight: 600; }

.card { background: var(--card); border-radius: var(--radius); overflow: hidden; }
.card.pad { padding: 14px; }
.empty { margin: 0; padding: 16px; color: var(--hint); font-size: 15px; }

.quote-card {
  position: relative; overflow: hidden;
  padding: 14px 18px 16px; border-radius: 18px; background: var(--chip);
}
.quote-card::after {
  content: "\201D"; position: absolute; right: 12px; top: -14px;
  font: 700 96px/1 Georgia, "Times New Roman", serif; color: var(--accent); opacity: 0.18; pointer-events: none;
}
.quote-label {
  font-size: 12px; line-height: 16px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent);
}
.quote-text { position: relative; margin: 6px 0 0; font-size: 20px; line-height: 27px; font-weight: 700; text-wrap: pretty; }

.row { display: flex; align-items: center; gap: 2px; padding: 2px 12px 2px 2px; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: none; }
.row.repeat { opacity: 0.55; }
.check {
  flex: none; width: 44px; height: 44px; padding: 0; border: none; background: transparent;
  display: flex; align-items: center; justify-content: center;
}
.check::before {
  content: ""; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--accent); box-sizing: border-box;
}
.check.square::before { border-radius: 6px; }
.check.on::before {
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E") center / 14px no-repeat;
}
.spacer { flex: none; width: 44px; height: 44px; }
.row-main {
  flex: 1; min-width: 0; min-height: 52px; padding: 6px 0;
  display: flex; align-items: center; gap: 10px;
  border: none; background: transparent; text-align: left;
}
.emoji { flex: none; width: 26px; text-align: center; font-size: 20px; }
.lines { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.title { font-size: 16px; line-height: 20px; overflow-wrap: anywhere; }
.sub { font-size: 13px; line-height: 17px; color: var(--hint); }
.sub.danger { color: var(--danger); }
.strike { text-decoration: line-through; color: var(--hint); }
.side-btn { flex: none; height: 44px; padding: 0 8px; border: none; background: transparent; color: var(--accent); font-size: 15px; }

.draft { display: flex; flex-direction: column; gap: 12px; padding: 14px; border-bottom: 1px solid var(--line); }
.draft:last-child { border-bottom: none; }
.draft-head { display: flex; gap: 10px; align-items: flex-start; }
.actions { display: flex; gap: 8px; }
.actions > * { flex: 1; }

.btn {
  min-height: 44px; padding: 0 14px; border: none; border-radius: 10px;
  background: var(--chip); color: var(--accent); font-size: 15px; font-weight: 600;
}
.btn.primary { background: var(--btn); color: var(--btn-text); }
.btn.plain { background: var(--chip); color: var(--text); font-weight: 400; }
.btn.danger { color: var(--danger); }
.btn.big { min-height: 48px; font-size: 16px; border-radius: 12px; }
.btn.link { background: transparent; }
.btn:disabled { opacity: 0.5; }

.fab {
  position: fixed; z-index: 6;
  right: max(16px, calc(50% - 280px + 16px)); bottom: calc(var(--tabs-h) + 16px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 28px; border: none;
  background: var(--btn); color: var(--btn-text);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.22);
}
.fab svg { width: 26px; height: 26px; stroke-width: 2.2; }

.tabs {
  position: fixed; z-index: 7; left: 0; right: 0; bottom: 0;
  max-width: 560px; margin: 0 auto;
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding: 0 4px env(safe-area-inset-bottom);
  display: flex; background: var(--card); border-top: 1px solid var(--line);
}
.tabs button {
  flex: 1; min-width: 0; padding: 0; border: none; background: transparent; color: var(--hint);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 11px; font-weight: 500;
}
.tabs button[aria-current="page"] { color: var(--accent); font-weight: 700; }

.toast {
  position: fixed; z-index: 30; left: 16px; right: 88px;
  bottom: calc(var(--tabs-h) + 20px + env(safe-area-inset-bottom));
  max-width: 456px; margin: 0 auto;
  padding: 12px 14px; border-radius: 12px; background: var(--text); color: var(--card);
  font-size: 14px; line-height: 19px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
}

/* календарь */
.cal-head { display: flex; align-items: center; gap: 2px; padding: 2px 0 4px 8px; }
.cal-head h2 { flex: 1; margin: 0; font-size: 17px; font-weight: 600; text-transform: capitalize; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px; padding: 0 6px 6px; }
.cal-wd { text-align: center; font-size: 12px; line-height: 24px; font-weight: 600; color: var(--hint); }
.cal-wd.weekend { color: var(--danger); }
.cal-day {
  height: 46px; padding: 0; border: none; border-radius: 12px; background: transparent;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 16px;
}
.cal-day.today { color: var(--accent); font-weight: 700; }
.cal-day.selected { background: var(--btn); color: var(--btn-text); font-weight: 700; }
.dot { width: 6px; height: 6px; border-radius: 50%; border: 1.5px solid transparent; box-sizing: border-box; }
.dot.real { background: currentColor; border-color: currentColor; }
.cal-day:not(.selected) .dot.real { background: var(--accent); border-color: var(--accent); }
.dot.repeat { border-color: var(--accent); }
.cal-day.selected .dot.repeat { border-color: var(--btn-text); }
.legend { display: flex; gap: 16px; padding: 4px 14px 12px; font-size: 12px; color: var(--hint); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* платежи */
.totals { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.total { background: var(--card); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; }
.total b { font-size: 20px; line-height: 24px; }
.total span { font-size: 13px; color: var(--hint); }
.amount { flex: none; font-weight: 600; font-size: 15px; padding-left: 8px; }

/* идеи */
.chips { display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px; padding: 0 16px 2px; scrollbar-width: none; }
.chip {
  flex: none; height: 36px; padding: 0 14px; border: none; border-radius: 18px;
  background: var(--chip); color: var(--text); font-size: 14px; font-weight: 600; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--btn); color: var(--btn-text); }
.note {
  display: flex; gap: 12px; align-items: flex-start; width: 100%; padding: 14px; text-align: left;
  border: none; border-radius: var(--radius); background: var(--card);
}
.note-links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.link-btn {
  max-width: 100%; height: 32px; padding: 0 10px; border: none; border-radius: 16px;
  background: var(--chip); color: var(--accent); font-size: 13px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.list { display: flex; flex-direction: column; gap: 10px; }

/* покупки */
.add-row { display: flex; gap: 8px; }
.add-row input { flex: 1; min-width: 0; }

/* категории */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.tile {
  min-height: 64px; display: flex; align-items: center; gap: 10px; padding: 10px 12px; text-align: left;
  border: none; border-radius: var(--radius); background: var(--bg);
}
.tile .emoji { font-size: 24px; width: 30px; }

/* шторка */
.sheet-wrap { position: fixed; inset: 0; z-index: 20; }
.sheet-overlay { position: absolute; inset: 0; border: none; padding: 0; background: rgba(0, 0, 0, 0.4); }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-width: 560px; margin: 0 auto;
  max-height: calc(var(--tg-viewport-stable-height, 100vh) * 0.9);
  display: flex; flex-direction: column;
  background: var(--card); border-radius: 18px 18px 0 0; box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.18);
}
.sheet-head { flex: none; display: flex; align-items: center; gap: 2px; padding: 8px 6px 4px 8px; }
.sheet-head h2 { flex: 1; margin: 0; padding-left: 8px; font-size: 18px; line-height: 24px; font-weight: 700; }
.sheet-body {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: 4px 16px calc(24px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 14px;
}
.sheet-body .card, .sheet-body .note { background: var(--bg); }

/* форма */
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--hint); }
.field input, .field select, .field textarea, .add-row input {
  width: 100%; min-height: 44px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--input); color: var(--text); font-size: 16px;
}
.field textarea { padding: 10px 12px; line-height: 22px; resize: vertical; min-height: 88px; }
.field input[type="date"], .field input[type="time"] { min-width: 0; -webkit-appearance: none; appearance: none; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.hint { margin: 0; font-size: 13px; line-height: 18px; color: var(--hint); }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }

.switch-row { min-height: 60px; display: flex; align-items: center; gap: 12px; }
.switch {
  flex: none; position: relative; width: 52px; height: 32px; padding: 0; border: none; border-radius: 16px;
  background: var(--line);
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%;
  background: #ffffff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); transition: left 0.15s;
}
.switch[aria-checked="true"] { background: var(--btn); }
.switch[aria-checked="true"]::after { left: 23px; }
.time-row { min-height: 56px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); }
.time-row:last-child { border-bottom: none; }
.time-row span { flex: 1; }
.time-row input {
  min-height: 40px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--input); color: var(--text); font-size: 16px;
}

.answer { padding: 14px; border-radius: var(--radius); background: var(--bg); white-space: pre-wrap; line-height: 21px; }
.center { margin: 30vh 24px 0; text-align: center; color: var(--hint); line-height: 22px; }
.loading { padding: 24px; text-align: center; color: var(--hint); }
.tile .title { font-size: 15px; font-weight: 600; overflow-wrap: normal; hyphens: auto; }
.tile { gap: 8px; padding: 10px; }
.tile .emoji { font-size: 22px; width: 26px; }
