/* ========================================================================
   FarmIoT 대시보드 — 범용 구조 전용 추가 스타일
   ------------------------------------------------------------------------
   기존 style.css 의 디자인 언어(색 변수, 카드, 여백)를 그대로 따르고,
   구성에서 그려지는 요소에만 필요한 규칙을 더한다. 원본 규칙은 고치지 않는다.
   ======================================================================== */

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ── 시연 고지 ─────────────────────────────────────────────────── */
.demo-banner {
  max-width: var(--max-width);
  margin: 16px auto 0;
  padding: 12px 18px;
  background: var(--amber-bg);
  color: var(--amber-text);
  border: 1px solid #fcd34d;
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.6;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  align-items: baseline;
}
.demo-banner strong { font-weight: 600; }

/* ── 구성 전환 막대 ────────────────────────────────────────────── */
.preset-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.preset-bar-label { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.preset-title { font-size: 12px; color: var(--text-muted); letter-spacing: 0.02em; }
.preset-desc { font-size: 14px; color: var(--text-primary); font-weight: 500; }
.preset-select {
  min-width: 190px;
  padding: 9px 12px;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color var(--transition);
}
.preset-select:hover { border-color: var(--accent); }
.preset-note {
  margin: 10px 2px 0;
  font-size: 12.5px;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* ── 섹션 제목 옆 개수 ─────────────────────────────────────────── */
.section-count {
  margin-left: 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--border-light);
  padding: 2px 9px;
  border-radius: 20px;
  vertical-align: middle;
}

/* ── 센서 카드 (구성에서 생성) ─────────────────────────────────── */
.sensor-card { display: flex; gap: 14px; align-items: flex-start; }
.sensor-card.is-missing { opacity: 0.55; }

.sensor-card-icon {
  width: 38px; height: 38px; flex: none;
  display: flex; align-items: center; justify-content: center;
  border-radius: 10px;
  background: var(--border-light);
  color: var(--text-secondary);
}
.sensor-card-icon.temp     { background: #fee2e2; color: var(--color-temp); }
.sensor-card-icon.humidity { background: #dbeafe; color: var(--color-humidity); }
.sensor-card-icon.light    { background: #fef3c7; color: var(--color-light); }
.sensor-card-icon.water    { background: #cffafe; color: #0891b2; }
.sensor-card-icon.power    { background: #ede9fe; color: var(--color-power); }
.sensor-card-icon.air      { background: #dcfce7; color: #16a34a; }
.sensor-card-icon.level    { background: #e0e7ff; color: var(--color-converter); }

.sensor-card-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: 1; }

.sensor-gauge {
  height: 5px;
  background: var(--border-light);
  border-radius: 3px;
  overflow: hidden;
  margin: 4px 0 2px;
}
.sensor-gauge-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--accent);
  transition: width 0.5s ease;
}
.sensor-card[data-type="temp"]     .sensor-gauge-fill { background: var(--color-temp); }
.sensor-card[data-type="humidity"] .sensor-gauge-fill { background: var(--color-humidity); }
.sensor-card[data-type="light"]    .sensor-gauge-fill { background: var(--color-light); }
.sensor-card[data-type="water"]    .sensor-gauge-fill { background: #0891b2; }
.sensor-card[data-type="power"]    .sensor-gauge-fill { background: var(--color-power); }
.sensor-card[data-type="air"]      .sensor-gauge-fill { background: #16a34a; }
.sensor-card[data-type="level"]    .sensor-gauge-fill { background: var(--color-converter); }

/* ── 채널 카드 (구성에서 생성) ─────────────────────────────────── */
.relay-card { display: flex; flex-direction: column; gap: 10px; }
.relay-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.relay-name { font-size: 15px; font-weight: 600; color: var(--text-primary); }
.relay-desc { font-size: 12.5px; color: var(--text-secondary); margin: 0; line-height: 1.5; }
.relay-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 2px; }

/* 토글 스위치. 원본에 정의가 없어 새로 만든다. */
.switch { position: relative; display: inline-block; width: 46px; height: 26px; flex: none; }
.switch input {
  position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 2;
}
.switch .slider {
  position: absolute; inset: 0;
  background: #cbd5e1;
  border-radius: 26px;
  transition: background var(--transition);
}
.switch .slider::before {
  content: '';
  position: absolute;
  width: 20px; height: 20px;
  left: 3px; top: 3px;
  background: #ffffff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: transform var(--transition);
}
.switch input:checked + .slider { background: var(--green); }
.switch input:checked + .slider::before { transform: translateX(20px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 채널 상태 표시등. 원본은 아이콘을 담는 큰 원이었으나 여기서는 상태만 보인다. */
.relay-card .relay-indicator {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  box-shadow: none;
}
.relay-card .relay-indicator.on  { background: var(--green); }
.relay-card .relay-indicator.off { background: var(--border-light); }

.relay-mode {
  font-size: 12px;
  padding: 4px 11px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}
.relay-mode.auto { background: var(--accent-light); color: var(--accent-hover); border-color: #bfdbfe; }
.relay-mode.manual { background: var(--border-light); color: var(--text-secondary); }
button.relay-mode:hover { border-color: var(--accent); }

/* 게이트웨이 지표의 라벨이 좁은 카드에서 두 줄로 깨지지 않게 한다 */
.system-metrics .sys-label { white-space: nowrap; }

/* ── 카메라 (영상 확인) ────────────────────────────────────────── */
.camera-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}
.camera-card { display: flex; flex-direction: column; gap: 0; overflow: hidden; padding: 0; }

.camera-frame {
  position: relative;
  aspect-ratio: 4 / 3;
  background: #0f1419;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.camera-frame img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.camera-wait {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  color: #6b7280; font-size: 12.5px;
}
/* hidden 속성이 display 선언에 밀리지 않게 한다. 사진 뒤로 대기 문구가 비치는 것을 막는다. */
.camera-wait[hidden] { display: none; }
.camera-frame img[hidden] { display: none; }

.camera-body { display: flex; flex-direction: column; gap: 6px; padding: 14px 16px 16px; }
.camera-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.camera-name { font-size: 14.5px; font-weight: 600; color: var(--text-primary); }
.camera-desc { margin: 0; font-size: 12.5px; color: var(--text-secondary); line-height: 1.5; }
.camera-meta { font-size: 12px; color: var(--text-muted); }

.camera-badge {
  font-size: 11.5px; padding: 3px 9px; border-radius: 20px; white-space: nowrap;
}
.camera-badge.on  { background: var(--green-bg); color: var(--green-text); }
.camera-badge.off { background: var(--border-light); color: var(--text-muted); }

/* ── 자동 제어 (세 조건) ───────────────────────────────────────── */
.settings-lead {
  margin: 0 0 16px;
  font-size: 13.5px;
  color: var(--text-secondary);
  line-height: 1.7;
}
.settings-row {
  display: flex; flex-wrap: wrap; gap: 20px;
  padding-bottom: 16px; margin-bottom: 16px;
  border-bottom: 1px solid var(--border-light);
}
.settings-field { display: flex; align-items: center; gap: 10px; }
.settings-field > label { font-size: 13px; color: var(--text-secondary); }

.settings-input {
  padding: 8px 11px;
  font-size: 13.5px;
  color: var(--text-primary);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color var(--transition);
}
.settings-input:focus { outline: none; border-color: var(--accent); }
.settings-input-num { width: 88px; }

.settings-conditions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
}
.cond-card {
  display: flex; flex-direction: column; gap: 8px;
  padding: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.cond-index {
  font-size: 11px; font-weight: 600; letter-spacing: 0.04em;
  color: var(--accent); text-transform: uppercase;
}
.cond-name { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.cond-inputs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.cond-sep { font-size: 12.5px; color: var(--text-secondary); }
.cond-state {
  align-self: flex-start;
  font-size: 12px; font-weight: 500;
  padding: 3px 10px; border-radius: 20px;
  background: var(--border-light); color: var(--text-secondary);
}
.cond-state.ok { background: var(--green-bg); color: var(--green-text); }
.cond-state.ng { background: var(--border-light); color: var(--text-muted); }

.settings-actions {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 12px; margin-top: 18px;
}
.settings-verdict { font-size: 13.5px; font-weight: 500; color: var(--text-secondary); }
.settings-verdict.ok { color: var(--green-text); }
.settings-hint {
  margin: 10px 0 0; font-size: 12px; color: var(--text-muted); line-height: 1.6;
}

/* ── 차트 영역 ─────────────────────────────────────────────────── */
.chart-header {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 14px;
}
.chart-header .section-title { margin: 0; }
.chart-actions { display: flex; gap: 8px; align-items: center; }
.chart-card { padding: 18px; }
.chart-tabs { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 16px; }
.chart-tab {
  font-size: 12.5px; padding: 6px 13px;
  border: 1px solid var(--border); border-radius: 20px;
  background: var(--bg); color: var(--text-secondary);
  cursor: pointer; transition: all var(--transition);
}
.chart-tab:hover { border-color: var(--accent); color: var(--accent); }
.chart-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chart-wrap { position: relative; height: 340px; }

/* ── 공통 ──────────────────────────────────────────────────────── */
.empty-note {
  font-size: 13px; color: var(--text-muted); margin: 0; padding: 10px 0;
}
.footer {
  max-width: var(--max-width);
  margin: 40px auto 32px;
  padding: 0 24px;
  text-align: center;
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.7;
}
.footer p { margin: 0; }
.footer-sub { color: var(--text-muted); opacity: 0.85; }

@media (max-width: 640px) {
  .demo-banner { margin: 12px 16px 0; font-size: 12.5px; }
  .preset-bar { flex-direction: column; align-items: stretch; }
  .preset-select { width: 100%; }
  .chart-wrap { height: 260px; }
  .settings-row { flex-direction: column; gap: 12px; }
}
