:root {
  color-scheme: light;
  --ink: #111411;
  --green: #7ee55f;
  --green-dark: #377a28;
  --green-soft: #e9fddd;
  --paper: #ffffff;
  --canvas: #f5f6f3;
  --muted: rgba(17, 20, 17, 0.52);
  --line: rgba(17, 20, 17, 0.09);
  --danger: #c9362b;
  --shadow: 0 10px 35px rgba(17, 20, 17, 0.05);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--canvas); color: var(--ink); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 16px; line-height: 1.5; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .62; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, p { margin-top: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

.button { display: inline-flex; min-height: 42px; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent; border-radius: 12px; padding: 9px 15px; background: transparent; color: var(--ink); font-weight: 700; transition: .18s ease; }
.button:hover { transform: translateY(-1px); }
.button-dark { background: var(--ink); color: #fff; }
.button-dark:hover { background: #000; }
.button-green { background: var(--green); color: #10230b; }
.button-green:hover { background: #6dd64f; }
.button-outline { border-color: var(--line); background: #fff; }
.button-ghost:hover { background: rgba(17,20,17,.06); }
.button-danger { background: var(--danger); color: #fff; }
.button-block { width: 100%; }

.topbar { position: sticky; top: 0; z-index: 20; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.94); backdrop-filter: blur(12px); }
.topbar-inner { display: flex; height: 80px; max-width: 1440px; margin: 0 auto; align-items: center; justify-content: space-between; gap: 20px; padding: 0 38px; }
.brand, .topbar-actions { display: flex; align-items: center; gap: 12px; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 18px; letter-spacing: -.03em; }
.brand small { color: var(--muted); font-size: 12px; }
.brand-mark { display: grid; width: 54px; height: 54px; place-items: center; border-radius: 18px; background: var(--ink); color: var(--green); font-size: 25px; font-weight: 900; }
.brand-mark.small { width: 40px; height: 40px; border-radius: 12px; font-size: 19px; }

.app-layout { display: grid; max-width: 1440px; min-height: calc(100vh - 81px); margin: 0 auto; grid-template-columns: 230px minmax(0, 1fr); }
.sidebar { display: flex; flex-direction: column; border-right: 1px solid var(--line); background: #fff; padding: 30px 20px; }
.sidebar nav { display: grid; gap: 8px; }
.sidebar nav a { border-radius: 12px; padding: 12px 14px; color: var(--muted); font-size: 14px; font-weight: 700; }
.sidebar nav a:hover { background: rgba(17,20,17,.04); color: var(--ink); }
.sidebar nav .nav-active { background: var(--green-soft); color: #183a12; }
.sidebar-note { margin-top: auto; border-radius: 22px; background: var(--ink); padding: 20px; color: #fff; }
.sidebar-note .note-icon { display: grid; width: 34px; height: 34px; place-items: center; border-radius: 11px; background: var(--green); color: var(--ink); font-weight: 900; }
.sidebar-note strong { display: block; margin-top: 40px; font-size: 14px; }
.sidebar-note p { margin: 6px 0 0; color: rgba(255,255,255,.55); font-size: 12px; line-height: 1.7; }

.workspace { min-width: 0; padding: 34px 38px 50px; }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; }
.eyebrow { margin-bottom: 4px; color: #438d32; font-size: 13px; font-weight: 800; letter-spacing: .06em; }
.page-heading h1 { margin-bottom: 4px; font-size: clamp(30px, 4vw, 40px); line-height: 1.12; letter-spacing: -.045em; }
.page-heading p:last-child, .panel-header p, .panel > p, .analytics-panel > p, .category-panel > p { margin-bottom: 0; color: var(--muted); font-size: 14px; }

.month-control { position: relative; }
.month-trigger { min-width: 220px; justify-content: flex-start; border-color: var(--line); background: #fff; box-shadow: 0 2px 9px rgba(17,20,17,.04); }
.month-trigger span:last-child { flex: 1; text-align: left; }
.month-picker { position: absolute; top: calc(100% + 8px); right: 0; z-index: 30; width: 320px; border: 1px solid var(--line); border-radius: 20px; background: #fff; padding: 16px; box-shadow: 0 18px 50px rgba(17,20,17,.16); }
.month-picker-head { display: flex; align-items: center; justify-content: space-between; }
.month-picker-head button { display: grid; width: 40px; height: 40px; place-items: center; border: 0; border-radius: 12px; background: transparent; font-size: 28px; }
.month-picker-head button:hover { background: var(--green-soft); }
.month-grid { display: grid; margin-top: 10px; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.month-grid button { border: 0; border-radius: 12px; background: transparent; padding: 11px 5px; color: rgba(17,20,17,.68); font-size: 14px; font-weight: 750; }
.month-grid button:hover { background: var(--green-soft); color: #183a12; }
.month-grid button.active { background: var(--ink); color: #fff; }

.alert { border-radius: 13px; padding: 12px 14px; font-size: 14px; }
.workspace > .alert { margin-top: 20px; }
.alert-error { border: 1px solid #f3c3bf; background: #fff1f0; color: #96261e; }

.summary-grid { display: grid; margin-top: 28px; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.summary-card { min-height: 132px; border: 1px solid var(--line); border-radius: 24px; background: #fff; padding: 20px; box-shadow: var(--shadow); }
.summary-card span { color: var(--muted); font-size: 14px; font-weight: 650; }
.summary-card strong { display: block; margin-top: 28px; font-size: clamp(20px, 2.4vw, 27px); letter-spacing: -.035em; }
.summary-dark { border-color: var(--ink); background: var(--ink); color: #fff; }
.summary-dark span { color: rgba(255,255,255,.58); }

.content-grid { display: grid; margin-top: 24px; grid-template-columns: minmax(0, 1.45fr) minmax(310px, .75fr); gap: 24px; align-items: start; }
.panel { overflow: hidden; border: 1px solid var(--line); border-radius: 26px; background: #fff; box-shadow: var(--shadow); }
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 18px; border-bottom: 1px solid var(--line); padding: 22px 24px; }
.panel h2 { margin-bottom: 3px; font-size: 19px; letter-spacing: -.025em; }
.panel-actions { display: flex; gap: 8px; }
.filter-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line); background: #fafbfa; padding: 12px 24px; }
.filter-row label { color: var(--muted); font-size: 14px; font-weight: 650; }
select, input { width: 100%; min-height: 44px; border: 1px solid rgba(17,20,17,.14); border-radius: 12px; outline: none; background: #fff; padding: 9px 12px; color: var(--ink); }
select:focus, input:focus { border-color: #5ebd44; box-shadow: 0 0 0 3px rgba(126,229,95,.24); }
.filter-row select { width: 210px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th, td { border-bottom: 1px solid var(--line); padding: 15px 12px; text-align: left; font-size: 14px; }
th:first-child, td:first-child { padding-left: 24px; }
th { color: rgba(17,20,17,.45); font-size: 12px; font-weight: 700; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcfa; }
td:first-child { min-width: 170px; font-weight: 750; white-space: normal; }
.money { text-align: right; font-weight: 800; }
.money.income { color: var(--green-dark); }
.tag { display: inline-flex; border-radius: 999px; padding: 5px 9px; background: var(--green-soft); color: var(--green-dark); font-size: 12px; font-weight: 750; }
.tag.fixed { background: rgba(17,20,17,.07); color: rgba(17,20,17,.66); }
.row-actions { display: flex; justify-content: flex-end; gap: 4px; }
.row-actions button, .icon-button { display: grid; width: 36px; height: 36px; place-items: center; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-size: 17px; }
.row-actions button:hover, .icon-button:hover { background: rgba(17,20,17,.06); color: var(--ink); }
.row-actions .delete-action:hover { background: #fff0ef; color: var(--danger); }
.empty-state { display: grid; min-height: 270px; place-items: center; padding: 45px 24px; text-align: center; color: var(--muted); }
.empty-state > * { margin-left: auto; margin-right: auto; }
.empty-state h3 { margin: 12px 0 4px; color: var(--ink); }
.empty-state p { max-width: 340px; margin-bottom: 0; font-size: 14px; }
.empty-icon { display: grid; width: 48px; height: 48px; place-items: center; border-radius: 16px; background: var(--green-soft); color: var(--green-dark); font-weight: 900; }

.right-column { display: grid; gap: 24px; }
.analytics-panel, .category-panel { padding: 24px; }
.analytics-grid { display: grid; margin-top: 24px; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.analytics-grid > div:first-child { border-right: 1px solid var(--line); padding-right: 16px; }
.analytics-grid h3 { text-align: center; font-size: 14px; }
.donut { display: grid; width: 108px; height: 108px; margin: 14px auto; place-items: center; border-radius: 50%; background: #edf0eb; }
.donut > span { display: grid; width: 76px; height: 76px; place-content: center; border-radius: 50%; background: #fff; text-align: center; }
.donut small, .donut strong { display: block; }
.donut small { color: var(--muted); font-size: 10px; }
.donut strong { max-width: 68px; overflow: hidden; font-size: 11px; text-overflow: ellipsis; }
.legend { display: grid; gap: 9px; }
.legend-item { min-width: 0; font-size: 12px; }
.legend-label { display: flex; min-width: 0; align-items: center; gap: 6px; color: var(--muted); }
.legend-label span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-dot { width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; }
.legend-item strong { display: block; padding-left: 14px; font-size: 12px; }
.segmented { display: grid; margin-top: 18px; grid-template-columns: 1fr 1fr; gap: 4px; border-radius: 13px; background: rgba(17,20,17,.055); padding: 4px; }
.segmented button { min-height: 38px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-size: 14px; font-weight: 750; }
.segmented button.active { background: var(--ink); color: #fff; box-shadow: 0 2px 7px rgba(17,20,17,.12); }
.segmented button[data-category-kind="income"].active, .kind-selector button[data-kind="income"].active { background: var(--green); color: #10230b; }
.category-summary { display: grid; margin-top: 20px; gap: 16px; }
.category-row-head { display: flex; justify-content: space-between; gap: 15px; font-size: 14px; }
.category-row-head strong { white-space: nowrap; }
.bar { height: 8px; margin-top: 8px; overflow: hidden; border-radius: 99px; background: rgba(17,20,17,.06); }
.bar span { display: block; height: 100%; border-radius: inherit; background: var(--ink); }
.bar.income span { background: var(--green); }
.muted-message { padding: 25px 0; color: var(--muted); text-align: center; font-size: 14px; }

.modal { width: min(520px, calc(100% - 28px)); max-height: calc(100vh - 28px); border: 1px solid var(--line); border-radius: 24px; padding: 0; color: var(--ink); box-shadow: 0 24px 80px rgba(0,0,0,.24); }
.modal::backdrop { background: rgba(10,12,10,.56); backdrop-filter: blur(3px); }
.modal form > header { display: flex; align-items: start; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--line); padding: 20px 22px; }
.modal h2 { margin-bottom: 3px; font-size: 21px; }
.modal header p { margin-bottom: 0; color: var(--muted); font-size: 14px; }
.modal-body { display: grid; padding: 20px 22px; gap: 16px; }
.modal label, .auth-form label { display: grid; gap: 7px; font-size: 14px; font-weight: 750; }
.modal .segmented { margin-top: 0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.money-input { position: relative; }
.money-input span { position: absolute; top: 50%; left: 12px; transform: translateY(-50%); color: var(--muted); font-size: 14px; font-weight: 800; }
.money-input input { padding-left: 42px; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 0 22px 22px; }
.confirm-modal { width: min(440px, calc(100% - 28px)); }
.confirm-modal form > header { border-bottom: 0; }

.auth-shell { display: grid; min-height: 100vh; place-items: center; padding: 24px; background: radial-gradient(circle at 10% 10%, rgba(126,229,95,.24), transparent 32%), var(--canvas); }
.auth-card { width: min(480px, 100%); border: 1px solid var(--line); border-radius: 28px; background: #fff; padding: 34px; box-shadow: 0 24px 70px rgba(17,20,17,.11); }
.auth-card .brand-mark { margin-bottom: 25px; }
.auth-card h1 { margin-bottom: 8px; font-size: 30px; letter-spacing: -.04em; }
.auth-copy { margin-bottom: 22px; color: var(--muted); }
.auth-form { display: grid; margin-top: 18px; gap: 15px; }
.auth-form .alert { margin-bottom: 4px; }
.auth-card > .button { margin-top: 18px; }

@media (max-width: 1120px) {
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .content-grid { grid-template-columns: 1fr; }
  .right-column { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .topbar-inner { height: 70px; padding: 0 16px; }
  .brand small, .topbar-actions form { display: none; }
  .button[data-new="income"] { padding: 9px 12px; font-size: 13px; }
  .app-layout { display: block; }
  .sidebar { display: none; }
  .workspace { padding: 24px 16px 38px; }
  .page-heading { align-items: stretch; flex-direction: column; }
  .month-control, .month-trigger { width: 100%; }
  .month-picker { right: auto; left: 0; width: min(320px, calc(100vw - 32px)); }
  .summary-grid { gap: 12px; }
  .summary-card { min-height: 116px; padding: 17px; }
  .summary-card strong { margin-top: 22px; font-size: 19px; }
  .panel-header { align-items: stretch; flex-direction: column; padding: 19px; }
  .panel-actions .button { flex: 1; }
  .filter-row { align-items: stretch; flex-direction: column; padding: 12px 19px; }
  .filter-row select { width: 100%; }
  .right-column { grid-template-columns: 1fr; }
  .analytics-panel, .category-panel { padding: 20px; }
}

@media (max-width: 480px) {
  .topbar-actions .button { font-size: 0; }
  .topbar-actions .button span { font-size: 20px; }
  .summary-grid { grid-template-columns: 1fr; }
  .summary-card { min-height: 104px; }
  .summary-card strong { margin-top: 16px; }
  .analytics-grid { grid-template-columns: 1fr; }
  .analytics-grid > div:first-child { border-right: 0; border-bottom: 1px solid var(--line); padding: 0 0 18px; }
  .form-grid { grid-template-columns: 1fr; }
  .auth-card { padding: 26px 20px; }
}
