/* app.css — ShareTrip. Токены из фирменного стиля, сетка под планшет,
   тёмная тема по системной настройке. Ни одной внешней зависимости. */

:root {
  /* Фирменная палитра */
  --navy: #0F2D5B;
  --teal: #22C997;
  --sky:  #8FD2FF;
  --gold: #FFC857;
  --light:#F2F7FB;

  --bg:        var(--light);
  --bg-card:   #ffffff;
  --bg-sunken: #e8eff7;
  --fg:        var(--navy);
  --fg-muted:  #5b738f;
  --fg-faint:  #8fa4bd;
  --line:      #d7e3f0;
  --line-soft: #e8eef6;

  --accent:      var(--teal);
  --accent-fg:   #06331f;
  --positive:    #12a877;
  --negative:    #d9455f;
  --warn:        #b5730a;
  --warn-bg:     #fff6e2;

  --radius:   14px;
  --radius-l: 20px;
  --tap:      52px;

  --shadow-1: 0 1px 2px rgba(15, 45, 91, .06), 0 2px 8px rgba(15, 45, 91, .05);
  --shadow-2: 0 8px 28px rgba(15, 45, 91, .16);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
          "Noto Sans", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --safe-b: env(safe-area-inset-bottom, 0px);
  /* Высота нижней панели. Запас под неё живёт в отступе КОНТЕНТА (.view), а не
     в padding у body: отступ body не удлиняет прокрутку, если внешняя оболочка
     задала body фиксированную высоту (D-012). */
  --nav-h: 64px;
  --nav-clear: calc(var(--nav-h) + var(--safe-b) + 20px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:        #0b1a2e;
    --bg-card:   #12263f;
    --bg-sunken: #0d1f36;
    --fg:        #e8f1fb;
    --fg-muted:  #93aac6;
    --fg-faint:  #6b83a1;
    --line:      #1e3a5c;
    --line-soft: #17304e;
    --accent-fg: #06331f;
    --positive:  #35d6a0;
    --negative:  #ff7089;
    --warn:      #ffc857;
    --warn-bg:   #2e2412;
    --shadow-1:  0 1px 2px rgba(0,0,0,.3), 0 2px 8px rgba(0,0,0,.25);
    --shadow-2:  0 8px 28px rgba(0,0,0,.45);
  }
}
:root[data-theme="dark"] {
  --bg:        #0b1a2e;
  --bg-card:   #12263f;
  --bg-sunken: #0d1f36;
  --fg:        #e8f1fb;
  --fg-muted:  #93aac6;
  --fg-faint:  #6b83a1;
  --line:      #1e3a5c;
  --line-soft: #17304e;
  --accent-fg: #06331f;
  --positive:  #35d6a0;
  --negative:  #ff7089;
  --warn:      #ffc857;
  --warn-bg:   #2e2412;
  --shadow-1:  0 1px 2px rgba(0,0,0,.3), 0 2px 8px rgba(0,0,0,.25);
  --shadow-2:  0 8px 28px rgba(0,0,0,.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

body {
  min-height: 100dvh;
}

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .6em; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.num { font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ layout */

.app { max-width: 880px; margin: 0 auto; padding: 0 16px; }

.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 30;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px calc(10px + env(safe-area-inset-top, 0px));
  padding-top: max(10px, env(safe-area-inset-top, 0px));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line-soft);
}
.topbar__logo { width: 30px; height: 30px; flex: none; }
.topbar__title { flex: 1; min-width: 0; }
.topbar__title b { display: block; font-size: 1.05rem; line-height: 1.2; }
.topbar__title small { color: var(--fg-muted); font-size: .8rem; }

.view { padding: 16px 0 var(--nav-clear); }
.view > * + * { margin-top: 14px; }

.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.row--wrap { flex-wrap: wrap; }
.spacer { flex: 1; }

/* ------------------------------------------------------------------- cards */

.card {
  background: var(--bg-card);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-1);
  padding: 16px;
}
.card--flat { box-shadow: none; }
.card__head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.card__head h2 { flex: 1; }

.hero {
  background: linear-gradient(135deg, var(--navy), #1b4a8f 65%, #226bb5);
  color: #fff; border: none;
}
.hero .hero__label { color: rgba(255,255,255,.72); font-size: .85rem; }
.hero .hero__value { font-size: 2.1rem; font-weight: 800; letter-spacing: -.02em; }
.hero .hero__sub { color: rgba(255,255,255,.8); font-size: .9rem; }
.hero__grid { display: flex; gap: 20px; flex-wrap: wrap; margin-top: 12px; }
.hero__grid div { min-width: 96px; }
.hero__grid b { display: block; font-size: 1.05rem; }
.hero__grid span { color: rgba(255,255,255,.7); font-size: .78rem; }

/* ------------------------------------------------------------------ pills */

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: 999px;
  background: var(--bg-sunken); border: 1px solid transparent;
  font-size: .82rem; color: var(--fg-muted); white-space: nowrap;
}
.pill--accent { background: color-mix(in srgb, var(--teal) 18%, transparent); color: var(--positive); }
.pill--warn   { background: var(--warn-bg); color: var(--warn); }
.pill--danger { background: color-mix(in srgb, var(--negative) 15%, transparent); color: var(--negative); }

/* ---------------------------------------------------------------- buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 18px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg-card); color: var(--fg);
  font-weight: 600; font-size: .95rem;
  transition: transform .06s ease, background .12s ease, border-color .12s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.975); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn--primary { background: var(--teal); border-color: var(--teal); color: var(--accent-fg); }
.btn--navy    { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn--ghost   { background: transparent; border-color: transparent; color: var(--fg-muted); }
.btn--danger  { background: transparent; border-color: color-mix(in srgb, var(--negative) 45%, transparent); color: var(--negative); }
.btn--block   { width: 100%; }
.btn--sm      { min-height: 38px; padding: 0 12px; font-size: .85rem; }

.fab {
  position: fixed; right: 18px; z-index: 40;
  bottom: calc(84px + var(--safe-b));
  width: 62px; height: 62px; border-radius: 50%;
  background: var(--teal); color: var(--accent-fg);
  border: none; box-shadow: var(--shadow-2);
  font-size: 2rem; line-height: 1; font-weight: 300;
  display: flex; align-items: center; justify-content: center;
}
.fab:active { transform: scale(.93); }

/* ------------------------------------------------------------------- nav */

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: flex;
  padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--bg-card) 94%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--line-soft);
}
.nav button {
  flex: 1; border: none; background: none;
  padding: 9px 4px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--fg-faint); font-size: .7rem; font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}
.nav button svg { width: 23px; height: 23px; }
.nav button[aria-current="page"] { color: var(--teal); }

/* ----------------------------------------------------------------- lists */

.list { display: flex; flex-direction: column; }
.list__day {
  display: flex; align-items: baseline; gap: 8px;
  padding: 14px 4px 6px;
  font-size: .8rem; font-weight: 700; color: var(--fg-faint);
  text-transform: uppercase; letter-spacing: .04em;
}
.list__day .spacer { flex: 1; }

.item {
  display: flex; align-items: center; gap: 12px;
  width: 100%; text-align: left;
  min-height: var(--tap); padding: 11px 14px;
  background: var(--bg-card);
  border: 1px solid var(--line-soft); border-radius: var(--radius);
  margin-bottom: 8px;
  -webkit-tap-highlight-color: transparent;
}
.item:active { background: var(--bg-sunken); }
.item__icon {
  width: 40px; height: 40px; flex: none; border-radius: 12px;
  background: var(--bg-sunken);
  display: flex; align-items: center; justify-content: center; font-size: 1.15rem;
}
.item__body { flex: 1; min-width: 0; }
.item__title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item__sub { font-size: .8rem; color: var(--fg-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item__amount { text-align: right; flex: none; }
.item__amount b { display: block; font-weight: 700; }
.item__amount span { font-size: .76rem; color: var(--fg-faint); }

.empty {
  text-align: center; padding: 44px 20px; color: var(--fg-muted);
}
.empty__icon { font-size: 2.6rem; opacity: .55; margin-bottom: 8px; }

/* ----------------------------------------------------------------- forms */

.field { display: block; margin-bottom: 14px; }
.field__label {
  display: block; font-size: .78rem; font-weight: 700;
  color: var(--fg-muted); text-transform: uppercase; letter-spacing: .04em;
  margin-bottom: 6px;
}
.field__hint { font-size: .78rem; color: var(--fg-faint); margin-top: 5px; }
.field__error { font-size: .82rem; color: var(--negative); margin-top: 5px; font-weight: 600; }

.input, .select, .textarea {
  width: 100%; min-height: var(--tap);
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1.5px solid var(--line); border-radius: var(--radius);
  outline: none;
  transition: border-color .12s ease, box-shadow .12s ease;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--teal) 22%, transparent);
}
.textarea { min-height: 76px; resize: vertical; padding-top: 12px; }
.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath fill='%238fa4bd' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 12px;
  padding-right: 38px;
}

.amount-input {
  display: flex; align-items: stretch; gap: 8px;
}
.amount-input .input {
  font-size: 2rem; font-weight: 800; text-align: right;
  min-height: 68px; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}
.amount-input .select { max-width: 116px; font-weight: 700; }

.seg {
  display: flex; gap: 4px; padding: 4px;
  background: var(--bg-sunken); border-radius: var(--radius);
}
.seg button {
  flex: 1; min-height: 42px; border: none; border-radius: 10px;
  background: transparent; color: var(--fg-muted);
  font-size: .87rem; font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}
.seg button[aria-pressed="true"] {
  background: var(--bg-card); color: var(--fg); box-shadow: var(--shadow-1);
}

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 44px; padding: 0 14px;
  border: 1.5px solid var(--line); border-radius: var(--radius);
  background: var(--bg-card); color: var(--fg);
  font-size: .9rem; font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}
.chip[aria-pressed="true"] {
  border-color: var(--teal);
  background: color-mix(in srgb, var(--teal) 14%, transparent);
}
.chip__icon { font-size: 1.05rem; }

/* Нативный выбор даты стоит в одном ряду с чипами-пресетами и выглядит как они. */
.chips .input--date {
  width: auto;
  flex: 0 0 auto;
  min-height: 44px;
  padding: 0 12px;
  border-width: 1.5px;
  font-size: .9rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.switch-row {
  display: flex; align-items: center; gap: 12px;
  min-height: var(--tap); padding: 6px 0;
}
.switch-row__label { flex: 1; }
.switch-row__label small { display: block; color: var(--fg-muted); font-size: .8rem; }

/* --------------------------------------------------------------- sheets */

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(8, 22, 40, .45);
  backdrop-filter: blur(2px);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .16s ease;
}
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(24px); opacity: .6; } }

.sheet {
  width: 100%; max-width: 880px;
  max-height: 92dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg);
  border-radius: 22px 22px 0 0;
  padding: 8px 16px calc(24px + var(--safe-b));
  animation: rise .2s cubic-bezier(.2,.8,.3,1);
}
@media (min-width: 720px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 22px; max-width: 640px; max-height: 88dvh; }
}
.sheet__grip {
  width: 40px; height: 4px; border-radius: 2px;
  background: var(--line); margin: 6px auto 10px;
}
.sheet__head {
  display: flex; align-items: center; gap: 10px;
  padding: 2px 0 14px; position: sticky; top: 0;
  background: var(--bg); z-index: 2;
}
.sheet__head h2 { flex: 1; }
.sheet__actions {
  display: flex; gap: 10px; padding-top: 16px;
  position: sticky; bottom: 0; background: var(--bg);
  padding-bottom: 4px;
}
.sheet__actions .btn { flex: 1; }

/* --------------------------------------------------------------- tables */

.kv { display: flex; align-items: baseline; gap: 10px; padding: 7px 0; }
.kv + .kv { border-top: 1px solid var(--line-soft); }
.kv__k { color: var(--fg-muted); font-size: .9rem; flex: 1; }
.kv__v { font-weight: 600; text-align: right; }

.bar {
  height: 7px; border-radius: 4px; background: var(--bg-sunken);
  overflow: hidden; margin-top: 6px;
}
.bar > i { display: block; height: 100%; background: var(--teal); border-radius: 4px; }

/* -------------------------------------------------------------- verdict */

.verdict { text-align: center; padding: 8px 0 4px; }
.verdict__who { font-size: .95rem; color: var(--fg-muted); }
.verdict__amount {
  font-size: 2.4rem; font-weight: 800; letter-spacing: -.03em;
  margin: 2px 0 4px; line-height: 1.1;
}
.verdict--settled .verdict__amount { color: var(--positive); font-size: 1.7rem; }

.pos { color: var(--positive); }
.neg { color: var(--negative); }

/* --------------------------------------------------------------- notice */

.notice {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--radius);
  background: var(--warn-bg); color: var(--warn);
  font-size: .88rem; font-weight: 500;
  border: 1px solid color-mix(in srgb, var(--warn) 25%, transparent);
}
.notice--danger {
  background: color-mix(in srgb, var(--negative) 12%, transparent);
  color: var(--negative);
  border-color: color-mix(in srgb, var(--negative) 30%, transparent);
}
.notice b { font-weight: 700; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(96px + var(--safe-b)); z-index: 200;
  background: var(--navy); color: #fff;
  padding: 11px 18px; border-radius: 999px;
  font-size: .88rem; font-weight: 600;
  box-shadow: var(--shadow-2);
  animation: rise .2s ease;
  max-width: calc(100vw - 40px); text-align: center;
}

/* --------------------------------------------------------------- splash */

.splash {
  min-height: 100dvh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 18px;
  padding: 24px; text-align: center;
  padding-bottom: max(24px, var(--nav-clear));
}
.splash img { max-width: 100%; }

/* Словесный знак на заставке до загрузки скриптов: те же правила, что и в ui.js —
   «Share» берёт цвет текста темы, «Trip» — фирменный зелёный. */
.wordmark-boot { display: inline-flex; align-items: center; gap: 10px; }
.wordmark-boot > span {
  font-size: 40px; font-weight: 800; letter-spacing: -.025em; line-height: 1;
}
.wordmark-boot b { color: var(--fg); font-weight: 800; }
.wordmark-boot i { color: var(--teal); font-style: normal; font-weight: 800; }
.splash p { color: var(--fg-muted); max-width: 34ch; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 420px) { .grid2 { grid-template-columns: 1fr; } }

.mono { font-family: var(--mono); font-size: .9em; }
.muted { color: var(--fg-muted); }
.small { font-size: .82rem; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
