:root {
  --bg: #0e1116;
  --surface: #161b23;
  --surface-2: #1d242e;
  --border: #262e3a;
  --text: #e6eaf0;
  --muted: #8b95a5;
  --accent: #5eead4;
  --accent-dim: rgba(94, 234, 212, .12);
  --danger: #f87171;
  --warn: #fbbf24;
  --radius: 14px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

body { padding: 16px 16px 32px; max-width: 480px; margin: 0 auto; }

h1 { font-size: 20px; font-weight: 700; letter-spacing: -.02em; }

/* ---------- tabs ---------- */
.tabs {
  display: flex; gap: 4px; margin-top: 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 4px;
}
.tab {
  flex: 1; border: none; background: transparent; color: var(--muted);
  font-family: inherit; font-size: 13px; font-weight: 600;
  padding: 9px 0; border-radius: 10px; cursor: pointer; transition: all .15s;
}
.tab.active { background: var(--surface-2); color: var(--text); }

.page { display: none; }
.page.active { display: block; }

h2 {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .12em; color: var(--muted); margin: 24px 0 10px;
}

/* ---------- stats cards ---------- */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
}
.card.wide { grid-column: 1 / -1; }
.card .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; }
.card .value { font-size: 22px; font-weight: 700; margin-top: 4px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }

/* ---------- next payment ---------- */
.nextpay {
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius); padding: 14px 16px; margin-top: 10px;
}
.nextpay.urgent { border-left-color: var(--warn); }
.np-top { display: flex; align-items: baseline; justify-content: space-between; }
.np-price { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.np-name { font-size: 17px; font-weight: 600; margin-top: 6px; letter-spacing: -.01em; }
.np-date { font-size: 12px; color: var(--muted); margin-top: 3px; }

/* ---------- subscription rows ---------- */
#subs { display: flex; flex-direction: column; gap: 10px; padding-top: 12px; }
.sub {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px;
}
.sub .info { flex: 1; min-width: 0; }
.sub .name { font-weight: 600; }
.sub .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.badge {
  font-size: 11px; font-weight: 600; padding: 4px 9px;
  border-radius: 999px; white-space: nowrap;
}
.badge.ok { color: var(--accent); background: var(--accent-dim); }
.badge.soon { color: var(--warn); background: rgba(251, 191, 36, .12); }
.badge.today { color: var(--danger); background: rgba(248, 113, 113, .12); }
.price { font-weight: 600; font-variant-numeric: tabular-nums; }

.sub .actions { display: flex; gap: 6px; }
.iconbtn {
  width: 30px; height: 30px; border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface-2); color: var(--muted); font-size: 14px;
  cursor: pointer; display: grid; place-items: center; transition: all .15s;
}
.iconbtn:hover { color: var(--text); border-color: var(--muted); }
.iconbtn.del:hover { color: var(--danger); border-color: var(--danger); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; border-radius: var(--radius); padding: 12px 18px;
  font-size: 14px; font-weight: 600; cursor: pointer; transition: filter .15s;
  font-family: inherit;
}
.btn:active { filter: brightness(.85); }
.btn.primary { background: var(--accent); color: #06281f; width: 100%; margin-top: 16px; }
.btn.ghost {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  padding: 8px 14px; font-size: 13px;
}
.btn.danger { background: transparent; color: var(--danger); border: 1px solid rgba(248,113,113,.4); padding: 8px 14px; font-size: 13px; }
.btn.danger:hover { background: rgba(248,113,113,.08); }

/* ---------- confirm modal ---------- */
.confirm-text { color: var(--muted); font-size: 14px; line-height: 1.5; margin-bottom: 18px; }

/* ---------- manage modal ---------- */
.m-current {
  font-size: 12px; color: var(--muted); text-align: center;
  padding: 8px 0 14px; border-bottom: 1px solid var(--border); margin-bottom: 16px;
}
.m-stepper {
  display: flex; align-items: center; gap: 14px; margin-bottom: 14px;
}
.step-btn {
  width: 52px; height: 52px; border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface-2); color: var(--text); font-size: 24px; font-weight: 500;
  cursor: pointer; font-family: inherit; transition: all .12s; flex-shrink: 0;
}
.step-btn:hover { border-color: var(--accent); color: var(--accent); }
.step-btn:active { transform: scale(.92); }
.m-center { flex: 1; text-align: center; }
.m-amount {
  font-size: 34px; font-weight: 700; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums; line-height: 1.1;
}
.m-unit-toggle {
  display: inline-flex; gap: 2px; margin-top: 6px;
  background: var(--bg); border-radius: 9px; padding: 2px;
}
.unit {
  border: none; background: transparent; color: var(--muted);
  font-family: inherit; font-size: 11px; font-weight: 600;
  padding: 5px 12px; border-radius: 7px; cursor: pointer; transition: all .12s;
}
.unit.active { background: var(--surface-2); color: var(--text); }
.m-presets { display: flex; gap: 6px; justify-content: center; margin-bottom: 8px; }
.m-presets:last-of-type { margin-bottom: 14px; }
.chip {
  border: 1px solid var(--border); background: transparent; color: var(--muted);
  font-family: inherit; font-size: 12px; font-weight: 600;
  padding: 6px 12px; border-radius: 999px; cursor: pointer; transition: all .12s;
}
.chip:hover { color: var(--accent); border-color: var(--accent); }
.chip.neg:hover { color: var(--danger); border-color: var(--danger); }
.m-preview {
  text-align: center; font-size: 13px; color: var(--muted);
  background: var(--surface-2); border-radius: 10px; padding: 10px; margin-bottom: 16px;
  font-variant-numeric: tabular-nums;
}
.m-apply { width: auto; flex: 1; margin-top: 0; }
.row2 .m-apply { width: 100%; }

/* ---------- calendar ---------- */
#tab-calendar .cal { margin-top: 16px; }
.cal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-bottom: 10px; }
.cal-title { font-weight: 600; font-size: 14px; flex: 1; text-align: center; }
.cal-nav {
  width: 28px; height: 28px; border: none; border-radius: 8px;
  background: var(--surface-2); color: var(--muted); cursor: pointer;
  font-size: 14px; line-height: 1; display: grid; place-items: center; padding: 0;
}
.cal-nav:hover { color: var(--text); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-grid .dow { font-size: 10px; color: var(--muted); text-align: center; padding: 4px 0; text-transform: uppercase; }
.cal-grid .day {
  aspect-ratio: 1; display: grid; place-items: center;
  font-size: 12px; border-radius: 8px; color: var(--muted); position: relative;
}
.cal-grid .day.dim { opacity: .3; }
.cal-grid .day.today { color: var(--text); font-weight: 700; box-shadow: inset 0 0 0 1px var(--border); }
.cal-grid .day.due { color: #06281f; font-weight: 700; background: var(--accent); }
.cal-grid .day.due.soon { background: var(--warn); color: #2d2000; }
.cal-grid .day.due.over { background: var(--danger); color: #3d0a0a; }
.cal-legend { display: flex; gap: 14px; margin-top: 10px; font-size: 11px; color: var(--muted); }
.cal-legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* ---------- modal ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); backdrop-filter: blur(4px);
  display: none; align-items: flex-end; justify-content: center; z-index: 10;
}
.overlay.open { display: flex; }
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px 20px 0 0; padding: 20px; width: 100%; max-width: 480px;
}
.modal h3 { font-size: 16px; margin-bottom: 16px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; margin-bottom: 6px; }
.field input {
  width: 100%; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 11px 12px; color: var(--text);
  font-size: 15px; font-family: inherit; outline: none; transition: border-color .15s;
}
.field input:focus { border-color: var(--accent); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modal .btn.primary { margin-top: 8px; }

.empty {
  text-align: center; color: var(--muted); padding: 36px 0;
  font-size: 13px; line-height: 1.7;
}
.empty::before {
  content: ""; display: block; width: 34px; height: 2px;
  background: var(--border); margin: 0 auto 16px; border-radius: 1px;
}

/* Telegram viewport padding */
body { padding-top: max(16px, env(safe-area-inset-top)); }
