:root {
  --bg: #f5f5f7;
  --bg-grad: radial-gradient(1200px 600px at 80% -10%, #eaf1ff 0%, transparent 60%), #f5f5f7;
  --surface: #ffffff;
  --surface-2: #f0f0f3;
  --surface-3: #e8e8ec;
  --border: rgba(0, 0, 0, .08);
  --border-strong: rgba(0, 0, 0, .14);
  --text: #1d1d1f;
  --muted: #6e6e73;
  --accent: #007aff;
  --accent-hover: #0066d6;
  --success: #34c759;
  --danger: #ff3b30;
  --warning: #ff9500;
  --radius-lg: 26px;
  --radius: 18px;
  --radius-sm: 13px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 6px 20px rgba(0,0,0,.06);
  --shadow-lg: 0 12px 48px rgba(0,0,0,.18), 0 2px 8px rgba(0,0,0,.08);
  --topbar-bg: rgba(255, 255, 255, .72);
  --cell-stroke: rgba(0, 0, 0, .06);
  --hm-0: #ebedf0;
  --hm-alt: #dadde2;
  --hm-1: #b6e3c4;
  --hm-2: #74cd8c;
  --hm-3: #41b35e;
  --hm-4: #2a9047;
}
[data-theme="dark"] {
  --bg: #1c1c1e;
  --bg-grad: radial-gradient(1200px 600px at 80% -10%, #15233f 0%, transparent 55%), #1c1c1e;
  --surface: #2c2c2e;
  --surface-2: #3a3a3c;
  --surface-3: #48484a;
  --border: rgba(255, 255, 255, .1);
  --border-strong: rgba(255, 255, 255, .18);
  --text: #f5f5f7;
  --muted: #98989d;
  --accent: #0a84ff;
  --accent-hover: #409cff;
  --success: #30d158;
  --danger: #ff453a;
  --warning: #ff9f0a;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 28px rgba(0,0,0,.4);
  --shadow-lg: 0 16px 56px rgba(0,0,0,.6);
  --topbar-bg: rgba(28, 28, 30, .72);
  --cell-stroke: rgba(255, 255, 255, .08);
  --hm-0: #1b1b1d;
  --hm-alt: #38383b;
  --hm-1: #0e4429;
  --hm-2: #006d32;
  --hm-3: #26a641;
  --hm-4: #39d353;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "Inter", "Segoe UI", Roboto, sans-serif;
  background: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: none; opacity: .85; }
h1 { font-size: 26px; margin: 0; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 17px; margin: 0; font-weight: 600; letter-spacing: -0.01em; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-weight: 400; font-size: 12px; }
hr { border: none; border-top: 1px solid var(--border); margin: 18px 0; }

.icon { display: inline-block; vertical-align: -0.18em; flex-shrink: 0; }

/* ---------- Topbar ---------- */
.topbar {
  background: var(--topbar-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.topbar-inner {
  max-width: 1080px; margin: 0 auto; padding: 0 22px;
  height: 58px; display: flex; align-items: center; gap: 22px;
}
.brand { font-weight: 600; font-size: 16px; color: var(--text); display: inline-flex; align-items: center; gap: 9px; }
.brand .icon { color: var(--accent); }
.brand:hover { opacity: .7; }
.nav { display: flex; gap: 2px; flex: 1; }
.nav a {
  color: var(--muted); padding: 7px 14px; border-radius: 9px; font-weight: 500; font-size: 14px;
  transition: background .15s, color .15s;
}
.nav a:hover { background: var(--surface-2); color: var(--text); opacity: 1; }
.nav a.active { background: var(--surface-2); color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.theme-toggle {
  background: var(--surface-2); border: none; border-radius: 50%;
  width: 36px; height: 36px; cursor: pointer; color: var(--text);
  display: grid; place-items: center; transition: background .15s, transform .1s;
}
.theme-toggle:hover { background: var(--surface-3); }
.theme-toggle:active { transform: scale(.92); }
.icon-sun { display: none; }
[data-theme="dark"] .icon-sun { display: inline-block; }
[data-theme="dark"] .icon-moon { display: none; }

.usermenu { position: relative; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, #0a84ff, #5e5ce6);
  color: #fff; display: grid; place-items: center; font-weight: 600; cursor: pointer;
  border: none; font-size: 15px; font-family: inherit; transition: transform .1s;
}
.avatar:active { transform: scale(.92); }
.usermenu-dropdown {
  position: absolute; right: 0; top: 46px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); min-width: 230px; padding: 7px; display: none;
  transform-origin: top right; animation: pop .14s ease;
}
@keyframes pop { from { opacity: 0; transform: scale(.96) translateY(-4px); } to { opacity: 1; transform: none; } }
.usermenu.open .usermenu-dropdown { display: block; }
.usermenu-name { font-weight: 600; padding: 8px 12px 1px; }
.usermenu-email { color: var(--muted); font-size: 13px; padding: 0 12px 9px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.usermenu-dropdown a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 9px; color: var(--text); font-size: 14px; }
.usermenu-dropdown a .icon { color: var(--muted); }
.usermenu-dropdown a:hover { background: var(--surface-2); opacity: 1; }

/* ---------- Layout ---------- */
.container { max-width: 1080px; margin: 0 auto; padding: 34px 22px 70px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 26px; gap: 16px; }
.head-actions { display: flex; gap: 10px; flex-shrink: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
@media (max-width: 820px) { .grid-2 { grid-template-columns: 1fr; } }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 24px; box-shadow: var(--shadow); margin-bottom: 22px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.card-head h2 { display: inline-flex; align-items: center; gap: 9px; }
.card-head h2 .icon { color: var(--muted); }

/* ---------- Stats ---------- */
.stats-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin-bottom: 22px; }
@media (max-width: 640px) { .stats-row { grid-template-columns: 1fr; } }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow); }
.stat-label { color: var(--muted); font-size: 13px; font-weight: 500; }
.stat-value { font-size: 28px; font-weight: 700; margin-top: 7px; letter-spacing: -0.02em; }
.stat-paid .stat-value { color: var(--success); }
.stat-upcoming .stat-value { color: var(--warning); }

/* ---------- Heatmap ---------- */
.heatmap-wrap { overflow-x: auto; padding-bottom: 4px; }
.heatmap { min-width: 760px; }
.heatmap-months {
  display: grid; grid-template-columns: repeat(var(--cols), 15px); gap: 3px;
  margin-left: 32px; margin-bottom: 5px; height: 14px;
}
.month-label { font-size: 11px; color: var(--muted); white-space: nowrap; font-weight: 500; }
.heatmap-body { display: flex; gap: 6px; }
.weekday-labels { display: grid; grid-template-rows: repeat(7, 15px); gap: 3px; }
.weekday-labels span { font-size: 10px; color: var(--muted); height: 15px; line-height: 15px; }
.heatmap-grid { display: flex; gap: 3px; }
.week-col { display: grid; grid-template-rows: repeat(7, 15px); gap: 3px; }
.day-cell { width: 15px; height: 15px; border-radius: 5px; background: var(--hm-0); box-shadow: inset 0 0 0 1px var(--cell-stroke); transition: transform .1s; }
.day-cell.m-alt.level-0 { background: var(--hm-alt); }
.day-cell.level-1 { background: var(--hm-1); }
.day-cell.level-2 { background: var(--hm-2); }
.day-cell.level-3 { background: var(--hm-3); }
.day-cell.level-4 { background: var(--hm-4); }
.day-cell.out { opacity: 0; pointer-events: none; }
.day-cell.has-items { cursor: pointer; }
.day-cell.has-items:hover { outline: 2px solid var(--accent); outline-offset: 1px; transform: scale(1.15); }
.day-cell.today { box-shadow: 0 0 0 1.5px var(--accent); }
.heatmap-legend { display: flex; align-items: center; gap: 4px; margin-top: 14px; font-size: 12px; color: var(--muted); }

/* ---------- Months bars ---------- */
.months-bars { display: flex; align-items: flex-end; gap: 8px; }
.month-bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; }
.bar-amount { font-size: 10px; color: var(--muted); white-space: nowrap; height: 14px; line-height: 14px; font-weight: 500; }
.bar-col { height: 140px; display: flex; align-items: flex-end; width: 100%; justify-content: center; }
.bar { width: 68%; max-width: 26px; display: flex; flex-direction: column-reverse; border-radius: 7px 7px 3px 3px; overflow: hidden; transition: height .4s cubic-bezier(.2,.8,.2,1); }
.seg { width: 100%; }
.seg.paid { background: var(--success); }
.seg.upcoming { background: var(--warning); }
.bar-label { font-size: 11px; color: var(--muted); margin-top: 7px; }
.month-bar.current .bar-label { color: var(--accent); font-weight: 700; }
.month-bar.current .bar-amount { color: var(--accent); font-weight: 600; }
.legend-inline { display: flex; gap: 18px; margin-top: 16px; font-size: 13px; color: var(--muted); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 4px; margin-right: 5px; vertical-align: middle; }
.dot.paid { background: var(--success); } .dot.upcoming { background: var(--warning); }

/* ---------- Upcoming list ---------- */
.upcoming-list { list-style: none; margin: 0; padding: 0; }
.upcoming-list li { display: flex; align-items: center; gap: 14px; padding: 13px 0; border-bottom: 1px solid var(--border); }
.upcoming-list li:last-child { border-bottom: none; }
.up-date { min-width: 92px; }
.up-day { display: block; font-weight: 600; }
.up-badge { font-size: 11px; color: var(--muted); }
.up-badge.soon { color: var(--warning); }
.up-badge.urgent { color: var(--danger); font-weight: 600; }
.up-info { flex: 1; }
.up-service { font-weight: 600; }
.up-desc { font-size: 12px; color: var(--muted); }
.up-amount { font-weight: 700; white-space: nowrap; letter-spacing: -0.01em; }
.empty { text-align: center; color: var(--muted); padding: 38px 20px; }
.empty .icon { color: var(--surface-3); margin-bottom: 10px; }
[data-theme="dark"] .empty .icon { color: var(--surface-3); }

/* ---------- Tables ---------- */
.ptable { width: 100%; border-collapse: collapse; }
.ptable th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 6px 12px; border-bottom: 1px solid var(--border); font-weight: 600; }
.ptable td { padding: 14px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.ptable tr:last-child td { border-bottom: none; }
.ptable tbody tr { transition: background .12s; }
.ptable tbody tr:hover td { background: var(--surface-2); }
.row-paid { opacity: .55; }
.nowrap { white-space: nowrap; }
.desc-cell { color: var(--muted); font-size: 13px; max-width: 240px; }
.actions { white-space: nowrap; text-align: right; }
.actions .btn, .actions .inline { vertical-align: middle; }
.inline { display: inline; }

/* ---------- Tags ---------- */
.tag { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.tag-paid { background: rgba(52,199,89,.16); color: var(--success); }
.tag-soon { background: rgba(255,149,0,.16); color: var(--warning); }
.tag-urgent, .tag-overdue { background: rgba(255,59,48,.16); color: var(--danger); }
.badge { background: var(--accent); color: #fff; border-radius: 20px; padding: 2px 9px; font-size: 12px; font-weight: 600; margin-left: 8px; }

/* ---------- Segmented control (tabs) ---------- */
.tabs { display: inline-flex; gap: 2px; margin-bottom: 18px; background: var(--surface-2); padding: 4px; border-radius: 15px; }
.tabs a { padding: 7px 16px; border-radius: 11px; color: var(--muted); font-weight: 500; font-size: 14px; transition: all .15s; }
.tabs a:hover { color: var(--text); opacity: 1; }
.tabs a.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 40px; padding: 0 18px; border-radius: 13px; font-weight: 500; font-size: 14px; cursor: pointer;
  border: 1px solid transparent; background: var(--surface-2); color: var(--text);
  transition: transform .08s, background .15s, box-shadow .15s; font-family: inherit;
  letter-spacing: -0.01em; white-space: nowrap;
}
.btn:hover { opacity: 1; }
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.1); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface-2); }
.btn-secondary:hover { background: var(--surface-3); }
.btn-ghost { background: transparent; border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(1.05); }
.btn-danger { background: transparent; border-color: var(--border-strong); color: var(--danger); }
.btn-danger:hover { background: rgba(255,59,48,.1); }
.btn-sm { height: 34px; padding: 0 13px; font-size: 13px; border-radius: 11px; gap: 6px; }
.btn-icon { padding: 0; width: 34px; height: 34px; flex-shrink: 0; }
.btn-block { width: 100%; margin-top: 8px; }

/* ---------- Forms ---------- */
label { display: block; font-weight: 500; font-size: 14px; margin-bottom: 14px; }
input, textarea, select {
  display: block; width: 100%; margin-top: 6px; padding: 11px 14px; font-size: 14px;
  border: 1px solid var(--border-strong); border-radius: 14px; background: var(--surface);
  color: var(--text); font-family: inherit; transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px rgba(0,122,255,.15);
}
textarea { resize: vertical; }
select { -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236e6e73' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px;
}
.btn-row { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.email-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.email-row input { margin-top: 0; }
.email-row .btn { flex-shrink: 0; }

/* ---------- Auth ---------- */
.auth-page { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 24px; box-shadow: var(--shadow-lg); padding: 40px; width: 100%; max-width: 410px; text-align: center; }
.auth-logo { width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 18px; display: grid; place-items: center;
  background: linear-gradient(135deg, #0a84ff, #5e5ce6); color: #fff; box-shadow: 0 8px 24px rgba(10,132,255,.35); }
.auth-card h1 { margin: 6px 0 3px; }
.auth-sub { color: var(--muted); margin: 0 0 24px; }
.auth-card form { text-align: left; }
.auth-foot { margin-top: 20px; color: var(--muted); font-size: 14px; }

/* ---------- Alerts ---------- */
.alert { display: flex; align-items: center; gap: 10px; padding: 13px 16px; border-radius: 16px; margin-bottom: 18px; font-size: 14px; text-align: left; }
.alert .icon { flex-shrink: 0; }
.alert .btn { margin-left: auto; }
.alert-error { background: rgba(255,59,48,.12); color: var(--danger); }
.alert-info { background: rgba(52,199,89,.14); color: var(--success); }
.alert-accent { background: rgba(0,122,255,.12); color: var(--accent); }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.4); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); display: grid; place-items: center; z-index: 100; padding: 20px; animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal[hidden] { display: none; }
.modal-card { background: var(--surface); border-radius: 26px; padding: 26px; width: 100%; max-width: 440px; box-shadow: var(--shadow-lg); animation: rise .2s cubic-bezier(.2,.8,.2,1); }
@keyframes rise { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.modal-close { background: var(--surface-2); border: none; border-radius: 50%; width: 30px; height: 30px; cursor: pointer; color: var(--muted); display: grid; place-items: center; transition: background .15s; }
.modal-close:hover { background: var(--surface-3); color: var(--text); }

/* ---------- Year nav ---------- */
.year-nav { display: flex; align-items: center; gap: 6px; }
.year-label { font-weight: 600; min-width: 50px; text-align: center; }

/* ---------- Tooltip ---------- */
.tooltip {
  position: fixed; z-index: 200; background: rgba(40,40,42,.96); color: #fff;
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  padding: 11px 13px; border-radius: 12px; font-size: 13px; max-width: 280px;
  box-shadow: var(--shadow-lg); pointer-events: none; border: 1px solid rgba(255,255,255,.1);
}
.tooltip[hidden] { display: none; }
.tooltip .tt-date { font-weight: 700; margin-bottom: 7px; }
.tooltip .tt-item { display: flex; justify-content: space-between; gap: 14px; padding: 1px 0; }
.tooltip .tt-item.paid { opacity: .6; }
.tooltip .tt-total { margin-top: 7px; padding-top: 7px; border-top: 1px solid rgba(255,255,255,.2); font-weight: 700; display: flex; justify-content: space-between; }
