:root {
    --blue: #0f4c81;
    --blue-dark: #0a355b;
    --blue-soft: #e9f2f8;
    --green: #19875d;
    --green-soft: #e8f5ef;
    --orange: #d85f00;
    --orange-soft: #fff1e5;
    --red: #c9302c;
    --red-soft: #fdecea;
    --ink: #202b38;
    --muted: #66717d;
    --line: #d8e1e8;
    --canvas: #f4f7f9;
    --surface: #ffffff;
    --shadow: 0 12px 28px rgba(15, 76, 129, .09);
    font-family: Inter, "Segoe UI", Arial, sans-serif;
    color: var(--ink);
    background: var(--canvas);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; background: var(--canvas); }
button, input, select { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
a { color: var(--blue); }

.app-header {
    position: sticky;
    top: 0;
    z-index: 30;
    min-height: 70px;
    display: grid;
    grid-template-columns: 230px minmax(280px, 680px) auto;
    align-items: center;
    gap: 24px;
    padding: 10px 28px;
    background: rgba(255, 255, 255, .97);
    border-bottom: 1px solid var(--line);
}

.app-brand { display: flex; align-items: center; gap: 8px; text-decoration: none; }
.app-brand img { width: 156px; height: auto; display: block; }
.app-brand span { border-left: 1px solid var(--line); padding-left: 8px; color: var(--muted); font-size: 13px; font-weight: 700; }

.global-search { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) auto; }
.global-search label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.global-search input, .filter-bar input, .filter-bar select, .list-toolbar input {
    min-height: 42px;
    width: 100%;
    border: 1px solid #b9c8d4;
    border-radius: 5px;
    background: #fff;
    color: var(--ink);
    padding: 0 13px;
    outline: none;
}
.global-search input { border-radius: 5px 0 0 5px; }
.global-search input:focus, .filter-bar input:focus, .filter-bar select:focus, .list-toolbar input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(15, 76, 129, .12); }
.global-search > button, .filter-bar button, .load-more {
    min-height: 42px;
    border: 0;
    border-radius: 0 5px 5px 0;
    padding: 0 18px;
    color: #fff;
    background: var(--blue);
    font-weight: 800;
}
.search-suggestions {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    z-index: 50;
    max-height: 420px;
    overflow-y: auto;
    padding: 6px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 5px;
    box-shadow: 0 16px 38px rgba(7, 32, 52, .18);
}
.search-suggestions[hidden] { display: none; }
.suggestion-item {
    width: 100%;
    min-height: 58px;
    display: grid;
    gap: 3px;
    padding: 9px 11px;
    color: var(--ink);
    background: #fff;
    border: 0;
    border-bottom: 1px solid #edf1f4;
    border-radius: 3px;
    text-align: left;
}
.suggestion-item:last-child { border-bottom: 0; }
.suggestion-item:hover, .suggestion-item:focus { background: var(--blue-soft); outline: none; }
.suggestion-item strong { font-size: 13px; line-height: 1.25; }
.suggestion-item span { color: var(--muted); font-size: 11px; }
.suggestion-empty { padding: 14px; color: var(--muted); font-size: 12px; text-align: center; }
.official-link { justify-self: end; font-size: 13px; font-weight: 800; text-decoration: none; }

.app-shell { display: grid; grid-template-columns: 230px minmax(0, 1fr); min-height: calc(100vh - 70px); }
.sidebar {
    position: sticky;
    top: 70px;
    height: calc(100vh - 70px);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 20px 14px;
    background: #fff;
    border-right: 1px solid var(--line);
}
.sidebar nav { display: grid; gap: 5px; }
.nav-item {
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border: 0;
    border-radius: 5px;
    padding: 0 14px;
    background: transparent;
    color: #52606c;
    text-align: left;
    font-weight: 750;
}
.nav-item:hover { background: #f0f5f8; }
.nav-item.active { color: var(--blue); background: var(--blue-soft); }
.nav-item b { min-width: 23px; padding: 3px 6px; border-radius: 10px; color: #fff; background: var(--blue); font-size: 11px; text-align: center; }
.sidebar-source { display: grid; gap: 8px; padding: 14px; border-top: 1px solid var(--line); font-size: 12px; }
.sidebar-source strong { color: var(--muted); text-transform: uppercase; font-size: 10px; }
.sidebar-source a { text-decoration: none; }

.workspace { width: 100%; max-width: 1500px; margin: 0 auto; padding: 22px 30px 70px; outline: none; }
.status-strip { margin-bottom: 20px; border-left: 4px solid var(--green); padding: 11px 14px; background: var(--green-soft); color: #125e42; font-size: 13px; font-weight: 750; }
.status-strip.stale { border-color: var(--orange); color: #88400c; background: var(--orange-soft); }
.status-strip.error { border-color: var(--red); color: #8c2523; background: var(--red-soft); }
.status-strip.loading { border-color: var(--blue); color: var(--blue); background: var(--blue-soft); }

.view { display: none; }
.view.active { display: block; animation: enter .18s ease-out; }
@keyframes enter { from { opacity: .2; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.view-heading { display: flex; justify-content: space-between; gap: 24px; align-items: flex-start; margin-bottom: 22px; }
.view-heading h1 { margin: 3px 0 5px; font-size: clamp(27px, 3vw, 38px); line-height: 1.1; letter-spacing: 0; }
.view-heading p { margin: 0; color: var(--muted); }
.eyebrow { margin: 0; color: var(--blue); font-size: 11px; font-weight: 900; text-transform: uppercase; }
.entity-heading { padding: 20px 22px; color: #fff; background: var(--blue-dark); border-radius: 7px; box-shadow: var(--shadow); }
.entity-heading .eyebrow, .entity-heading p { color: #c9ddea; }
.follow-button { min-height: 40px; border: 1px solid rgba(255,255,255,.55); border-radius: 5px; padding: 0 16px; color: #fff; background: transparent; font-weight: 800; }
.follow-button.following { color: #0b5439; border-color: #b7e2d0; background: #dff4e9; }
.follow-button:disabled { opacity: .5; cursor: default; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 24px; }
.metric-grid > .empty { grid-column: 1 / -1; }
.metric { min-height: 130px; padding: 16px; background: #fff; border: 1px solid var(--line); border-radius: 6px; }
.metric span { display: block; color: var(--muted); font-size: 11px; font-weight: 750; text-transform: uppercase; }
.metric strong { display: block; margin: 14px 0 5px; color: var(--blue-dark); font-size: clamp(20px, 2vw, 29px); line-height: 1; }
.metric small { color: var(--muted); font-size: 11px; }
.metric.attention strong { color: var(--orange); }
.metric.risk strong { color: var(--red); }

.budget-section, .entity-tab, .ranking-layout > section { background: #fff; border: 1px solid var(--line); border-radius: 7px; }
.budget-section { margin-bottom: 20px; padding: 18px; }
.section-heading, .ranking-heading, .list-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.section-heading h2, .list-toolbar h2, .ranking-heading h2 { margin: 2px 0 0; font-size: 18px; }
.section-heading > span { color: var(--muted); font-size: 12px; }
.budget-flow { display: grid; grid-template-columns: repeat(7, minmax(110px, 1fr)); gap: 1px; margin-top: 16px; overflow-x: auto; background: var(--line); border: 1px solid var(--line); }
.budget-stage { min-width: 118px; padding: 13px 11px; background: #fff; }
.budget-stage span { display: block; min-height: 30px; color: var(--muted); font-size: 10px; font-weight: 800; text-transform: uppercase; }
.budget-stage strong { display: block; margin-top: 7px; color: var(--blue-dark); font-size: 15px; white-space: nowrap; }

.content-tabs { display: flex; gap: 4px; margin-bottom: -1px; padding-left: 10px; }
.content-tabs button { min-height: 40px; border: 1px solid transparent; border-radius: 5px 5px 0 0; padding: 0 18px; color: var(--muted); background: transparent; font-weight: 800; }
.content-tabs button.active { color: var(--blue); background: #fff; border-color: var(--line); border-bottom-color: #fff; }
.entity-tab { display: none; padding: 18px; }
.entity-tab.active { display: block; }
.list-toolbar { margin-bottom: 14px; }
.list-toolbar p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.list-toolbar input { max-width: 390px; }

.project-list, .alert-list, .entity-list, .ranking-list { display: grid; gap: 8px; }
.project-row, .entity-row, .ranking-row, .alert-row { border: 1px solid var(--line); border-radius: 5px; background: #fff; }
.project-row { display: grid; grid-template-columns: minmax(0, 1fr) 120px 110px 38px; align-items: center; gap: 14px; padding: 13px; }
.project-row:hover, .entity-row:hover { border-color: #97b6cd; box-shadow: 0 4px 14px rgba(15, 76, 129, .06); }
.project-main span, .entity-main span { color: var(--green); font-size: 10px; font-weight: 850; text-transform: uppercase; }
.project-main strong, .entity-main strong { display: block; margin-top: 4px; line-height: 1.32; }
.project-amount, .project-progress { text-align: right; }
.project-amount span, .project-progress span { display: block; color: var(--muted); font-size: 10px; }
.project-progress strong { color: var(--green); }
.open-project { width: 34px; height: 34px; border: 0; border-radius: 50%; color: #fff; background: var(--blue); font-size: 20px; line-height: 1; }

.alert-row { display: grid; grid-template-columns: 8px minmax(0, 1fr) auto; gap: 12px; padding: 13px; }
.alert-row i { border-radius: 4px; background: var(--blue); }
.alert-row.urgent i { background: var(--red); }
.alert-row.attention i { background: var(--orange); }
.alert-row.resolved i { background: var(--green); }
.alert-row strong { display: block; }
.alert-row p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.alert-row time { color: var(--muted); font-size: 11px; }

.filter-bar { display: grid; grid-template-columns: minmax(240px, 1fr) 230px auto; gap: 8px; margin-bottom: 14px; }
.filter-bar button { border-radius: 5px; }
.entity-row { display: grid; grid-template-columns: minmax(0, 1fr) 140px 110px 120px; align-items: center; gap: 14px; padding: 14px; }
.entity-location { color: var(--muted); font-size: 12px; }
.entity-budget span, .entity-execution span { display: block; color: var(--muted); font-size: 10px; }
.entity-execution strong { color: var(--green); }
.entity-actions { display: flex; justify-content: flex-end; gap: 6px; }
.entity-actions button { min-height: 35px; border: 1px solid var(--line); border-radius: 4px; padding: 0 10px; background: #fff; color: var(--blue); font-weight: 800; }
.entity-actions button.primary { color: #fff; border-color: var(--blue); background: var(--blue); }
.load-more { display: block; margin: 18px auto 0; border-radius: 5px; }
.load-more[hidden] { display: none; }

.ranking-layout { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.ranking-layout > section { overflow: hidden; }
.ranking-heading { padding: 15px 16px; border-bottom: 1px solid var(--line); }
.ranking-heading.positive { border-top: 4px solid var(--green); }
.ranking-heading.attention { border-top: 4px solid var(--orange); }
.ranking-heading span { color: var(--muted); font-size: 11px; }
.ranking-list { padding: 8px; }
.ranking-row { display: grid; grid-template-columns: 35px minmax(0, 1fr) 65px; align-items: center; gap: 9px; padding: 10px; cursor: pointer; }
.ranking-row b { color: var(--muted); text-align: center; }
.ranking-row strong { font-size: 12px; }
.ranking-row span { color: var(--green); font-size: 13px; font-weight: 900; text-align: right; }

.support-band { display: flex; align-items: center; gap: 20px; margin-top: 22px; padding: 16px; border-left: 4px solid var(--blue); background: var(--blue-soft); }
.support-band div { display: grid; gap: 3px; margin-right: auto; }
.support-band span { color: var(--muted); font-size: 12px; }
.support-band a { font-size: 13px; font-weight: 800; }

.project-dialog { width: min(920px, calc(100% - 30px)); max-height: 88vh; padding: 0; border: 0; border-radius: 7px; box-shadow: 0 28px 80px rgba(7, 32, 52, .3); }
.project-dialog::backdrop { background: rgba(10, 28, 42, .65); }
.dialog-head { position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; gap: 20px; padding: 20px; background: #fff; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 4px 0 0; font-size: 21px; line-height: 1.3; }
.dialog-head button { flex: 0 0 38px; width: 38px; height: 38px; border: 0; border-radius: 50%; background: #eef3f6; font-size: 27px; }
.dialog-body { display: grid; gap: 14px; padding: 20px; background: var(--canvas); }
.detail-panel { padding: 16px; background: #fff; border: 1px solid var(--line); border-radius: 6px; }
.detail-panel h3 { margin: 0 0 4px; font-size: 16px; }
.detail-panel > p { margin: 0 0 12px; color: var(--muted); font-size: 12px; }
.detail-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border: 1px solid var(--line); }
.detail-value { padding: 11px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.detail-value span { display: block; color: var(--muted); font-size: 9px; font-weight: 800; text-transform: uppercase; }
.detail-value strong { display: block; margin-top: 5px; font-size: 13px; }
.spending-list { display: grid; gap: 8px; }
.spending-item { padding: 11px; background: #f8fafb; border-left: 3px solid var(--green); }
.spending-item strong { display: block; font-size: 12px; }
.spending-item span { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }
.progress-group { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 16px; }
.progress-block { margin-top: 10px; }
.progress-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.progress-head strong { font-size: 12px; }
.progress-head b { color: var(--blue); font-size: 13px; }
.progress-track { height: 9px; margin-top: 7px; overflow: hidden; background: #dce5eb; }
.progress-fill { display: block; height: 100%; background: var(--blue); }
.progress-fill.green { background: var(--green); }
.progress-block small { display: block; margin-top: 6px; color: var(--muted); font-size: 10px; }
.spending-item .progress-block { margin-top: 9px; }
.spending-item .progress-head strong { color: var(--muted); font-size: 10px; font-weight: 700; }
.data-note { margin: 12px 0 0 !important; color: var(--muted); font-size: 10px !important; }
.data-pending { display: grid; gap: 4px; padding: 12px; color: var(--ink); background: var(--blue-soft); border-left: 3px solid var(--blue); font-size: 12px; }
.data-pending span { color: var(--muted); }
.notice { padding: 11px; color: #7b3b0e; background: var(--orange-soft); border-left: 3px solid var(--orange); font-size: 12px; }
.empty { padding: 30px 16px; color: var(--muted); background: #fff; border: 1px dashed #b9c8d4; text-align: center; }
.skeleton { min-height: 70px; background: linear-gradient(90deg, #edf2f5 25%, #f7f9fa 45%, #edf2f5 65%); background-size: 300% 100%; animation: pulse 1.3s infinite; }
@keyframes pulse { to { background-position: -150% 0; } }
.toast { position: fixed; z-index: 80; right: 20px; bottom: 22px; max-width: 380px; padding: 12px 15px; color: #fff; background: var(--ink); border-radius: 5px; box-shadow: var(--shadow); opacity: 0; transform: translateY(12px); pointer-events: none; transition: .2s; }
.toast.show { opacity: 1; transform: none; }
.mobile-nav { display: none; }

@media (max-width: 1050px) {
    .app-header { grid-template-columns: 190px minmax(240px, 1fr); }
    .official-link { display: none; }
    .app-shell { grid-template-columns: 190px minmax(0, 1fr); }
    .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .project-row { grid-template-columns: minmax(0, 1fr) 105px 90px 38px; }
    .entity-row { grid-template-columns: minmax(0, 1fr) 115px 100px; }
    .entity-actions { grid-column: 1 / -1; justify-content: flex-start; }
}

@media (max-width: 760px) {
    body { padding-bottom: 64px; }
    .app-header { min-height: 64px; grid-template-columns: 1fr auto; padding: 9px 14px; }
    .app-brand img { width: 142px; }
    .global-search { grid-column: 1 / -1; grid-row: 2; }
    .app-shell { display: block; min-height: auto; }
    .sidebar { display: none; }
    .workspace { padding: 16px 12px 30px; }
    .status-strip { margin-bottom: 14px; }
    .view-heading { display: block; }
    .view-heading h1 { font-size: 27px; }
    .entity-heading { padding: 17px; }
    .entity-heading .follow-button { margin-top: 14px; width: 100%; }
    .metric-grid { gap: 8px; }
    .metric { min-height: 112px; padding: 13px; }
    .metric strong { font-size: 21px; }
    .budget-section, .entity-tab { padding: 14px; }
    .list-toolbar { display: block; }
    .list-toolbar input { max-width: none; margin-top: 12px; }
    .project-row { grid-template-columns: minmax(0, 1fr) 34px; gap: 8px; }
    .project-amount, .project-progress { text-align: left; }
    .project-amount { grid-column: 1; }
    .project-progress { grid-column: 1; }
    .open-project { grid-column: 2; grid-row: 1 / span 3; align-self: center; }
    .filter-bar { grid-template-columns: 1fr; }
    .entity-row { grid-template-columns: minmax(0, 1fr) 90px; }
    .entity-budget { display: none; }
    .entity-actions { grid-column: 1 / -1; }
    .ranking-layout { grid-template-columns: 1fr; }
    .support-band { display: grid; gap: 8px; }
    .detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .progress-group { grid-template-columns: 1fr; }
    .dialog-head, .dialog-body { padding: 15px; }
    .mobile-nav { position: fixed; z-index: 40; left: 0; right: 0; bottom: 0; height: 62px; display: grid; grid-template-columns: repeat(4, 1fr); background: #fff; border-top: 1px solid var(--line); }
    .mobile-nav button { border: 0; background: #fff; color: var(--muted); font-size: 11px; font-weight: 800; }
    .mobile-nav button.active { color: var(--blue); background: var(--blue-soft); }
}

@media (max-width: 430px) {
    .metric-grid { grid-template-columns: 1fr 1fr; }
    .metric { min-width: 0; }
    .metric strong { overflow-wrap: anywhere; }
    .content-tabs { padding-left: 0; }
    .content-tabs button { flex: 1; padding: 0 10px; }
    .alert-row { grid-template-columns: 6px minmax(0, 1fr); }
    .alert-row time { grid-column: 2; }
    .detail-grid { grid-template-columns: 1fr; }
}
