:root {
  --bg: #f5f6f8;
  --bg-elev: #ffffff;
  --bg-card: #ffffff;
  --border: #e6e8ee;
  --border-strong: #d4d8e1;
  --text: #0f172a;
  --text-dim: #64748b;
  --accent: #2563eb;
  --accent-soft: #eff4ff;
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --radius: 14px;
  --nav-h: 64px;
  --pad: 16px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); min-height: 100vh; }
body {
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* Desktop readability: центр страницы на широком экране */
#app { max-width: 520px; margin: 0 auto; }
@media (min-width: 900px) {
  #app { max-width: 720px; }
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
}

/* Header */
header.screen-header {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 14px) var(--pad) 14px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.screen-header h1 { margin: 0; font-size: 22px; font-weight: 600; letter-spacing: -0.01em; }
.screen-header .user-chip { font-size: 12px; color: var(--text-dim); }
main.screen { padding: var(--pad); display: flex; flex-direction: column; gap: 14px; }

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.card-title {
  font-size: 11px; color: var(--text-dim); text-transform: uppercase;
  letter-spacing: 0.06em; margin: 0 0 6px; font-weight: 500;
}
.card-value {
  font-size: 30px; font-weight: 700; margin: 0; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.card-value.muted { color: var(--text-dim); }
.card-value.pos { color: var(--ok); }
.card-value.neg { color: var(--bad); }
.card-sub { font-size: 13px; color: var(--text-dim); margin: 6px 0 0; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.grid-3 .card { padding: 14px; }
.grid-3 .card-value { font-size: 22px; }

/* Bottom nav */
#bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  display: flex; justify-content: space-around; align-items: center;
  z-index: 20;
  box-shadow: 0 -2px 10px rgba(15, 23, 42, 0.04);
}
@media (min-width: 900px) {
  #bottom-nav { max-width: 720px; left: 50%; transform: translateX(-50%); border-radius: 14px 14px 0 0; }
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: var(--nav-h); color: var(--text-dim); font-size: 11px; font-weight: 500;
}
.nav-item.active { color: var(--accent); }
.nav-item.nav-fab span {
  display: flex; align-items: center; justify-content: center;
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--accent); color: white; font-size: 26px; font-weight: 600;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}

/* Login */
.login-wrap {
  min-height: 100vh; display: flex; flex-direction: column; justify-content: center;
  padding: 28px var(--pad); gap: 18px;
}
.login-wrap h1 { font-size: 40px; margin: 0; font-weight: 700; letter-spacing: -0.025em; }
.login-wrap p { color: var(--text-dim); margin: 0; }
.login-form { display: flex; flex-direction: column; gap: 12px; margin-top: 24px; }
.login-form input {
  padding: 14px 16px; background: var(--bg-elev); border: 1px solid var(--border-strong);
  border-radius: 12px; font-size: 16px; color: var(--text);
}
.login-form input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-form button {
  padding: 14px; background: var(--accent); color: white; border: none;
  border-radius: 12px; font-size: 16px; font-weight: 600; cursor: pointer;
}
.login-form button:hover { filter: brightness(1.05); }
.login-form .err { color: var(--bad); font-size: 14px; min-height: 18px; }

/* Lists */
.list { display: flex; flex-direction: column; gap: 8px; }
.list-item {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; display: flex; justify-content: space-between; align-items: center;
}
.list-item .title { font-weight: 500; color: var(--text); }
.list-item .sub { font-size: 12px; color: var(--text-dim); margin-top: 3px; }
.list-item .right { text-align: right; font-size: 14px; color: var(--text-dim); font-variant-numeric: tabular-nums; }

/* Utils */
.section-title {
  font-size: 12px; color: var(--text-dim); text-transform: uppercase;
  letter-spacing: 0.06em; margin: 14px 0 4px; font-weight: 500;
}
.money { font-variant-numeric: tabular-nums; }
.spinner { padding: 40px; text-align: center; color: var(--text-dim); }

/* Pipeline stage tabs */
.stage-tabs {
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
  padding: 10px var(--pad); background: var(--bg);
  border-bottom: 1px solid var(--border); position: sticky; top: 55px; z-index: 9;
}
.stage-tabs::-webkit-scrollbar { display: none; }
.stage-tab {
  flex-shrink: 0; padding: 8px 14px; background: transparent;
  border: 1px solid var(--border-strong); border-radius: 999px;
  font-size: 13px; font-weight: 500; color: var(--text-dim); cursor: pointer;
  transition: all 0.15s;
}
.stage-tab.active { background: var(--accent); color: white; border-color: var(--accent); }

/* Bottom sheet */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 100;
}
.sheet {
  background: var(--bg); width: 100%; max-width: 520px;
  border-radius: 20px 20px 0 0; padding: 12px 20px 28px;
  max-height: 85vh; overflow-y: auto;
  animation: slide-up 0.25s ease-out;
}
.sheet-handle {
  width: 40px; height: 4px; background: var(--border-strong);
  border-radius: 2px; margin: 0 auto 14px;
}
@keyframes slide-up {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.stage-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px;
}
.stage-btn {
  padding: 12px; background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 10px; font-size: 14px; font-weight: 500; color: var(--text); cursor: pointer;
}
.stage-btn:hover { border-color: var(--accent); }
.stage-btn.current { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.del-btn {
  width: 100%; padding: 12px; background: transparent; border: 1px solid var(--bad);
  border-radius: 10px; color: var(--bad); font-weight: 500; cursor: pointer;
}

/* Mini buttons (task quick actions) */
.mini-btn {
  display: inline-block; padding: 6px 10px; margin-left: 4px;
  background: var(--bg-elev); border: 1px solid var(--border-strong);
  border-radius: 8px; font-size: 12px; font-weight: 500; color: var(--text);
  cursor: pointer;
}
.mini-btn:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
