:root {
  color-scheme: light;
  --ink: #18211d;
  --muted: #66716b;
  --paper: #f4f6f1;
  --card: #ffffff;
  --accent: #146c4a;
  --accent-dark: #0c5137;
  --line: #dfe5de;
  --danger: #9b2c2c;
}
* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body { font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--ink); background: var(--paper); }

.auth-page { display: grid; min-height: 100vh; place-items: center; padding: 24px; background: radial-gradient(circle at top left, #dfeee6, transparent 38%), var(--paper); }
.auth-card { width: min(100%, 430px); padding: 42px; border: 1px solid var(--line); border-radius: 20px; background: color-mix(in srgb, var(--card) 96%, transparent); box-shadow: 0 22px 60px rgba(24, 33, 29, .09); }
.mark { display: grid; width: 46px; height: 46px; place-items: center; border-radius: 13px; color: white; background: var(--accent); font-size: 22px; font-weight: 750; }
.mark.small { display: inline-grid; width: 34px; height: 34px; margin-right: 10px; border-radius: 9px; font-size: 16px; vertical-align: middle; }
.eyebrow { margin: 26px 0 8px; color: var(--accent); font-size: 12px; font-weight: 750; letter-spacing: .12em; text-transform: uppercase; }
h1 { margin: 0; font-size: 31px; line-height: 1.15; letter-spacing: -.035em; }
.muted { margin: 14px 0 28px; color: var(--muted); line-height: 1.55; }
.auth-form { display: grid; gap: 17px; }
label { display: grid; gap: 7px; color: #38433d; font-size: 13px; font-weight: 650; }
input { width: 100%; padding: 13px 14px; border: 1px solid #cbd4cd; border-radius: 10px; background: #fff; color: var(--ink); font: inherit; outline: none; }
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(20, 108, 74, .12); }
button { padding: 13px 18px; border: 0; border-radius: 10px; background: var(--accent); color: white; font: inherit; font-weight: 700; cursor: pointer; }
button:hover { background: var(--accent-dark); }
.notice { margin: 0 0 18px; padding: 12px 14px; border-radius: 9px; font-size: 14px; }
.notice.error { color: var(--danger); background: #fff0f0; }
.notice.success { color: var(--accent-dark); background: #eaf7f0; }
.footnote { margin: 24px 0 0; color: #849088; font-size: 11px; line-height: 1.5; text-align: center; }

.dashboard-page { min-height: 100vh; overflow: hidden; background: #eef1ed; }
.topbar { display: flex; height: 58px; align-items: center; justify-content: space-between; padding: 0 20px; border-bottom: 1px solid var(--line); background: #fff; }
.topbar > div, .account { display: flex; align-items: center; gap: 12px; }
.brand { min-width: 0; }
.portal-nav { display: flex; align-items: center; gap: 4px; margin-left: 16px; }
.portal-nav a { padding: 8px 12px; border-radius: 9px; color: var(--muted); font-size: 13px; font-weight: 700; text-decoration: none; }
.portal-nav a:hover { color: var(--accent-dark); background: #edf5f0; }
.portal-nav a.active { color: var(--accent-dark); background: #e4f2e9; }
.account { color: var(--muted); font-size: 13px; }
.scope-badge { padding: 5px 8px; border-radius: 999px; color: var(--accent-dark); background: #eaf7f0; font-size: 11px; font-weight: 700; }
.account form { margin: 0; }
.link-button { padding: 8px 10px; background: transparent; color: var(--accent); }
.link-button:hover { background: #edf5f0; }
.dashboard-shell { height: calc(100vh - 58px); padding: 10px; }
.dashboard-shell iframe { width: 100%; height: 100%; border: 1px solid var(--line); border-radius: 12px; background: #fff; }

.budgets-page { min-height: 100vh; background: #eef1ed; }
.budgets-shell { width: min(1440px, 100%); margin: 0 auto; padding: 34px 28px 54px; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.page-heading .eyebrow { margin: 0 0 8px; }
.page-heading h1 { font-size: clamp(28px, 4vw, 42px); }
.subline { margin: 9px 0 0; color: var(--muted); font-size: 13px; }
.source-link { flex: 0 0 auto; padding: 10px 14px; border: 1px solid #cad7ce; border-radius: 10px; color: var(--accent-dark); background: rgba(255,255,255,.7); font-size: 13px; font-weight: 700; text-decoration: none; }
.source-link:hover { background: #fff; }
.budget-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.account-kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.kpi-card { min-height: 135px; padding: 21px; border: 1px solid var(--line); border-radius: 16px; background: var(--card); box-shadow: 0 8px 26px rgba(24,33,29,.045); }
.kpi-card > span { display: block; color: var(--muted); font-size: 12px; font-weight: 750; letter-spacing: .02em; }
.kpi-card strong { display: block; margin: 12px 0 9px; font-size: clamp(22px, 2.3vw, 31px); line-height: 1; letter-spacing: -.04em; }
.kpi-card small { color: #849088; font-size: 12px; }
.accent-card { color: #fff; border-color: var(--accent); background: linear-gradient(140deg, var(--accent), #0d593c); }
.accent-card > span, .accent-card small { color: #cde7d9; }
.data-note { display: flex; align-items: flex-start; gap: 12px; margin: 16px 0; padding: 14px 16px; border: 1px solid #d5e1d8; border-radius: 12px; color: #52615a; background: #f8fbf8; font-size: 12px; line-height: 1.55; }
.data-note > span { display: grid; flex: 0 0 22px; width: 22px; height: 22px; place-items: center; border-radius: 50%; color: white; background: var(--accent); font-weight: 800; }
.data-note p { margin: 1px 0 0; }
.warning-note { border-color: #ecd9b9; color: #77551e; background: #fff9ee; }
.warning-note > span { background: #ad7823; }
.registry-tabs { display: flex; gap: 6px; margin: 20px 0 0; padding: 5px; overflow-x: auto; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,255,255,.72); scrollbar-width: thin; }
.registry-tabs button { display: inline-flex; flex: 1 0 auto; align-items: center; justify-content: center; gap: 9px; min-height: 43px; padding: 9px 14px; border: 0; border-radius: 10px; color: #647169; background: transparent; font: inherit; font-size: 12px; font-weight: 750; white-space: nowrap; cursor: pointer; }
.registry-tabs button:hover { color: var(--ink); background: #f4f7f5; }
.registry-tabs button.active { color: #fff; background: var(--accent); box-shadow: 0 5px 14px rgba(20,108,74,.2); }
.registry-tabs button span { min-width: 24px; padding: 3px 6px; border-radius: 999px; color: #68766e; background: #e8eeea; font-size: 9px; }
.registry-tabs button.active span { color: var(--accent-dark); background: #dff1e7; }
.registry-visibility-bar { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-top: 10px; padding: 13px 15px; border: 1px solid #d5e1d8; border-radius: 14px; background: #f8fbf8; }
.registry-visibility-bar > div:first-child { display: grid; gap: 4px; }
.registry-visibility-bar strong { font-size: 12px; }
.registry-visibility-bar small { color: var(--muted); font-size: 10px; line-height: 1.4; }
.registry-visibility-actions { display: flex; flex: 0 0 auto; align-items: center; gap: 8px; }
.visibility-switch { display: inline-flex; align-items: center; gap: 7px; min-height: 34px; padding: 7px 10px; border-radius: 9px; color: #52615a; background: #e9f1eb; font-size: 10px; font-weight: 750; cursor: pointer; }
.visibility-switch input { margin: 0; accent-color: var(--accent); }
.visibility-switch span { min-width: 20px; padding: 2px 5px; border-radius: 999px; color: var(--accent-dark); background: #fff; text-align: center; }
.secondary-button { min-height: 34px; padding: 7px 10px; border: 1px solid #c9d5cc; border-radius: 9px; color: var(--accent-dark); background: #fff; font-size: 10px; }
.secondary-button:hover { color: #fff; border-color: var(--accent); background: var(--accent); }
.secondary-button.danger-outline { color: #9a493f; }
.secondary-button.danger-outline:hover { color: #fff; border-color: #a95146; background: #a95146; }
.secondary-button:disabled, .secondary-button:disabled:hover { color: #9ca59f; border-color: #e0e5e1; background: #f1f3f2; cursor: not-allowed; }
.registry-toolbar { display: grid; grid-template-columns: minmax(240px, 2fr) repeat(3, minmax(170px, 1fr)); gap: 12px; margin: 10px 0 18px; padding: 15px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,255,255,.78); }
.registry-toolbar label { gap: 6px; color: var(--muted); font-size: 10px; letter-spacing: .05em; text-transform: uppercase; }
.registry-toolbar input, .registry-toolbar select { min-height: 42px; padding: 10px 12px; border: 1px solid #cbd4cd; border-radius: 9px; color: var(--ink); background: #fff; font: inherit; text-transform: none; }
.registry-toolbar select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(20,108,74,.12); outline: none; }
.registry-toolbar select:disabled { color: #9ca59f; border-color: #e0e5e1; background: #f1f3f2; cursor: not-allowed; }
.budget-table-card { overflow: hidden; border: 1px solid var(--line); border-radius: 16px; background: var(--card); box-shadow: 0 10px 30px rgba(24,33,29,.05); }
.registry-card { margin-top: 18px; }
.table-count { flex: 0 0 auto; padding: 6px 9px; border-radius: 999px; color: var(--muted); background: #eef1ef; font-size: 10px; font-weight: 750; }
.table-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 20px 22px; border-bottom: 1px solid var(--line); }
.table-heading h2, .empty-state h2 { margin: 0; font-size: 18px; letter-spacing: -.02em; }
.table-heading p, .empty-state p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.legend { display: flex; gap: 14px; color: var(--muted); font-size: 11px; }
.legend span { display: flex; align-items: center; gap: 6px; }
.dot, .status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }
.danger-dot { background: #d46252; }
.good-dot { background: #2a8a60; }
.budget-table-wrap { overflow-x: auto; }
.budget-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.budget-table th { padding: 12px 16px; color: #77837c; background: #fafbfa; font-size: 10px; font-weight: 800; letter-spacing: .055em; text-align: right; text-transform: uppercase; white-space: nowrap; }
.budget-table th:first-child { text-align: left; }
.budget-table td { padding: 17px 16px; border-top: 1px solid #edf0ed; text-align: right; vertical-align: middle; white-space: nowrap; }
.budget-table tbody tr:first-child td { border-top: 0; }
.budget-table td:first-child { min-width: 220px; text-align: left; white-space: normal; }
.budget-table td strong { font-variant-numeric: tabular-nums; }
.budget-table td small { display: block; margin-top: 5px; color: #8a958f; font-size: 10px; }
.registry-table th:first-child, .registry-table td:first-child { text-align: left; }
.registry-table td { white-space: normal; }
.registry-table td code { font-size: 11px; overflow-wrap: anywhere; }
.registry-table tr.is-personally-hidden { background: #faf3f1; opacity: .62; }
.row-visibility-button { min-height: 30px; padding: 6px 9px; border: 1px solid #d0d9d3; border-radius: 8px; color: #607068; background: #fff; font-size: 9px; white-space: nowrap; }
.row-visibility-button:hover { color: #fff; border-color: #67756e; background: #67756e; }
.row-visibility-button.restore { color: var(--accent-dark); border-color: #b8d3c3; background: #e8f5ed; }
.row-visibility-button:disabled { color: #9b8a86; border-color: #e8dcd9; background: #f7efed; cursor: not-allowed; }
.account-registry-table td:nth-child(2), .account-registry-table td:nth-child(3) { min-width: 210px; text-align: left; }
.account-name { display: flex; align-items: center; gap: 11px; }
.account-name .status-dot { flex: 0 0 auto; width: 9px; height: 9px; background: #94a099; box-shadow: 0 0 0 4px #eef1ef; }
.state-needs_funding .status-dot { background: #d46252; box-shadow: 0 0 0 4px #fbeceb; }
.state-funded .status-dot, .state-complete .status-dot { background: #2a8a60; box-shadow: 0 0 0 4px #e8f5ed; }
.progress { width: 92px; height: 5px; margin: 7px 0 0 auto; overflow: hidden; border-radius: 99px; background: #e7ebe8; }
.progress span { display: block; height: 100%; border-radius: inherit; background: var(--accent); }
.danger-text { color: #b44538; }
.warning-text { color: #9c6a19 !important; }
.state-pill { display: inline-flex; padding: 5px 8px; border-radius: 999px; font-size: 10px; font-weight: 800; }
.state-pill.good { color: #176542; background: #e8f5ed; }
.state-pill.neutral { color: #66716b; background: #eef1ef; }
.mapping-pill { display: inline-flex; margin-top: 7px; padding: 4px 7px; border-radius: 999px; font-size: 9px; font-weight: 800; text-transform: none; }
.mapping-confirmed { color: #176542; background: #e8f5ed; }
.mapping-suggested { color: #815c1e; background: #fff3d9; }
.mapping-unmatched { color: #8b3c34; background: #fdecea; }
.tag-list { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; max-width: 260px; margin-left: auto; }
.tag-list span { padding: 4px 6px; border-radius: 6px; color: #53635b; background: #edf2ee; font-size: 9px; font-weight: 700; }
.registry-details summary { display: flex; align-items: center; justify-content: space-between; padding: 20px 22px; cursor: pointer; list-style: none; }
.registry-details summary::-webkit-details-marker { display: none; }
.registry-details summary::after { color: var(--accent); content: "Показать"; font-size: 11px; font-weight: 800; }
.registry-details[open] summary { border-bottom: 1px solid var(--line); }
.registry-details[open] summary::after { content: "Скрыть"; }
.registry-details summary span { display: grid; gap: 5px; }
.registry-details summary small { color: var(--muted); font-size: 11px; font-weight: 400; }
.registry-table tr[hidden] { display: none !important; }
.registry-panel[hidden] { display: none !important; }
.empty-state { padding: 54px 24px; border: 1px solid var(--line); border-radius: 16px; background: #fff; text-align: center; }

@media (max-width: 980px) {
  .budget-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .account-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .registry-toolbar { grid-template-columns: 1fr 1fr; }
  .registry-toolbar label:first-child { grid-column: 1 / -1; }
  .registry-visibility-bar { align-items: flex-start; flex-direction: column; }
  .registry-visibility-actions { flex-wrap: wrap; }
  .portal-nav { margin-left: 6px; }
}

@media (max-width: 600px) {
  .auth-card { padding: 30px 24px; }
  .topbar { height: 56px; padding: 0 10px; }
  .brand > strong { display: none; }
  .mark.small { margin-right: 0; }
  .portal-nav a { padding: 8px 9px; }
  .account span { display: none; }
  .account .scope-badge { display: inline; }
  .dashboard-shell { padding: 0; }
  .dashboard-shell iframe { border: 0; border-radius: 0; }
  .budgets-shell { padding: 24px 14px 42px; }
  .page-heading { align-items: flex-start; }
  .source-link { display: none; }
  .budget-kpis { grid-template-columns: 1fr 1fr; gap: 9px; }
  .account-kpis { grid-template-columns: 1fr 1fr; gap: 9px; }
  .registry-tabs { margin-top: 16px; }
  .registry-tabs button { flex: 0 0 auto; }
  .registry-visibility-actions { width: 100%; }
  .visibility-switch { flex: 1 0 100%; justify-content: space-between; }
  .registry-toolbar { grid-template-columns: 1fr; }
  .registry-toolbar label:first-child { grid-column: auto; }
  .kpi-card { min-height: 116px; padding: 16px; }
  .kpi-card strong { font-size: 21px; }
  .table-heading { align-items: flex-start; padding: 17px; }
  .legend { display: none; }
  .budget-table-wrap { overflow: visible; }
  .budget-table, .budget-table tbody { display: block; }
  .budget-table thead { display: none; }
  .budget-table tr { display: grid; grid-template-columns: 1fr 1fr; gap: 0; padding: 14px 15px; border-top: 1px solid var(--line); }
  .budget-table tbody tr:first-child { border-top: 0; }
  .budget-table td { display: block; min-width: 0 !important; padding: 9px 6px; border: 0; text-align: left; white-space: normal; }
  .budget-table td:first-child { grid-column: 1 / -1; padding-bottom: 12px; }
  .budget-table td::before { display: block; margin-bottom: 4px; color: #89948e; content: attr(data-label); font-size: 9px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; }
  .budget-table td:first-child::before { display: none; }
  .progress { margin-left: 0; }
  .tag-list { justify-content: flex-start; margin-left: 0; }
  .registry-details summary { padding: 17px; }
}
