:root {
  --bg: #f3f6f8;
  --surface: #ffffff;
  --surface-soft: #f8fafb;
  --ink: #18242f;
  --muted: #667786;
  --line: #d9e2e8;
  --line-strong: #bdcbd5;
  --brand: #17324d;
  --brand-2: #245a75;
  --accent: #ef8f40;
  --accent-soft: #fff0e2;
  --green: #18755a;
  --green-soft: #e8f6f0;
  --red: #b74141;
  --red-soft: #fff0f0;
  --blue-soft: #eaf3fb;
  --shadow: 0 10px 30px rgba(30, 52, 70, .08);
  --radius: 18px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: var(--brand-2); }
.hidden { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.app-shell { min-height: 100vh; }
.topbar {
  min-height: 72px;
  padding: 14px clamp(16px, 3vw, 36px);
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-icon { width: 42px; height: 42px; border-radius: 12px; box-shadow: 0 4px 12px rgba(0,0,0,.18); }
.brand-title { font-size: 18px; font-weight: 750; letter-spacing: -.02em; }
.brand-subtitle { font-size: 12px; opacity: .76; }
.topbar .button-ghost { color: #fff; border-color: rgba(255,255,255,.35); background: rgba(255,255,255,.08); }

.context-bar {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  padding: 14px clamp(16px, 3vw, 36px);
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.context-field { min-width: 190px; }
.context-field label { display: block; color: var(--muted); font-size: 11px; font-weight: 750; letter-spacing: .05em; text-transform: uppercase; margin-bottom: 5px; }
.context-control { display: flex; gap: 6px; align-items: center; }
.context-control select { min-width: 160px; }
.context-hint { margin-top: 4px; color: var(--muted); font-size: 11px; }
select, input[type="text"], input[type="number"], input[type="date"], textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
  padding: 9px 10px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
select:focus, input:focus, textarea:focus { border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(36,90,117,.12); }
.icon-button {
  width: 36px; height: 36px; flex: 0 0 36px;
  border: 1px solid var(--line-strong); border-radius: 9px; background: #fff; color: var(--brand);
  display: inline-grid; place-items: center; font-size: 20px; line-height: 1;
}
.icon-button:hover { background: var(--surface-soft); }
.privacy-pill { margin-left: auto; align-self: center; display: inline-flex; align-items: center; gap: 8px; padding: 8px 11px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: 12px; background: var(--surface-soft); white-space: nowrap; }
.privacy-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px var(--green-soft); }

.tabbar {
  display: flex;
  gap: 4px;
  padding: 10px clamp(16px, 3vw, 36px) 0;
  background: #fff;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}
.tab { border: 0; background: transparent; color: var(--muted); padding: 10px 14px 12px; font-weight: 700; border-bottom: 3px solid transparent; white-space: nowrap; }
.tab:hover { color: var(--ink); }
.tab.active { color: var(--brand); border-bottom-color: var(--accent); }

main { width: min(1600px, 100%); margin: 0 auto; padding: 24px clamp(14px, 3vw, 36px) 56px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.page-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; margin-bottom: 20px; }
.page-heading h1 { margin: 2px 0 5px; font-size: clamp(24px, 3vw, 34px); letter-spacing: -.035em; line-height: 1.12; }
.page-heading p { margin: 0; color: var(--muted); max-width: 760px; }
.eyebrow { font-size: 11px !important; font-weight: 800; color: var(--brand-2) !important; letter-spacing: .1em; text-transform: uppercase; }
.heading-actions, .button-row { display: flex; flex-wrap: wrap; gap: 8px; }
.button { border: 1px solid var(--line-strong); border-radius: 9px; background: #fff; color: var(--ink); padding: 9px 13px; font-weight: 700; min-height: 38px; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.button:hover { background: var(--surface-soft); }
.button-primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.button-primary:hover { background: #204361; }
.button-danger { background: var(--red); color: #fff; border-color: var(--red); }
.button-small { min-height: 30px; padding: 5px 9px; font-size: 12px; }
.button-link { border: 0; background: transparent; color: var(--brand-2); padding: 3px 5px; min-height: auto; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 15px; min-width: 0; }
.kpi-label { color: var(--muted); font-size: 12px; font-weight: 700; }
.kpi-value { font-size: clamp(20px, 2.3vw, 28px); font-weight: 800; letter-spacing: -.025em; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi small { display: block; color: var(--muted); margin-top: 4px; }
.kpi.accent { border-top: 4px solid var(--accent); }
.kpi.green { border-top: 4px solid var(--green); }
.kpi.blue { border-top: 4px solid var(--brand-2); }

.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; overflow: hidden; }
.card-header { padding: 16px 18px 12px; display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; border-bottom: 1px solid var(--line); }
.card-header h2 { margin: 0 0 3px; font-size: 17px; }
.card-header p { margin: 0; color: var(--muted); font-size: 12px; }
.card-body { padding: 18px; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; color: var(--muted); font-size: 11px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; border: 1px solid var(--line-strong); }
.legend-swatch.earning { background: #f4f8fb; }
.legend-swatch.deduction { background: #f8fafb; }
.legend-swatch.total { background: var(--accent-soft); }

.sheet-scroll { overflow: auto; max-width: 100%; background: #fff; }
.sheet-table { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; font-variant-numeric: tabular-nums; }
.sheet-table th, .sheet-table td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 0; min-width: 104px; height: 42px; background: #fff; }
.sheet-table thead th { position: sticky; top: 0; z-index: 8; background: #f6f8fa; color: #415462; font-size: 11px; font-weight: 800; text-align: right; padding: 0 9px; white-space: nowrap; }
.sheet-table thead th:first-child { text-align: left; min-width: 210px; }
.sheet-table th.sticky-col, .sheet-table td.sticky-col { position: sticky; left: 0; z-index: 5; min-width: 210px; max-width: 210px; background: #fff; }
.sheet-table thead th.sticky-col { z-index: 10; background: #f6f8fa; }
.sheet-table td.sticky-col { padding: 0 10px; font-weight: 650; }
.sheet-table .section-row td { height: 32px; padding: 0 10px; font-size: 11px; font-weight: 850; letter-spacing: .08em; text-transform: uppercase; color: var(--brand-2); background: #f3f7fa; }
.sheet-table .section-row td.sticky-col { background: #f3f7fa; }
.sheet-table .money-cell { width: 103px; height: 41px; border: 0; border-radius: 0; text-align: right; padding: 0 9px; background: transparent; box-shadow: none; font-size: 13px; font-variant-numeric: tabular-nums; }
.sheet-table .money-cell:focus { outline: 2px solid rgba(36,90,117,.3); outline-offset: -2px; background: #fafdff; }
.sheet-table .total-cell { background: var(--accent-soft); font-weight: 800; text-align: right; padding: 0 9px; }
.sheet-table .total-row td { font-weight: 850; background: #f8fafb; text-align: right; padding: 0 9px; }
.sheet-table .total-row td.sticky-col { text-align: left; background: #f8fafb; }
.sheet-table .total-row .total-cell { background: #ffd9b7; }
.sheet-table .net-row td { background: var(--green-soft); font-weight: 850; text-align: right; padding: 0 9px; }
.sheet-table .net-row td.sticky-col { text-align: left; background: var(--green-soft); }
.sheet-table .group-row td { background: #f6f3ff; color: #4c4565; text-align: right; padding: 0 9px; font-size: 12px; }
.sheet-table .group-row td.sticky-col { text-align: left; background: #f6f3ff; font-style: italic; }
.row-meta { display: block; font-size: 10px; font-weight: 600; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.two-column-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.rules-grid { padding: 18px; display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.rule-block h3, .source-list h3 { margin: 0 0 8px; font-size: 14px; }
.rule-block ul { margin: 0; padding-left: 19px; color: var(--muted); }
.rule-block li { margin: 5px 0; }
.source-list { border-top: 1px solid var(--line); padding: 16px 18px 20px; display: grid; gap: 6px; }
.source-list a { text-decoration: none; font-weight: 650; }
.source-list a:hover { text-decoration: underline; }
.danger-card { border-color: #f2cece; }

.notice { margin: 14px 0 0; padding: 12px 13px; border-radius: 10px; font-size: 12px; }
.notice-neutral { background: #f2f6f9; color: #506575; border: 1px solid #d8e3ea; }
.notice-warning { background: #fff7e9; color: #7a531b; border: 1px solid #f1d7a4; }
.notice-success { background: var(--green-soft); color: #245f4f; border: 1px solid #bfe3d6; }

.declaration-stack { display: grid; gap: 14px; }
.declaration-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.declaration-card > summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 15px 18px; font-weight: 800; }
.declaration-card > summary::-webkit-details-marker { display: none; }
.declaration-card > summary::after { content: "+"; font-size: 20px; color: var(--muted); }
.declaration-card[open] > summary::after { content: "−"; }
.declaration-card[open] > summary { border-bottom: 1px solid var(--line); }
.declaration-content { padding: 18px; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 12px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0,1fr)); }
.field { display: grid; gap: 5px; font-size: 12px; font-weight: 750; color: #415462; }
.field.checkbox-field { display: flex; align-items: center; gap: 8px; padding-top: 24px; }
.field.checkbox-field input { width: 17px; height: 17px; }
.field-help { margin: 5px 0 0; color: var(--muted); font-size: 11px; }
.inline-summary { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 8px; }
.summary-chip { border: 1px solid var(--line); background: var(--surface-soft); border-radius: 999px; padding: 7px 10px; font-size: 12px; }
.summary-chip strong { margin-left: 4px; }
.mini-grid-scroll { overflow-x: auto; margin-top: 12px; }
.mini-month-grid { display: grid; grid-template-columns: repeat(12, minmax(86px,1fr)); gap: 7px; min-width: 1040px; }
.mini-month { display: grid; gap: 4px; font-size: 10px; color: var(--muted); }
.mini-month input { padding: 7px; }

.edit-table { width: 100%; border-collapse: collapse; }
.edit-table th, .edit-table td { border-bottom: 1px solid var(--line); padding: 8px 6px; text-align: left; vertical-align: middle; }
.edit-table th { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.edit-table input, .edit-table select { padding: 7px 8px; }
.edit-table td.amount { width: 150px; }
.edit-table td.action { width: 62px; text-align: right; }
.subsection-title { margin: 18px 0 8px; font-size: 13px; }

.regime-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 15px; }
.regime-option { border: 1px solid var(--line); border-radius: 13px; padding: 13px; display: flex; gap: 9px; align-items: flex-start; cursor: pointer; }
.regime-option input { margin-top: 3px; }
.regime-option.selected { border-color: var(--brand-2); box-shadow: inset 0 0 0 1px var(--brand-2); background: #f7fbfd; }
.regime-option strong { display: block; }
.regime-option span { color: var(--muted); font-size: 11px; }

.tax-comparison { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 16px; }
.tax-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.tax-card.selected { border-color: var(--brand-2); box-shadow: 0 10px 30px rgba(36,90,117,.15), inset 0 0 0 1px var(--brand-2); }
.tax-card-head { padding: 15px 17px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 12px; }
.tax-card-head h2 { font-size: 16px; margin: 0; }
.tax-card-head span { color: var(--muted); font-size: 11px; }
.tax-card-total { padding: 18px 17px 8px; font-size: 30px; font-weight: 850; letter-spacing: -.035em; }
.tax-card-caption { padding: 0 17px 15px; color: var(--muted); font-size: 12px; }
.tax-lines { border-top: 1px solid var(--line); padding: 9px 17px 13px; }
.tax-line { display: flex; justify-content: space-between; gap: 14px; padding: 5px 0; font-size: 12px; }
.tax-line span:first-child { color: var(--muted); }
.tax-line strong { font-variant-numeric: tabular-nums; text-align: right; }
.tax-line.strong { font-size: 13px; border-top: 1px dashed var(--line); margin-top: 5px; padding-top: 9px; }

.monthly-plan { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.monthly-plan th, .monthly-plan td { border-bottom: 1px solid var(--line); padding: 9px 10px; text-align: right; }
.monthly-plan th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; background: #f8fafb; }
.monthly-plan th:first-child, .monthly-plan td:first-child { text-align: left; }
.balance-positive { color: var(--red); }
.balance-negative { color: var(--green); }

.modal { border: 0; padding: 0; background: transparent; width: min(620px, calc(100% - 24px)); max-height: calc(100vh - 24px); }
.modal.modal-wide { width: min(920px, calc(100% - 24px)); }
.modal::backdrop { background: rgba(20, 35, 48, .55); backdrop-filter: blur(2px); }
.modal-card { background: #fff; border-radius: 18px; box-shadow: 0 22px 70px rgba(12,28,40,.28); padding: 18px; max-height: calc(100vh - 24px); overflow: auto; }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.modal-header h2 { margin: 0; font-size: 21px; }
.modal-header .eyebrow { margin: 0 0 3px; }
.close-button { border: 0; font-size: 26px; color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.modal-intro { color: var(--muted); margin: -5px 0 15px; }
.compact-field { max-width: 240px; }
.month-entry-section { margin: 13px 0; }
.month-entry-section h3 { margin: 0 0 8px; font-size: 13px; color: var(--brand-2); }
.month-entry-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px 12px; }
.month-entry-item { display: grid; grid-template-columns: minmax(140px,1fr) 150px; align-items: center; gap: 10px; }
.month-entry-item label { font-size: 12px; font-weight: 700; }
.month-entry-item input { text-align: right; }
.month-totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.month-total { border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; background: var(--surface-soft); }
.month-total span { display: block; font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.month-total strong { font-size: 16px; }

.manager-section { border: 1px solid var(--line); border-radius: 13px; padding: 13px; margin: 10px 0; }
.manager-section h3 { margin: 0 0 9px; font-size: 14px; }
.manager-row { display: grid; grid-template-columns: minmax(170px,1fr) minmax(150px,.7fr) 42px; gap: 8px; align-items: center; margin: 7px 0; }
.group-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin: 9px 0; }
.group-card-top { display: grid; grid-template-columns: minmax(180px,1fr) 160px 42px; gap: 8px; align-items: center; }
.group-members { margin-top: 10px; display: flex; gap: 7px; flex-wrap: wrap; }
.member-check { display: inline-flex; align-items: center; gap: 5px; padding: 6px 8px; background: var(--surface-soft); border: 1px solid var(--line); border-radius: 999px; font-size: 11px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 24px); z-index: 100; background: #172733; color: #fff; padding: 10px 14px; border-radius: 10px; box-shadow: 0 12px 30px rgba(0,0,0,.22); opacity: 0; pointer-events: none; transition: .2s ease; max-width: min(520px, calc(100% - 30px)); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 980px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .form-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .tax-comparison, .two-column-grid, .rules-grid { grid-template-columns: 1fr; }
  .privacy-pill { display: none; }
}

@media (max-width: 720px) {
  body { font-size: 13px; }
  .topbar { min-height: 62px; padding: 10px 14px; }
  .brand-icon { width: 38px; height: 38px; }
  .brand-subtitle { display: none; }
  .context-bar { position: static; padding: 10px 14px; align-items: stretch; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .context-field { min-width: 0; }
  .context-control select { min-width: 0; }
  .tabbar { padding-left: 9px; padding-right: 9px; }
  main { padding: 18px 10px 42px; }
  .page-heading { align-items: flex-start; flex-direction: column; }
  .heading-actions { width: 100%; }
  .heading-actions .button { flex: 1 1 auto; }
  .kpi-grid { gap: 8px; }
  .kpi { padding: 12px; }
  .card { border-radius: 13px; }
  .card-header { padding: 13px; flex-direction: column; }
  .sheet-table th.sticky-col, .sheet-table td.sticky-col, .sheet-table thead th:first-child { min-width: 170px; max-width: 170px; }
  .form-grid, .form-grid.two { grid-template-columns: 1fr; }
  .field.checkbox-field { padding-top: 6px; }
  .regime-switch { grid-template-columns: 1fr; }
  .declaration-content { padding: 13px; }
  .month-entry-grid { grid-template-columns: 1fr; }
  .month-entry-item { grid-template-columns: minmax(130px,1fr) 130px; }
  .month-totals { grid-template-columns: 1fr; }
  .manager-row, .group-card-top { grid-template-columns: minmax(0,1fr) 120px 38px; }
  .modal-card { padding: 14px; border-radius: 14px; }
  .edit-table { min-width: 680px; }
  .edit-table-wrap { overflow-x: auto; }
}

@media (max-width: 440px) {
  .context-bar { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .kpi-value { font-size: 18px; }
  .brand-title { font-size: 16px; }
  .top-actions .button { padding: 7px 9px; font-size: 11px; }
  .month-entry-item { grid-template-columns: 1fr 115px; }
}
