:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: rgba(255,255,255,.88);
  --surface-solid: #ffffff;
  --surface-2: #eceef2;
  --text: #101216;
  --muted: #70757f;
  --border: rgba(15,23,42,.08);
  --accent: #111827;
  --accent-contrast: #ffffff;
  --green: #169b62;
  --orange: #d97706;
  --red: #dc4c4c;
  --blue: #3b6fd8;
  --shadow: 0 14px 40px rgba(16,24,40,.08);
  --radius: 24px;
  --radius-sm: 16px;
  --nav-h: 78px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #090b0f;
    --surface: rgba(20,23,29,.88);
    --surface-solid: #14171d;
    --surface-2: #1c2028;
    --text: #f7f8fa;
    --muted: #9aa0aa;
    --border: rgba(255,255,255,.08);
    --accent: #f7f8fa;
    --accent-contrast: #111318;
    --shadow: 0 18px 50px rgba(0,0,0,.34);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #090b0f;
  --surface: rgba(20,23,29,.88);
  --surface-solid: #14171d;
  --surface-2: #1c2028;
  --text: #f7f8fa;
  --muted: #9aa0aa;
  --border: rgba(255,255,255,.08);
  --accent: #f7f8fa;
  --accent-contrast: #111318;
  --shadow: 0 18px 50px rgba(0,0,0,.34);
}

:root[data-theme="light"] {
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body {
  min-height: 100dvh;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button, input, select, textarea { font: inherit; }
button { color: inherit; }
a { color: inherit; }
button, .tap { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--blue) 35%, transparent);
  outline-offset: 2px;
}

.app-shell {
  min-height: 100dvh;
  padding: calc(18px + var(--safe-top)) 16px calc(var(--nav-h) + 34px + var(--safe-bottom));
}

.container {
  width: min(100%, 760px);
  margin: 0 auto;
}

.boot-screen, .login-screen {
  min-height: calc(100dvh - 40px - var(--safe-top));
  display: grid;
  place-content: center;
  gap: 22px;
  width: min(100%, 420px);
  margin: 0 auto;
}

.boot-screen { text-align: center; color: var(--muted); }
.boot-screen h1 { color: var(--text); margin: 14px 0 4px; font-size: 30px; }
.boot-screen p { margin: 0; }

.brand-mark {
  width: 44px; height: 44px; border-radius: 14px;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-contrast);
  font-weight: 850; letter-spacing: -.04em;
  box-shadow: var(--shadow);
}
.brand-mark.large { width: 66px; height: 66px; border-radius: 21px; margin: 0 auto; font-size: 28px; }

.login-card, .panel, .summary-card, .bill-card, .month-card, .settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.login-card {
  border-radius: 30px;
  padding: 28px;
}

.login-head { display: flex; align-items: center; gap: 14px; margin-bottom: 24px; }
.login-head h1 { margin: 0; font-size: 26px; letter-spacing: -.04em; }
.login-head p { margin: 3px 0 0; color: var(--muted); font-size: 14px; }

.field { display: grid; gap: 8px; margin: 14px 0; }
.field label { font-size: 13px; color: var(--muted); font-weight: 700; }
.input, .select, .textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 15px;
  min-height: 48px;
  padding: 12px 14px;
  outline: none;
}
.textarea { min-height: 92px; resize: vertical; }

.btn {
  min-height: 46px;
  border: 0;
  border-radius: 15px;
  padding: 0 16px;
  font-weight: 800;
  cursor: pointer;
  transition: transform .15s ease, opacity .15s ease, background .15s ease;
}
.btn:active { transform: scale(.985); }
.btn[disabled] { opacity: .55; cursor: wait; }
.btn-primary { background: var(--accent); color: var(--accent-contrast); }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: color-mix(in srgb, var(--red) 12%, var(--surface-solid)); color: var(--red); border: 1px solid color-mix(in srgb, var(--red) 18%, transparent); }
.btn-block { width: 100%; }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  margin: 2px 0 22px;
}
.topbar-title { display: flex; gap: 12px; align-items: center; }
.topbar h1 { margin: 0; font-size: 24px; letter-spacing: -.04em; }
.topbar p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.icon-btn {
  width: 46px; height: 46px; border-radius: 15px;
  border: 1px solid var(--border); background: var(--surface);
  display: grid; place-items: center; cursor: pointer;
  font-size: 24px; line-height: 1;
}

.month-nav {
  display: grid; grid-template-columns: 46px 1fr 46px; align-items: center;
  gap: 8px; margin-bottom: 14px;
}
.month-label { text-align: center; font-size: 17px; font-weight: 850; letter-spacing: -.02em; }
.chev {
  width: 44px; height: 44px; border: 0; border-radius: 14px;
  background: transparent; color: var(--muted); font-size: 25px; cursor: pointer;
}

.summary-card {
  border-radius: 30px;
  padding: 22px;
  margin-bottom: 24px;
}
.summary-main {
  display: flex; justify-content: space-between; gap: 20px; align-items: flex-end;
  margin-bottom: 18px;
}
.summary-main small { display: block; color: var(--muted); font-weight: 700; margin-bottom: 5px; }
.summary-main strong { display: block; font-size: clamp(30px, 9vw, 46px); letter-spacing: -.055em; line-height: 1; }
.progress-caption { text-align: right; color: var(--muted); font-size: 13px; font-weight: 750; }
.progress-caption b { display: block; color: var(--text); font-size: 18px; }

.progress {
  height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden;
}
.progress > span {
  display: block; height: 100%; width: 0%;
  border-radius: inherit; background: var(--accent);
  transition: width .35s ease;
}

.summary-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 10px; margin-top: 18px;
}
.stat {
  padding: 12px; border-radius: 16px; background: var(--surface-2);
  min-width: 0;
}
.stat span { display: block; color: var(--muted); font-size: 11px; font-weight: 750; text-transform: uppercase; letter-spacing: .04em; }
.stat strong { display: block; margin-top: 6px; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.section-head {
  display: flex; justify-content: space-between; align-items: center;
  margin: 0 2px 12px;
}
.section-head h2 { margin: 0; font-size: 17px; letter-spacing: -.025em; }
.section-head span { color: var(--muted); font-size: 13px; }

.bill-list { display: grid; gap: 10px; }
.bill-card {
  border-radius: 21px;
  padding: 15px;
  display: grid;
  grid-template-columns: minmax(0,1fr) auto auto;
  gap: 12px;
  align-items: center;
}
.bill-main { min-width: 0; }
.bill-name {
  font-weight: 850; letter-spacing: -.02em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bill-meta { display: flex; gap: 8px; align-items: center; margin-top: 5px; color: var(--muted); font-size: 12px; }
.amount-wrap { text-align: right; }
.amount-wrap strong { display: block; font-size: 17px; letter-spacing: -.03em; }
.amount-wrap small { color: var(--muted); font-size: 11px; }

.status-dot {
  width: 7px; height: 7px; border-radius: 999px; display: inline-block; background: var(--blue);
}
.status-dot.paid { background: var(--green); }
.status-dot.due-soon { background: var(--orange); }
.status-dot.overdue { background: var(--red); }
.status-text.paid { color: var(--green); }
.status-text.due-soon { color: var(--orange); }
.status-text.overdue { color: var(--red); }

.check-btn {
  width: 44px; height: 44px; border-radius: 15px;
  border: 1px solid var(--border); background: var(--surface-2);
  display: grid; place-items: center; cursor: pointer;
  font-size: 19px; font-weight: 900;
  transition: transform .15s ease, background .2s ease, color .2s ease;
}
.check-btn.paid { background: color-mix(in srgb, var(--green) 14%, var(--surface-solid)); color: var(--green); }
.check-btn:active { transform: scale(.92); }

.empty {
  text-align: center; padding: 38px 24px; border: 1px dashed var(--border);
  border-radius: 22px; color: var(--muted);
}
.empty strong { display: block; color: var(--text); margin-bottom: 6px; }

.bottom-nav {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(10px + var(--safe-bottom));
  z-index: 30;
  width: min(calc(100% - 24px), 720px);
  min-height: var(--nav-h);
  display: grid;
  grid-template-columns: repeat(4,1fr);
  gap: 4px;
  padding: 8px;
  background: color-mix(in srgb, var(--surface-solid) 92%, transparent);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: 0 20px 50px rgba(0,0,0,.18);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
}
.nav-btn {
  border: 0; background: transparent; border-radius: 17px;
  min-height: 58px; display: grid; place-content: center; gap: 4px;
  color: var(--muted); cursor: pointer; font-size: 11px; font-weight: 750;
}
.nav-btn .nav-icon { font-size: 20px; line-height: 1; }
.nav-btn.active { background: var(--surface-2); color: var(--text); }

.fab {
  position: fixed; right: max(18px, calc((100vw - 760px)/2 + 18px));
  bottom: calc(var(--nav-h) + 32px + var(--safe-bottom));
  width: 56px; height: 56px; border-radius: 18px; border: 0;
  background: var(--accent); color: var(--accent-contrast);
  box-shadow: var(--shadow); font-size: 30px; cursor: pointer; z-index: 20;
}

.page-title { margin: 6px 0 18px; }
.page-title h2 { margin: 0; font-size: 30px; letter-spacing: -.05em; }
.page-title p { color: var(--muted); margin: 6px 0 0; }

.template-list, .history-list { display: grid; gap: 10px; }
.template-card, .month-card, .settings-card {
  border-radius: 21px; padding: 16px;
}
.template-row, .month-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.template-card strong, .month-card strong { display: block; }
.template-card small, .month-card small { color: var(--muted); display: block; margin-top: 5px; }
.pill {
  display: inline-flex; align-items: center; min-height: 26px; padding: 0 9px;
  border-radius: 999px; background: var(--surface-2); color: var(--muted);
  font-size: 11px; font-weight: 800;
}

.year-stats {
  display: grid; grid-template-columns: repeat(2,1fr); gap: 10px; margin-bottom: 18px;
}
.year-stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 16px;
}
.year-stat span { color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.year-stat strong { display: block; margin-top: 7px; font-size: 20px; letter-spacing: -.035em; }

.settings-group { display: grid; gap: 10px; margin-bottom: 20px; }
.settings-label { margin: 0 3px 8px; color: var(--muted); font-size: 12px; font-weight: 850; text-transform: uppercase; letter-spacing: .06em; }
.setting-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.segmented { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 13px; }
.segmented button {
  min-height: 36px; border: 0; border-radius: 10px; padding: 0 11px; background: transparent; color: var(--muted); font-weight: 750; cursor: pointer;
}
.segmented button.active { background: var(--surface-solid); color: var(--text); box-shadow: 0 3px 12px rgba(0,0,0,.08); }

.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  display: grid; align-items: end;
  background: rgba(0,0,0,.42);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  padding: 10px;
}
.modal {
  width: min(100%, 620px);
  margin: 0 auto;
  max-height: calc(100dvh - 20px - var(--safe-top));
  overflow: auto;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: 28px;
  padding: 18px;
  padding-bottom: calc(18px + var(--safe-bottom));
  box-shadow: 0 24px 80px rgba(0,0,0,.28);
  animation: sheetIn .18s ease-out;
}
@keyframes sheetIn { from { transform: translateY(24px); opacity: .5; } to { transform: translateY(0); opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin-bottom: 10px; }
.modal-head h3 { margin: 0; font-size: 21px; letter-spacing: -.035em; }
.close-btn { width: 42px; height: 42px; border-radius: 14px; border: 0; background: var(--surface-2); font-size: 20px; cursor: pointer; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.form-grid .full { grid-column: 1 / -1; }
.modal-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; margin-top: 18px; }

.detail-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 16px 0; }
.detail-box { padding: 13px; border-radius: 16px; background: var(--surface-2); }
.detail-box span { color: var(--muted); font-size: 11px; font-weight: 800; }
.detail-box strong { display: block; margin-top: 5px; }

.tx-list { display: grid; gap: 8px; margin-top: 10px; }
.tx-row { display: flex; justify-content: space-between; gap: 12px; padding: 12px 2px; border-bottom: 1px solid var(--border); }

.toast-region {
  position: fixed; top: calc(12px + var(--safe-top)); left: 50%; transform: translateX(-50%);
  z-index: 200; width: min(calc(100% - 30px), 440px); pointer-events: none;
}
.toast {
  background: var(--text); color: var(--bg);
  border-radius: 15px; padding: 12px 15px; margin-bottom: 8px;
  font-size: 13px; font-weight: 750; box-shadow: var(--shadow);
  animation: toastIn .18s ease-out;
}
@keyframes toastIn { from { transform: translateY(-10px); opacity: 0; } }

.skeleton {
  position: relative; overflow: hidden; color: transparent !important;
  background: var(--surface-2) !important;
}
.skeleton::after {
  content: ""; position: absolute; inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.15), transparent);
  animation: shimmer 1.1s infinite;
}
@keyframes shimmer { to { transform: translateX(100%); } }

.local-note {
  margin-top: 14px; padding: 12px 14px; border-radius: 15px; font-size: 12px;
  background: color-mix(in srgb, var(--orange) 11%, var(--surface-solid)); color: var(--orange);
  border: 1px solid color-mix(in srgb, var(--orange) 20%, transparent);
}

@media (min-width: 760px) {
  .app-shell { padding-left: 24px; padding-right: 24px; }
  .summary-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .bottom-nav { width: 500px; }
  .modal-backdrop { align-items: center; }
  .fab { right: calc((100vw - 760px)/2 + 16px); }
}

@media (max-width: 480px) {
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
  .summary-grid { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .stat { padding: 10px; }
  .stat strong { font-size: 13px; }
  .year-stats { grid-template-columns: 1fr 1fr; }
  .bill-card { grid-template-columns: minmax(0,1fr) auto auto; padding: 14px; gap: 9px; }
}


.danger-zone {
  margin-top: 22px;
  padding: 16px;
  border-radius: 18px;
  border: 1px solid color-mix(in srgb, var(--red) 16%, var(--border));
  background: color-mix(in srgb, var(--red) 5%, var(--surface-solid));
}
.danger-zone > div:first-child strong { display: block; }
.danger-zone > div:first-child small {
  display: block;
  color: var(--muted);
  line-height: 1.45;
  margin-top: 5px;
}
.danger-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 14px;
}
.confirm-copy {
  color: var(--muted);
  line-height: 1.55;
  margin: 8px 2px 4px;
}


.hidden { display: none !important; }

.auth-card { width: 100%; }
.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  padding: 5px;
  margin: 0 0 18px;
  border-radius: 15px;
  background: var(--surface-2);
}
.auth-tabs button {
  min-height: 42px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
  cursor: pointer;
}
.auth-tabs button.active {
  background: var(--surface-solid);
  color: var(--text);
  box-shadow: 0 4px 14px rgba(0,0,0,.08);
}
.auth-foot {
  margin: 16px 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
.link-btn {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--text);
  font-weight: 850;
  cursor: pointer;
}

.check-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}
.check-option {
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 13px;
  border-radius: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  cursor: pointer;
  font-weight: 750;
}
.check-option input {
  width: 19px;
  height: 19px;
  accent-color: var(--accent);
}

.info-strip {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 13px 14px;
  margin: 0 0 14px;
  border-radius: 16px;
  background: var(--surface-2);
}
.info-strip span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.info-strip strong {
  text-align: right;
  font-size: 13px;
}

.edit-scope-note {
  margin: 18px 0 10px;
  padding: 14px;
  border-radius: 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.edit-scope-note strong { display: block; }
.edit-scope-note small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  line-height: 1.5;
}
.stack-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 10px;
}

.danger-card {
  border-color: color-mix(in srgb, var(--red) 18%, var(--border));
}
.danger-card > div > strong { display: block; }
.danger-card > div > small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  line-height: 1.45;
}
.warning-box {
  padding: 14px;
  margin: 4px 0 14px;
  border-radius: 16px;
  color: var(--red);
  background: color-mix(in srgb, var(--red) 8%, var(--surface-solid));
  border: 1px solid color-mix(in srgb, var(--red) 18%, transparent);
}
.warning-box strong { display: block; }
.warning-box p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.admin-user-list { display: grid; gap: 9px; margin-top: 14px; }
.admin-user-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border-radius: 17px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.admin-user-row strong { display: block; }
.admin-user-row small {
  display: block;
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.4;
}
.admin-user-actions {
  display: grid;
  justify-items: end;
  gap: 7px;
  flex: 0 0 auto;
}
.pill-inactive {
  color: var(--red);
  background: color-mix(in srgb, var(--red) 10%, var(--surface-solid));
}

.settings-card small {
  display: block;
  color: var(--muted);
  margin-top: 3px;
}

@media (min-width: 540px) {
  .check-grid { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .stack-actions { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 520px) {
  .admin-user-row { align-items: flex-start; flex-direction: column; }
  .admin-user-actions {
    width: 100%;
    grid-template-columns: auto 1fr;
    align-items: center;
  }
  .admin-user-actions .btn { width: 100%; }
}
