:root {
    --navy: #112b46;
    --navy-2: #193b5d;
    --blue: #1677ff;
    --blue-soft: #eaf3ff;
    --cyan: #21a9a1;
    --green: #14a36d;
    --red: #e65353;
    --amber: #e59b18;
    --ink: #17212b;
    --muted: #687684;
    --line: #e4e9ee;
    --surface: #ffffff;
    --canvas: #f4f6f8;
    --shadow: 0 9px 28px rgba(20, 42, 66, .08);
    --radius: 14px;
    font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
    margin: 0;
    color: var(--ink);
    background: var(--canvas);
    font-size: 14px;
}
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
a { color: inherit; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 236px 1fr; }
.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 24px 16px 18px;
    display: flex;
    flex-direction: column;
    color: #dce7f3;
    background: linear-gradient(180deg, #102a44 0%, #0b2035 100%);
}
.sidebar-brand { display: flex; align-items: center; gap: 11px; padding: 0 8px 24px; }
.sidebar-brand strong { display: block; color: #fff; font-size: 17px; }
.sidebar-brand span { display: block; margin-top: 2px; font-size: 11px; color: #9db2c6; }
.brand-mark {
    width: 38px;
    height: 38px;
    border-radius: 11px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    color: #fff;
    font-weight: 800;
    background: linear-gradient(145deg, #1c83ff, #13aaa0);
    box-shadow: 0 7px 18px rgba(22, 119, 255, .28);
}
.main-nav { display: grid; gap: 5px; }
.main-nav button {
    border: 0;
    border-radius: 10px;
    padding: 11px 12px;
    display: flex;
    gap: 10px;
    align-items: center;
    text-align: left;
    color: #bbcad9;
    background: transparent;
    transition: .18s ease;
}
.main-nav button span { width: 19px; font-size: 17px; text-align: center; color: #7fa1bf; }
.main-nav button:hover { color: #fff; background: rgba(255,255,255,.07); }
.main-nav button.active { color: #fff; background: rgba(38, 130, 228, .23); }
.main-nav button.active span { color: #54a8ff; }
.sidebar-footer { margin-top: auto; display: grid; gap: 12px; }
.sidebar-footer > a { padding: 4px 10px; color: #8da4b8; text-decoration: none; font-size: 12px; }
.analyst-button {
    border: 1px solid rgba(99, 178, 255, .35);
    border-radius: 11px;
    padding: 11px;
    color: #fff;
    background: linear-gradient(135deg, rgba(28,131,255,.35), rgba(33,169,161,.24));
}

.content { min-width: 0; }
.topbar {
    min-height: 91px;
    padding: 18px 26px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    border-bottom: 1px solid var(--line);
    background: rgba(255,255,255,.94);
}
.topbar h1 { margin: 2px 0 0; font-size: 24px; letter-spacing: -.02em; }
.eyebrow { margin: 0; color: var(--blue); text-transform: uppercase; letter-spacing: .11em; font-size: 10px; font-weight: 800; }
.topbar-actions { display: flex; align-items: end; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.date-field { display: grid; gap: 4px; color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; }
input, select, textarea {
    min-height: 38px;
    border: 1px solid #d7dee5;
    border-radius: 9px;
    padding: 8px 10px;
    color: var(--ink);
    background: #fff;
    outline: none;
}
input:focus, select:focus, textarea:focus { border-color: #75aff1; box-shadow: 0 0 0 3px rgba(22,119,255,.1); }
.button {
    min-height: 38px;
    border: 1px solid #d7dee5;
    border-radius: 9px;
    padding: 8px 13px;
    color: var(--ink);
    background: #fff;
    font-weight: 700;
}
.button:hover { border-color: #aebbc7; }
.button-primary { border-color: var(--blue); color: #fff; background: var(--blue); }
.button-primary:hover { border-color: #0968dc; background: #0968dc; }
.button-small { min-height: 30px; padding: 5px 9px; font-size: 12px; }
.sync-strip {
    margin: 13px 26px 0;
    padding: 9px 12px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: #36546f;
    background: #eaf2f9;
    font-size: 12px;
}
.sync-strip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--green); }
#viewRoot { padding: 16px 26px 34px; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; }
.metric-card, .panel {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}
.metric-card { min-height: 132px; padding: 17px; position: relative; overflow: hidden; }
.metric-card::after {
    content: "";
    position: absolute;
    right: -28px;
    bottom: -40px;
    width: 105px;
    height: 105px;
    border-radius: 50%;
    background: var(--tint, var(--blue-soft));
}
.metric-card .label { color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
.metric-card .value { margin-top: 12px; font-size: 28px; line-height: 1.05; font-weight: 760; letter-spacing: -.035em; }
.metric-card .foot { position: relative; z-index: 1; margin-top: 9px; color: var(--muted); font-size: 11px; }
.metric-card.positive .value { color: var(--green); }
.metric-card.negative .value { color: var(--red); }
.metric-card.warning .value { color: var(--amber); }
.delta { margin-left: 5px; font-weight: 800; }
.delta.up { color: var(--green); }
.delta.down { color: var(--red); }

.dashboard-grid { margin-top: 12px; display: grid; grid-template-columns: repeat(12, minmax(0,1fr)); gap: 12px; }
.panel { padding: 18px; min-width: 0; }
.span-12 { grid-column: span 12; }
.span-8 { grid-column: span 8; }
.span-7 { grid-column: span 7; }
.span-6 { grid-column: span 6; }
.span-5 { grid-column: span 5; }
.span-4 { grid-column: span 4; }
.panel-header { margin-bottom: 14px; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.panel h2, .panel h3 { margin: 0; letter-spacing: -.01em; }
.panel h2 { font-size: 17px; }
.panel h3 { font-size: 14px; }
.panel-subtitle { margin: 4px 0 0; color: var(--muted); font-size: 11px; }
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border-radius: 99px;
    padding: 5px 8px;
    color: #3d5b75;
    background: #edf3f8;
    font-size: 10px;
    font-weight: 800;
}
.badge.warning { color: #8b5c00; background: #fff2cf; }
.badge.danger { color: #a23232; background: #fee9e9; }
.chart-wrap { height: 260px; position: relative; }
.chart-wrap.tall { height: 330px; }
.chart-wrap canvas { width: 100%; height: 100%; display: block; }
.legend { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; color: var(--muted); font-size: 11px; }
.legend i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 5px; }

.split-list { display: grid; gap: 12px; }
.split-item { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: center; }
.split-item .name { font-weight: 700; }
.split-item .number { font-variant-numeric: tabular-nums; font-weight: 750; }
.bar-track { grid-column: 1/-1; height: 7px; overflow: hidden; border-radius: 99px; background: #edf1f4; }
.bar-fill { height: 100%; border-radius: inherit; background: var(--bar, var(--blue)); }
.doctor-rank { counter-reset: doctor; display: grid; gap: 10px; }
.doctor-row { counter-increment: doctor; display: grid; grid-template-columns: 30px 1fr auto; gap: 10px; align-items: center; }
.doctor-row::before {
    content: counter(doctor);
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    color: var(--blue);
    background: var(--blue-soft);
    font-weight: 800;
}
.doctor-row .meta { color: var(--muted); font-size: 11px; }
.doctor-row strong { font-variant-numeric: tabular-nums; }

.analysis-box {
    border: 1px solid #dfe8f2;
    border-radius: 12px;
    padding: 14px 15px;
    color: #30475c;
    background: linear-gradient(145deg, #f7fbff, #f2f8f7);
    line-height: 1.5;
}
.analysis-box strong { color: var(--navy); }
.analysis-list { margin: 8px 0 0; padding-left: 18px; }
.analysis-list li + li { margin-top: 5px; }

.view-tools { margin-bottom: 12px; display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.view-tools-group { display: flex; align-items: center; justify-content: flex-end; gap: 7px; flex-wrap: wrap; }
.button-small { min-height: 32px; padding: 6px 10px; font-size: 11px; }
.segmented { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: #e8edf2; }
.segmented button { border: 0; border-radius: 7px; padding: 7px 11px; color: var(--muted); background: transparent; font-size: 12px; font-weight: 750; }
.segmented button.active { color: var(--ink); background: #fff; box-shadow: 0 2px 8px rgba(20,40,60,.1); }

.comparison-panel { border-color: #d8e6f5; background: linear-gradient(135deg, #fff, #f7fbff); }
.comparison-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 9px; }
.comparison-item {
    position: relative;
    min-width: 0;
    border: 1px solid #e4ebf2;
    border-radius: 11px;
    padding: 11px 12px;
    background: rgba(255,255,255,.9);
}
.comparison-name { display: block; min-height: 28px; color: #536473; font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .025em; }
.comparison-values { margin-top: 7px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.comparison-values div { min-width: 0; }
.comparison-values small { display: block; color: var(--muted); font-size: 9px; }
.comparison-values strong { display: block; margin-top: 2px; overflow: hidden; color: var(--ink); font-size: 14px; font-variant-numeric: tabular-nums; text-overflow: ellipsis; white-space: nowrap; }
.comparison-change { display: inline-flex; margin-top: 8px; border-radius: 99px; padding: 3px 7px; font-size: 10px; font-weight: 850; }
.comparison-change.favorable { color: #08724d; background: #e8f7f1; }
.comparison-change.unfavorable { color: #b13b3b; background: #fdeeee; }
.comparison-change.neutral { color: #607181; background: #edf1f4; }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { padding: 11px 12px; border-bottom: 1px solid #edf0f3; vertical-align: top; }
th { position: sticky; top: 0; z-index: 2; text-align: left; color: #6b7884; background: #f7f9fa; text-transform: uppercase; letter-spacing: .035em; font-size: 9px; }
td.numeric, th.numeric { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tr.total td { font-weight: 800; background: #f3f8fd; }
tr.subtotal td { font-weight: 800; }
.pnl-table { max-height: 70vh; }
.pnl-table th:first-child,
.pnl-table td:first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    min-width: 250px;
    background: #fff;
}
.pnl-table th:first-child { z-index: 3; background: #f7f9fa; }
.pnl-table tr.section td { color: #075da8; font-weight: 850; background: #edf7ff; }
.pnl-table tr.section td:first-child { background: #edf7ff; }
.pnl-table tr.subtotal td { color: #0a527f; background: #f1f8fc; }
.pnl-table tr.subtotal td:first-child { background: #f1f8fc; }
.pnl-table tr.emphasis td { color: #075f47; }
.pnl-table tr.total td { color: #075f47; background: #edf8f4; }
.pnl-table tr.total td:first-child { background: #edf8f4; }
.pnl-table tr.detail td:first-child { padding-left: 28px; color: #52616e; }
.pnl-table tr.separator td { border-top: 2px solid #cfd8e1; }
.pnl-table tr.finance-start td { border-top: 3px solid #b9c8d7; color: #3d5368; font-weight: 850; background: #f2f5f8; }
.pnl-table tr.finance-start td:first-child { background: #f2f5f8; }
.pnl-table tr.finance td { color: #4d5e6d; background: #f8fafb; }
.pnl-table tr.finance td:first-child { background: #f8fafb; }
.table-note { margin: 10px 3px 0; color: var(--muted); font-size: 10px; line-height: 1.4; }
.amount-credit { color: var(--green); font-weight: 750; }
.amount-debit { color: var(--red); font-weight: 750; }
.purpose { max-width: 520px; color: var(--muted); line-height: 1.35; }
.status-dot { width: 7px; height: 7px; display: inline-block; margin-right: 5px; border-radius: 50%; background: var(--green); }
.status-dot.unallocated { background: var(--amber); }
.category-select { max-width: 230px; min-height: 32px; padding: 5px 8px; font-size: 11px; }
.filters { display: flex; align-items: end; gap: 8px; flex-wrap: wrap; }
.filters label { display: grid; gap: 4px; color: var(--muted); font-size: 9px; font-weight: 800; text-transform: uppercase; }
.filters input, .filters select { min-height: 34px; }
.empty { padding: 42px 20px; text-align: center; color: var(--muted); }
.loader { min-height: 350px; display: grid; place-items: center; color: var(--muted); }
.error-card { border: 1px solid #f2cccc; border-radius: 12px; padding: 18px; color: #8f3333; background: #fff1f1; }

.analyst-panel {
    position: fixed;
    z-index: 30;
    inset: 0 0 0 auto;
    width: min(430px, 94vw);
    padding: 20px;
    display: flex;
    flex-direction: column;
    background: #fff;
    box-shadow: -12px 0 45px rgba(15,36,57,.2);
    transform: translateX(105%);
    transition: transform .22s ease;
}
.analyst-panel.open { transform: translateX(0); }
.analyst-panel header { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; padding-bottom: 15px; border-bottom: 1px solid var(--line); }
.analyst-panel h2 { margin: 3px 0 0; }
.analyst-panel header button { border: 0; background: transparent; font-size: 28px; color: var(--muted); }
.analyst-messages { flex: 1; overflow: auto; padding: 18px 0; display: grid; align-content: start; gap: 10px; }
.message { max-width: 90%; border-radius: 12px; padding: 11px 13px; line-height: 1.45; white-space: pre-wrap; }
.message.assistant { color: #29445d; background: #edf5fb; }
.message.user { justify-self: end; color: #fff; background: var(--blue); }
.analyst-form { display: grid; gap: 8px; }
.analyst-form textarea { resize: vertical; }
.panel-backdrop { position: fixed; z-index: 29; inset: 0; display: none; background: rgba(11,26,40,.35); }
.panel-backdrop.open { display: block; }

.login-body { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(145deg, #eef4f8, #dce8f0); }
.login-card { width: min(420px, 100%); border: 1px solid rgba(255,255,255,.8); border-radius: 22px; padding: 32px; background: rgba(255,255,255,.93); box-shadow: 0 24px 70px rgba(17,43,70,.17); }
.login-card .brand-mark { margin-bottom: 22px; }
.login-card h1 { margin: 5px 0 8px; font-size: 29px; }
.muted { color: var(--muted); }
.login-form { margin-top: 22px; display: grid; gap: 14px; }
.login-form label { display: grid; gap: 6px; color: #4d5d6b; font-size: 12px; font-weight: 750; }
.alert { border-radius: 9px; padding: 10px; }
.alert-danger { color: #9d3333; background: #fee8e8; }

@media (max-width: 1180px) {
    .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .span-8, .span-7, .span-6, .span-5, .span-4 { grid-column: span 12; }
    .topbar { align-items: flex-start; }
}
@media (max-width: 780px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: relative; height: auto; padding: 14px; }
    .sidebar-brand { padding-bottom: 12px; }
    .main-nav { display: flex; overflow-x: auto; }
    .main-nav button { flex: 0 0 auto; }
    .sidebar-footer { margin-top: 12px; grid-template-columns: 1fr auto; align-items: center; }
    .topbar { padding: 16px; display: block; }
    .topbar-actions { margin-top: 14px; justify-content: flex-start; }
    .sync-strip { margin: 10px 14px 0; }
    #viewRoot { padding: 12px 14px 24px; }
    .metric-grid { grid-template-columns: 1fr; }
    .comparison-grid { grid-template-columns: 1fr; }
}
