:root {
    color-scheme: light;
    --bg: #f5f7f8;
    --surface: #ffffff;
    --surface-soft: #f8faf9;
    --surface-elevated: #ffffff;
    --sidebar: #102a26;
    --sidebar-soft: #173832;
    --text: #18211f;
    --muted: #687672;
    --subtle: #94a19d;
    --line: #e4eae7;
    --green: #1b8b69;
    --green-dark: #11684f;
    --green-soft: #e8f5ef;
    --amber: #c27a22;
    --amber-soft: #fff5e7;
    --red: #c94f54;
    --blue: #4a72d8;
    --purple: #8062c6;
    --shadow: 0 1px 2px rgba(17, 37, 32, 0.03), 0 12px 32px rgba(20, 52, 43, 0.045);
    --radius: 14px;
    --sidebar-width: 246px;
    font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html[data-theme="dark"] {
    color-scheme: dark;
    --bg: #101514;
    --surface: #171e1c;
    --surface-soft: #1b2421;
    --surface-elevated: #1d2523;
    --text: #edf3f0;
    --muted: #9daba6;
    --subtle: #77847f;
    --line: #2a3532;
    --green: #45bd91;
    --green-dark: #7bd5b3;
    --green-soft: #183a30;
    --amber: #e2a654;
    --amber-soft: #3b2c18;
    --shadow: 0 14px 36px rgba(0, 0, 0, 0.18);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
button, input, select { font: inherit; }
button { color: inherit; }
a { color: inherit; }

.skip-link { position: fixed; top: 8px; left: 8px; z-index: 1000; padding: 9px 14px; background: var(--surface); border-radius: 8px; transform: translateY(-160%); }
.skip-link:focus { transform: translateY(0); }
.app-shell { min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 20; width: var(--sidebar-width); display: flex; flex-direction: column; padding: 24px 16px 18px; color: #d8e6e1; background: var(--sidebar); }
.brand { display: flex; align-items: center; gap: 11px; padding: 0 10px 29px; }
.brand-mark { width: 33px; height: 33px; display: grid; place-items: center; border-radius: 9px; background: #d8f3e7; color: #133f33; font-size: 17px; font-weight: 800; font-family: Georgia, serif; }
.brand-copy { display: flex; flex-direction: column; line-height: 1.2; }
.brand-copy strong { color: #fff; font-size: 15px; letter-spacing: 0.01em; }
.brand-copy small { margin-top: 3px; color: #88a59d; font-size: 9px; text-transform: uppercase; letter-spacing: 0.12em; }
.main-nav { display: flex; flex-direction: column; gap: 3px; }
.nav-label { margin: 20px 12px 7px; color: #66847b; font-size: 9px; font-weight: 700; letter-spacing: 0.13em; text-transform: uppercase; }
.nav-label:first-child { margin-top: 0; }
.nav-link { display: flex; align-items: center; gap: 11px; padding: 9px 11px; border-radius: 8px; color: #a9beb8; text-decoration: none; font-size: 12px; font-weight: 550; transition: .18s ease; }
.nav-link:hover { background: rgba(255,255,255,.05); color: #f2faf7; }
.nav-link.is-active { background: var(--sidebar-soft); color: #fff; box-shadow: inset 2px 0 #6fd3aa; }
.nav-link.is-disabled { cursor: default; opacity: .68; }
.nav-icon { width: 23px; height: 23px; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.09); border-radius: 6px; color: #86a39a; font-size: 8px; font-weight: 700; }
.nav-link.is-active .nav-icon { border-color: rgba(112, 211, 170, .35); color: #83d9b6; }
.sidebar-footer { margin-top: auto; padding: 13px 11px 0; border-top: 1px solid rgba(255,255,255,.08); }
.data-health { display: flex; align-items: center; gap: 9px; }
.health-dot { width: 8px; height: 8px; border: 2px solid #72d5ad; border-radius: 50%; box-shadow: 0 0 0 3px rgba(114,213,173,.12); }
.data-health span:last-child { display: flex; flex-direction: column; }
.data-health small { color: #78958c; font-size: 9px; }
.data-health strong { color: #c9dad5; font-size: 10px; }
.sidebar-footer p { margin: 10px 0 0 17px; color: #66847b; font-size: 9px; }

.workspace { min-height: 100vh; margin-left: var(--sidebar-width); }
.topbar { height: 67px; position: sticky; top: 0; z-index: 15; display: flex; align-items: center; justify-content: space-between; padding: 0 31px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(16px); }
.topbar-title { display: flex; flex-direction: column; line-height: 1.25; }
.topbar-title small { color: var(--subtle); font-size: 9px; text-transform: uppercase; letter-spacing: .11em; }
.topbar-title strong { margin-top: 2px; font-size: 13px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.icon-button { width: 35px; height: 35px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); cursor: pointer; }
.icon-button:hover { background: var(--surface-soft); }
.menu-button { display: none; }
.profile-button { display: flex; align-items: center; gap: 9px; padding: 0 7px 0 0; border: 0; color: inherit; background: transparent; text-decoration: none; }
.profile-button > span:first-child { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 9px; background: var(--green-soft); color: var(--green-dark); font-size: 10px; font-weight: 750; }
.profile-copy { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.25; }
.profile-copy strong { font-size: 10px; }
.profile-copy small { color: var(--muted); font-size: 9px; }
.logout-form { margin: 0; }
.logout-button { padding: 6px 9px; border: 1px solid var(--line); border-radius: 8px; color: var(--muted); background: var(--surface); font-size: 9px; cursor: pointer; }
.logout-button:hover { color: var(--text); background: var(--surface-soft); }
.setup-banner { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 31px; padding: 6px 20px; color: #76501c; background: var(--amber-soft); border-bottom: 1px solid color-mix(in srgb, var(--amber) 20%, transparent); font-size: 10px; }
.setup-banner strong { text-transform: uppercase; letter-spacing: .06em; }
.demo-banner { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 31px; padding: 6px 20px; color: #76501c; background: var(--amber-soft); border-bottom: 1px solid color-mix(in srgb, var(--amber) 20%, transparent); font-size: 10px; }
.demo-banner strong { text-transform: uppercase; letter-spacing: .06em; }
.main-content { max-width: 1500px; margin: 0 auto; padding: 28px 31px 40px; }

.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.eyebrow { margin: 0 0 4px; color: var(--green); font-size: 8px; font-weight: 800; letter-spacing: .13em; }
h1, h2, h3, p { overflow-wrap: anywhere; }
h1 { margin: 0; font-size: 25px; line-height: 1.2; letter-spacing: -.025em; }
.heading-copy { margin: 7px 0 0; color: var(--muted); font-size: 11px; }
.filter-bar { display: flex; align-items: center; gap: 8px; }
.filter-bar button { min-width: 120px; display: grid; grid-template-columns: 1fr auto; grid-template-areas: "small span" "strong span"; padding: 7px 10px 6px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); text-align: left; cursor: pointer; }
.filter-bar button small { grid-area: small; color: var(--subtle); font-size: 8px; }
.filter-bar button strong { grid-area: strong; font-size: 10px; }
.filter-bar button span { grid-area: span; align-self: center; color: var(--subtle); font-size: 12px; }
.section-block { margin-bottom: 16px; }
.section-heading, .panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.compact-heading { align-items: flex-end; margin-bottom: 10px; }
.section-heading h2, .panel-heading h2 { margin: 0; font-size: 14px; line-height: 1.3; letter-spacing: -.015em; }
.freshness { display: flex; align-items: center; gap: 6px; margin: 0 2px 2px; color: var(--subtle); font-size: 8px; }
.freshness span { width: 6px; height: 6px; border-radius: 50%; background: var(--green); }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 9px; }
.metric-card { min-width: 0; padding: 13px 14px 10px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); box-shadow: 0 1px 1px rgba(17, 37, 32, .02); transition: transform .15s ease, box-shadow .15s ease; }
.metric-card:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.metric-topline { display: flex; align-items: center; justify-content: space-between; }
.metric-topline h3 { margin: 0; color: var(--muted); font-size: 9px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; }
.metric-topline button { border: 0; color: var(--subtle); background: transparent; cursor: pointer; line-height: 1; }
.metric-value { margin: 7px 0 3px; font-size: clamp(17px, 1.55vw, 22px); font-weight: 725; letter-spacing: -.035em; white-space: nowrap; }
.metric-comparison { display: flex; align-items: center; gap: 5px; color: var(--subtle); font-size: 8px; }
.delta { padding: 1px 4px; border-radius: 4px; font-weight: 750; }
.delta.up { color: var(--green-dark); background: var(--green-soft); }
.delta.down { color: var(--red); background: color-mix(in srgb, var(--red) 10%, transparent); }
.metric-attention .delta.down { color: var(--amber); background: var(--amber-soft); }
.metric-footer { height: 30px; display: flex; align-items: flex-end; justify-content: space-between; margin-top: 5px; border-top: 1px solid var(--line); color: var(--subtle); font-size: 8px; }
.sparkline { width: 72px; height: 24px; }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.75fr) minmax(280px, .85fr); gap: 11px; margin-top: 11px; }
.lower-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(300px, .8fr); gap: 11px; margin-top: 11px; }
.panel { min-width: 0; padding: 17px 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.panel-heading { align-items: center; }
.legend { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 11px; color: var(--muted); font-size: 8px; }
.legend span::before { content: ""; width: 7px; height: 7px; display: inline-block; margin-right: 5px; border-radius: 2px; }
.legend-revenue::before { background: var(--green); }
.legend-ebitda::before { background: var(--blue); }
.legend-income::before { background: var(--purple); }
.chart-wrap { position: relative; height: 255px; margin-top: 15px; }
.main-chart { width: 100%; height: 100%; }
.text-button { padding: 0; border: 0; color: var(--green); background: none; font-size: 8px; font-weight: 700; cursor: pointer; }
.cost-list { display: flex; flex-direction: column; gap: 14px; margin: 19px 0 17px; }
.cost-row { display: grid; grid-template-columns: minmax(120px, 1fr) minmax(90px, .9fr); align-items: center; gap: 12px; }
.cost-label { display: flex; align-items: center; gap: 8px; }
.cost-label > span:last-child { display: flex; flex-direction: column; }
.cost-label strong { font-size: 9px; font-weight: 650; }
.cost-label small { margin-top: 1px; color: var(--subtle); font-size: 8px; }
.cost-dot { width: 7px; height: 7px; flex: 0 0 auto; border-radius: 50%; }
.cost-1 { background: #257a65; } .cost-2 { background: #5f8e80; } .cost-3 { background: #89aaa0; } .cost-4 { background: #b1c6c0; } .cost-5 { background: #d4dfdc; }
.cost-share { display: grid; grid-template-columns: 1fr 25px; align-items: center; gap: 7px; }
.cost-share > div { height: 4px; overflow: hidden; border-radius: 20px; background: var(--line); }
.cost-share > div span { width: 0; height: 100%; display: block; border-radius: inherit; background: var(--green); transition: width .5s ease; }
.cost-share strong { color: var(--muted); font-size: 8px; text-align: right; }
.cost-total { display: flex; align-items: center; justify-content: space-between; padding-top: 12px; border-top: 1px solid var(--line); }
.cost-total span { color: var(--muted); font-size: 8px; }
.cost-total strong { font-size: 11px; }
.rule-badge, .status-chip { padding: 3px 7px; border-radius: 20px; color: var(--green-dark); background: var(--green-soft); font-size: 7px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.movement-list { margin-top: 13px; }
.movement-item { display: grid; grid-template-columns: 27px 1fr 20px; gap: 9px; align-items: start; padding: 11px 0; border-top: 1px solid var(--line); }
.movement-item:first-child { border-top: 0; }
.movement-icon { width: 25px; height: 25px; display: grid; place-items: center; border-radius: 7px; font-size: 11px; font-weight: 800; }
.movement-positive { color: var(--green-dark); background: var(--green-soft); }
.movement-attention { color: var(--amber); background: var(--amber-soft); }
.movement-title { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.movement-title span { color: var(--green); font-size: 7px; font-weight: 750; text-transform: uppercase; letter-spacing: .05em; }
.movement-title strong { font-size: 9px; }
.movement-item p { margin: 3px 0 0; color: var(--muted); font-size: 8px; }
.movement-item button { border: 0; color: var(--subtle); background: none; font-size: 18px; cursor: pointer; }
.forecast-hero { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin: 20px 0 14px; }
.forecast-hero > div:first-child { display: flex; flex-direction: column; }
.forecast-hero small { color: var(--muted); font-size: 8px; }
.forecast-hero strong { margin: 3px 0 0; font-size: 21px; letter-spacing: -.03em; }
.forecast-hero span { color: var(--subtle); font-size: 8px; }
.forecast-ring { width: 64px; height: 64px; display: grid; align-content: center; justify-items: center; border: 5px solid var(--green-soft); border-top-color: var(--green); border-right-color: var(--green); border-radius: 50%; transform: rotate(8deg); }
.forecast-ring span, .forecast-ring small { transform: rotate(-8deg); }
.forecast-ring span { color: var(--green-dark); font-size: 13px; font-weight: 750; }
.forecast-ring small { font-size: 6px; }
.forecast-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.forecast-stats div { display: flex; flex-direction: column; padding: 9px 10px; border-radius: 8px; background: var(--surface-soft); }
.forecast-stats small { color: var(--muted); font-size: 7px; }
.forecast-stats strong { margin-top: 2px; font-size: 10px; }
.forecast-note { display: flex; gap: 6px; margin: 12px 0 0; color: var(--subtle); font-size: 7px; }
.forecast-note span { width: 13px; height: 13px; display: grid; place-items: center; flex: 0 0 auto; border: 1px solid var(--line); border-radius: 50%; font-weight: 700; }
.empty-state { max-width: 620px; margin: 70px auto; padding: 46px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); text-align: center; }
.empty-mark { width: 47px; height: 47px; display: grid; place-items: center; margin: 0 auto 18px; border-radius: 12px; color: var(--green-dark); background: var(--green-soft); font: 800 22px Georgia, serif; }
.empty-state h2 { margin: 0; font-size: 19px; }
.empty-state p { max-width: 450px; margin: 9px auto 0; color: var(--muted); font-size: 11px; }

.auth-body { min-height: 100vh; background: radial-gradient(circle at 15% 10%, color-mix(in srgb, var(--green) 13%, transparent), transparent 35%), var(--bg); }
.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 28px 18px; }
.auth-card { width: min(100%, 430px); padding: 34px; border: 1px solid var(--line); border-radius: 20px; background: var(--surface); box-shadow: 0 24px 70px rgba(16, 42, 38, .12); }
.auth-brand { display: flex; align-items: center; gap: 11px; }
.auth-brand > span:last-child { display: flex; flex-direction: column; line-height: 1.2; }
.auth-brand strong { font-size: 15px; }
.auth-brand small { margin-top: 3px; color: var(--subtle); font-size: 8px; letter-spacing: .12em; text-transform: uppercase; }
.auth-heading { margin: 30px 0 22px; }
.auth-heading h1 { font-size: 27px; }
.auth-heading > p:last-child { margin: 8px 0 0; color: var(--muted); font-size: 11px; }
.auth-notice, .auth-error { display: flex; flex-direction: column; gap: 3px; margin-bottom: 16px; padding: 11px 12px; border-radius: 9px; font-size: 10px; }
.auth-notice { color: #76501c; background: var(--amber-soft); }
.auth-notice span { opacity: .86; }
.auth-error { color: var(--red); background: color-mix(in srgb, var(--red) 9%, transparent); }
.auth-form { display: flex; flex-direction: column; }
.auth-form label { margin: 12px 0 5px; color: var(--muted); font-size: 10px; font-weight: 650; }
.auth-form input { width: 100%; min-height: 43px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; color: var(--text); background: var(--surface); outline: none; }
.auth-form input:focus { border-color: var(--green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 14%, transparent); }
.auth-form button { min-height: 43px; margin-top: 20px; border: 0; border-radius: 9px; color: #fff; background: var(--green-dark); font-weight: 700; cursor: pointer; }
.auth-form button:hover { background: var(--green); }
.auth-form button:disabled { cursor: not-allowed; opacity: .5; }
.auth-security-note { display: flex; align-items: center; justify-content: center; gap: 6px; margin: 20px 0 0; color: var(--subtle); font-size: 8px; }
.auth-security-note span { color: var(--green); font-size: 7px; }
.success-message { margin: 0 0 14px; padding: 10px 12px; border-radius: 9px; color: var(--green-dark); background: var(--green-soft); font-size: 10px; }
.admin-heading { align-items: flex-start; }
.admin-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(300px, .75fr); gap: 12px; }
.table-wrap { margin-top: 16px; overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 10px; }
.data-table th { padding: 8px 9px; border-bottom: 1px solid var(--line); color: var(--subtle); text-align: left; text-transform: uppercase; letter-spacing: .06em; font-size: 7px; }
.data-table td { padding: 11px 9px; border-bottom: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.data-table td:first-child { display: flex; flex-direction: column; }
.data-table td strong { color: var(--text); }
.data-table td small { margin-top: 2px; color: var(--subtle); }
.role-chip { padding: 3px 6px; border-radius: 12px; color: var(--green-dark); background: var(--green-soft); font-size: 7px; font-weight: 750; }
.admin-form { display: flex; flex-direction: column; margin-top: 12px; }
.admin-form label { margin: 10px 0 4px; color: var(--muted); font-size: 9px; font-weight: 650; }
.admin-form input, .admin-form select { min-height: 38px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; color: var(--text); background: var(--surface); outline: none; }
.admin-form input:focus, .admin-form select:focus { border-color: var(--green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 12%, transparent); }
.admin-form p { margin: 7px 0 0; color: var(--subtle); font-size: 8px; }
.admin-form button { min-height: 39px; margin-top: 15px; border: 0; border-radius: 8px; color: #fff; background: var(--green-dark); font-size: 10px; font-weight: 700; cursor: pointer; }

@media (max-width: 1120px) {
    .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .dashboard-grid, .lower-grid { grid-template-columns: 1fr; }
    .admin-grid { grid-template-columns: 1fr; }
    .cost-list { display: grid; grid-template-columns: 1fr 1fr; }
}

@media (max-width: 780px) {
    .sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: 20px 0 50px rgba(0,0,0,.24); }
    .sidebar.is-open { transform: translateX(0); }
    .workspace { margin-left: 0; }
    .topbar { height: 61px; padding: 0 16px; }
    .menu-button { display: grid; }
    .main-content { padding: 22px 16px 32px; }
    .page-heading { align-items: flex-start; flex-direction: column; }
    .filter-bar { width: 100%; overflow-x: auto; padding-bottom: 3px; }
    .filter-bar button { min-width: 112px; }
    .demo-banner { align-items: flex-start; flex-direction: column; gap: 0; padding: 7px 16px; }
    .setup-banner { align-items: flex-start; flex-direction: column; gap: 0; padding: 7px 16px; }
    .profile-copy { display: none; }
}

@media (max-width: 540px) {
    h1 { font-size: 22px; }
    .metric-grid { grid-template-columns: 1fr; }
    .metric-value { font-size: 22px; }
    .cost-list { grid-template-columns: 1fr; }
    .panel { padding: 15px; }
    .panel-heading { align-items: flex-start; }
    .performance-panel .panel-heading { flex-direction: column; }
    .legend { justify-content: flex-start; }
    .chart-wrap { height: 220px; }
    .forecast-hero { align-items: flex-start; }
    .auth-card { padding: 26px 22px; }
}

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