/* EcoSentinel Aqua System — styled after the Uzbekhydroenergo slide system:
   blue header band, gradient section bars, dense figures on a light sheet. */
:root {
  --band: #0070C0;
  --band-deep: #005A9C;
  --green: #29AD7E;
  --cyan: #0CADC9;
  --sheet: #F2F5F8;
  --panel: #FFFFFF;
  --line: #D9E2EA;
  --ink: #1B2836;
  --ink-2: #4D5D6C;
  --ink-3: #7A8896;
  --s1: #0070C0;
  --s2: #B8860B;
  --ok: #23824F;
  --near: #B45F06;
  --over: #C62828;
  --r: 8px;
  --head: 'Fira Sans Condensed', 'Arial Narrow', sans-serif;
  --body: 'Fira Sans', 'Segoe UI', sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--sheet); color: var(--ink); font: 400 14px/1.45 var(--body); }
a { color: var(--band-deep); }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid #F2B705; outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: #fff; padding: 6px 10px; z-index: 2000; }
.skip:focus { left: 8px; }

/* ---------- header band ---------- */
.band {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 20px;
  background: var(--band); color: #fff; padding: 10px 24px 10px 0; min-height: 68px;
}
.brand {
  display: flex; align-items: center; gap: 10px; background: #fff; color: var(--band);
  padding: 10px 18px 10px 20px; align-self: stretch; margin: -10px 0; text-decoration: none;
  clip-path: polygon(0 0, 100% 0, calc(100% - 18px) 100%, 0 100%); padding-right: 34px;
}
.brand-name { font: 700 19px/1 var(--head); letter-spacing: .01em; display: flex; flex-direction: column; }
.brand-name small { font: 600 11px/1.3 var(--head); color: var(--green); letter-spacing: .08em; }
.band-title {
  margin: 0; text-align: center; font: 700 clamp(17px, 2.1vw, 26px)/1.15 var(--head);
  text-transform: uppercase; letter-spacing: .02em;
}
.band-tools { display: flex; align-items: center; gap: 12px; }
.lang { display: flex; border: 1px solid rgba(255,255,255,.55); border-radius: 6px; overflow: hidden; }
.lang button { background: none; border: 0; color: #fff; padding: 6px 10px; cursor: pointer; font: 600 13px var(--head); }
.lang button[aria-pressed="true"] { background: #fff; color: var(--band); }
.btn-report { color: #fff; font: 600 14px var(--head); text-decoration: none; border-bottom: 2px solid rgba(255,255,255,.5); padding-bottom: 1px; }
.btn-report:hover { border-color: #fff; }
.yearbox { border: 2px solid #fff; border-radius: 4px; padding: 4px 12px; font: 600 24px/1 var(--head); }

.statusline { display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: center; padding: 8px 24px; color: var(--ink-2); font-size: 13px; }
.src { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; color: var(--ink); }
.src .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--near); }
.src.live .dot { background: var(--ok); box-shadow: 0 0 0 3px rgba(35,130,79,.18); }

/* ---------- sheet grid ---------- */
.sheet {
  display: grid; gap: 14px; padding: 0 24px 24px;
  grid-template-columns: repeat(12, minmax(0, 1fr));
}
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 0 16px 14px; min-width: 0; }
.p-current, .p-map, .p-trend, .p-kpi { grid-column: span 7; }
.p-network, .p-alerts, .p-ai, .p-partners { grid-column: span 5; }

.bar {
  display: flex; align-items: center; justify-content: center; gap: 12px; position: relative;
  margin: 10px -6px 12px; padding: 7px 14px; min-height: 36px; border-radius: 6px;
  color: #fff; font: 700 16px/1.2 var(--head); text-align: center;
}
.bar-blue { background: linear-gradient(90deg, var(--band) 0%, #1B8FD0 55%, var(--cyan) 100%); }
.bar-green { background: linear-gradient(90deg, var(--green) 0%, #1BAE9F 55%, var(--cyan) 100%); }
.bar .seg { position: absolute; right: 8px; }
.seg { display: inline-flex; background: rgba(255,255,255,.18); border-radius: 5px; padding: 2px; gap: 2px; }
.seg button { border: 0; background: none; color: #fff; padding: 3px 10px; border-radius: 4px; cursor: pointer; font: 600 13px var(--head); }
.seg button[aria-checked="true"], .seg button.on { background: #fff; color: var(--band); }
.seg-light { background: #E8EEF4; }
.seg-light button { color: var(--ink-2); }
.seg-light button[aria-checked="true"] { background: var(--band); color: #fff; }
.note { color: var(--ink-3); font-size: 12px; margin: 8px 0 0; }
h3 { font: 600 15px var(--head); margin: 14px 0 4px; color: var(--band-deep); }

/* ---------- current readings ---------- */
.readings { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 18px; }
.rd {
  display: grid; grid-template-columns: minmax(0, 1fr) auto 72px; grid-template-rows: auto auto;
  column-gap: 10px; align-items: center; padding: 7px 0; border-bottom: 1px solid #EDF1F5;
}
.rd-name { font: 500 13.5px/1.2 var(--body); color: var(--ink); }
.rd-lim { grid-row: 2; font-size: 11.5px; color: var(--ink-3); }
.rd-val { grid-row: 1 / span 2; grid-column: 2; font: 600 26px/1 var(--head); color: var(--band); text-align: right; white-space: nowrap; }
.rd-val small { font: 500 12px var(--head); color: var(--ink-2); margin-left: 3px; }
.rd-spark { grid-row: 1 / span 2; grid-column: 3; height: 30px; }
.rd-st { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 500; margin-left: 6px; }
.rd-st svg { width: 12px; height: 12px; flex: none; }
.st-ok { color: var(--ok); } .st-near { color: var(--near); } .st-over { color: var(--over); } .st-none { color: var(--ink-3); }

/* ---------- network ---------- */
.figures { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 12px; margin-bottom: 12px; }
.fig { border-left: 3px solid var(--green); padding: 2px 0 2px 10px; }
.fig b { display: block; font: 700 30px/1 var(--head); color: var(--band); }
.fig span { font-size: 12.5px; color: var(--ink-2); line-height: 1.25; display: block; margin-top: 3px; }
.stations { display: grid; gap: 10px; }
.stn { display: grid; grid-template-columns: 36px 1fr auto; gap: 10px; align-items: center; border: 1px solid var(--line); border-radius: 6px; padding: 10px; }
.stn-badge { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; color: #fff; font: 700 14px var(--head); }
.stn h3 { margin: 0; font-size: 15px; color: var(--ink); }
.stn p { margin: 1px 0 0; font-size: 12.5px; color: var(--ink-2); }
.stn-state { text-align: right; font-size: 12.5px; }

/* ---------- map ---------- */
.map { height: 430px; border-radius: 6px; border: 1px solid var(--line); background: #E6EEF3; }
.leaflet-container { font: 13px var(--body); }
.stn-pin { width: 30px; height: 30px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.35); display: grid; place-items: center; }
.stn-pin span { transform: rotate(45deg); color: #fff; font: 700 12px var(--head); }
.stn-pin.alarm { animation: pulse 1.6s ease-out infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(198,40,40,.55); } 100% { box-shadow: 0 0 0 16px rgba(198,40,40,0); } }
@media (prefers-reduced-motion: reduce) { .stn-pin.alarm { animation: none; box-shadow: 0 0 0 4px rgba(198,40,40,.5); } }
.leaflet-control-layers { font-size: 13px; }

/* ---------- alerts ---------- */
.alerts { list-style: none; margin: 10px 0 0; padding: 0; max-height: 400px; overflow: auto; }
.al { border: 1px solid var(--line); border-left-width: 4px; border-radius: 6px; padding: 9px 11px; margin-bottom: 8px; }
.al.sev-critical { border-left-color: var(--over); }
.al.sev-high { border-left-color: var(--near); }
.al.sev-medium { border-left-color: var(--cyan); }
.al.sev-low { border-left-color: #A9B4BF; }
.al-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.al-type { font: 600 15px var(--head); }
.al-time { font-size: 12px; color: var(--ink-3); white-space: nowrap; }
.al-meta { font-size: 12.5px; color: var(--ink-2); margin: 2px 0 6px; }
.al-sev { font-weight: 600; }
.al-params { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12.5px; }
.al-params b { font: 600 14px var(--head); color: var(--ink); }
.al-params .over b { color: var(--over); }
.al-foot { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 6px; margin-top: 8px; }
.rev { font-size: 12px; font-weight: 500; padding: 2px 8px; border-radius: 10px; background: #EEF2F6; color: var(--ink-2); }
.rev.verified { background: #E3F2E9; color: var(--ok); }
.rev.dismissed { text-decoration: line-through; }
.al-actions { display: flex; gap: 6px; }
.al-actions button, .link { border: 1px solid var(--line); background: #fff; border-radius: 5px; padding: 3px 9px; font-size: 12.5px; cursor: pointer; }
.al-actions button:hover, .link:hover { border-color: var(--band); color: var(--band); }
.empty { color: var(--ink-2); padding: 18px 4px; }

/* ---------- trend chart ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center; margin-bottom: 6px; }
.filters select { border: 1px solid var(--line); border-radius: 5px; padding: 5px 8px; background: #fff; min-width: 200px; }
.filters .link { margin-left: auto; }
.chart { position: relative; min-height: 300px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart.loading { opacity: .5; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 12.5px; color: var(--ink-2); margin-top: 4px; }
.legend i { display: inline-block; width: 16px; height: 2px; vertical-align: middle; margin-right: 6px; }
.legend i.dash { background: none; border-top: 2px dashed var(--ink-3); height: 0; }
.legend i.tri { width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; border-bottom: 9px solid var(--over); }
.chart-table { max-height: 300px; overflow: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 6px 8px; border-bottom: 1px solid #E8EDF2; text-align: left; vertical-align: top; }
th { font: 600 13px var(--head); color: var(--ink-2); background: #F6F9FB; position: sticky; top: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tooltip { position: fixed; z-index: 1500; pointer-events: none; background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; box-shadow: 0 4px 14px rgba(20,40,60,.14); font-size: 12.5px; min-width: 150px; }
.tooltip .tt-time { color: var(--ink-3); margin-bottom: 3px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 6px; }
.tooltip .tt-row i { width: 12px; height: 2px; display: inline-block; }
.tooltip .tt-row b { font: 600 15px var(--head); margin-right: 2px; }

/* ---------- AI assistant ---------- */
.chat { height: 286px; overflow: auto; display: flex; flex-direction: column; gap: 8px; padding: 4px 2px; }
.msg { max-width: 88%; padding: 8px 11px; border-radius: 10px; white-space: pre-wrap; font-size: 13.5px; }
.msg.user { align-self: flex-end; background: var(--band); color: #fff; border-bottom-right-radius: 3px; }
.msg.bot { align-self: flex-start; background: #EEF4F8; border-bottom-left-radius: 3px; }
.msg.bot small { display: block; color: var(--ink-3); margin-top: 4px; font-size: 11.5px; }
.msg.wait { color: var(--ink-3); font-style: italic; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chips button { border: 1px solid #BFE3DA; background: #F1FAF7; color: #17694C; border-radius: 14px; padding: 4px 10px; font-size: 12.5px; cursor: pointer; }
.chips button:hover { background: #DFF3EC; }
.ask { display: flex; gap: 6px; }
.ask input { flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; }
.ask button { border: 0; background: var(--green); color: #fff; border-radius: 6px; padding: 8px 16px; font: 600 14px var(--head); cursor: pointer; }
.ask button:disabled { opacity: .5; }

/* ---------- KPI and partners ---------- */
.p-kpi { overflow-x: auto; }
.kpi td:first-child { font: 600 14px var(--head); color: var(--band-deep); }
.kpi td.target { font: 600 15px var(--head); color: var(--band); white-space: nowrap; }
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; font-weight: 500; white-space: nowrap; }
.pill svg { width: 13px; height: 13px; }
.phase1 { margin: 12px 0 0; padding: 8px 12px; background: #F1FAF7; border-left: 3px solid var(--green); font: 500 14px var(--head); color: var(--ink); }
.p-partners p { margin: 6px 0; }
.code { background: #0F2537; color: #D7E8F5; border-radius: 6px; padding: 10px 12px; font: 12px/1.5 ui-monospace, Consolas, monospace; overflow: auto; }

.foot { padding: 16px 24px 28px; color: var(--ink-2); font-size: 12.5px; border-top: 1px solid var(--line); margin: 0 24px; }
.foot p { margin: 2px 0; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .p-current, .p-map, .p-trend, .p-kpi, .p-network, .p-alerts, .p-ai, .p-partners { grid-column: span 12; }
}
@media (max-width: 720px) {
  .band { grid-template-columns: 1fr; padding: 0 0 10px; gap: 8px; }
  .brand { margin: 0; clip-path: none; justify-content: center; }
  .band-tools { justify-content: center; flex-wrap: wrap; }
  .yearbox { display: none; }
  .sheet { padding: 0 10px 16px; gap: 10px; }
  .statusline { padding: 8px 12px; }
  .readings { grid-template-columns: 1fr; }
  .figures { grid-template-columns: repeat(2, 1fr); }
  .bar { flex-wrap: wrap; }
  .bar .seg { position: static; }
  .map { height: 360px; }
  .kpi { font-size: 12.5px; }
  .kpi th, .kpi td { padding: 5px 4px; }
  .kpi td:first-child { font-size: 13px; }
  .kpi td.target { white-space: normal; }
  .foot { margin: 0 10px; padding: 14px 4px 24px; }
}
