:root {
  --bg: #0b1020;
  --bg-2: #0f1630;
  --card: #141b33;
  --card-2: #1a2240;
  --line: #243056;
  --text: #e8ecf8;
  --muted: #8d97b5;
  --accent: #7c9cff;
  --accent-2: #a78bfa;
  --pos: #34d399;
  --neg: #f87171;
  --warn: #fbbf24;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  --nav-h: 64px;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fb;
    --bg-2: #eef1f9;
    --card: #ffffff;
    --card-2: #f6f8fd;
    --line: #e2e7f3;
    --text: #141a2e;
    --muted: #6b7591;
    --accent: #4f6bff;
    --accent-2: #7c5cff;
    --pos: #059669;
    --neg: #dc2626;
    --warn: #d97706;
    --shadow: 0 8px 24px rgba(20, 26, 46, 0.08);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
a { color: var(--accent); text-decoration: none; }
code { background: var(--card-2); padding: 1px 6px; border-radius: 6px; font-size: 0.95em; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.warn { color: var(--warn); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.error-text { color: var(--neg); }

/* ── Login ── */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(1200px 600px at 20% -10%, rgba(124, 156, 255, 0.25), transparent),
              radial-gradient(800px 500px at 110% 110%, rgba(167, 139, 250, 0.2), transparent), var(--bg);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 32px 28px;
  text-align: center;
  box-shadow: var(--shadow);
}
.login-card h1 { margin-top: 12px; font-size: 26px; }
.login-steps { text-align: left; margin-top: 20px; padding: 16px; background: var(--card-2); border-radius: var(--radius-sm); }
.login-steps p { margin: 0 0 8px; }
.login-steps p:last-child { margin: 0; }

/* ── Layout ── */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 236px;
  flex-shrink: 0;
  padding: 24px 16px;
  border-right: 1px solid var(--line);
  background: var(--bg-2);
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 0 8px 24px; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-weight: 550;
}
.nav a:hover { background: var(--card); color: var(--text); }
.nav a.active { background: var(--card); color: var(--text); box-shadow: inset 3px 0 0 var(--accent); }
.nav-ico { width: 22px; text-align: center; font-size: 18px; }
.sidebar-foot { margin-top: auto; }

.main { flex: 1; min-width: 0; padding: 24px 32px 48px; max-width: 1180px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; min-height: 40px; }
.topbar h1 { font-size: 26px; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.grid { display: grid; gap: 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid > .span-2 { grid-column: span 2; }
.stack { display: flex; flex-direction: column; gap: 16px; }

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: auto;
    height: calc(var(--nav-h) + env(safe-area-inset-bottom));
    padding: 0 8px env(safe-area-inset-bottom);
    flex-direction: row;
    border-right: 0;
    border-top: 1px solid var(--line);
    z-index: 20;
    backdrop-filter: blur(16px);
    background: color-mix(in srgb, var(--bg-2) 88%, transparent);
  }
  .brand, .sidebar-foot { display: none; }
  .nav { flex-direction: row; width: 100%; justify-content: space-around; gap: 0; }
  .nav a { flex-direction: column; gap: 2px; padding: 8px 4px; font-size: 11px; flex: 1; text-align: center; }
  .nav a.active { background: none; box-shadow: none; color: var(--accent); }
  .nav a:hover { background: none; }
  .nav-ico { font-size: 20px; }
  .main {
    padding: calc(14px + env(safe-area-inset-top)) 14px calc(var(--nav-h) + 28px + env(safe-area-inset-bottom));
  }
  .topbar h1 { font-size: 24px; }
  .grid { grid-template-columns: minmax(0, 1fr); }
  .grid > .span-2 { grid-column: auto; }
}

/* ── Cards ── */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.card-head h2 { font-size: 16px; }
.card-head .muted { font-size: 13px; }
.card-foot { display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--line); margin-top: 12px; padding-top: 12px; }

.hero {
  background: linear-gradient(135deg, rgba(124, 156, 255, 0.22), rgba(167, 139, 250, 0.14) 60%, transparent), var(--card);
  position: relative;
  overflow: hidden;
}
.hero-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.hero-amount { font-size: 40px; font-weight: 750; letter-spacing: -0.02em; margin: 6px 0 2px; }
.hero-split { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 16px; }
.hero-split div { background: color-mix(in srgb, var(--card) 70%, transparent); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; }
.hero-split span { display: block; font-size: 12px; color: var(--muted); }
.hero-split b { font-size: 17px; }
.spark { margin-top: 14px; height: 70px; }
@media (max-width: 520px) {
  .hero-amount { font-size: 34px; }
  .hero-split { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero-split div:last-child { grid-column: span 2; }
}

.alert {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  border-radius: var(--radius);
  padding: 14px 16px;
  border: 1px solid;
}
.alert.danger { background: color-mix(in srgb, var(--neg) 12%, transparent); border-color: color-mix(in srgb, var(--neg) 40%, transparent); }
.alert.warning { background: color-mix(in srgb, var(--warn) 12%, transparent); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.alert.info { background: color-mix(in srgb, var(--accent) 12%, transparent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.alert b { display: block; }
.alert-ico { font-size: 20px; line-height: 1.2; }

/* ── Lists ── */
.list { display: flex; flex-direction: column; }
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  min-width: 0;
}
.row:last-child { border-bottom: 0; }
.row.clickable { cursor: pointer; margin: 0 -8px; padding-left: 8px; padding-right: 8px; border-radius: var(--radius-sm); }
.row.clickable:hover { background: var(--card-2); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-end { text-align: right; flex-shrink: 0; }
.row-end .row-sub { white-space: nowrap; }
.ico {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--card-2);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 18px;
  flex-shrink: 0;
}
.date-chip {
  width: 44px;
  flex-shrink: 0;
  text-align: center;
  border-radius: 12px;
  background: var(--card-2);
  border: 1px solid var(--line);
  padding: 4px 0;
  line-height: 1.1;
}
.date-chip b { display: block; font-size: 17px; }
.date-chip span { font-size: 11px; color: var(--muted); text-transform: uppercase; }
.day-head { font-size: 12px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; padding: 16px 0 4px; }
.day-head:first-child { padding-top: 0; }

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 650;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--muted);
  vertical-align: middle;
}
.badge.ok { color: var(--pos); border-color: color-mix(in srgb, var(--pos) 40%, transparent); }
.badge.err { color: var(--neg); border-color: color-mix(in srgb, var(--neg) 40%, transparent); }
.badge.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }

.empty { text-align: center; color: var(--muted); padding: 24px 8px; }
.empty .btn { margin-top: 12px; }

/* ── Progress / bars ── */
.progress { height: 10px; border-radius: 999px; background: var(--card-2); border: 1px solid var(--line); overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width 0.4s; }
.progress.over > i { background: var(--neg); }
.progress.warn > i { background: var(--warn); }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-top: 14px; }
.kv div span { display: block; font-size: 12px; color: var(--muted); }
.kv div b { font-size: 17px; }

.hbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: center; padding: 8px 0; cursor: pointer; }
.hbar .bar { grid-column: span 2; height: 6px; border-radius: 999px; background: var(--card-2); overflow: hidden; }
.hbar .bar i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.hbar:hover .row-title { color: var(--accent); }

.year-chart { display: flex; align-items: flex-end; gap: 6px; height: 160px; padding-top: 8px; }
.year-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; min-width: 0; }
.year-bars { flex: 1; display: flex; align-items: flex-end; gap: 2px; width: 100%; justify-content: center; }
.year-bars i { width: 42%; max-width: 14px; border-radius: 4px 4px 0 0; min-height: 2px; }
.year-bars i.in { background: var(--pos); }
.year-bars i.out { background: var(--neg); opacity: 0.85; }
.year-col span { font-size: 11px; color: var(--muted); }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* ── Forms / buttons ── */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  white-space: nowrap;
  transition: transform 0.05s, background 0.15s, opacity 0.15s;
}
.btn:hover { background: var(--line); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: progress; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--neg); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 6px 12px; font-size: 13px; border-radius: 10px; }
.btn.block { width: 100%; }
.icon-btn { appearance: none; border: 0; background: transparent; color: var(--muted); font-size: 18px; cursor: pointer; padding: 6px; border-radius: 8px; }
.icon-btn:hover { background: var(--card-2); color: var(--text); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; color: var(--muted); font-weight: 550; }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  width: 100%;
  min-width: 0;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); padding: 0; }
.check { display: flex; gap: 10px; align-items: center; cursor: pointer; }
.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar input[type="search"] { flex: 1 1 200px; }
.toolbar select, .toolbar input[type="month"] { flex: 0 1 auto; width: auto; }
.seg { display: inline-flex; background: var(--card-2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; }
.seg button { appearance: none; border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600; padding: 6px 12px; border-radius: 9px; cursor: pointer; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15); }

.month-nav { display: flex; align-items: center; gap: 8px; }
.month-nav strong { min-width: 140px; text-align: center; text-transform: capitalize; }

.reply { margin-top: 12px; white-space: pre-wrap; background: var(--card-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px; font-size: 14px; }
.reply.ok { border-color: color-mix(in srgb, var(--pos) 40%, transparent); }
.reply.bad { border-color: color-mix(in srgb, var(--neg) 40%, transparent); }

.fab {
  position: fixed;
  right: 20px;
  bottom: calc(var(--nav-h) + 20px + env(safe-area-inset-bottom));
  width: 56px;
  height: 56px;
  border-radius: 18px;
  border: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-size: 28px;
  box-shadow: var(--shadow);
  cursor: pointer;
  z-index: 15;
}
@media (min-width: 901px) { .fab { bottom: 28px; right: 28px; } }
body.has-fab .main { padding-bottom: calc(var(--nav-h) + 96px + env(safe-area-inset-bottom)); }
[role="button"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Sheet (modal) ── */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 20, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
  animation: fade 0.15s ease-out;
}
.sheet {
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  animation: pop 0.18s ease-out;
}
.sheet header { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 8px; }
.sheet header h3 { font-size: 18px; }
.sheet-body { padding: 8px 18px; }
.sheet footer { display: flex; gap: 8px; justify-content: flex-end; padding: 8px 18px 18px; }
.sheet footer .spacer { flex: 1; }
.sheet .error-text { margin: 0 0 12px; font-size: 14px; }
@media (max-width: 600px) {
  .sheet-backdrop { align-items: flex-end; padding: 0; }
  .sheet { max-width: none; border-radius: 22px 22px 0 0; padding-bottom: env(safe-area-inset-bottom); animation: slide 0.22s ease-out; }
}
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(0.96); opacity: 0; } }
@keyframes slide { from { transform: translateY(40px); opacity: 0.5; } }

/* ── Toasts ── */
.toasts { position: fixed; top: calc(16px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px); pointer-events: none; }
.toast { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); animation: pop 0.2s ease-out; white-space: pre-wrap; pointer-events: auto; }
.toast.ok { border-left-color: var(--pos); }
.toast.err { border-left-color: var(--neg); }

/* ── Skeleton ── */
.skel { background: linear-gradient(90deg, var(--card) 25%, var(--card-2) 50%, var(--card) 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: var(--radius); border: 1px solid var(--line); }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.spin { display: inline-block; animation: rot 0.9s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }
