:root {
  --brand: #e60000;
  --brand-dark: #b30000;
  --header: #1b1b1b;
  --header-2: #262626;
  --page: #f4f4f2;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  /* status (spec: red open, orange pending, yellow monitoring, green closed, blue info) */
  --st-open: #d03b3b;
  --st-pending: #ec835a;
  --st-monitoring: #fab219;
  --st-closed: #0ca30c;
  --st-info: #2a78d6;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); background: var(--page); color: var(--ink); font-size: 14px; }
a { color: var(--st-info); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }

/* ---------- header ---------- */
header.top {
  position: sticky; top: 0; z-index: 30; height: 56px; display: flex; align-items: center; gap: 16px;
  padding: 0 16px; background: var(--header); color: #fff; border-bottom: 3px solid var(--brand);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; white-space: nowrap; }
.brand .logo { width: 30px; height: 30px; border-radius: 50%; background: var(--brand); display: grid; place-items: center; }
.brand .logo::after { content: ""; width: 12px; height: 12px; border-radius: 50% 50% 50% 0; background: #fff; transform: rotate(-45deg); }
.brand small { display: block; font-weight: 400; color: #bdbdbd; font-size: 11px; }
.top .spacer { flex: 1; }
.top select, .top .btn-ghost { background: var(--header-2); color: #fff; border: 1px solid #3a3a3a; border-radius: 6px; padding: 6px 10px; }
.top .btn-ghost { cursor: pointer; position: relative; }
.top .btn-ghost:hover { border-color: #666; }
.badge { position: absolute; top: -6px; right: -6px; background: var(--brand); color: #fff; font-size: 11px; border-radius: 10px; padding: 1px 6px; }
.updated { color: #bdbdbd; font-size: 12px; white-space: nowrap; }
#menuBtn { display: none; }

/* ---------- layout ---------- */
.layout { display: flex; min-height: calc(100vh - 56px); }
nav.side { width: 236px; flex: none; background: #fff; border-right: 1px solid var(--border); padding: 12px 8px; position: sticky; top: 56px; height: calc(100vh - 56px); overflow-y: auto; }
nav.side a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px; color: var(--ink-2); }
nav.side a:hover { background: #f3f3f1; text-decoration: none; }
nav.side a.active { background: #fdeaea; color: var(--brand-dark); font-weight: 600; }
nav.side .sec { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 10px 6px; }
nav.side .ico { width: 20px; text-align: center; }
main { flex: 1; min-width: 0; padding: 20px 24px 40px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; font-size: 22px; }
.page-head p { margin: 4px 0 0; color: var(--ink-2); font-size: 13px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- buttons ---------- */
.btn { border: 1px solid var(--border); background: #fff; color: var(--ink); padding: 7px 12px; border-radius: 6px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--axis); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { color: var(--st-open); }
.btn.small { padding: 4px 8px; font-size: 12px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; background: #fff; }
.seg button { border: 0; background: none; padding: 4px 10px; cursor: pointer; font-size: 12px; color: var(--ink-2); }
.seg button.on { background: var(--ink); color: #fff; }

/* ---------- KPI tiles ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; position: relative; overflow: hidden; }
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--kpi-c, var(--axis)); }
.kpi .lbl { font-size: 12px; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.kpi .val { font-size: 26px; font-weight: 600; margin-top: 4px; }
.kpi .sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
a.kpi { color: inherit; }
a.kpi:hover { text-decoration: none; border-color: var(--axis); }

/* ---------- cards / grid ---------- */
.grid { display: grid; gap: 16px; grid-template-columns: repeat(12, 1fr); margin-bottom: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.card h3 { margin: 0 0 2px; font-size: 15px; }
.card .hint { color: var(--muted); font-size: 12px; margin: 0 0 10px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 8px; }
.c3 { grid-column: span 3; } .c4 { grid-column: span 4; } .c5 { grid-column: span 5; } .c6 { grid-column: span 6; }
.c7 { grid-column: span 7; } .c8 { grid-column: span 8; } .c12 { grid-column: span 12; }
.chart-box { position: relative; height: 260px; width: 100%; min-width: 0; }
.chart-box canvas { max-width: 100%; }
.grid > * { min-width: 0; }
.chart-box.tall { height: 340px; }
.empty { color: var(--muted); padding: 28px 8px; text-align: center; font-size: 13px; }

/* ---------- pills ---------- */
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; background: #f0efec; color: var(--ink); white-space: nowrap; }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--pc, var(--muted)); }
.pill.Open { --pc: var(--st-open); } .pill.Pending { --pc: var(--st-pending); } .pill.Monitoring { --pc: var(--st-monitoring); }
.pill.Closed { --pc: var(--st-closed); } .pill.info { --pc: var(--st-info); }
.age { font-variant-numeric: tabular-nums; padding: 1px 6px; border-radius: 4px; font-size: 12px; }
.age.yellow { background: #fff3c4; } .age.orange { background: #ffe0cc; } .age.red { background: #fbd5d5; color: #8a1414; font-weight: 600; }
.prio { font-weight: 700; font-size: 12px; padding: 1px 6px; border-radius: 4px; background: #f0efec; }
.prio.P1 { background: #fbd5d5; color: #8a1414; } .prio.P2 { background: #ffe0cc; color: #8a3a0f; }
.flag { color: var(--st-open); font-weight: 600; }

/* ---------- tables ---------- */
.tbl-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 16px; min-width: 0; }
.tbl-bar { display: flex; gap: 8px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tbl-bar h3 { margin: 0; font-size: 15px; margin-right: auto; }
.tbl-bar input[type=search] { border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; width: 220px; max-width: 100%; }
.tbl-bar select { border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px; background: #fff; }
.tbl-scroll { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th { text-align: left; font-weight: 600; color: var(--ink-2); background: #f7f7f5; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; cursor: pointer; user-select: none; position: sticky; top: 0; }
table.data th.sorted::after { content: " ▾"; } table.data th.sorted.asc::after { content: " ▴"; }
table.data td { padding: 7px 10px; border-bottom: 1px solid #efeeea; vertical-align: top; }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.wrap { max-width: 380px; white-space: normal; color: var(--ink-2); }
table.data tr.clickable { cursor: pointer; }
table.data tr.clickable:hover td { background: #faf6f6; }
.grid > .tbl-wrap { grid-column: span 12; }
.tbl-bar h3 .edit-hint, .edit-hint { font-weight: 400; font-size: 12px; color: var(--muted); }
td.edit-cell { width: 1%; white-space: nowrap; text-align: right; }
@media print { td.edit-cell, th[data-k="__edit"] { display: none; } }
.tbl-foot { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; color: var(--muted); font-size: 12px; }
.tbl-foot .pager button { margin-left: 4px; }

/* ---------- forms / modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; width: 760px; max-width: 100%; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.modal header { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal header h2 { margin: 0; font-size: 17px; }
.modal .body { padding: 16px 18px; max-height: 70vh; overflow-y: auto; }
.modal footer { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.form-grid .full { grid-column: 1 / -1; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); }
label.f input, label.f select, label.f textarea { border: 1px solid var(--axis); border-radius: 6px; padding: 7px 9px; font-size: 14px; color: var(--ink); background: #fff; }
label.f textarea { min-height: 70px; resize: vertical; }
label.f input:focus, label.f select:focus, label.f textarea:focus { outline: 2px solid #f3b4b4; border-color: var(--brand); }
.err { color: var(--st-open); font-size: 13px; }
.history { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 10px; font-size: 12px; color: var(--ink-2); }
.history div { padding: 3px 0; }

/* ---------- login ---------- */
.login-bg { position: fixed; inset: 0; background: var(--header); display: grid; place-items: center; z-index: 100; padding: 16px; }
.login { background: #fff; border-radius: 14px; padding: 28px; width: 360px; max-width: 100%; border-top: 5px solid var(--brand); }
.login h1 { font-size: 20px; margin: 0 0 4px; }
.login p { margin: 0 0 18px; color: var(--ink-2); font-size: 13px; }
.login label.f { margin-bottom: 12px; }
.login .btn { width: 100%; padding: 10px; }

/* ---------- alerts drawer ---------- */
.drawer { position: fixed; top: 56px; right: 0; width: 400px; max-width: 100%; bottom: 0; background: #fff; z-index: 40; box-shadow: -8px 0 30px rgba(0, 0, 0, .15); overflow-y: auto; padding: 14px; }
.alert { border-left: 4px solid var(--st-pending); background: #fafaf8; border-radius: 6px; padding: 10px 12px; margin-bottom: 10px; }
.alert.critical { border-left-color: var(--st-open); }
.alert b { display: block; font-size: 13px; }
.alert span { font-size: 12px; color: var(--ink-2); }

/* ---------- site 360 ---------- */
.s360-search { display: flex; gap: 8px; margin-bottom: 16px; position: relative; max-width: 560px; }
.s360-search input { flex: 1; border: 1px solid var(--axis); border-radius: 6px; padding: 9px 12px; font-size: 15px; }
.suggest { position: absolute; top: 44px; left: 0; right: 90px; background: #fff; border: 1px solid var(--border); border-radius: 8px; z-index: 20; box-shadow: 0 8px 24px rgba(0, 0, 0, .1); }
.suggest div { padding: 8px 12px; cursor: pointer; } .suggest div:hover { background: #f5f5f3; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; font-size: 13px; }
dl.kv dt { color: var(--muted); } dl.kv dd { margin: 0; font-weight: 500; }
.timeline { border-left: 2px solid var(--grid); margin-left: 6px; padding-left: 14px; }
.timeline div { position: relative; padding: 4px 0 8px; font-size: 13px; }
.timeline div::before { content: ""; position: absolute; left: -20px; top: 9px; width: 10px; height: 10px; border-radius: 50%; background: var(--pc, var(--axis)); }
.timeline small { color: var(--muted); }
#map { height: 420px; border-radius: 8px; }
.note { background: #f3f7fd; border: 1px solid #d6e4f7; border-radius: 8px; padding: 10px 12px; font-size: 13px; color: #24456f; margin-bottom: 16px; }
.loading { padding: 60px; text-align: center; color: var(--muted); }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .c3, .c4 { grid-column: span 6; } .c5, .c6, .c7, .c8 { grid-column: span 12; }
}
@media (max-width: 760px) {
  #menuBtn { display: inline-block; }
  nav.side { position: fixed; left: 0; top: 56px; z-index: 35; transform: translateX(-100%); transition: transform .2s; box-shadow: 4px 0 20px rgba(0, 0, 0, .15); }
  nav.side.open { transform: none; }
  main { padding: 16px; }
  .c3, .c4, .c5, .c6, .c7, .c8 { grid-column: span 12; }
  .brand small, .updated { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  header.top { gap: 6px; padding: 0 8px; }
  .brand > div { font-size: 13px; max-width: 96px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #districtFilter { max-width: 112px; }
  .uname { display: none; }
}

@media (max-width: 440px) {
  .brand > div { display: none; }
}

/* ---------- print / PDF ---------- */
@media print {
  header.top, nav.side, .actions, .tbl-bar input, .tbl-bar select, .tbl-bar .btn, .tbl-foot .pager, .drawer { display: none !important; }
  body { background: #fff; }
  main { padding: 0; }
  .card, .kpi, .tbl-wrap { break-inside: avoid; }
  .tbl-scroll { overflow: visible; }
}
