/* standalone base (the artifact host used to add these) */
:root { padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
[hidden] { display: none !important; }
img { max-width: 100%; }

/* Layout: header + pipeline bar (play controls | 측정 → AI 판정 → 자동 대응), each stage opens a two-card page. Site cards with ring gauges on the left, detail on the right. */
:root {
  --bg: #f2f4f7; --panel: #ffffff; --panel-2: #f6f8fa; --sunk: #eef1f5; --ink: #0e1116; --muted: #5b6675; --faint: #8a94a3;
  --line: #e2e7ed; --grid: #edf0f4; --teal: #0f766e; --teal-soft: #e7f5f2; --indigo: #4f46e5; --indigo-soft: #eef0fe;
  --green: #15803d; --red: #dc2626; --amber: #c26a06; --slate-2: #64748b; --on-teal: #ffffff;
  --green-soft: #e8f5ec; --amber-soft: #fdf3e3; --red-soft: #fdecec; --agit: rgba(194, 106, 6, 0.09);
  --h2s: #2a78d6; --nh3: #eb6834; --ch4: #1baf7a;
  --shadow: 0 1px 2px rgba(15,23,42,.05), 0 4px 14px rgba(15,23,42,.04);
  --font: "IBM Plex Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0f14; --panel: #131920; --panel-2: #18202a; --sunk: #1c2530; --ink: #e7ecf2; --muted: #9aa6b4; --faint: #6b7684;
    --line: #252f3b; --grid: #1d2631; --teal: #2dd4bf; --teal-soft: #0f2a28; --indigo: #818cf8; --indigo-soft: #1c1f3a;
    --green: #4ade80; --red: #f87171; --amber: #fbbf24; --slate-2: #94a3b8; --on-teal: #04201d;
    --green-soft: #10261a; --amber-soft: #2e230b; --red-soft: #351819; --agit: rgba(251, 191, 36, 0.08);
    --h2s: #3987e5; --nh3: #d95926; --ch4: #199e70;
    --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0f14; --panel: #131920; --panel-2: #18202a; --sunk: #1c2530; --ink: #e7ecf2; --muted: #9aa6b4; --faint: #6b7684;
  --line: #252f3b; --grid: #1d2631; --teal: #2dd4bf; --teal-soft: #0f2a28; --indigo: #818cf8; --indigo-soft: #1c1f3a;
  --green: #4ade80; --red: #f87171; --amber: #fbbf24; --slate-2: #94a3b8; --on-teal: #04201d;
  --green-soft: #10261a; --amber-soft: #2e230b; --red-soft: #351819; --agit: rgba(251, 191, 36, 0.08);
  --h2s: #3987e5; --nh3: #d95926; --ch4: #199e70;
  --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 14px; line-height: 1.5; font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; border-radius: 6px; }
h1, h2, h3 { text-wrap: balance; }
.num { font-family: var(--mono); }
.wrap { max-width: 1560px; margin: 0 auto; padding-block: 18px 28px; padding-left: max(22px, env(safe-area-inset-left, 0px)); padding-right: max(22px, env(safe-area-inset-right, 0px)); }

/* header */
header { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.logo { width: 42px; height: 42px; flex: none; }
.brand { min-width: 0; }
.brand h1 { margin: 0; font-size: 21px; font-weight: 700; letter-spacing: -.01em; }
.brand p { margin: 1px 0 0; color: var(--muted); font-size: 13px; }
.status { margin-left: auto; display: flex; align-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 7px 14px 7px 12px; font-size: 13px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--green); flex: none; }
.dot[data-s="1"] { background: var(--amber); } .dot[data-s="2"] { background: var(--red); }
.status .bar { width: 96px; height: 4px; border-radius: 4px; background: var(--sunk); overflow: hidden; }
.status .bar i { display: block; height: 100%; width: 0; background: var(--teal); }
.note { margin: 10px 0 0; font-size: 12px; color: var(--faint); }

/* pipeline bar */
.flow { margin-top: 16px; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 12px 16px; align-items: stretch; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 12px; box-shadow: var(--shadow); }
.ctl { display: flex; flex-direction: column; justify-content: center; gap: 8px; padding: 2px 14px 2px 4px; border-right: 1px solid var(--line); }
.btn { border: 1px solid var(--line); background: var(--panel-2); border-radius: 10px; padding: 8px 14px; cursor: pointer; font-weight: 600; font-size: 13px; }
.btn:hover { border-color: var(--teal); }
.btn.primary { background: var(--teal); border-color: var(--teal); color: var(--on-teal); padding: 10px 18px; font-size: 14px; }
.btn.primary:hover { filter: brightness(1.08); }
.speed { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); }
.seg { display: inline-flex; background: var(--sunk); border-radius: 8px; padding: 2px; }
.seg button { border: 0; background: none; padding: 3px 8px; border-radius: 6px; font-size: 12px; cursor: pointer; color: var(--muted); white-space: nowrap; }
.seg button[aria-pressed="true"] { background: var(--panel); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }
.stages-col { display: grid; gap: 10px; min-width: 0; }
.stages { display: grid; grid-template-columns: minmax(0, 1fr) 44px minmax(0, 1fr) 44px minmax(0, 1fr); align-items: stretch; }
.stage { text-align: left; border: 1px solid var(--line); background: var(--panel); border-radius: 12px; padding: 10px 14px; cursor: pointer; min-width: 0; }
.stage:hover { background: var(--panel-2); }
.stage[aria-selected="true"] { border-color: var(--teal); background: var(--teal-soft); box-shadow: inset 0 0 0 1px var(--teal); }
.stage .k { display: flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 600; color: var(--muted); }
.stage .k b { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; color: #fff; }
.stage .v { font-size: 19px; font-weight: 700; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stage .s { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pipe { position: relative; align-self: center; height: 2px; margin: 0 6px; background: var(--line); }
.pipe::after { content: ""; position: absolute; right: -2px; top: -4px; border: 5px solid transparent; border-left: 7px solid var(--line); border-right: 0; }
.pipe i { position: absolute; top: -3px; width: 8px; height: 8px; border-radius: 50%; background: var(--teal); opacity: 0; }
.pipe.on { background: var(--teal); } .pipe.on::after { border-left-color: var(--teal); }
.pipe.on i { animation: flow 1.1s linear infinite; opacity: 1; } .pipe.on i + i { animation-delay: .55s; }
@keyframes flow { from { left: 0; } to { left: calc(100% - 8px); } }
.timeline { display: flex; align-items: center; gap: 12px; font-size: 12px; color: var(--muted); padding: 0 2px; }
.timeline input { flex: 1; min-width: 0; accent-color: var(--teal); margin: 0; }
.timeline .num { color: var(--ink); white-space: nowrap; }

/* pages + cards */
.page { display: none; margin-top: 16px; gap: 16px; }
.page.on { display: grid; }
#p-sense { grid-template-columns: minmax(0, 1fr); }
#p-ai { grid-template-columns: minmax(340px, 400px) minmax(0, 1fr); }
#p-act { grid-template-columns: minmax(320px, 380px) minmax(0, 1fr); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 16px; box-shadow: var(--shadow); min-width: 0; align-self: start; }
.card h2 { margin: 0; font-size: 16px; font-weight: 700; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.sec { display: flex; align-items: center; gap: 10px; margin: 16px 0 8px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.sec::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.live { margin-left: auto; display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--muted); }
.live .dot { background: var(--faint); }
.live.on { color: var(--red); } .live.on .dot { background: var(--red); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .3; } }
.chk { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; margin-top: 8px; }
.chk input { accent-color: var(--teal); width: 15px; height: 15px; }

/* facility board */
.summary { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 12px; align-items: center; }
.sum { display: flex; align-items: center; gap: 10px; border-radius: 12px; padding: 8px 16px 8px 12px; background: var(--green-soft); }
.sum[data-s="1"] { background: var(--amber-soft); } .sum[data-s="2"] { background: var(--red-soft); }
.sum svg { width: 20px; height: 20px; }
.sum b { font-size: 26px; font-weight: 700; line-height: 1; }
.sum span { font-size: 13px; font-weight: 600; color: var(--green); }
.sum[data-s="1"] span { color: var(--amber); } .sum[data-s="2"] span { color: var(--red); }
.board { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.fac { text-align: left; border: 1px solid var(--line); border-left: 5px solid var(--green); background: var(--panel); border-radius: 12px; padding: 10px 12px; cursor: pointer; display: grid; gap: 4px; min-width: 0; }
.fac[data-s="1"] { border-left-color: var(--amber); background: var(--amber-soft); }
.fac[data-s="2"] { border-left-color: var(--red); background: var(--red-soft); }
.fac:hover { box-shadow: 0 0 0 1px var(--slate-2); }
.fac[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--teal); }
.fac-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.fac-name { font-weight: 700; font-size: 15px; }
.fac-state { display: inline-flex; align-items: center; gap: 5px; font-weight: 700; font-size: 14px; color: var(--green); }
.fac[data-s="1"] .fac-state { color: var(--amber); } .fac[data-s="2"] .fac-state { color: var(--red); }
.fac-state svg { width: 16px; height: 16px; }
.fac-type { font-size: 14px; font-weight: 500; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: -2px; }
.fac-why { font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fac .spark { width: 100%; height: 28px; display: block; }
.fac-vals { display: flex; flex-wrap: wrap; gap: 2px 10px; font-size: 11.5px; color: var(--muted); }
.fac-vals b { font-family: var(--mono); color: var(--ink); font-size: 12.5px; font-weight: 500; }
.fac-scn { font-size: 11px; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(300px, 1fr); gap: 4px 24px; align-items: start; }
.detail-side .raw { grid-template-columns: minmax(0, 1fr); gap: 4px; }
.badge { margin-left: auto; font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 999px; white-space: nowrap; background: var(--green-soft); color: var(--green); }
.badge[data-s="1"] { background: var(--amber-soft); color: var(--amber); }
.badge[data-s="2"] { background: var(--red-soft); color: var(--red); }

/* detail */
.detail-head { display: flex; gap: 12px; align-items: flex-start; }
.detail-head .badge { margin-left: auto; font-size: 12px; padding: 3px 10px; }
.alert { margin-top: 10px; border-radius: 12px; padding: 10px 14px; background: var(--green-soft); display: flex; gap: 10px; align-items: flex-start; font-size: 13px; }
.alert[data-s="1"] { background: var(--amber-soft); } .alert[data-s="2"] { background: var(--red-soft); }
.alert strong { display: block; font-size: 14px; }
.alert span { color: var(--muted); }
.alert svg { width: 18px; height: 18px; flex: none; margin-top: 2px; }
.gtiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 10px; }
.tile { background: var(--panel-2); border-radius: 10px; padding: 8px 10px; min-width: 0; }
.tile span { display: block; font-size: 11.5px; color: var(--muted); }
.tile strong { font-size: 17px; font-weight: 700; }
.tile .k2 { display: flex; align-items: center; gap: 6px; }
.tile em { display: block; font-style: normal; font-size: 11.5px; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.key { width: 12px; height: 3px; border-radius: 2px; display: inline-block; flex: none; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 11.5px; color: var(--muted); align-items: center; margin-bottom: 4px; }
.legend span { display: inline-flex; gap: 6px; align-items: center; }
.lk { width: 16px; height: 0; border-top: 2px solid var(--slate-2); display: inline-block; }
.lk.dash { border-top-style: dashed; border-color: var(--faint); }
.lk.band { height: 10px; border: none; background: var(--agit); border-radius: 2px; box-shadow: inset 0 0 0 1px var(--line); }
.lk.alarm { height: 6px; border: none; border-radius: 2px; }
.chart { position: relative; }
.ctitle { font-size: 13px; font-weight: 700; margin: 10px 0 2px; display: flex; gap: 8px; align-items: center; }
.ctitle .num { font-weight: 400; color: var(--muted); font-size: 11.5px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; cursor: crosshair; touch-action: pan-y; }
.chart text { font-family: var(--mono); font-size: 10.5px; fill: var(--faint); }
.tip { position: absolute; pointer-events: none; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 12px; box-shadow: 0 8px 28px rgba(15,23,42,.14); min-width: 160px; z-index: 3; }
.tip .rw { display: flex; justify-content: space-between; gap: 12px; }
.tip .rw span:first-child { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); }
.raw { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.cnote { font-size: 11.5px; color: var(--muted); margin: 6px 0 0; }
.log { max-height: 180px; overflow: auto; font-size: 12.5px; border-top: 1px solid var(--line); padding-top: 6px; }
.log div { display: flex; gap: 10px; padding: 2px 0; }
.log time { color: var(--faint); flex: none; white-space: nowrap; width: 40px; font-family: var(--mono); font-size: 12px; }
.log .s2 { color: var(--red); } .log .s1 { color: var(--amber); } .log .s0 { color: var(--green); } .log .truth { color: var(--faint); } .log .agit { color: var(--indigo); }
.empty { color: var(--faint); padding: 10px 0; font-size: 12.5px; }

/* AI page */
.ptiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.meters { display: grid; gap: 10px; }
.meter { display: grid; grid-template-columns: 96px minmax(0, 1fr) 46px 40px; gap: 8px; align-items: center; font-size: 12.5px; }
.meter .trk { height: 8px; background: var(--sunk); border-radius: 4px; overflow: hidden; position: relative; }
.meter .trk i { display: block; height: 100%; background: var(--green); border-radius: 0 4px 4px 0; }
.meter .trk b { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--ink); opacity: .55; }
.meter[data-s="1"] .trk i { background: var(--amber); } .meter[data-s="2"] .trk i { background: var(--red); }
.meter .st { font-weight: 600; font-size: 12px; }
.meter[data-s="0"] .st { color: var(--green); } .meter[data-s="1"] .st { color: var(--amber); } .meter[data-s="2"] .st { color: var(--red); }
.feats { margin: 0; padding-left: 18px; font-size: 13px; display: grid; gap: 3px; color: var(--muted); }
.feats b { color: var(--ink); font-weight: 600; }
.insight { margin-top: 14px; background: var(--teal-soft); border-radius: 12px; padding: 12px 14px; }
.insight h3 { margin: 0 0 4px; font-size: 12.5px; color: var(--teal); font-weight: 700; }
.insight p, .insight li { margin: 0; font-size: 13px; line-height: 1.65; }
.insight ul { margin: 0; padding-left: 18px; display: grid; gap: 4px; }
.insight b { font-weight: 700; }
.cmp { display: grid; grid-template-columns: 132px repeat(3, minmax(0, 1fr)); gap: 8px 14px; align-items: center; }
.cmp .hd { font-size: 12px; color: var(--muted); font-weight: 600; }
.cmp .mname { font-size: 12.5px; font-weight: 600; }
.cmp .cell { display: grid; gap: 3px; min-width: 0; }
.cmp svg { width: 100%; height: 12px; display: block; }
.outcome { font-size: 11.5px; display: flex; gap: 6px; align-items: center; color: var(--muted); }
.outcome i { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.tbl { overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th { position: sticky; top: 0; background: var(--panel-2); color: var(--muted); font-weight: 600; text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 7px 10px; border-bottom: 1px solid var(--grid); vertical-align: top; }
tbody th { position: static; background: none; color: var(--ink); border-bottom: 1px solid var(--grid); white-space: normal; }
tr:last-child td, tr:last-child th { border-bottom: none; }
.pm { display: grid; grid-template-columns: 34px minmax(30px, 1fr) 34px; gap: 6px; align-items: center; font-size: 11.5px; color: var(--muted); }
.pm .trk { height: 5px; background: var(--sunk); border-radius: 3px; overflow: hidden; }
.pm .trk i { display: block; height: 100%; border-radius: 0 3px 3px 0; }
.ok { color: var(--green); font-weight: 600; } .bad { color: var(--red); font-weight: 600; }
.verdict { font-size: 11.5px; margin-top: 2px; }
.twocol { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 20px; }

/* response page */
.acts { list-style: none; margin: 0; padding: 0; }
.acts li { display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--grid); font-size: 13px; }
.acts li:last-child { border-bottom: none; }
.acts .dev { color: var(--muted); }
.acts .st { display: flex; gap: 8px; align-items: baseline; font-weight: 600; }
.acts .st i { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--green); transform: translateY(-1px); }
.acts .st[data-s="1"] i { background: var(--amber); } .acts .st[data-s="2"] i { background: var(--red); }
.rules { margin: 0; padding-left: 18px; font-size: 13px; color: var(--muted); display: grid; gap: 4px; }
.rules b { color: var(--ink); }
.clickrow { cursor: pointer; } .clickrow:hover td, .clickrow:hover th { background: var(--panel-2); }
.clickrow.sel td, .clickrow.sel th { background: var(--teal-soft); }
.cellst { display: inline-flex; gap: 6px; align-items: center; white-space: nowrap; }
.cellst i { width: 7px; height: 7px; border-radius: 50%; background: var(--green); }
.cellst[data-s="1"] i { background: var(--amber); } .cellst[data-s="2"] i { background: var(--red); }
.devices { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.device { background: var(--panel-2); border-radius: 12px; padding: 10px 12px; font-size: 12.5px; }
.device h3 { margin: 0 0 6px; font-size: 13px; display: flex; gap: 8px; align-items: center; }
.device p { margin: 0 0 4px; color: var(--muted); }
.device p b { color: var(--ink); font-weight: 600; }

/* toast */
.toast { position: fixed; right: calc(22px + env(safe-area-inset-right, 0px)); bottom: calc(22px + env(safe-area-inset-bottom, 0px)); background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--red); border-radius: 12px; padding: 10px 16px; box-shadow: 0 8px 28px rgba(15,23,42,.14); max-width: 360px; transform: translateY(16px); opacity: 0; pointer-events: none; transition: all .25s; z-index: 20; }
.toast.on { transform: none; opacity: 1; }
.toast[data-s="1"] { border-left-color: var(--amber); }
.toast strong { display: block; font-size: 13.5px; }
.toast span { font-size: 12.5px; color: var(--muted); }

@media (max-width: 1180px) {
  #p-sense, #p-ai, #p-act { grid-template-columns: minmax(0, 1fr); }
  .detail-grid { grid-template-columns: minmax(0, 1fr); }
  .detail-side .raw { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
}
@media (max-width: 900px) { .board { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px) {
  .wrap { padding-block: 14px 24px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
  .flow { grid-template-columns: minmax(0, 1fr); }
  .ctl { border-right: 0; border-bottom: 1px solid var(--line); padding: 0 0 12px; }
  .stages { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .pipe { display: none; }
  .raw, .detail-side .raw, .twocol, .devices { grid-template-columns: minmax(0, 1fr); }
  .status { margin-left: 0; width: 100%; }
  .gtiles, .ptiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cmp { grid-template-columns: 84px repeat(3, minmax(0, 1fr)); gap: 8px; }
  .cmp .mname { font-size: 11px; }
  .meter { grid-template-columns: 84px minmax(0, 1fr) 40px 34px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
