:root {
    --bg: #f4f7fb;
    --surface: #ffffff;
    --text: #172033;
    --muted: #64748b;
    --border: #dfe7f1;
    --primary: #2357d9;
    --primary-dark: #153b9f;
    --success: #12805c;
    --warning: #b66a00;
    --danger: #bd2c3f;
    --sidebar: #101a33;
    --radius: 14px;
    --shadow: 0 14px 36px rgba(33, 51, 84, .09);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { min-height: 100vh; margin: 0; color: var(--text); background: var(--bg); }
a { color: var(--primary); }
button, input, select { font: inherit; }

.auth-shell { background: radial-gradient(circle at 15% 15%, #dce7ff, transparent 32%), linear-gradient(140deg, #f8fbff, #edf3ff); }
.auth-container { width: min(100% - 32px, 470px); margin: 0 auto; padding: 64px 0; }
.auth-brand { justify-content: center; margin-bottom: 22px; color: var(--text); }
.auth-card, .panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px; }
.auth-card .text-link { display: inline-block; margin-top: 20px; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; text-decoration: none; color: #fff; }
.brand-mark { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 11px; background: var(--primary); color: #fff; font-size: 13px; letter-spacing: .04em; }

.app-shell { display: grid; grid-template-columns: 264px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 24px 18px; background: var(--sidebar); color: #fff; display: flex; flex-direction: column; overflow-y: auto; z-index: 20; }
.nav-list { display: grid; gap: 6px; margin-top: 34px; }
.nav-list a, .nav-disabled, .sidebar-footer a, .link-button { width: 100%; padding: 11px 12px; border-radius: 9px; color: #dce5ff; text-decoration: none; background: transparent; border: 0; text-align: left; display: flex; justify-content: space-between; cursor: pointer; }
.nav-list a:hover, .sidebar-footer a:hover, .link-button:hover { background: rgba(255,255,255,.09); color: #fff; }
.nav-disabled { opacity: .55; cursor: default; }
.nav-disabled small { font-size: 10px; }
.sidebar-footer { margin-top: auto; padding-top: 20px; border-top: 1px solid rgba(255,255,255,.12); }
.sidebar-footer form { margin: 0; }
.main-column { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 10; min-height: 72px; display: flex; justify-content: flex-end; align-items: center; gap: 14px; padding: 12px 28px; background: rgba(255,255,255,.94); border-bottom: 1px solid var(--border); backdrop-filter: blur(8px); }
.topbar > div { display: grid; text-align: right; }
.menu-button { display: none; margin-right: auto; }
.content { width: min(100%, 1440px); margin: 0 auto; padding: 30px; }
.breadcrumb { display: flex; gap: 8px; color: var(--muted); font-size: 13px; margin-bottom: 18px; }
.breadcrumb > * + *::before { content: "/"; margin-right: 8px; color: #a2aec0; }
.page-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 24px; }
.page-heading h1, .section-heading h1 { margin: 4px 0 8px; font-size: clamp(26px, 4vw, 38px); }
.page-heading p, .section-heading p { margin: 0; color: var(--muted); line-height: 1.6; }
.eyebrow { color: var(--primary); font-size: 12px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.muted { color: var(--muted); font-size: 13px; }

.card-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 22px; }
.metric-card { display: grid; gap: 7px; min-height: 128px; padding: 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.metric-card span, .metric-card small { color: var(--muted); }
.metric-card strong { font-size: 23px; overflow-wrap: anywhere; }
.empty-state, .error-state { text-align: center; padding: 56px 28px; }
.empty-icon { width: 64px; height: 64px; border-radius: 18px; display: grid; place-items: center; margin: 0 auto 16px; color: #fff; background: var(--primary); font-weight: 800; }
.empty-state p, .error-state p { max-width: 680px; margin: 0 auto 22px; color: var(--muted); line-height: 1.65; }
.two-column { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.panel h2 { margin-top: 0; }

.form-stack { display: grid; gap: 17px; margin-top: 24px; }
label { display: grid; gap: 7px; font-size: 14px; font-weight: 700; }
label small { color: var(--muted); font-weight: 400; line-height: 1.5; }
input, select { width: 100%; min-height: 46px; border: 1px solid #c9d5e4; border-radius: 9px; padding: 10px 12px; color: var(--text); background: #fff; }
input[type="checkbox"], input[type="color"] { width: auto; }
input:focus, select:focus { outline: 3px solid rgba(35,87,217,.16); border-color: var(--primary); }
input:disabled { color: var(--muted); background: #f3f5f8; }
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 10px 18px; border: 1px solid var(--border); border-radius: 9px; background: #fff; color: var(--text); text-decoration: none; font-weight: 800; cursor: pointer; }
.button-primary { color: #fff; background: var(--primary); border-color: var(--primary); }
.button-primary:hover { background: var(--primary-dark); }
.button-danger { color: #fff; background: var(--danger); border-color: var(--danger); }
.alert { border-radius: 10px; padding: 13px 15px; margin-bottom: 18px; line-height: 1.5; }
.alert-error { color: #7d1726; background: #ffedf0; border: 1px solid #ffc8d0; }
.alert-success { color: #075c40; background: #e8f8f1; border: 1px solid #b8ead7; }
.status-badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 7px 11px; font-size: 12px; font-weight: 800; }
.status-success { color: #075c40; background: #dcf7ec; }
.status-warning { color: #7b4800; background: #fff1d8; }
.status-neutral { color: #475569; background: #eef2f6; }
.status-danger { color: #7d1726; background: #ffedf0; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.status-dot { display: inline-block; width: 9px; height: 9px; margin-right: 7px; border-radius: 50%; }
.status-dot.ok { background: var(--success); }
.status-dot.fail { background: var(--danger); }
pre, code { overflow-wrap: anywhere; white-space: pre-wrap; }
.section-gap { margin-top: 20px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 17px; }
.inline-form { align-items: end; }
.inline-form .button { align-self: end; }
.checkbox-label { grid-template-columns: auto 1fr; align-items: start; font-weight: 500; }
.gateway-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.provider-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.provider-grid article { display: grid; gap: 7px; padding: 16px; border: 1px solid var(--border); border-radius: 10px; }
.provider-grid span, .provider-grid small { color: var(--muted); }
.pagination, .tab-nav, .compact-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 16px; }
.compact-actions { margin-top: 0; }
.compact-actions form { display: flex; gap: 8px; align-items: center; margin: 0; }
.compact-actions input { min-width: 150px; }
input[type="file"] { padding: 8px; }
.stacked-form { display: grid; gap: 15px; }
textarea { width: 100%; min-height: 110px; resize: vertical; border: 1px solid #c9d5e4; border-radius: 9px; padding: 10px 12px; color: var(--text); background: #fff; }
textarea:focus { outline: 3px solid rgba(35,87,217,.16); border-color: var(--primary); }
.button-small { min-height: 34px; padding: 6px 10px; font-size: 12px; }
.button-secondary { color: var(--primary); background: #edf3ff; border-color: #cbdafe; }
.badge { display: inline-flex; border-radius: 999px; padding: 5px 9px; color: #334155; background: #eef2f6; font-size: 12px; font-weight: 800; }
.text-danger { color: var(--danger); }
.break-word { word-break: break-all; }
.details-list { display: grid; grid-template-columns: minmax(120px, .35fr) 1fr; gap: 10px 16px; }
.details-list dt { color: var(--muted); font-weight: 700; }
.details-list dd { margin: 0; }
.section-header, .page-header { display: flex; align-items: start; justify-content: space-between; gap: 16px; }
.stats-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card { display: grid; gap: 6px; padding: 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.stat-card span, .stat-card small { color: var(--muted); }
.stat-card strong { font-size: 20px; }
.portal-shell { min-height: 100vh; background: #f4f7fb; }
.portal-header { position: sticky; z-index: 10; top: 0; min-height: 68px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 12px max(18px, calc((100vw - 1180px)/2)); background: #fff; border-bottom: 1px solid var(--border); }
.portal-content { width: min(100% - 32px, 1180px); margin: 0 auto; padding: 28px 0 60px; }
.portal-list-item { display: grid; gap: 12px; padding: 16px 0; border-bottom: 1px solid var(--border); }
.portal-list-item > div { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.portal-list-item small { display: block; color: var(--muted); }
.portal-list-item details { width: 100%; }
.compact-list { margin: 16px 0 0; padding-left: 18px; line-height: 1.8; }

.public-shell { background: #f7f9fc; }
.public-header { width: min(100% - 36px, 1180px); margin: 0 auto; min-height: 78px; display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.public-header nav { display: flex; align-items: center; gap: 20px; }
.public-header nav > a:not(.button) { color: var(--text); font-weight: 700; text-decoration: none; }
.public-brand { color: var(--text); }
.public-main { min-height: calc(100vh - 150px); }
.public-alert { width: min(100% - 36px, 980px); margin: 16px auto; }
.public-footer { width: min(100% - 36px, 1180px); margin: 40px auto 0; min-height: 72px; display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--border); color: var(--muted); }
.hero { width: min(100% - 36px, 1180px); margin: 58px auto 36px; display: grid; grid-template-columns: 1.35fr .65fr; gap: 34px; align-items: center; }
.hero-copy h1 { margin: 10px 0 18px; font-size: clamp(38px, 6vw, 68px); line-height: 1.02; letter-spacing: -.04em; }
.hero-copy p { color: var(--muted); font-size: 19px; line-height: 1.7; max-width: 740px; }
.hero-actions { display: flex; gap: 12px; margin-top: 28px; }
.hero-panel { padding: 28px; color: #fff; background: linear-gradient(145deg, #101a33, #224fbf); border-radius: 22px; box-shadow: var(--shadow); }
.hero-panel > span { color: #9fb8ff; text-transform: uppercase; font-size: 12px; font-weight: 800; letter-spacing: .1em; }
.hero-panel > strong { display: block; margin: 8px 0 20px; font-size: 28px; }
.hero-panel ul { margin: 0; padding-left: 20px; line-height: 2; }
.feature-strip { width: min(100% - 36px, 1180px); margin: 0 auto; display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.feature-strip article { display: grid; gap: 5px; padding: 22px; border: 1px solid var(--border); background: #fff; border-radius: var(--radius); }
.feature-strip span { color: var(--muted); }
.public-heading { width: min(100% - 36px, 900px); margin: 56px auto 30px; text-align: center; }
.public-heading.compact { margin-top: 38px; }
.public-heading h1 { margin: 8px 0; font-size: clamp(32px, 5vw, 52px); }
.public-heading p { color: var(--muted); line-height: 1.65; }
.pricing-grid { width: min(100% - 36px, 1180px); margin: 0 auto; display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.pricing-card { display: flex; flex-direction: column; padding: 26px; border: 1px solid var(--border); border-radius: 18px; background: #fff; box-shadow: var(--shadow); }
.pricing-card p, .pricing-card li { color: var(--muted); line-height: 1.55; }
.pricing-card ul { flex: 1; padding-left: 20px; }
.price { display: block; margin: 16px 0; font-size: 25px; }
.public-form-card, .legal-document { width: min(100% - 36px, 880px); margin: 0 auto; padding: 30px; background: #fff; border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow); }
.public-form-card.narrow { max-width: 560px; }
.legal-document { margin-top: 52px; }
.legal-text { margin-top: 26px; color: #334155; line-height: 1.8; }
.subscription-summary { grid-template-columns: repeat(4, 1fr); }

.dashboard-heading { align-items: flex-end; }
.dashboard-filters { margin-bottom: 16px; }
.dashboard-filter-grid { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 14px; align-items: end; }
.dashboard-filter-grid label { min-width: 0; }
.cache-state { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px 18px; margin-bottom: 18px; padding: 13px 16px; color: #174723; background: #eaf8ed; border: 1px solid #bfe6c7; border-radius: var(--radius); }
.cache-state-error { color: #7b1d1d; background: #fff0f0; border-color: #f1bcbc; }
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi-card { display: grid; gap: 6px; min-height: 118px; padding: 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 6px 20px rgba(17, 32, 67, .04); }
.kpi-card span, .kpi-card small { color: var(--muted); }
.kpi-card strong { align-self: center; font-size: clamp(19px, 2vw, 25px); overflow-wrap: anywhere; }
.comparison-panel { display: grid; grid-template-columns: .5fr 1.5fr; gap: 20px; margin-bottom: 20px; }
.comparison-panel h2 { margin-bottom: 4px; }
.comparison-values { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.comparison-values span { display: grid; gap: 5px; padding: 12px; color: var(--muted); background: var(--background); border-radius: 10px; }
.comparison-values strong { color: var(--text); }
.dashboard-chart-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-bottom: 20px; }
.chart-panel { min-width: 0; margin: 0; }
.bar-chart { display: grid; gap: 13px; margin-top: 18px; max-height: 420px; overflow-y: auto; }
.bar-group { display: grid; gap: 5px; }
.bar-group > span { color: var(--muted); font-size: 13px; font-weight: 700; }
.bar-line { position: relative; min-height: 23px; display: flex; align-items: center; background: #eef2f8; border-radius: 6px; overflow: hidden; }
.bar-line small { position: relative; z-index: 1; padding: 3px 7px; color: var(--text); font-weight: 700; text-shadow: 0 1px #fff; }
.bar-fill { position: absolute; inset: 0 auto 0 0; min-width: 2px; border-radius: inherit; }
.bar-income { background: #9fe2b0; }
.bar-expense { background: #ffc3c3; }
.bar-provider { background: #b8cdfc; }
.bar-margin { background: #d7c4fb; }
.ranking-grid { margin-bottom: 18px; }
.scope-note { padding: 12px 15px; color: #624500; background: #fff7dc; border: 1px solid #f0da8a; border-radius: 10px; }

@media (max-width: 980px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: fixed; left: 0; transform: translateX(-100%); width: min(82vw, 290px); transition: transform .2s ease; }
    .sidebar.is-open { transform: translateX(0); }
    .menu-button { display: inline-flex; }
    .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .hero, .pricing-grid { grid-template-columns: 1fr; }
    .provider-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .dashboard-filter-grid, .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .comparison-panel { grid-template-columns: 1fr; }
    .comparison-values { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
    .content { padding: 20px 16px; }
    .topbar { padding: 12px 16px; }
    .topbar .muted { display: none; }
    .card-grid, .two-column, .form-grid, .feature-strip, .subscription-summary, .stats-grid, .dashboard-filter-grid, .kpi-grid, .dashboard-chart-grid, .comparison-values { grid-template-columns: 1fr; }
    .section-header, .page-header { display: grid; }
    .portal-content { width: min(100% - 24px, 1180px); padding-top: 18px; }
    .provider-grid { grid-template-columns: 1fr; }
    .page-heading { display: grid; }
    .auth-container { padding: 30px 0; }
    .auth-card, .panel { padding: 22px; }
    .public-header { min-height: 68px; align-items: flex-start; padding: 14px 0; }
    .public-header nav { flex-wrap: wrap; justify-content: flex-end; gap: 10px; }
    .public-header nav > a:not(.button) { display: none; }
    .public-footer { display: grid; gap: 8px; padding: 20px 0; }
    .hero { margin-top: 30px; }
    .hero-actions { align-items: stretch; flex-direction: column; }
    .public-form-card, .legal-document { padding: 22px; }
}

@media (prefers-reduced-motion: reduce) {
    * { scroll-behavior: auto !important; transition: none !important; }
}
