/* 대시보드 탭 (js/ui/dash.js) — PLC 메모리 모니터링 · 실시간 입출력.
   색은 앱 테마 토큰(app.css)만 — 다른 탭과 같은 테마 (다크 = 검정·녹색 #76B900, 라이트면 라이트). 강조색 테두리 카드 · '정상'(--ok) 값. */
#p-dash {
  /* 앱 테마 토큰(app.css)만 씀 — 다크는 남색·청록, 라이트는 푸른 회색·짙은 청록으로 다른 탭과 같은 색 */
  --d-card: var(--surface-2);
  --d-card-2: color-mix(in srgb, var(--accent) 12%, var(--surface));     /* 상태 카드·로봇 줄 */
  --d-card-2-line: color-mix(in srgb, var(--accent) 45%, var(--line));
  --d-line: var(--accent);
  --d-line-soft: color-mix(in srgb, var(--accent) 38%, transparent);
  --d-ink: var(--ink);
  --d-ink-2: var(--ink-2);
  --d-ink-3: var(--ink-3);
  --d-teal: var(--accent);
  --d-teal-ink: var(--accent-ink);
  --d-ok: var(--ok);
  --d-warn: var(--warn-text);
  --d-bad: var(--alarm);
  --d-off: var(--ink-3);
  --d-wait: var(--path-free);
  --d-in: var(--bg);                                                     /* 입력 칸 바탕 */
  --d-lamp-off: var(--line-2);
  --d-lamp-off-line: var(--line);
  --d-glow: color-mix(in srgb, var(--ok) 80%, transparent);
  color: var(--d-ink);
  padding: 14px 14px 28px;
  font-variant-numeric: tabular-nums;
}
.dash { display: grid; gap: 14px; }
.dash__card {
  background: var(--d-card);
  border: 2px solid var(--d-line-soft);
  border-radius: 6px;
}
.dash__card--line { border-color: var(--d-line); box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 12%, transparent), 0 6px 22px rgb(4 12 40 / .25); }

/* ── 머리 */
.dash__hero { display: flex; align-items: center; gap: 16px; padding: 14px 18px; border-color: var(--d-line); }
.dash__chip {
  flex: none; width: 64px; height: 64px; border-radius: 50%;
  display: grid; place-items: center;
  border: 2px solid var(--d-line); background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.dash__chipsvg { width: 38px; height: 38px; stroke: var(--d-teal); stroke-linecap: round; stroke-width: 3; }
.dash__chipsvg .dash__chipcore { fill: var(--d-teal); }
.dash__chipsvg--sm { width: 30px; height: 30px; }
.dash__herotxt { min-width: 0; flex: 1; }
.dash__title { margin: 0; font-size: clamp(20px, 3.4cqi, 28px); line-height: 1.12; font-weight: 800; letter-spacing: -0.01em; color: var(--d-ink); }
.dash__src { margin: 6px 0 0; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 13px; color: var(--d-ink-2); }
.dash__ro { font-size: 12px; font-weight: 700; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--d-line-soft); color: var(--d-teal); }
.dash__srcpick { display: grid; gap: 6px; flex: none; }
.dash__srcpick button {
  min-height: 34px; padding: 0 12px; border-radius: 4px; cursor: pointer;
  border: 1px solid var(--d-line-soft); background: transparent; color: var(--d-ink-2); font: inherit; font-size: 13px; font-weight: 700;
}
.dash__srcpick button[aria-checked="true"] { background: var(--d-teal); color: var(--d-teal-ink); border-color: var(--d-teal); }

/* ── 보기 탭 (감시 목록 · 실시간 IO · 변화 기록 · 진단) */
.dash__tabs {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px;
  padding: 4px; border-radius: 6px; background: var(--surface-2);
}
.dash__tabs button {
  min-height: 48px; border: 0; border-radius: 4px; cursor: pointer;
  background: transparent; color: var(--d-ink-2); font: inherit; font-size: 16px; font-weight: 800; letter-spacing: -0.01em;
  word-break: keep-all;
}
.dash__tabs button:hover { color: var(--d-ink); background: color-mix(in srgb, var(--ink) 7%, transparent); }
.dash__tabs button[aria-selected="true"] { background: var(--d-teal); color: var(--d-teal-ink); }
.dash__tabs button:focus-visible, .dash button:focus-visible, .dash select:focus-visible, .dash input:focus-visible {
  outline: 3px solid var(--d-ink); outline-offset: 2px;
}

.dash__pane { display: grid; gap: 10px; }
.dash__pane[hidden] { display: none; }
.dash__label {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; justify-content: space-between;
  font-size: 15px; font-weight: 800; color: var(--d-teal); letter-spacing: .01em;
}
.dash__ctl { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 6px; font-size: 13px; font-weight: 600; color: var(--d-ink-2); }
.dash__btn, .dash__sel, .dash__in {
  min-height: 36px; border-radius: 4px; font: inherit; font-size: 14px;
  border: 1px solid var(--d-line-soft); background: var(--d-in); color: var(--d-ink);
}
.dash__btn { padding: 0 12px; font-weight: 700; cursor: pointer; }
.dash__btn:hover:not(:disabled) { border-color: var(--d-line); }
.dash__btn:disabled { opacity: .45; cursor: default; }
.dash__btn[aria-pressed="true"] { color: var(--d-ok); }
.dash__btn[aria-pressed="false"] { color: var(--d-warn); }
.dash__btn--teal { background: var(--d-teal); color: var(--d-teal-ink); border-color: var(--d-teal); }
.dash__sel { padding: 0 8px; }
.dash__in { padding: 0 10px; min-width: 0; }
.dash__in::placeholder { color: var(--d-ink-3); }
.dash__note {
  margin: 0; padding: 8px 12px; border-radius: 4px; font-size: 13.5px; line-height: 1.45;
  background: var(--warn-soft); border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent); color: var(--d-ink);
}
.dash__note--sum { background: transparent; border: 0; padding: 0; color: var(--d-ink-2); font-size: 14px; }
.dash__help { margin: 0; font-size: 13px; color: var(--d-ink-2); line-height: 1.5; }
.dash__link { border: 0; background: none; padding: 0; font: inherit; color: var(--d-teal); text-decoration: underline; cursor: pointer; }
.dash__msg { margin: 0; min-height: 1.2em; font-size: 13px; color: var(--d-ok); }
.dash__msg[data-bad] { color: var(--d-bad); }

/* ── 감시 표 */
.dash__tblwrap { overflow-x: auto; }
.dash__tbl { width: 100%; border-collapse: collapse; table-layout: fixed; }
.dash__tbl th, .dash__tbl td { padding: 0 10px; text-align: left; vertical-align: middle; }
.dash__tbl thead th {
  height: 52px; font-size: 16px; font-weight: 800; color: var(--d-ink);
  border-bottom: 2px solid var(--d-line);
}
.dash__tbl thead th + th { border-left: 1px solid var(--d-line-soft); }
.dash__tbl tbody tr { height: 60px; border-top: 1.5px solid var(--d-line-soft); }
.dash__tbl tbody tr:first-child { border-top: 0; }
.dash__tbl th:nth-child(1) { width: 25%; }
.dash__tbl th:nth-child(2) { width: 20%; }
.dash__tbl th:nth-child(3) { width: 15%; }
.dash__tbl th:nth-child(5) { width: 44px; }
.dash__addr { font-size: 20px; font-weight: 800; color: var(--d-ink); letter-spacing: -0.01em; overflow-wrap: anywhere; }
.dash__addr small { display: block; font-size: 11.5px; font-weight: 600; color: var(--d-ink-3); }
.dash__val { font-size: 21px; font-weight: 800; color: var(--d-ok); overflow-wrap: anywhere; }
.dash__v[data-bit] { display: inline-flex; align-items: center; gap: 8px; }
.dash__v[data-bit]::before {
  content: ""; width: 11px; height: 11px; border-radius: 50%; flex: none;
  background: var(--d-lamp-off); border: 1.5px solid var(--d-lamp-off-line);
}
.dash__v[data-on]::before { background: var(--d-ok); border-color: var(--d-ok); box-shadow: 0 0 10px var(--d-glow); }
.dash__st { font-size: 17px; font-weight: 800; color: var(--d-ok); white-space: nowrap; }
.dash__dot { display: inline-block; width: 8px; height: 8px; margin-left: 5px; border-radius: 50%; background: currentColor; vertical-align: middle; }
.dash__tbl tr[data-s="chg"] .dash__st { color: var(--d-warn); }
.dash__tbl tr[data-s="chg"] .dash__val { color: var(--d-ok); animation: dash-flash 1.2s ease-out; }
.dash__tbl tr[data-s="bad"] .dash__st, .dash__tbl tr[data-s="bad"] .dash__val { color: var(--d-bad); }
.dash__tbl tr[data-s="wait"] .dash__st { color: var(--d-wait); }
.dash__tbl tr[data-s="wait"] .dash__val, .dash__tbl tr[data-s="stop"] .dash__val, .dash__tbl tr[data-s="stop"] .dash__st { color: var(--d-off); }
.dash__tbl tr[data-s="wait"] .dash__dot { animation: dash-blink 1s steps(2) infinite; }
@keyframes dash-flash { from { text-shadow: 0 0 14px var(--d-glow); } to { text-shadow: none; } }
@keyframes dash-blink { 50% { opacity: .2; } }
@media (prefers-reduced-motion: reduce) {
  .dash__tbl tr[data-s="chg"] .dash__val, .dash__tbl tr[data-s="wait"] .dash__dot { animation: none; }
}
.dash__subrow { height: 44px !important; }
.dash__subrow .dash__addr, .dash__subrow .dash__val { font-size: 16px; }
.dash__note-in {
  width: 100%; min-height: 40px; padding: 0 8px; margin-left: -8px;
  border: 1px solid transparent; border-radius: 4px; background: transparent;
  font: inherit; font-size: 17px; font-weight: 600; color: var(--d-ink);
}
.dash__note-in::placeholder { color: var(--d-ink-3); font-weight: 500; }
.dash__note-in[data-io]::placeholder { color: color-mix(in srgb, var(--accent) 60%, var(--ink-2)); font-weight: 600; }
.dash__note-in:hover { border-color: var(--d-line-soft); }
.dash__note-in:focus { border-color: var(--d-line); background: var(--d-in); }
.dash__x { text-align: center !important; padding: 0 4px !important; }
.dash__del {
  width: 32px; height: 32px; border-radius: 4px; border: 1px solid transparent; background: transparent; cursor: pointer;
  color: var(--d-ink-3); font-size: 20px; line-height: 1;
}
.dash__del:hover { color: var(--d-bad); border-color: color-mix(in srgb, var(--alarm) 50%, transparent); }
.dash__more td, .dash__empty td { padding: 14px 12px !important; font-size: 13.5px; color: var(--d-ink-2); }
.dash__add { display: grid; grid-template-columns: minmax(0, 1.2fr) auto minmax(0, 1fr) auto; gap: 8px; }
.dash__add .dash__sel[hidden] { display: none; }

/* ── 실시간 입출력 */
.dash__pill {
  padding: 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 800;
  border: 1px solid var(--d-line-soft); color: var(--d-ink-2);
}
.dash__pill[data-s="ok"] { color: var(--d-ok); border-color: color-mix(in srgb, var(--ok) 50%, transparent); }
.dash__pill[data-s="bad"] { color: var(--d-bad); border-color: color-mix(in srgb, var(--alarm) 50%, transparent); }
.dash__io { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@container (max-width: 520px) { .dash__io { grid-template-columns: 1fr; } .dash__add { grid-template-columns: 1fr 1fr; } }
.dash__iocol { padding: 10px 12px; min-width: 0; }
.dash__iocol h3 { margin: 0 0 6px; font-size: 15px; font-weight: 800; color: var(--d-ink); }
.dash__dio { list-style: none; margin: 0; padding: 0; display: grid; }
.dash__dioi {
  display: grid; grid-template-columns: 16px auto minmax(0, 1fr) auto; align-items: center; gap: 4px 10px;
  min-height: 42px; border-top: 1px solid var(--d-line-soft);
}
.dash__dioi:first-child { border-top: 0; }
.dash__lamp { width: 14px; height: 14px; border-radius: 50%; background: var(--d-lamp-off); border: 1.5px solid var(--d-lamp-off-line); }
.dash__dioi[data-on] .dash__lamp { background: var(--d-ok); border-color: var(--d-ok); box-shadow: 0 0 10px var(--d-glow); }
.dash__dioi[data-unknown] .dash__lamp { background: transparent; border-style: dashed; }
.dash__dioi[data-err] .dash__lamp { background: transparent; border-color: var(--d-bad); position: relative; }
.dash__dioi[data-err] .dash__lamp::after { content: "?"; position: absolute; inset: -2px 0 0; font-size: 10px; font-weight: 900; text-align: center; color: var(--d-bad); }
.dash__dnum { font-size: 16px; font-weight: 800; color: var(--d-ink); }
.dash__dioi[data-on] .dash__dnum { color: var(--d-ok); }
.dash__dname { font-size: 14px; color: var(--d-ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dash__dioi[data-tag] .dash__dname { color: color-mix(in srgb, var(--accent) 60%, var(--ink)); }
.dash__djob { font-size: 11.5px; color: var(--d-ink-3); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.dash__dioempty { padding: 10px 0; font-size: 13px; color: var(--d-ink-3); }

/* ── 변화 기록 */
.dash__tbl--log tbody tr { height: 46px; }
.dash__tbl--log th:nth-child(1) { width: 17%; }
.dash__tbl--log th:nth-child(2) { width: 27%; }
.dash__tbl--log th:nth-child(3) { width: 34%; }
.dash__tbl--log th:nth-child(4) { width: auto; }
.dash__tbl--log .dash__addr { font-size: 15px; }
.dash__kind { display: inline !important; margin-right: 6px; padding: 1px 6px; border-radius: 6px; background: color-mix(in srgb, var(--ink) 9%, transparent); }
.dash__t { font-size: 14px; color: var(--d-ink-2); }
.dash__chg { font-size: 15px; color: var(--d-ink-2); overflow-wrap: anywhere; }
.dash__to { color: var(--d-ok); }
.dash__lognote { font-size: 14px; color: var(--d-ink); overflow-wrap: anywhere; }

/* ── 진단 */
.dash__diag { margin: 0; padding: 6px 14px; display: grid; grid-template-columns: max-content 1fr; }
.dash__diag dt, .dash__diag dd { margin: 0; padding: 9px 0; border-top: 1px solid var(--d-line-soft); font-size: 14px; }
.dash__diag dt { padding-right: 16px; font-weight: 800; color: var(--d-teal); }
.dash__diag dd { color: var(--d-ink); overflow-wrap: anywhere; }
.dash__diag dt:first-of-type, .dash__diag dt:first-of-type + dd { border-top: 0; }

/* ── 상태 카드 · 아래 띠 · 로봇 */
.dash__cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dash__stat {
  display: grid; justify-items: center; align-content: center; gap: 4px; text-align: center;
  min-height: 132px; padding: 14px 12px; background: var(--d-card-2); border-color: var(--d-card-2-line);
}
.dash__k { font-size: 15px; font-weight: 800; color: var(--d-ink); }
.dash__big { font-size: clamp(19px, 3.2cqi, 27px); font-weight: 900; letter-spacing: -0.01em; line-height: 1.15; overflow-wrap: anywhere; }
.dash__big[data-s="ok"] { color: var(--d-ok); }
.dash__big[data-s="ok"]::after, .dash__big[data-s="bad"]::after { content: " ●"; font-size: .55em; vertical-align: middle; }
.dash__big[data-s="warn"] { color: var(--d-warn); }
.dash__big[data-s="bad"] { color: var(--d-bad); }
.dash__big[data-s="off"] { color: var(--d-off); }
.dash__big[data-s="wait"] { color: var(--d-wait); }
.dash__sub { font-size: 14px; color: var(--d-ink); line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.dash__strip { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; padding: 12px 14px; }
.dash__si { display: flex; align-items: center; gap: 10px; min-width: 0; }
.dash__sichip { flex: none; display: grid; place-items: center; }
.dash__sitxt { display: grid; min-width: 0; line-height: 1.2; }
.dash__sik { font-size: 12.5px; font-weight: 800; color: var(--d-ink); }
.dash__si b { font-size: 17px; font-weight: 900; color: var(--d-ink); overflow-wrap: anywhere; }
.dash__si[data-s="ok"] b { color: var(--d-ok); }
.dash__si[data-s="warn"] b { color: var(--d-warn); }
.dash__si small { font-size: 12px; color: var(--d-ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@container (max-width: 520px) { .dash__strip { grid-template-columns: 1fr; } .dash__cards { grid-template-columns: 1fr; } }
.dash__robot { padding: 12px 16px; background: var(--d-card-2); border-color: var(--d-card-2-line); }
.dash__robot p { margin: 0; }
.dash__robot1 { font-size: 15px; font-weight: 800; color: var(--d-ink); padding-bottom: 8px; border-bottom: 1px solid color-mix(in srgb, var(--ink) 18%, transparent); }
.dash__robot2 { padding-top: 8px; font-size: 14.5px; color: var(--d-ink); overflow-wrap: anywhere; }
.dash__robot[data-busy] .dash__robot1 { color: var(--d-warn); }
