/* =================== v3: hero, map, holidays, polish =================== */
body { background:
  radial-gradient(1200px 500px at 85% -10%, color-mix(in srgb, var(--brand-navy) 10%, transparent), transparent 60%),
  radial-gradient(900px 400px at -10% 20%, color-mix(in srgb, var(--brand-red) 6%, transparent), transparent 60%),
  var(--bg); background-attachment: fixed; }
.card, .kpi { transition: transform .15s ease, box-shadow .15s ease; }
.kpi:hover { transform: translateY(-2px); box-shadow: 0 6px 22px rgba(9, 45, 116, .12); }
.kpi-icon { position: absolute; right: 14px; top: 12px; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  font-size: 17px; font-weight: 700; color: var(--brand-navy); background: color-mix(in srgb, var(--brand-navy) 9%, transparent); }
.kpi--hero .kpi-icon { color: var(--brand-red); background: color-mix(in srgb, var(--brand-red) 10%, transparent); }
:root[data-theme="dark"] .kpi-icon { color: #9db9ff; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.kpi-value { font-size: 30px; }

.hero {
  display: grid; grid-template-columns: minmax(280px, 380px) minmax(0, 1fr); border-radius: 18px; overflow: hidden;
  background: linear-gradient(135deg, #0a2a6b 0%, #0b1f4d 45%, #1d1650 75%, #3a0f2e 100%); color: #fff;
  box-shadow: 0 10px 40px rgba(9, 45, 116, .28); position: relative;
}
.hero::after { content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(500px 220px at 15% 0%, rgba(56, 189, 248, .22), transparent 70%), radial-gradient(400px 260px at 30% 110%, rgba(207, 0, 36, .25), transparent 70%); }
.hero-left { padding: 26px 26px 20px; display: grid; align-content: start; gap: 10px; position: relative; z-index: 1; }
.hero-label { font-size: 14px; color: #c7d4f0; display: flex; align-items: center; gap: 8px; }
.live-dot { width: 10px; height: 10px; border-radius: 50%; background: #22c55e; animation: pulse 1.8s infinite; }
.live-dot.stale { background: #ef4444; animation: none; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, .6); } 70% { box-shadow: 0 0 0 12px rgba(34, 197, 94, 0); } 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); } }
.hero-value { font-size: 64px; font-weight: 700; line-height: 1; letter-spacing: -1.5px; font-variant-numeric: tabular-nums; color: #ffffff; text-shadow: 0 2px 24px rgba(147, 197, 253, .35); }
.hero-value small { font-size: 20px; font-weight: 500; margin-left: 8px; letter-spacing: 0; color: #9fb6e6; text-shadow: none; }
.hero-spark { height: 70px; position: relative; }
.hero-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hero-stats div { background: rgba(255, 255, 255, .07); border: 1px solid rgba(255, 255, 255, .1); border-radius: 12px; padding: 10px 12px; display: grid; }
.hero-stats span { font-size: 12px; color: #aebfe2; }
.hero-stats b { font-size: 22px; font-variant-numeric: tabular-nums; }
.hero-stats small { font-size: 11px; color: #8ea3cf; }
.hero-foot { font-size: 12px; color: #aebfe2; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tou-chip { padding: 3px 10px; border-radius: 999px; font-weight: 600; font-size: 12px; }
.tou-on { background: rgba(235, 104, 52, .25); color: #ffc2a6; border: 1px solid rgba(235, 104, 52, .5); }
.tou-off { background: rgba(42, 120, 214, .25); color: #b9d6ff; border: 1px solid rgba(42, 120, 214, .5); }
.tou-hol { background: rgba(27, 175, 122, .22); color: #b0f0d6; border: 1px solid rgba(27, 175, 122, .5); }
.hero-map { position: relative; z-index: 1; padding: 12px 12px 12px 0; }

/* map */
.sitemap { width: 100%; height: auto; display: block; font-family: "Plex Thai", sans-serif; }
.map-card { border-radius: 18px; overflow: hidden; box-shadow: 0 10px 40px rgba(9, 45, 116, .25); background: #071433; }
.map-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.map-side { position: sticky; top: 64px; }
.map-bld { cursor: pointer; }
.map-bld polygon { transition: fill-opacity .2s; }
.map-bld:hover polygon { fill-opacity: .5; }
.map-bld-letter { fill: #ffffff; font-size: 34px; font-weight: 700; text-anchor: middle; paint-order: stroke; stroke: rgba(0, 0, 0, .35); stroke-width: 3px; }
.map-bld-kw { fill: #e2e8f0; font-size: 15px; font-weight: 600; text-anchor: middle; paint-order: stroke; stroke: rgba(0, 0, 0, .45); stroke-width: 3px; }
.map-road { fill: #9fb3d9; font-size: 14px; text-anchor: middle; opacity: .8; }
.map-north { fill: #cbd5e1; font-size: 13px; font-weight: 700; text-anchor: middle; }
.map-flow { stroke-dasharray: 4 22; animation: flow 1.4s linear infinite; opacity: .9; }
.map-flow--stop { animation: none; opacity: 0; }
@keyframes flow { to { stroke-dashoffset: -26; } }
.map-ring { transform-origin: center; transform-box: fill-box; animation: ring 2.2s ease-out infinite; }
.map-ring--stale { stroke: #ef4444; animation: none; }
@keyframes ring { 0% { transform: scale(.7); opacity: .9; } 100% { transform: scale(1.8); opacity: 0; } }
.map-pulse { animation: blink 2s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .45; } }
.map-badge, .map-marker, .map-server, .map-surge { cursor: pointer; }
.map-badge:hover rect:first-child { stroke: #93c5fd; }
.map-badge-h { fill: #a9b9d8; font-size: 11.5px; font-weight: 500; }
.map-badge-v { fill: #ffffff; font-size: 24px; font-weight: 700; }
.map-badge-u { fill: #9fb3d9; font-size: 12px; }
.map-badge-s { fill: #cbd5e1; font-size: 11.5px; }
.map-server-t { fill: #e2e8f0; font-size: 14px; font-weight: 700; text-anchor: middle; }
.map-server-s { fill: #93c5fd; font-size: 11px; text-anchor: middle; }
.map-legend-t { fill: #cbd5e1; font-size: 12.5px; }
.sitemap--compact .map-legend { display: none; }
.ms-body { display: grid; gap: 10px; font-size: 14px; }
.ms-body .big { font-size: 34px; font-weight: 700; font-variant-numeric: tabular-nums; }
.ms-body dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0; }
.ms-body dt { color: var(--text-muted); }
.ms-body dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

/* holidays */
.hol-tools { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; font-size: 14px; }
.hol-wrap { max-height: 520px; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; }
table.hol th { position: sticky; top: 0; z-index: 1; }
table.hol td { vertical-align: middle; }
table.hol input[type=date] { width: 150px; text-align: left; }
table.hol input.hn { width: 100%; min-width: 220px; text-align: left; }
table.hol tr.off td { opacity: .55; }
table.hol .wd { color: var(--text-secondary); white-space: nowrap; }
table.hol .wd.we { color: var(--text-muted); }
table.hol input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--brand-navy); }
table.hol tr.yr td { background: var(--surface-2); font-weight: 700; color: var(--tab-active); }

@media screen and (max-width: 1100px) {
  .hero { grid-template-columns: minmax(0, 1fr); }
  .hero-map { padding: 0 12px 12px; }
  .map-layout { grid-template-columns: minmax(0, 1fr); }
  .map-side { position: static; }
}
@media screen and (max-width: 600px) {
  .hero-value { font-size: 48px; }
  .hero-left { padding: 20px 18px 14px; }
}
@media (prefers-reduced-motion: reduce) { .map-flow, .map-ring, .map-pulse, .live-dot { animation: none !important; } }

/* =================== v4: navy "control room" theme (default) =================== */
:root[data-theme="dark"] body {
  background:
    radial-gradient(1100px 520px at 90% -10%, rgba(56, 189, 248, .10), transparent 60%),
    radial-gradient(900px 480px at -10% 30%, rgba(207, 0, 36, .10), transparent 60%),
    radial-gradient(800px 500px at 50% 120%, rgba(98, 80, 214, .12), transparent 60%),
    #06112b;
  background-attachment: fixed;
}
:root[data-theme="dark"] .card, :root[data-theme="dark"] .kpi {
  background: linear-gradient(180deg, rgba(18, 36, 82, .92), rgba(10, 24, 58, .92));
  border-color: #1d3266; box-shadow: 0 10px 30px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .04);
}
:root[data-theme="dark"] .kpi:hover { box-shadow: 0 12px 34px rgba(0, 0, 0, .45), 0 0 0 1px rgba(56, 189, 248, .35); }
:root[data-theme="dark"] .tabs { background: rgba(6, 17, 43, .92); backdrop-filter: blur(8px); border-bottom-color: #1d3266; }
:root[data-theme="dark"] .tabs button.active { color: #ffffff; }
:root[data-theme="dark"] th { background: rgba(16, 34, 80, .9); }
:root[data-theme="dark"] tr.grand td { background: rgba(56, 189, 248, .10); }
:root[data-theme="dark"] select, :root[data-theme="dark"] input[type=month], :root[data-theme="dark"] input[type=number],
:root[data-theme="dark"] input[type=text], :root[data-theme="dark"] input[type=password], :root[data-theme="dark"] input[type=date],
:root[data-theme="dark"] textarea { background: #0a1735; border-color: #22397a; color: #eef3ff; color-scheme: dark; }
:root[data-theme="dark"] .btn { background: linear-gradient(135deg, #1d4ed8, #0a2a6b); box-shadow: 0 4px 14px rgba(29, 78, 216, .35); }
:root[data-theme="dark"] .btn-light { background: #102250; border-color: #22397a; color: #eef3ff; }
:root[data-theme="dark"] .kpi::before { background: linear-gradient(180deg, #38bdf8, #1d4ed8); }
:root[data-theme="dark"] .kpi--hero::before { background: linear-gradient(180deg, #ff4d6d, #b11e29); }
:root[data-theme="dark"] .kpi-value { color: #ffffff; text-shadow: 0 0 18px rgba(147, 197, 253, .25); }
:root[data-theme="dark"] .kpi-icon { background: rgba(56, 189, 248, .12); color: #7dd3fc; }
:root[data-theme="dark"] .kpi--hero .kpi-icon { background: rgba(255, 77, 109, .14); color: #ff8fa3; }
:root[data-theme="dark"] .insights li { background: rgba(16, 34, 80, .7); border-left-color: #38bdf8; }
:root[data-theme="dark"] .hbar-track { background: rgba(255, 255, 255, .06); }
:root[data-theme="dark"] .meter { background: rgba(10, 24, 58, .8); border-color: #1d3266; }
:root[data-theme="dark"] .sim-out div { background: rgba(10, 24, 58, .8); }
:root[data-theme="dark"] .card h2 { color: #ffffff; }
:root[data-theme="dark"] .status { background: #ffffff; }
:root[data-theme="dark"] .foot { color: #8597c2; }
:root[data-theme="dark"] .hol-wrap { border-color: #1d3266; }
:root[data-theme="dark"] .tip { background: #0c1a3d; border-color: #22397a; color: #eef3ff; }
.age { font-variant-numeric: tabular-nums; opacity: .8; font-weight: 500; }

/* heatmap labels v5 */
.hm-row { grid-template-columns: 112px repeat(24, minmax(20px, 1fr)); }
.hm-head { font-size: 12px; font-weight: 600; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.hm-unit { font-size: 11px; color: var(--text-muted); }
.hm-band .hm-day { font-size: 11px; color: var(--text-muted); }
.hm-tou { height: 6px; border-radius: 3px; display: block; }
.hm-tou.on { background: var(--s2); }
.hm-tou.off { background: transparent; }
.hm-key { display: inline-flex; align-items: center; gap: 6px; margin-left: 16px; }
.hm-key .hm-tou { width: 26px; display: inline-block; }

/* heatmap day markers v6 */
.hm-we { color: var(--text-muted); }
.hm-ph { color: #fbbf24; font-size: 11px; }
.hm-row--ph .hm-day { color: #fbbf24; font-weight: 700; }
.hm-day[data-tip] { cursor: help; }
:root[data-theme="light"] .hm-ph, :root[data-theme="light"] .hm-row--ph .hm-day { color: #b45309; }

/* Ft current period */
tr.ft-cur td { background: rgba(56, 189, 248, .10); }
#ft-src a { color: #7dd3fc; }
:root[data-theme="light"] #ft-src a { color: var(--brand-navy); }

/* phase balance */
.phbars { white-space: nowrap; }
.phbar { display: inline-grid; grid-template-columns: 54px auto; align-items: center; gap: 4px; margin-left: 8px; font-size: 12px; }
.phbar i { display: block; height: 8px; border-radius: 4px; min-width: 2px; }
.phbar b { font-weight: 600; font-variant-numeric: tabular-nums; }
.ps-row { cursor: pointer; }
.ps-row:hover td { background: rgba(56, 189, 248, .08); }
#ph-kpis .kpi-value { font-size: 26px; }

/* smart insights */
.badge { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; margin-left: 6px; border-radius: 999px;
  font-size: 12px; font-weight: 700; color: #fff; vertical-align: 1px; }
.badge--bad { background: var(--critical); animation: blink 1.6s ease-in-out infinite; }
.badge--warn { background: #d97706; }
.alerts { display: grid; gap: 10px; max-height: 620px; overflow-y: auto; padding-right: 4px; }
.alert { border: 1px solid var(--border); border-left: 4px solid var(--s1); border-radius: 10px; padding: 10px 14px; background: rgba(16, 34, 80, .55); }
.alert--bad { border-left-color: var(--critical); }
.alert--warn { border-left-color: #f59e0b; }
.alert--info { border-left-color: var(--s1); }
.alert--old { opacity: .55; }
.alert-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 12px; color: var(--text-muted); }
.alert-lv { font-weight: 700; padding: 1px 8px; border-radius: 999px; color: #fff; background: var(--s1); }
.alert--bad .alert-lv { background: var(--critical); }
.alert--warn .alert-lv { background: #d97706; }
.alert-time { margin-left: auto; }
.alert-title { font-weight: 700; font-size: 15px; margin-top: 4px; }
.alert-detail { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.alert-action { font-size: 13px; margin-top: 6px; color: var(--text-primary); }
:root[data-theme="light"] .alert { background: var(--surface-2); }

/* TV / kiosk mode */
body.tv .tabs, body.tv .controls, body.tv .tabs-right, body.tv .foot, body.tv #theme, body.tv a[href="/logout"] { display: none !important; }
body.tv main { max-width: none; padding: 18px 28px; }
body.tv .hero-value { font-size: 84px; }
body.tv .kpi-value { font-size: 36px; }
body.tv #tvmode { outline: 2px solid #38bdf8; }

/* small screens: phones */
@media screen and (max-width: 700px) {
  .brand-right { gap: 8px; }
  .status { font-size: 11px; padding: 5px 10px; }
  .icon-btn { width: 30px; height: 30px; }
  .tabs button { padding: 12px 10px 10px; font-size: 14px; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { padding: 12px; }
  .kpi-value { font-size: 20px; }
  .kpi-icon { display: none; }
  .hero-stats b { font-size: 18px; }
  .card { padding: 14px; }
  .card-head { flex-direction: column; align-items: stretch; }
  .controls { gap: 8px; }
  .controls label { display: grid; gap: 2px; flex: 1 1 140px; }
  .controls select, .controls input { width: 100%; }
  .chart-box, .chart-box--tall { height: 240px; }
  .hm-row { grid-template-columns: 62px repeat(24, minmax(10px, 1fr)); }
  .hm-head { font-size: 9px; }
  .hm-day { font-size: 10px; }
  .alert-time { margin-left: 0; }
}
@media screen and (max-width: 420px) {
  .kpis { grid-template-columns: 1fr; }
  .brand-right .status { display: none; }
}
/* very large screens (TV 4K) */
@media screen and (min-width: 2200px) { html { font-size: 18px; } body { font-size: 18px; } main { max-width: 2000px; } }
