/* Планфакт — веб-приложение на экран «Домой». Вид — как у системных приложений iOS. */
:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --ink: #111114;
  --ink2: #6c6c72;
  --ink3: #a3a3ab;
  --line: rgba(60, 60, 67, .14);
  --fill: rgba(118, 118, 128, .12);
  --accent: #0071e3;
  --green: #1c9a4a;
  --red: #e0352b;
  --orange: #c97400;
  --bar: rgba(242, 242, 247, .82);
  --tabbar: rgba(250, 250, 252, .9);
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --tabs-h: 54px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --ink: #f5f5f7;
    --ink2: #98989f;
    --ink3: #5e5e64;
    --line: rgba(84, 84, 88, .55);
    --fill: rgba(118, 118, 128, .26);
    --accent: #0a84ff;
    --green: #30d158;
    --red: #ff453a;
    --orange: #ff9f0a;
    --bar: rgba(0, 0, 0, .78);
    --tabbar: rgba(22, 22, 24, .9);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.3 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { border: 0; background: none; padding: 0; cursor: pointer; }
[hidden] { display: none !important; }

.num {
  font-family: ui-rounded, "SF Pro Rounded", -apple-system, system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.pos { color: var(--green); }
.neg { color: var(--red); }
.mut { color: var(--ink2); }
.warn { color: var(--orange); }

/* ── верхняя полоса ── */
#bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  height: calc(44px + var(--sat)); padding: var(--sat) 8px 0;
  display: flex; align-items: center; justify-content: space-between;
  pointer-events: none;
}
#bar.solid {
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-bottom: .5px solid var(--line);
}
#bar > * { pointer-events: auto; }
#bartitle {
  position: absolute; left: 96px; right: 96px; text-align: center;
  font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  opacity: 0; transition: opacity .15s;
}
#bar.solid #bartitle { opacity: 1; }
#back, #baract { color: var(--accent); min-height: 44px; min-width: 44px; display: flex; align-items: center; gap: 5px; padding: 0 8px; }
#baract { margin-left: auto; justify-content: flex-end; font-size: 22px; }
#baract svg { width: 24px; height: 24px; }

/* ── содержимое ── */
#view {
  max-width: 620px; margin: 0 auto;
  padding: calc(44px + var(--sat)) 0 calc(var(--tabs-h) + var(--sab) + 28px);
  min-height: 100vh;
}
h1.title { font-size: 34px; line-height: 1.12; font-weight: 700; letter-spacing: -.02em; margin: 2px 20px 2px; }
.subtitle { margin: 2px 20px 10px; color: var(--ink2); font-size: 15px; }
.sect-h {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  padding: 22px 32px 7px; color: var(--ink2); font-size: 13px; text-transform: uppercase; letter-spacing: .02em;
}
.sect-h .num { font-size: 13px; }
.sect-f { padding: 7px 32px 0; color: var(--ink2); font-size: 13px; line-height: 1.35; }
button.sect-h { width: 100%; text-align: left; }
.sect-h .chev { display: inline-block; margin-left: 6px; transition: transform .18s; color: var(--ink3); }
.sect-h.open .chev { transform: rotate(90deg); }
.sect-h .sum { margin-left: auto; }

.card { margin: 0 16px; background: var(--card); border-radius: 14px; overflow: hidden; }
.card + .card { margin-top: 12px; }
.row {
  display: flex; align-items: center; gap: 12px;
  min-height: 46px; padding: 10px 16px; position: relative;
}
.row + .row::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: .5px solid var(--line); }
.row .grow { flex: 1; min-width: 0; }
.row .amt { font-weight: 500; text-align: right; }
.row .chevr { color: var(--ink3); font-weight: 600; }
.row .sub { font-size: 13px; color: var(--ink2); margin-top: 1px; }
.balance + .row::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: .5px solid var(--line); }
a.row { color: inherit; text-decoration: none; }
a.row:active, button.row:active, .item .main:active { background: var(--fill); }
button.row { width: 100%; text-align: left; }
.empty { padding: 18px 16px; color: var(--ink2); text-align: center; }

/* ── остатки ── */
.balance { padding: 16px 16px 8px; }
.balance .lbl { color: var(--ink2); font-size: 15px; }
.balance .big { font-size: 36px; font-weight: 700; letter-spacing: -.02em; line-height: 1.15; }
.balance .big small { font-size: 22px; font-weight: 600; color: var(--ink2); }

/* ── строка плана ── */
.item { align-items: flex-start; padding: 0 16px 0 6px; gap: 2px; }
.item .chk { flex: none; width: 44px; height: 46px; display: grid; place-items: center; }
.item .chk i {
  width: 23px; height: 23px; border-radius: 50%; border: 1.6px solid var(--ink3); display: grid; place-items: center;
  font-style: normal; font-size: 14px; font-weight: 700; color: transparent;
}
.item.done .chk i { background: var(--green); border-color: var(--green); color: #fff; }
.item.excl .chk i { border-style: dashed; color: var(--ink3); }
.item .main { flex: 1; min-width: 0; padding: 10px 8px 10px 0; border-radius: 8px; }
.item .name { overflow-wrap: anywhere; }
.item .sub { font-size: 13px; color: var(--ink2); margin-top: 2px; }
.item .sub.bad { color: var(--red); }
.item .amt { padding: 10px 0; }
.item.done .name, .item.excl .name { text-decoration: line-through; color: var(--ink2); }
.item.done .amt, .item.excl .amt { color: var(--ink2); }
.item.busy { opacity: .45; pointer-events: none; }
.item + .item::before { left: 50px; }

/* ── сводная сетка план/учёт/банк ── */
.grid { display: grid; grid-template-columns: auto repeat(3, minmax(0, 1fr)); gap: 9px 6px; padding: 14px 14px; align-items: baseline; }
.grid .h { font-size: 12px; color: var(--ink2); text-align: right; }
.grid .l { font-size: 15px; font-weight: 500; }
.grid .v { text-align: right; font-size: min(14px, 3.45vw); font-weight: 600; letter-spacing: -.02em; }
.grid .v small { display: block; font-size: 11px; font-weight: 400; color: var(--ink2); }

/* ── проекты ── */
.proj { display: block; padding: 12px 16px; }
.proj .top { display: flex; align-items: baseline; gap: 10px; }
.proj .pname { flex: 1; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.proj .meta { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--ink2); margin-top: 2px; }
.proj .progress { height: 4px; border-radius: 2px; background: var(--fill); margin: 9px 0 5px; overflow: hidden; }
.proj .progress i { display: block; height: 100%; width: 0; border-radius: 2px; background: var(--accent); }
.proj.k-plan .progress i { background: var(--green); }
.proj .foot { font-size: 12px; color: var(--ink2); }

/* ── переключатель, фильтры, поиск ── */
.seg { display: flex; margin: 14px 16px 0; padding: 2px; border-radius: 9px; background: var(--fill); }
.seg button { flex: 1; padding: 6px 4px; border-radius: 7px; font-size: 14px; font-weight: 500; }
.seg button.on { background: var(--card); box-shadow: 0 1px 3px rgba(0, 0, 0, .14); font-weight: 600; }
@media (prefers-color-scheme: dark) { .seg button.on { background: #636366; } }
.search { margin: 12px 16px 0; position: relative; }
.search input {
  width: 100%; height: 38px; border: 0; border-radius: 10px; background: var(--fill); padding: 0 12px 0 34px; outline: none;
  -webkit-appearance: none; appearance: none;
}
.search::before {
  content: ""; position: absolute; left: 11px; top: 11px; width: 11px; height: 11px;
  border: 2px solid var(--ink2); border-radius: 50%;
}
.search::after { content: ""; position: absolute; left: 23px; top: 23px; width: 6px; border-top: 2px solid var(--ink2); transform: rotate(45deg); transform-origin: left; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 12px 16px 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button { flex: none; padding: 6px 13px; border-radius: 16px; background: var(--fill); font-size: 14px; }
.chips button.on { background: var(--accent); color: #fff; }

/* ── операции банка ── */
.tx { align-items: flex-start; }
.tx .cp { overflow-wrap: anywhere; }
.tx .purpose { font-size: 13px; color: var(--ink2); margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tx .when { font-size: 12px; color: var(--ink2); margin-top: 3px; }
.more { display: grid; place-items: center; padding: 18px; }

/* ── подсказка про экран «Домой» ── */
.hint { margin: 10px 16px 12px; padding: 13px 16px; border-radius: 14px; background: var(--card); font-size: 14px; line-height: 1.4; display: flex; gap: 10px; }
.hint b { font-weight: 600; }
.hint button { color: var(--ink3); font-size: 20px; align-self: flex-start; padding: 0 4px; }

/* ── нижние вкладки ── */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  height: calc(var(--tabs-h) + var(--sab)); padding-bottom: var(--sab);
  display: flex; background: var(--tabbar);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-top: .5px solid var(--line);
}
#tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--ink3); text-decoration: none; font-size: 10.5px; font-weight: 500; }
#tabs a svg { width: 26px; height: 26px; }
#tabs a.on { color: var(--accent); }

.fab {
  position: fixed; right: 18px; bottom: calc(var(--tabs-h) + var(--sab) + 16px); z-index: 15;
  width: 54px; height: 54px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 30px; line-height: 1;
  box-shadow: 0 6px 18px rgba(0, 113, 227, .35); display: grid; place-items: center; padding-bottom: 3px;
}
.fab:active { transform: scale(.94); }

/* ── плашки ── */
#notice, #toast {
  position: fixed; left: 12px; right: 12px; z-index: 40; max-width: 596px; margin: 0 auto;
  padding: 11px 14px; border-radius: 13px; font-size: 14px; font-weight: 500; color: #fff;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .22); display: flex; align-items: center; gap: 12px;
}
#notice { bottom: calc(var(--tabs-h) + var(--sab) + 10px); background: #b86a00; }
#toast { bottom: calc(var(--tabs-h) + var(--sab) + 10px); background: #2c2c2e; }
#notice:not([hidden]) ~ #toast { bottom: calc(var(--tabs-h) + var(--sab) + 62px); }
#toast.bad { background: var(--red); }
#toast span { flex: 1; }
#toast button { color: #6cb6ff; font-weight: 600; }

/* ── лист снизу ── */
#sheet { position: fixed; inset: 0; z-index: 50; }
#sheet .backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .38); animation: fade .18s ease-out; }
#sheet .panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-width: 620px; margin: 0 auto; max-height: 88vh; overflow-y: auto;
  background: var(--bg); border-radius: 16px 16px 0 0; padding: 8px 0 calc(var(--sab) + 14px);
  animation: rise .22s cubic-bezier(.2, .8, .2, 1);
}
#sheet .grab { width: 36px; height: 5px; border-radius: 3px; background: var(--ink3); margin: 0 auto 10px; opacity: .6; }
#sheet h3 { margin: 4px 20px 2px; font-size: 17px; font-weight: 600; overflow-wrap: anywhere; }
#sheet .sub { margin: 0 20px 12px; color: var(--ink2); font-size: 14px; }
#sheet .card { margin-top: 10px; }
#sheet .act { justify-content: center; color: var(--accent); font-size: 18px; }
#sheet .act.danger { color: var(--red); }
#sheet .act.strong { font-weight: 600; }
#sheet label { display: block; padding: 9px 16px; position: relative; }
#sheet label + label::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: .5px solid var(--line); }
#sheet label span { display: block; font-size: 13px; color: var(--ink2); margin-bottom: 2px; }
#sheet input, #sheet textarea {
  width: 100%; border: 0; background: none; outline: none; padding: 2px 0; resize: none; min-height: 28px;
  -webkit-appearance: none; appearance: none; border-radius: 0;
}
#sheet input[type=date] { text-align: left; min-height: 30px; }
#sheet .nodate { color: var(--accent); font-size: 14px; margin-top: 4px; }
#sheet .err { margin: 10px 20px 0; color: var(--red); font-size: 14px; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(100%); } }

/* ── вход ── */
#login {
  position: fixed; inset: 0; z-index: 60; background: var(--bg); padding: calc(var(--sat) + 9vh) 32px 0;
  display: flex; flex-direction: column; align-items: center; gap: 12px; overflow-y: auto;
}
#login img { border-radius: 19px; }
#login h1 { margin: 6px 0 0; font-size: 32px; letter-spacing: -.02em; }
#login .brand { margin: 0 0 14px; font-size: 12px; font-weight: 600; letter-spacing: .18em; color: var(--ink2); }
#login input {
  width: 100%; max-width: 360px; height: 50px; border: 0; border-radius: 12px; background: var(--card); padding: 0 16px; outline: none;
  -webkit-appearance: none; appearance: none;
}
#login .err { margin: 0; color: var(--red); font-size: 14px; text-align: center; }
.primary { width: 100%; max-width: 360px; height: 50px; border-radius: 12px; background: var(--accent); color: #fff; font-weight: 600; }
.primary:disabled { opacity: .5; }

#fatal { position: fixed; top: calc(var(--sat) + 8px); left: 12px; right: 12px; z-index: 99; padding: 12px 14px; border-radius: 12px; background: var(--red); color: #fff; font-size: 14px; }

/* ── загрузка ── */
.spin { display: inline-block; width: 24px; height: 24px; border-radius: 50%; border: 2.5px solid var(--ink3); border-top-color: transparent; animation: turn .7s linear infinite; }
.loading { display: grid; place-items: center; padding: 30vh 0 0; }
.failed { padding: 22vh 32px 0; text-align: center; color: var(--ink2); }
.failed button { margin-top: 16px; }
#pull { position: fixed; top: calc(var(--sat) + 10px); left: 0; right: 0; z-index: 10; display: grid; place-items: center; opacity: 0; pointer-events: none; }
#pull.go .spin { animation-duration: .5s; }
@keyframes turn { to { transform: rotate(360deg); } }
