:root {
  --primary-dark: #1e3a5f; --primary-darker: #0f2744;
  --primary-gradient: linear-gradient(135deg, #1e3a5f 0%, #2c5282 100%);
  --accent: #3b82f6; --accent-dark: #1e40af; --accent-light: #dbeafe;
  --bg-page: #f5f7fa; --bg-card: #ffffff; --bg-section: #f8fafc; --bg-alt: #fafbfc;
  --t1: #1e293b; --t2: #475569; --t3: #64748b; --t4: #94a3b8;
  --b1: #e2e8f0; --b2: #cbd5e1;
  --good: #15803d; --good-bg: rgba(34,197,94,.10); --bad: #dc2626; --bad-bg: rgba(239,68,68,.10);
  --shadow-sm: 0 2px 4px rgba(0,0,0,.05); --shadow-md: 0 4px 12px rgba(0,0,0,.08); --shadow-lg: 0 4px 24px rgba(0,0,0,.08);
  --font: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, 'Helvetica Neue', sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg-page); color: var(--t1); font-family: var(--font); font-size: 13px; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
select { font-family: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-dark); }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

/* ---------------- header + filter bar (sticky) */
.tricolour { height: 4px; background: linear-gradient(90deg, #ff9933 0 33%, #ffffff 33% 66%, #138808 66%); }
.hdr { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; justify-content: space-between; height: 80px; padding: 0 28px; background: var(--primary-gradient); color: #fff; }
.hdr-left { display: flex; align-items: center; gap: 14px; }
.hdr-emblem { width: 46px; height: 46px; border-radius: 50%; background: #fff; display: flex; align-items: center; justify-content: center; }
.hdr-emblem img { width: 38px; height: 38px; object-fit: contain; }
.hdr h1 { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: .01em; }
.hdr p { margin: 2px 0 0; font-size: 12px; color: #cbd5e1; }
.hdr-right { font-size: 11px; color: #cbd5e1; text-align: right; line-height: 1.4; }
.hdr-right b { color: #fff; font-weight: 600; }

.fbar { position: sticky; top: 80px; z-index: 29; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 14px; min-height: 66px; padding: 8px 24px; background: linear-gradient(180deg, #f5f7fa 0%, #e4e8ec 100%); box-shadow: var(--shadow-sm); }
.fgroup { display: flex; align-items: center; gap: 8px; }
.sel { position: relative; display: flex; flex-direction: column; justify-content: center; height: 42px; min-width: 118px; padding: 0 30px 0 12px; border: 2px solid var(--t4); border-radius: 8px; background: var(--bg-card); }
.sel label { font-size: 9.5px; font-weight: 600; color: var(--t3); text-transform: uppercase; letter-spacing: .05em; line-height: 1; margin-bottom: 3px; }
.sel select { appearance: none; border: none; background: transparent; font-size: 12.5px; font-weight: 500; color: var(--t1); padding: 0; outline: none; width: 100%; }
.sel::after { content: ''; position: absolute; right: 11px; top: 17px; width: 7px; height: 7px; border-right: 2px solid var(--t3); border-bottom: 2px solid var(--t3); transform: rotate(45deg); pointer-events: none; }
.chips { display: flex; gap: 6px; }
.chip { height: 38px; padding: 0 10px; border-radius: 8px; font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; color: var(--t2); background: var(--bg-card); box-shadow: 0 2px 6px rgba(0,0,0,.08); transition: all .15s; }
.chip:hover { box-shadow: 0 3px 8px rgba(0,0,0,.14); }
.chip.active { background: var(--primary-gradient); color: #fef3c7; box-shadow: 0 0 0 3px rgba(59,130,246,.3); }
.vtoggle { display: flex; gap: 2px; padding: 4px; border-radius: 8px; background: rgba(255,255,255,.12); }
.hdr .vbtn { color: #e2e8f0; }
.hdr .vbtn.active { background: #fff; color: var(--primary-dark); }
.vbtn { display: flex; align-items: center; gap: 7px; padding: 8px 14px; border-radius: 6px; font-size: 12px; font-weight: 600; color: var(--t2); }
.vbtn.active { background: var(--primary-gradient); color: #fef3c7; }
.vbtn svg { width: 15px; height: 15px; }

/* ---------------- layout */
.page { padding: 18px 24px 40px; display: flex; flex-direction: column; gap: 18px; }
.card { background: var(--bg-card); border-radius: 12px; box-shadow: var(--shadow-lg); }
.crumb { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--t3); }
.crumb a { font-weight: 600; }
.crumb b { color: var(--t1); font-weight: 600; }
.crumb .sep { color: var(--t4); }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 20px; border-bottom: 1px solid var(--b1); min-height: 54px; }
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; font-size: 11.5px; color: var(--t3); }
.sw { display: inline-block; width: 11px; height: 11px; border-radius: 3px; vertical-align: -1px; margin-right: 5px; }
.btn { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 6px; font-size: 12px; font-weight: 600; color: var(--t2); border: 1px solid var(--b2); background: var(--bg-card); }
.btn:hover { border-color: var(--accent); color: var(--accent-dark); }
.btn.primary { background: var(--accent-light); color: var(--accent-dark); border-color: transparent; }

/* ---------------- table */
.twrap { overflow: auto; max-height: calc(100vh - 230px); scrollbar-width: thin; scrollbar-color: #c1c9d4 #f1f3f5; }
table.grid { width: 100%; table-layout: fixed; border-collapse: separate; border-spacing: 0; font-size: 12px; }
.grid th, .grid td { white-space: nowrap; }
.grid thead th { position: sticky; z-index: 5; }
.grid thead tr:first-child th { top: 0; }
.grid thead tr:nth-child(2) th { top: 44px; }
.gh { padding: 12px 14px; text-align: center; font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: #fff; border-left: 2px solid #fff; height: 44px; }
.gh.pending { background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%); }
.gh.age { background: linear-gradient(135deg, #d4a012 0%, #b8860b 100%); }
.gh.source { background: linear-gradient(135deg, #00897b 0%, #00695c 100%); }
.gh.casetype { background: linear-gradient(135deg, #e53935 0%, #c62828 100%); }
.gh.disposed { background: linear-gradient(135deg, #475569 0%, #334155 100%); }
.gh.entity { background: var(--primary-dark); text-align: left; left: 0; z-index: 7 !important; border-left: none; width: 236px; }
.gh.rank { background: var(--primary-darker); width: 64px; }
.ih { padding: 7px 6px; font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .02em; color: var(--t2); text-align: center; border-bottom: 1px solid var(--b1); line-height: 1.2; white-space: normal !important; cursor: pointer; user-select: none; }
.ih.pending { background: #dbeafe; } .ih.age { background: #fef3c7; } .ih.source { background: #d1fae5; } .ih.casetype { background: #fee2e2; } .ih.disposed { background: #e2e8f0; }
.ih.sorted { color: var(--accent-dark); box-shadow: inset 0 -2px 0 var(--accent); }
.ih .info { color: var(--t4); margin-left: 3px; }
.grid td { padding: 7px 6px; text-align: center; border-bottom: 1px solid var(--b1); color: var(--t2); overflow: hidden; text-overflow: ellipsis; }
.grid td.entity { position: sticky; left: 0; z-index: 3; text-align: left; padding: 7px 12px; font-weight: 600; color: var(--t1); background: var(--bg-card); box-shadow: 2px 0 8px rgba(0,0,0,.06); cursor: pointer; }
.grid td.entity small { margin-left: 6px; font-weight: 400; color: var(--t4); font-size: 11px; }
.grid td.entity .sub { display: block; font-weight: 400; color: var(--t3); font-size: 11px; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.grid td.entity.court { font-weight: 500; }
.unit { display: flex; gap: 2px; padding: 3px; background: var(--b1); border-radius: 8px; }
.unit .pill { padding: 5px 10px; font-size: 11px; }
.grid tbody tr:nth-child(even) td { background: var(--bg-alt); }
.grid tbody tr:hover td { background: #eef4ff; }
.grid tr.total td { background: var(--accent-light) !important; color: var(--accent-dark); font-weight: 700; border-bottom: 2px solid #bfdbfe; }
.grid tr.total td.entity { letter-spacing: .04em; font-size: 11.5px; }
td.good { color: var(--good) !important; font-weight: 600; }
td.bad { color: var(--bad) !important; font-weight: 600; }
.arrow { display: inline-flex; align-items: center; gap: 2px; }
.arrow svg { width: 11px; height: 11px; }
.rk { display: inline-flex; align-items: center; justify-content: center; min-width: 30px; height: 24px; padding: 0 7px; border-radius: 6px; font-weight: 700; font-size: 11.5px; background: var(--bg-section); color: var(--t2); }
.rk.r1 { background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%); color: #1c1917; }
.rk.r2 { background: linear-gradient(135deg, #d1d5db 0%, #9ca3af 100%); color: #1c1917; }
.rk.r3 { background: linear-gradient(135deg, #d97706 0%, #b45309 100%); color: #fff; }
.split-btn { opacity: 0; font-size: 10.5px; color: var(--accent); font-weight: 600; margin-left: 8px; }
.grid tr:hover .split-btn { opacity: 1; }

/* ---------------- KPI + map */
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)) 1.6fr; gap: 14px; }
.kpi { display: flex; flex-direction: column; gap: 3px; padding: 14px 18px; background: var(--bg-card); border-radius: 12px; box-shadow: var(--shadow-md); }
.kpi .l { font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--t3); }
.kpi .v { font-size: 24px; font-weight: 700; color: var(--t1); line-height: 1.15; }
.kpi .s { font-size: 11.5px; color: var(--t3); }
.kpi .s.good { color: var(--good); } .kpi .s.bad { color: var(--bad); }
.kpi.trend { padding: 10px 14px 6px; }
#trend { width: 100%; height: 78px; }
.maplayout { display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 18px; align-items: start; }
.mappanel { display: flex; flex-direction: column; gap: 12px; padding: 14px; }
.mode { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 12px; background: var(--bg-section); border-radius: 8px; }
.pills { display: flex; gap: 2px; padding: 3px; background: var(--b1); border-radius: 8px; }
.pill { padding: 7px 12px; border-radius: 6px; font-size: 11.5px; font-weight: 600; color: var(--t2); }
.pill.active { background: var(--primary-dark); color: #fff; }
.mapbox { position: relative; background: var(--bg-section); border-radius: 12px; height: 600px; overflow: hidden; }
#map, #mapL, #mapR { position: absolute; inset: 0; }
.cmp-layer { position: absolute; inset: 0; }
.cmp-handle { position: absolute; top: 0; bottom: 0; width: 0; z-index: 5; }
.cmp-handle .line { position: absolute; top: 0; bottom: 0; left: -2px; width: 4px; background: #6d28d9; }
.cmp-handle .grip { position: absolute; top: 50%; left: -18px; width: 36px; height: 36px; border-radius: 8px; background: #6d28d9; transform: translateY(-50%); cursor: ew-resize; display: flex; align-items: center; justify-content: center; gap: 3px; box-shadow: var(--shadow-md); }
.cmp-handle .grip span { width: 2px; height: 14px; background: #ede9fe; border-radius: 1px; }
.cmp-label { position: absolute; bottom: 14px; padding: 6px 12px; border-radius: 6px; background: rgba(255,255,255,.95); font-size: 12px; font-weight: 600; box-shadow: var(--shadow-md); z-index: 4; }
.cmp-label.l { left: 14px; border-left: 4px solid #6d28d9; } .cmp-label.r { right: 14px; border-right: 4px solid var(--primary-dark); }
.maplegend { display: flex; align-items: center; gap: 16px; padding: 8px 14px; background: var(--bg-section); border-radius: 8px; font-size: 11.5px; color: var(--t2); flex-wrap: wrap; }
.maplegend b { color: var(--t1); }
.maplegend .it { display: flex; align-items: center; gap: 6px; }
.maplegend .it i { width: 20px; height: 12px; border-radius: 3px; display: inline-block; }
.rankpanel { display: flex; flex-direction: column; gap: 8px; padding: 16px; max-height: 760px; overflow: auto; }
.rankpanel h3 { margin: 0; font-size: 15px; font-weight: 600; }
.rankpanel .hint { display: flex; gap: 12px; font-size: 11px; color: var(--t3); }
.rrow { display: flex; flex-direction: column; gap: 3px; padding: 6px 9px; border-radius: 8px; cursor: pointer; }
.rrow:hover { background: #eef4ff; }
.rrow.sel { background: var(--accent-light); }
.rrow .t { display: flex; justify-content: space-between; font-size: 12px; font-weight: 600; }
.rrow .b { display: flex; align-items: center; gap: 8px; }
.rrow .track { flex: 1; height: 12px; background: #eef2f7; border-radius: 6px; overflow: hidden; }
.rrow .fill { height: 100%; border-radius: 6px; }
.rrow .val { min-width: 48px; text-align: right; font-size: 12.5px; font-weight: 700; }
.rrow .d { font-size: 11px; }
.rrow .d.good { color: var(--good); } .rrow .d.bad { color: var(--bad); }

/* ---------------- drawer */
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: 640px; max-width: 100vw; z-index: 40; background: var(--bg-page); box-shadow: -8px 0 32px rgba(0,0,0,.18); display: flex; flex-direction: column; transform: translateX(105%); transition: transform .2s ease; }
.drawer.open { transform: none; }
.drawer .dh { display: flex; align-items: flex-start; justify-content: space-between; padding: 18px 22px 14px; background: var(--primary-gradient); color: #fff; }
.drawer .dh h2 { margin: 0; font-size: 17px; font-weight: 700; }
.drawer .dh p { margin: 4px 0 0; font-size: 12px; color: #cbd5e1; }
.drawer .dbody { overflow: auto; padding: 16px 22px 30px; display: flex; flex-direction: column; gap: 14px; }
.dk { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.dk .kpi { padding: 10px 14px; box-shadow: var(--shadow-sm); }
.dk .kpi .v { font-size: 20px; }
.dsec { background: var(--bg-card); border-radius: 12px; box-shadow: var(--shadow-sm); padding: 14px 16px; }
.dsec h4 { margin: 0 0 10px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--t3); display: flex; justify-content: space-between; }
.dsec h4 span { font-weight: 500; text-transform: none; letter-spacing: 0; }
.bl { display: flex; flex-direction: column; gap: 6px; }
.bl .r { display: grid; grid-template-columns: 170px 1fr 70px 52px; align-items: center; gap: 10px; font-size: 12px; }
.bl .r .n { color: var(--t1); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bl .r .n small { display: block; color: var(--t4); font-weight: 400; font-size: 10.5px; }
.bl .r .tr { height: 10px; background: #eef2f7; border-radius: 5px; overflow: hidden; }
.bl .r .fi { height: 100%; background: var(--accent); border-radius: 5px; }
.bl .r .fi.old { background: #b45309; }
.bl .r .v { text-align: right; font-weight: 600; color: var(--t1); }
.bl .r .p { text-align: right; color: var(--t3); }
.stack { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: #eef2f7; }
.stack i { display: block; height: 100%; }
.mini { width: 100%; border-collapse: collapse; font-size: 12px; }
.mini th { text-align: right; font-size: 10.5px; color: var(--t3); text-transform: uppercase; padding: 4px 6px; border-bottom: 1px solid var(--b1); }
.mini th:first-child, .mini td:first-child { text-align: left; }
.mini td { padding: 5px 6px; text-align: right; border-bottom: 1px solid var(--b1); color: var(--t2); }
.mini td:first-child { color: var(--t1); font-weight: 500; }
.close { width: 32px; height: 32px; border-radius: 6px; font-size: 20px; color: #e2e8f0; }
.close:hover { background: rgba(255,255,255,.15); }
.scrim { position: fixed; inset: 0; z-index: 39; background: rgba(15,23,42,.25); }

/* ---------------- misc */
.loading { position: fixed; top: 150px; left: 50%; transform: translateX(-50%); z-index: 50; padding: 8px 16px; border-radius: 8px; background: var(--primary-dark); color: #fff; font-size: 12px; box-shadow: var(--shadow-md); }
.empty { padding: 40px; text-align: center; color: var(--t3); }
.foot { font-size: 11px; color: var(--t4); text-align: center; }
@media (max-width: 1380px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } .maplayout { grid-template-columns: 1fr; } }
