/* ============================================================
   화면별 레이아웃 — 컴포넌트가 아니라 배치만 담당한다.
   ============================================================ */

/* ---------- 모드 스위치 (시그니처) ------------------------- */
.modeswitch {
  display: flex; align-items: center; gap: 8px;
  padding-left: 12px; margin-left: 2px;
  border-left: 1px solid var(--line);
  height: 26px;
}
.modeswitch__lbl {
  font-size: var(--fs-sm); color: var(--fg-faint);
  transition: color var(--dur) var(--ease);
  white-space: nowrap;
}
.modeswitch__lbl.is-on { color: var(--fg); font-weight: 600; }
[data-mode="before"] .modeswitch__lbl.is-on { color: var(--bf-text); font-weight: 400; }

.switch {
  position: relative;
  width: 40px; height: 22px; flex: none;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--bg-inset);
  cursor: pointer; padding: 0;
  transition: background var(--dur-mode) var(--ease), border-color var(--dur-mode) var(--ease);
}
.switch[aria-checked="true"] { background: var(--accent-weak); border-color: var(--accent-line); }
.switch__knob {
  position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--fg-faint);
  transition: transform var(--dur-mode) var(--ease), background var(--dur-mode) var(--ease);
}
.switch[aria-checked="true"] .switch__knob { transform: translateX(18px); background: var(--accent); }
/* 44px 터치 타겟 */
.switch::after { content: ""; position: absolute; inset: -11px; }

.helpwrap { position: relative; }

/* 첫 방문 안내 — 오버레이이므로 그림자를 쓴다 */
.coach {
  position: absolute; top: calc(100% + 10px); right: 8px; z-index: 70;
  width: 306px; padding: 12px 34px 12px 14px;
  background: var(--bg-raised);
  border: 1px solid var(--accent-line);
  border-radius: var(--r-panel);
  box-shadow: var(--shadow-overlay);
  font-size: var(--fs-sm); line-height: 1.55; color: var(--fg-muted);
  text-align: left;
  animation: coachin 220ms var(--ease) 600ms backwards;
}
.coach[hidden] { display: none; }
.coach::before {
  content: ""; position: absolute; top: -5px; right: 96px;
  width: 8px; height: 8px; transform: rotate(45deg);
  background: var(--bg-raised);
  border-left: 1px solid var(--accent-line);
  border-top: 1px solid var(--accent-line);
}
.coach b { color: var(--fg); font-weight: 600; }
.coach__x {
  position: absolute; top: 7px; right: 7px;
  width: 24px; height: 24px; padding: 0;
  display: grid; place-items: center;
  background: none; border: 0; border-radius: var(--r-ctl);
  color: var(--fg-faint); cursor: pointer;
}
.coach__x:hover { background: var(--bg-inset); color: var(--fg); }
@keyframes coachin { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
[data-mode="before"] .coach { display: none; }

/* 모드 전환 자체를 220ms 로 — transform/opacity 만 움직인다 */
.page, .topbar, .panel, .kpi { transition: opacity var(--dur-mode) var(--ease); }
[data-mode-anim="1"] .page { opacity: .55; }

/* ---------- 개요 ------------------------------------------- */
.ov-split {
  display: grid; gap: var(--gap-panel);
  grid-template-columns: minmax(0, 1.62fr) minmax(0, 1fr);
}

/* 3동 × 6설비군 맵 — 312개 센서를 한 화면에 전부 둔다 */
.plantmap {
  display: grid;
  grid-template-columns: 108px repeat(6, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
  border-radius: var(--r-ctl);
  overflow: hidden;
  border: 1px solid var(--line);
}
.plantmap__corner, .plantmap__ch, .plantmap__rh, .plantmap__c { background: var(--bg-panel); }
.plantmap__corner, .plantmap__ch {
  padding: 8px 10px;
  font-size: var(--fs-xs); font-weight: 600; color: var(--fg-faint);
  display: flex; align-items: center; gap: 6px;
  background: var(--bg-inset);
}
.plantmap__ch .icon { width: 13px; height: 13px; }
.plantmap__rh {
  padding: 10px; display: flex; flex-direction: column; gap: 3px;
  justify-content: center; background: var(--bg-inset);
}
.plantmap__rh b { font-size: var(--fs-tbl); font-weight: 600; color: var(--fg); }
.plantmap__rh span { font-size: var(--fs-xs); color: var(--fg-faint); font-family: var(--ff-mono); }
.plantmap__c {
  padding: 9px 10px 10px;
  display: flex; flex-direction: column; gap: 7px;
  min-width: 0;
  transition: background var(--dur) var(--ease);
}
.plantmap__c:hover { background: var(--bg-raised); }
.plantmap__top { display: flex; align-items: baseline; gap: 6px; justify-content: space-between; }
.plantmap__n { font-size: var(--fs-xs); font-family: var(--ff-mono); color: var(--fg-muted); }
.plantmap__c .chip { align-self: flex-start; }
/* 설비군 이름은 열 머리글이 담당한다. 열이 접히는 좁은 폭에서만 셀 안으로 옮긴다 */
.plantmap__cn { display: none; }

/* 이상 상위 목록 */
.toplist { display: flex; flex-direction: column; }
.toplist__i {
  display: grid; gap: 2px 10px;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  padding: 9px var(--panel-pad);
  border-bottom: 1px solid var(--line);
  transition: background var(--dur) var(--ease);
}
.toplist__i:last-child { border-bottom: 0; }
.toplist__i:hover { background: var(--bg-raised); }
.toplist__t {
  grid-column: 2; font-size: var(--fs-tbl); color: var(--fg); font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.toplist__meta {
  grid-column: 2; font-size: var(--fs-xs); color: var(--fg-faint);
  display: flex; gap: 8px; flex-wrap: wrap;
}
.toplist__meta .num { font-size: var(--fs-xs); }
.toplist__when { grid-column: 3; grid-row: 1 / span 2; font-size: var(--fs-xs); color: var(--fg-faint); font-family: var(--ff-mono); white-space: nowrap; }
.toplist__i > .chip { grid-column: 1; grid-row: 1 / span 2; }

/* 측정 불가 목록 */
.nolist__i {
  display: flex; align-items: center; gap: 10px;
  padding: 8px var(--panel-pad);
  border-bottom: 1px solid var(--line);
  font-size: var(--fs-sm);
}
.nolist__i:last-child { border-bottom: 0; }
.nolist__tag { font-family: var(--ff-mono); font-size: var(--fs-xs); color: var(--fg-muted); }
.nolist__why { color: var(--fg-faint); margin-left: auto; font-size: var(--fs-xs); white-space: nowrap; }

/* ---------- 설비 상세 -------------------------------------- */
.eq-split {
  display: grid; gap: var(--gap-panel);
  grid-template-columns: 232px minmax(0, 1fr);
  align-items: start;
}
.eqrail { position: sticky; top: 66px; }
.eqrail__i {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px;
  border-bottom: 1px solid var(--line);
  font-size: var(--fs-sm); color: var(--fg-muted);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.eqrail__i:last-child { border-bottom: 0; }
.eqrail__i:hover { background: var(--bg-raised); color: var(--fg); }
.eqrail__i[aria-current="page"] { background: var(--accent-weak); color: var(--fg); box-shadow: inset 2px 0 0 var(--accent); }
.eqrail__i .icon { color: var(--fg-faint); width: 14px; height: 14px; }
.eqrail__i b { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.eqrail__i .num { margin-left: auto; font-size: var(--fs-xs); color: var(--fg-faint); }
.eqrail__grp { padding: 8px 12px 4px; font-size: var(--fs-2xs); letter-spacing: .06em; color: var(--fg-faint); text-transform: uppercase; background: var(--bg-inset); }

.eq-cols { display: grid; gap: var(--gap-panel); grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.metabar { display: flex; flex-wrap: wrap; gap: 4px 22px; }
.metabar__i { display: flex; flex-direction: column; gap: 2px; }
.metabar__k { font-size: var(--fs-xs); color: var(--fg-faint); }
.metabar__v { font-size: var(--fs-tbl); color: var(--fg); }

/* ---------- 표 화면 (알람 · 센서) -------------------------- */
.tablepanel { min-height: 380px; }
.tablepanel .toolbar:first-child { border-radius: var(--r-panel) var(--r-panel) 0 0; }
.filterbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.filterbar__k { font-size: var(--fs-xs); color: var(--fg-faint); margin-right: -2px; }
.field--search { width: 236px; }

td .spark { width: 78px; height: 20px; }
.sparknum { font-family: var(--ff-sans); font-size: 13px; color: var(--bf-text); }
.gridnote { font-size: var(--fs-sm); color: var(--fg-faint); display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.gridnote__k {
  display: inline-flex; align-items: center; gap: 5px;
  color: var(--fg-muted);
}
.gridnote__k::before {
  content: ""; width: 11px; height: 11px; border-radius: 3px; background: var(--st-normal);
}
.gridnote__k--off::before { opacity: .22; }
.nolist__val { margin-left: 4px; }

/* ---------- 반응형 ----------------------------------------- */
@media (max-width: 1280px) {
  .ov-split { grid-template-columns: minmax(0, 1fr); }
  .eq-cols { grid-template-columns: minmax(0, 1fr); }
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .topbar { height: auto; flex-wrap: wrap; padding: 8px 14px; gap: 10px 14px; }
  .brand { border-right: 0; padding-right: 0; }
  .topbar__right { flex-wrap: wrap; gap: 8px 10px; }
  .nav { order: 3; width: 100%; overflow-x: auto; padding-bottom: 2px; }
  .eq-split { grid-template-columns: minmax(0, 1fr); }
  .eqrail { position: static; max-height: 260px; overflow: auto; }
  .plantmap { grid-template-columns: minmax(0, 1fr); }
  .plantmap__ch, .plantmap__corner { display: none; }
  .plantmap__cn {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: var(--fs-tbl); font-weight: 600; color: var(--fg);
    margin-right: auto;
  }
  .plantmap__cn .icon { width: 14px; height: 14px; color: var(--fg-faint); }
  .plantmap__top { gap: 10px; }
  .plantmap__rh { flex-direction: row; align-items: baseline; gap: 8px; }
  .page { padding: 14px 14px 32px; }
}
@media (max-width: 640px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sample-badge { font-size: var(--fs-2xs); }
  .clock { display: none; }
  .field--search { width: 100%; }
  .filterbar { width: 100%; }
  .page { --gap-section: 16px; }
  .modeswitch { padding-left: 0; border-left: 0; margin-left: 0; }
  .coach { width: min(306px, calc(100vw - 28px)); right: 0; }
  .coach::before { right: 40px; }
}

/* ---------- 모션 정지 -------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0ms !important;
    transition-delay: 0ms !important;
    scroll-behavior: auto !important;
  }
}
