*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font: 400 15px/1.4 var(--font);
  overflow-x: hidden; overflow-x: clip; -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
.num, .tabular { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }

.app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; min-width: 0; }
.boot { padding: var(--sp-5); color: var(--hint); }

/* ---------- шапка и вкладки ---------- */
.topbar {
  display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4) 0;
}
.brand { white-space: nowrap; font: 600 var(--fs-label)/1 var(--mono); letter-spacing: 0.14em; text-transform: uppercase; color: var(--hint); }
.who { margin-left: auto; font-size: var(--fs-meta); color: var(--hint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tabs {
  display: flex; gap: var(--sp-1); padding: 0 var(--sp-3); margin-top: var(--sp-2);
  overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--line); flex: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; background: none; border: 0; padding: var(--sp-3) var(--sp-3); min-height: var(--touch);
  color: var(--hint); font-weight: 500; position: relative; white-space: nowrap;
  transition: color var(--dur) var(--ease);
}
.tab::after {
  content: ""; position: absolute; left: var(--sp-3); right: var(--sp-3); bottom: -1px; height: 2px;
  background: var(--accent, var(--link)); transform: scaleX(0); transition: transform var(--dur) var(--ease);
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); }
.tab[aria-selected="true"]::after { transform: scaleX(1); }
.main { flex: 1; min-height: 0; display: flex; flex-direction: column; min-width: 0; }
.scroll { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: var(--sp-4); padding-bottom: 96px; }

/* ---------- кнопки и поля ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: 36px; padding: 0 var(--sp-4); border-radius: var(--r-m); border: 1px solid var(--line);
  background: transparent; font-weight: 500; white-space: nowrap;
  transition: background var(--dur) var(--ease), transform var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.btn:hover { background: var(--hover); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: default; transform: none; }
.btn.primary { background: var(--btn); color: var(--btn-text); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); background: var(--btn); }
.btn.danger { color: var(--c-over); border-color: var(--c-over); }
.btn.danger:hover { background: var(--c-over-bg); }
.btn.ghost { border-color: transparent; color: var(--link); }
.btn.small { min-height: 28px; padding: 0 var(--sp-3); font-size: var(--fs-meta); }
.fab { margin-left: var(--sp-2); }

.field {
  width: 100%; min-height: 36px; padding: 6px var(--sp-3); border-radius: var(--r-m);
  border: 1px solid var(--line); background: var(--bg); transition: border-color var(--dur) var(--ease);
}
.field:hover { border-color: var(--hint); }
.field:focus-visible { outline: 2px solid var(--link); outline-offset: 0; border-color: transparent; }
textarea.field { resize: vertical; min-height: 72px; line-height: 1.4; }
select.field { appearance: auto; }
.lbl { display: block; font: 600 var(--fs-label)/1.2 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--hint); margin-bottom: 6px; }

.filters { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; padding: var(--sp-3) var(--sp-4) 0; }
.filters .search { flex: 1 1 200px; max-width: 360px; }
.toggle {
  display: inline-flex; align-items: center; min-height: 36px; padding: 0 var(--sp-3); border-radius: 999px;
  border: 1px solid var(--line); background: none; color: var(--hint);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.toggle:hover { background: var(--hover); }
.toggle[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }

/* ---------- карточки: ряд и плитка ---------- */
.card {
  position: relative; background: var(--surface); border-radius: var(--r-m); border-left: 3px solid var(--accent, var(--hint));
  transition: background var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.card.final { opacity: 0.7; }
.card:hover { background: var(--hover); }
.card-open {
  display: block; width: 100%; text-align: left; background: none; border: 0; padding: var(--sp-3) var(--sp-3) var(--sp-3) var(--sp-3);
  min-height: var(--touch); border-radius: var(--r-m);
}
.card-title { display: flex; gap: var(--sp-2); align-items: baseline; font-size: var(--fs-title); font-weight: 600; line-height: 1.3; }
.card-title span.t { overflow-wrap: anywhere; }
.ztag {
  flex: none; font: 600 11px/1 var(--mono); padding: 3px 5px; border-radius: var(--r-s);
  background: var(--hover); color: var(--hint); letter-spacing: 0.02em; align-self: center;
}
.card-meta { display: flex; flex-wrap: wrap; gap: 2px var(--sp-3); margin-top: 6px; font-size: var(--fs-meta); color: var(--hint); }
.card-state { margin-top: 4px; font-size: var(--fs-meta); color: var(--text); opacity: 0.8; overflow-wrap: anywhere; }
/* кнопка следующей стадии — под текстом карточки, справа: название стадии видно целиком */
.card.has-next .card-open { padding-bottom: 56px; }
.card-next {
  position: absolute; right: var(--sp-3); bottom: var(--sp-3); max-width: calc(100% - 2 * var(--sp-3));
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card-next:active { transform: scale(0.97); }
.due { font-variant-numeric: tabular-nums; padding: 0 5px; border-radius: var(--r-s); }
.due.over { color: var(--c-over); background: var(--c-over-bg); font-weight: 600; }
.due.today { color: var(--c-today); background: var(--c-today-bg); font-weight: 600; }
.amount { font-variant-numeric: tabular-nums; color: var(--text); }

/* ---------- группы (мои дела, этапы) ---------- */
.group { margin-bottom: var(--sp-5); max-width: 760px; }
.group-head {
  display: flex; align-items: baseline; gap: var(--sp-2); margin-bottom: var(--sp-2);
  font: 600 var(--fs-label)/1 var(--mono); letter-spacing: 0.1em; text-transform: uppercase; color: var(--hint);
}
.group-head .count { font-variant-numeric: tabular-nums; }
.group.over .group-head { color: var(--c-over); }
.group.today .group-head { color: var(--c-today); }
.stack { display: flex; flex-direction: column; gap: var(--sp-2); }

.empty { max-width: 420px; margin: var(--sp-6) auto; text-align: center; color: var(--hint); }
.empty .mark { font: 300 48px/1 var(--mono); color: var(--line); margin-bottom: var(--sp-3); }
.empty strong { display: block; color: var(--text); font-size: 1.0625rem; margin-bottom: 4px; }
.loading { padding: var(--sp-5); color: var(--hint); }
.loading::before { content: ""; display: inline-block; width: 14px; height: 14px; margin-right: 8px; vertical-align: -2px;
  border: 2px solid var(--line); border-top-color: var(--link); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- toast и модалка ---------- */
.toasts { position: fixed; left: 0; right: 0; bottom: calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; z-index: 100; padding: 0 var(--sp-4); }
.toast {
  max-width: 460px; padding: 10px 14px; border-radius: var(--r-m); background: var(--text); color: var(--bg);
  font-size: var(--fs-meta); box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25); animation: fade-up var(--dur) var(--ease);
}
.toast.err { background: var(--c-over); color: #fff; }
.toast.out { opacity: 0; transition: opacity var(--dur); }
@keyframes fade-up { from { opacity: 0; transform: translateY(8px); } }

.scrim { position: fixed; inset: 0; background: var(--scrim); z-index: 50; display: flex; align-items: center; justify-content: center; padding: var(--sp-4); animation: fade var(--dur) var(--ease); }
@keyframes fade { from { opacity: 0; } }
.modal { width: min(440px, 100%); max-height: 100%; overflow-y: auto; background: var(--bg); border-radius: var(--r-l); padding: var(--sp-5); border: 1px solid var(--line); animation: fade-up 220ms var(--ease); }
.modal h2 { font-size: 1.125rem; margin-bottom: var(--sp-3); }
.modal p { color: var(--hint); margin-bottom: var(--sp-3); }
.modal .row { margin-bottom: var(--sp-3); }
.modal .actions { display: flex; gap: var(--sp-2); justify-content: flex-end; margin-top: var(--sp-4); }

/* ---------- вход ---------- */
.login { margin: auto; text-align: center; padding: var(--sp-5); max-width: 380px; }
.login h1 { font-size: var(--fs-screen); margin-bottom: var(--sp-2); }
.login p { color: var(--hint); margin-bottom: var(--sp-4); }
.login .widget { display: flex; justify-content: center; min-height: 44px; }

@media (max-width: 420px) { .who { display: none; } .fab { margin-left: auto; } }
@media (max-width: 899px) {
  .btn, .field, .toggle { min-height: var(--touch); }
  .btn.small { min-height: 36px; }
  .card-next { min-height: 36px; }
  .filters .search { flex: 1 1 100%; max-width: none; }
  .field { font-size: 16px; } /* iOS не приближает поле при фокусе */
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
