:root {
  --fon: #ffffff; --tekst: #1d1b26; --tihiy: #6b6880; --akcent: #4b3fa8; --akcent-tekst: #fff;
  --ramka: #e2e0ec; --panel: #f5f4fa; --moi: #ece9ff; --oshibka: #b3261e; --vvh: 100dvh;
}
@media (prefers-color-scheme: dark) {
  :root { --fon: #14131a; --tekst: #ecebf3; --tihiy: #a09db3; --ramka: #2c2a3a; --panel: #1d1b27;
    --moi: #2a2650; --akcent: #8b7ff0; --akcent-tekst: #14131a; --oshibka: #f2918a; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--fon); color: var(--tekst);
  font: 16px/1.4 -apple-system, "Segoe UI", Roboto, sans-serif; overflow-x: hidden;
  -webkit-text-size-adjust: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.koren { height: var(--vvh); display: flex; flex-direction: column; min-width: 0; }
.skryt { display: none !important; }

/* кнопки: не меньше 44 px */
.knopka { min-height: 44px; min-width: 44px; padding: 0 14px; border: 1px solid var(--ramka);
  border-radius: 12px; background: var(--panel); display: inline-flex; align-items: center;
  justify-content: center; gap: 6px; }
.knopka.glavnaya { background: var(--akcent); color: var(--akcent-tekst); border-color: var(--akcent); }
.knopka.opasnaya { color: var(--oshibka); }
.knopka:disabled { opacity: .45; cursor: default; }
.knopka.znak { padding: 0; font-size: 22px; }

/* вход */
.vhod { margin: auto; width: min(380px, 100%); padding: 24px 16px; display: flex;
  flex-direction: column; gap: 12px; }
.vhod h1 { margin: 0 0 4px; font-size: 26px; }
.vhod input { min-height: 48px; padding: 0 12px; border: 1px solid var(--ramka); border-radius: 12px;
  background: var(--fon); width: 100%; }
.preduprezhdenie { padding: 10px 12px; border-radius: 12px; background: var(--panel);
  color: var(--tihiy); font-size: 14px; }
.oshibka { color: var(--oshibka); font-size: 14px; }

/* шапка */
.shapka { display: flex; align-items: center; gap: 8px; padding: 6px 8px;
  padding-top: calc(6px + env(safe-area-inset-top)); border-bottom: 1px solid var(--ramka); }
.shapka .zagolovok { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.schetchik { font-size: 13px; color: var(--tihiy); white-space: nowrap; }

/* список диалогов */
.shirma { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; }
.panel { position: fixed; top: 0; bottom: 0; left: 0; width: min(86vw, 340px); background: var(--fon);
  z-index: 21; display: flex; flex-direction: column; border-right: 1px solid var(--ramka);
  padding-top: env(safe-area-inset-top); }
.panel .verh { display: flex; gap: 8px; padding: 8px; border-bottom: 1px solid var(--ramka); }
.panel .spisok { flex: 1; overflow-y: auto; }
.stroka-dialoga { display: flex; align-items: center; min-height: 52px; border-bottom: 1px solid var(--ramka); }
.stroka-dialoga .imya { flex: 1; min-width: 0; padding: 0 12px; text-align: left; background: none;
  border: 0; min-height: 52px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stroka-dialoga.tekushchiy { background: var(--panel); }
.stroka-dialoga .knopka { border: 0; background: none; }

/* лента */
.lenta { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 12px; display: flex;
  flex-direction: column; gap: 12px; min-height: 0; }
.pusto { margin: auto; text-align: center; color: var(--tihiy); max-width: 320px; }
.moe { align-self: flex-end; max-width: 92%; background: var(--moi); border-radius: 16px;
  padding: 8px 12px; }
.moe .tekst { white-space: pre-wrap; overflow-wrap: anywhere; }
.miniatyury { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.miniatyury img { width: 72px; height: 72px; object-fit: cover; border-radius: 8px; }
.otvet { align-self: flex-start; max-width: 100%; }
.otvet img.risunok { display: block; max-width: 100%; max-height: 60vh; border-radius: 12px; cursor: zoom-in; }
.podpis { font-size: 12px; color: var(--tihiy); margin-top: 4px; }
.risuyu { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 12px;
  border-radius: 14px; background: var(--panel); }
.vrashchenie { width: 18px; height: 18px; border: 3px solid var(--ramka); border-top-color: var(--akcent);
  border-radius: 50%; animation: kruzhim 1s linear infinite; }
@keyframes kruzhim { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .vrashchenie { animation: none; } }
.dejstviya { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }

/* поле ввода */
.vvod { border-top: 1px solid var(--ramka); padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: var(--fon); }
.vlozheniya { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; }
.vlozhenie { position: relative; flex: 0 0 auto; width: 76px; }
.vlozhenie img { width: 76px; height: 76px; object-fit: cover; border-radius: 10px; display: block; }
.vlozhenie .metka { display: block; width: 100%; min-height: 44px; font-size: 12px; border-radius: 0 0 10px 10px;
  border: 1px solid var(--ramka); background: var(--panel); padding: 0 2px; }
.vlozhenie .metka.zal { background: var(--akcent); color: var(--akcent-tekst); border-color: var(--akcent); }
.vlozhenie .ubrat { position: absolute; top: -6px; right: -6px; width: 44px; height: 44px; background: none;
  border: 0; display: flex; align-items: flex-start; justify-content: flex-end; padding: 0; }
.vlozhenie .ubrat span { width: 24px; height: 24px; border-radius: 50%; background: #000a; color: #fff;
  line-height: 24px; text-align: center; font-size: 16px; }
.stroka-vvoda { display: flex; align-items: flex-end; gap: 6px; }
.stroka-vvoda textarea { flex: 1; min-width: 0; min-height: 44px; max-height: 140px; resize: none; padding: 10px 12px;
  border: 1px solid var(--ramka); border-radius: 14px; background: var(--fon); }
.nizhnyaya { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.nizhnyaya select { flex: 1; min-width: 0; min-height: 44px; border: 1px solid var(--ramka);
  border-radius: 12px; background: var(--panel); padding: 0 8px; }
.zapis { background: var(--oshibka) !important; color: #fff !important; }

/* полноэкранный просмотр */
.prosmotr { position: fixed; inset: 0; z-index: 30; background: #000; display: flex; flex-direction: column; }
.prosmotr .kartinka { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
.prosmotr img { max-width: 100%; max-height: 100%; object-fit: contain; }
.prosmotr .dejstviya { padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); justify-content: center; margin: 0; }
.prosmotr .knopka { background: #fff2; color: #fff; border-color: #fff3; }

@media (min-width: 768px) {
  .koren { max-width: 920px; margin: 0 auto; border-left: 1px solid var(--ramka); border-right: 1px solid var(--ramka); }
}

/* страница «Расход» */
.rashod { position: fixed; inset: 0; z-index: 25; background: var(--fon); overflow-y: auto; overflow-x: hidden;
  padding: calc(8px + env(safe-area-inset-top)) 12px 24px; }
.rashod .verh { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.rashod h2 { font-size: 16px; margin: 16px 0 6px; }
.stroka-rashoda { display: flex; flex-wrap: wrap; gap: 4px 12px; padding: 6px 0; border-bottom: 1px solid var(--ramka);
  font-size: 14px; overflow-wrap: anywhere; }
.stroka-rashoda span:first-child { font-weight: 600; }
