:root {
  color-scheme: light;
  --bg: #f5f5f7;
  --bg-radial: radial-gradient(circle at top left, rgba(10, 132, 255, 0.16), transparent 34%), radial-gradient(circle at 85% 8%, rgba(191, 90, 242, 0.12), transparent 30%);
  --surface: rgba(255, 255, 255, 0.82);
  --surface-solid: #ffffff;
  --surface-strong: rgba(255, 255, 255, 0.96);
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: rgba(60, 60, 67, 0.14);
  --primary: #007aff;
  --primary-dark: #0064d2;
  --success: #34c759;
  --danger: #ff3b30;
  --warning: #ff9f0a;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.08);
  --soft-shadow: 0 10px 30px rgba(0, 0, 0, 0.06);
  --sidebar-width: 304px;
  --radius: 26px;
  --control-radius: 14px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #000000;
  --bg-radial: radial-gradient(circle at top left, rgba(10, 132, 255, 0.22), transparent 34%), radial-gradient(circle at 85% 8%, rgba(191, 90, 242, 0.18), transparent 30%);
  --surface: rgba(28, 28, 30, 0.78);
  --surface-solid: #1c1c1e;
  --surface-strong: rgba(44, 44, 46, 0.92);
  --text: #f5f5f7;
  --muted: #a1a1a6;
  --line: rgba(235, 235, 245, 0.16);
  --primary: #0a84ff;
  --primary-dark: #409cff;
  --success: #30d158;
  --danger: #ff453a;
  --warning: #ffd60a;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
  --soft-shadow: 0 12px 34px rgba(0, 0, 0, 0.32);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  min-width: 1180px;
  min-height: 100vh;
  margin: 0;
  background: var(--bg-radial), var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", Inter, system-ui, sans-serif;
  letter-spacing: -0.01em;
}

a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }
button:disabled { cursor: not-allowed; opacity: 0.45; }

.sidebar {
  position: fixed;
  inset: 18px auto 18px 18px;
  width: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 22px;
  z-index: 20;
  border: 1px solid var(--line);
  border-radius: 30px;
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(28px) saturate(180%);
  -webkit-backdrop-filter: blur(28px) saturate(180%);
}

.brand { display: flex; gap: 12px; align-items: center; font-weight: 800; font-size: 1.12rem; }
.brand-mark { width: 44px; height: 44px; border-radius: 15px; background: linear-gradient(145deg, #0a84ff, #64d2ff); color: white; display: grid; place-items: center; box-shadow: 0 14px 30px rgba(10, 132, 255, 0.32); }
.nav { display: grid; gap: 7px; }
.nav a { display: flex; justify-content: space-between; align-items: center; padding: 13px 14px; border-radius: 16px; color: var(--muted); font-weight: 700; transition: background .18s ease, color .18s ease, transform .18s ease; }
.nav a.active, .nav a:hover { color: var(--text); background: rgba(10, 132, 255, 0.14); transform: translateX(2px); }
.sidebar-footer { margin-top: auto; display: grid; gap: 10px; }
.mobile-topbar { display: none; position: sticky; top: 0; z-index: 30; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--line); align-items: center; justify-content: space-between; backdrop-filter: blur(22px); }

.main-content {
  margin-left: calc(var(--sidebar-width) + 36px);
  padding: 44px 44px 44px 28px;
  width: calc(100vw - var(--sidebar-width) - 36px);
  max-width: none;
}
.page-hero { display: flex; align-items: flex-start; justify-content: space-between; gap: 36px; margin-bottom: 30px; }
.eyebrow { color: var(--primary); font-weight: 800; letter-spacing: .08em; text-transform: uppercase; margin: 0 0 8px; font-size: .78rem; }
h1 { margin: 0; font-size: clamp(2.75rem, 4vw, 4.8rem); line-height: .94; letter-spacing: -.06em; }
h2 { margin: 0; font-size: 1.18rem; letter-spacing: -.03em; }
.muted { color: var(--muted); line-height: 1.55; }
.hero-actions, .form-actions { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  border: 0;
  border-radius: 999px;
  padding: 11px 18px;
  font-weight: 800;
  cursor: pointer;
  transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 12px 28px rgba(10, 132, 255, 0.24); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--surface-strong); color: var(--text); border: 1px solid var(--line); box-shadow: var(--soft-shadow); }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.btn-danger { background: rgba(255, 59, 48, .12); color: var(--danger); border: 1px solid rgba(255, 59, 48, .22); }
.link { color: var(--primary); font-weight: 800; }

.card, .kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
}
.card { padding: 24px; margin-bottom: 24px; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 22px; margin-bottom: 20px; }
.grid { display: grid; gap: 24px; }
.two-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; margin-bottom: 24px; }
.kpi { padding: 22px; }
.kpi small { color: var(--muted); font-weight: 750; }
.kpi strong { display: block; margin-top: 10px; font-size: 1.8rem; letter-spacing: -.05em; }
.kpi .positive { color: var(--success); }
.kpi .negative { color: var(--danger); }

.form-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.journal-form-grid { grid-template-columns: 150px 110px 190px minmax(250px, 1.4fr) minmax(250px, 1.4fr) 180px; align-items: end; }
.label-choice { min-width: 240px; }
.label-custom { min-width: 250px; }
.is-hidden { display: none !important; }
label { display: grid; gap: 7px; color: var(--muted); font-weight: 760; font-size: .84rem; }
input, select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--control-radius);
  background: var(--surface-strong);
  color: var(--text);
  padding: 10px 12px;
  outline: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.24);
}
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(10, 132, 255, .16); }
.search { max-width: 380px; }

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { border-bottom: 1px solid var(--line); padding: 13px 12px; text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .06em; }
td.money, th.money { text-align: right; font-variant-numeric: tabular-nums; }
tfoot td { font-weight: 850; }
.spreadsheet { min-width: 980px; }
.spreadsheet input { min-width: 130px; }
.spreadsheet .account-input { min-width: 210px; }
.account-hint { font-size: .75rem; color: var(--muted); margin-top: 4px; }

.status-pill { border-radius: 999px; padding: 8px 12px; font-size: .82rem; font-weight: 900; }
.status-pill.success { color: var(--success); background: rgba(52, 199, 89, .14); }
.status-pill.danger { color: var(--danger); background: rgba(255, 59, 48, .13); }
.status-pill.warning { color: var(--warning); background: rgba(255, 159, 10, .14); }

.empty-state { text-align: center; padding: 48px 18px; border: 1px dashed var(--line); border-radius: var(--radius); background: rgba(255, 255, 255, .42); }
.empty-state h3 { margin: 0 0 8px; }
.actions-cell { display: flex; justify-content: flex-end; gap: 8px; }
.group-title { margin: 24px 0 8px; padding-bottom: 8px; border-bottom: 2px solid var(--line); color: var(--primary); }
.chart-wrap { height: 360px; }

.toast-root, #toast-root { position: fixed; right: 24px; bottom: 24px; z-index: 50; display: grid; gap: 10px; }
.toast { min-width: 300px; padding: 14px 16px; border-radius: 18px; border: 1px solid var(--line); border-left: 5px solid var(--primary); background: var(--surface-strong); color: var(--text); box-shadow: var(--shadow); animation: slide-in .2s ease; }
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
@keyframes slide-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.modal-backdrop { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 18px; background: rgba(0, 0, 0, .34); backdrop-filter: blur(12px); }
.modal { width: min(540px, 100%); padding: 24px; border: 1px solid var(--line); border-radius: 28px; background: var(--surface-strong); box-shadow: var(--shadow); }
.modal-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 18px; }

@media (max-width: 1280px) {
  body { min-width: 1024px; }
  .journal-form-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  body { min-width: 0; }
  .mobile-topbar { display: flex; }
  .sidebar { inset: 12px auto 12px 12px; transform: translateX(calc(-100% - 24px)); transition: transform .2s ease; }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .main-content { margin-left: 0; width: 100%; padding: 22px; }
  .page-hero, .card-header { flex-direction: column; align-items: stretch; }
  .kpi-grid, .two-columns, .form-grid, .journal-form-grid { grid-template-columns: 1fr; }
  h1 { font-size: 2.6rem; }
}
