/* 밝은 대시보드 — 뷰포트(1920×1080 등)에 맞춰 세로·가로 채움 */
:root {
  --bg-page: #f1f5f9;
  --bg-canvas: #ffffff;
  --bg-surface: #f8fafc;
  --bg-surface-2: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --accent: #2563eb;
  --accent-2: #0ea5e9;
  --good: #059669;
  --warn: #d97706;
  --bad: #dc2626;
  --ad: #ea580c;
  --hql: #2563eb;
  --ql: #0891b2;
  --shadow: rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  min-height: 100%;
  max-height: 100%;
  background: var(--bg-page);
  color: var(--text);
  font-family: "Pretendard", "Segoe UI", system-ui, -apple-system, "Noto Sans KR", sans-serif;
  font-feature-settings: "tnum";
  overflow: hidden;
}

#canvas-1920 {
  width: 100%;
  max-width: none;
  margin: 0;
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  min-height: 0;
  background: var(--bg-canvas);
  box-shadow: none;
  border-bottom: 1px solid var(--border);
  display: grid;
  /* 헤더(배너 포함 한 덩어리) + 배합 + 센서 — 뷰포트 안에서만 분배, 넘치면 내부 스크롤 */
  grid-template-rows: auto minmax(0, 1fr) minmax(0, 1.05fr);
  padding: 0;
  gap: 8px;
}

/* 그리드 자식이 콘텐츠 최소 높이 때문에 뷰포트를 밀어내지 않도록 */
#canvas-1920 > * {
  min-height: 0;
}

/* 상단 — 시뮬 배너를 여기에 넣어 그리드 행 수가 바뀌지 않게 함 */
.top-bar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  padding: 8px 10px 6px;
  flex-shrink: 0;
}
.top-bar-main {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  min-height: 44px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 6px;
  height: 28px;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  border-radius: 3px;
}
.brand h1 { font-size: 20px; font-weight: 600; letter-spacing: -0.02em; margin: 0; color: var(--text); }

.top-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.btn-sim {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid #fecaca;
  background: linear-gradient(180deg, #fff1f2, #ffe4e6);
  color: #b91c1c;
  box-shadow: 0 1px 2px var(--shadow);
}
.btn-sim:hover { filter: brightness(0.97); }
.btn-sim.active {
  border-color: #991b1b;
  background: linear-gradient(180deg, #fecdd3, #fda4af);
  color: #7f1d1d;
}

.status {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-muted);
}
.status .sep { opacity: 0.5; }
.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  background: var(--text-muted);
}
.dot-ok { background: var(--good); box-shadow: 0 0 0 2px rgba(5, 150, 105, 0.25); }
.dot-warn { background: var(--warn); box-shadow: 0 0 0 2px rgba(217, 119, 6, 0.25); }
.dot-bad { background: var(--bad); box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.25); }
.dot-hql { background: var(--hql); }
.dot-ql { background: var(--ql); }
.dot-ad { background: var(--ad); }

.sim-banner {
  font-size: 12px;
  padding: 6px 10px;
  margin-top: 6px;
  border-radius: 8px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  font-weight: 600;
  line-height: 1.35;
}
.sim-banner[hidden] {
  display: none !important;
  margin-top: 0;
  padding: 0;
  border: none;
  overflow: hidden;
}

/* 섹션 타이틀 */
.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px 4px;
  flex-shrink: 0;
}
.section-title h2 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -0.01em; color: var(--text); }
.section-title .title-bar {
  width: 4px;
  height: 18px;
  background: var(--accent);
  border-radius: 2px;
}
.section-title .subtitle { font-size: 12px; color: var(--text-muted); margin-left: 6px; }

/* 카드 */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: 0 2px 8px var(--shadow);
}
.card-title {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 8px;
  font-weight: 600;
}

/* 배합 */
.blend-section {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  padding: 0;
}
.blend-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  grid-template-rows: minmax(0, auto) minmax(0, 1fr);
  gap: 10px;
}
.big-card { grid-column: 1 / 2; grid-row: 1 / 3; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.big-card > .card-title,
.big-card > .ratio-row,
.big-card > .ratio-bar,
.big-card > .feasible-line {
  flex-shrink: 0;
}
.kpi-card:nth-of-type(2) { grid-column: 2 / 3; grid-row: 1 / 2; }
.kpi-card:nth-of-type(3) { grid-column: 3 / 4; grid-row: 1 / 2; }
.price-card { grid-column: 2 / 3; grid-row: 2 / 3; min-height: 0; overflow: auto; }
.chart-card { grid-column: 3 / 4; grid-row: 2 / 3; display: flex; flex-direction: column; min-height: 0; }

.ratio-row { display: flex; gap: 10px; }
.ratio-pill {
  flex: 1;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}
.ratio-ad { border-left: 4px solid var(--ad); }
.ratio-hql { border-left: 4px solid var(--hql); }
.ratio-ql { border-left: 4px solid var(--ql); }
.ratio-label { font-size: 11px; color: var(--text-muted); letter-spacing: 0.06em; }
.ratio-value { font-size: 32px; font-weight: 700; letter-spacing: -0.02em; margin-top: 4px; color: var(--text); }

.ratio-bar {
  display: flex;
  height: 12px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #e2e8f0;
}
.ratio-bar > div { height: 100%; transition: width 0.45s ease; }
#bar-ad { background: var(--ad); }
#bar-hql { background: var(--hql); }
#bar-ql { background: var(--ql); }

.feasible-line {
  font-size: 13px;
  color: var(--text-muted);
  padding: 8px 10px;
  border-radius: 8px;
  background: #f1f5f9;
  border: 1px solid var(--border);
}
.feasible-line.ok { color: var(--good); font-weight: 600; }
.feasible-line.bad { color: var(--bad); font-weight: 600; }

.prior-blends {
  flex: 1 1 0;
  min-height: 96px;
  margin-top: 2px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.prior-blends-head {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.prior-blends-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.prior-blends-note {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.35;
}
.prior-table-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
}
.prior-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.prior-table th,
.prior-table td {
  text-align: right;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}
.prior-table th {
  text-align: right;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.prior-table th:first-child,
.prior-table td:first-child {
  text-align: left;
}
.prior-table .num { font-feature-settings: "tnum"; color: var(--text); }
.prior-row-na td.prior-msg {
  text-align: left;
  color: var(--warn);
  font-size: 11px;
}

.kpi-value { font-size: 36px; font-weight: 700; letter-spacing: -0.02em; color: var(--text); }
.kpi-money::after { content: " 원"; font-size: 18px; color: var(--text-muted); margin-left: 4px; font-weight: 500; }
.kpi-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.gauge { margin-top: 10px; }
.gauge-bar {
  position: relative;
  height: 10px;
  border-radius: 5px;
  background: linear-gradient(90deg, #e2e8f0, #cbd5e1);
  overflow: hidden;
}
#gauge-fill {
  position: absolute;
  left: 50%;
  right: 50%;
  height: 100%;
  background: linear-gradient(90deg, #6ee7b7, #22d3ee);
  border-radius: 5px;
}
#gauge-marker {
  position: absolute;
  top: -3px;
  width: 4px;
  height: 16px;
  background: var(--accent);
  border-radius: 2px;
  transition: left 0.45s ease;
}
.gauge-ticks { display: flex; justify-content: space-between; font-size: 10px; color: var(--text-muted); margin-top: 4px; }

.price-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.price-table th, .price-table td {
  text-align: left;
  padding: 6px 4px;
  border-bottom: 1px solid var(--border);
}
.price-table th { color: var(--text-muted); font-weight: 600; font-size: 11px; }
.price-table td.empty { color: var(--text-muted); text-align: center; }

.chart-wrap { flex: 1 1 0; min-height: 80px; position: relative; }
.chart-wrap.small {
  flex: 1 1 70px;
  min-height: 70px;
  max-height: 160px;
}

.ca-input-row {
  display: flex;
  gap: 14px;
  font-size: 12px;
  color: var(--text-muted);
  padding-top: 8px;
  flex-wrap: wrap;
}
.ca-input-row b { color: var(--text); }
.muted { color: var(--text-muted); font-size: 10px; margin-left: 4px; }

/* 센서 */
.sensor-section {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 0;
}
.sensor-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 10px;
  align-items: stretch;
}
.sensor-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
  gap: 8px;
  height: 100%;
}
.sensor-card.sim-active {
  box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.35);
  border-color: #fecaca;
  background: #fffafb;
}
.sensor-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.sensor-status { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.sensor-status-caption {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  text-transform: uppercase;
}
.sensor-block-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-top: 2px;
  margin-bottom: -2px;
}
.sensor-block-title.sub {
  color: #c2410c;
}
.sensor-title-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
  min-width: 0;
  flex: 1;
}
.sensor-name { font-size: 15px; font-weight: 600; color: var(--text); }
.sensor-db-cols {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  line-height: 1.4;
  word-break: break-word;
}
.sensor-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  flex: 1;
}

.badge {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  background: #f1f5f9;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.badge.normal { background: #ecfdf5; color: var(--good); border-color: #a7f3d0; }
.badge.anomaly { background: #fef2f2; color: var(--bad); border-color: #fecaca; font-weight: 700; }
.badge.insufficient, .badge.unavailable { background: #fffbeb; color: var(--warn); border-color: #fde68a; }

/* 소음 IF 보조 배지: 기본 .badge와 동일 팔레트, 크기만 약간 축소 */
.badge.badge-sub {
  font-size: 0.85em;
  padding: 0.12rem 0.45rem;
}

.metric-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; flex-shrink: 0; }
.metric-label { font-size: 10px; color: var(--text-muted); letter-spacing: 0.05em; text-transform: uppercase; }
.metric-value { font-size: 18px; font-weight: 600; margin-top: 2px; color: var(--text); }

.sensor-foot { font-size: 11px; color: var(--text-muted); flex-shrink: 0; }

.sensor-live {
  flex-shrink: 0;
  margin-top: 2px;
  padding: 10px 12px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 12px;
}
.sensor-live-title {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.sensor-live-dl {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sensor-live-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
}
.sensor-live-row dt {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  margin: 0;
  line-height: 1.35;
}
.sensor-live-row dd {
  margin: 0;
  text-align: right;
  min-width: 0;
}
.sensor-live-val {
  font-weight: 700;
  color: var(--text);
  font-feature-settings: "tnum";
}
.sensor-live-at {
  display: block;
  margin-top: 2px;
  font-size: 10px;
  font-weight: 500;
  color: var(--text-muted);
}

.sensor-graph-legend {
  flex-shrink: 0;
  margin-top: 4px;
  padding: 12px 10px 8px;
  font-size: 12px;
  line-height: 1.55;
  color: var(--text-muted);
  border-top: 1px dashed var(--border);
}
.sensor-graph-legend-lead {
  font-weight: 700;
  color: var(--text);
  margin: 0 0 8px;
  font-size: 12px;
}
.sensor-graph-legend p {
  margin: 0 0 8px;
}
.sensor-graph-legend p:last-child {
  margin-bottom: 0;
}
.sensor-graph-legend strong { color: #334155; }

/* 상세 페이지 */
.detail-page #canvas-1920 {
  height: auto;
  min-height: 100vh;
  overflow: auto;
}
.detail-page .top-bar-main {
  flex-wrap: wrap;
  gap: 10px;
}
.page-nav {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.page-nav a {
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
}
.page-nav a:hover { color: var(--accent); border-color: var(--accent); }
.page-nav a.active {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}
.detail-history-section {
  padding: 12px 16px 24px;
  border-top: 1px solid var(--border);
}
.history-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
  font-size: 13px;
}
.history-toolbar label { display: flex; align-items: center; gap: 6px; }
.history-toolbar input,
.history-toolbar select {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
}
.history-table-wrap {
  max-height: 420px;
  overflow: auto;
}
.history-table { width: 100%; }
.history-row { cursor: pointer; }
.history-row:hover { background: #f1f5f9; }
.history-pager {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 12px;
  font-size: 13px;
}
.detail-row-card { margin-bottom: 12px; }
.detail-row-body { font-size: 13px; line-height: 1.6; }
.detail-chart-card .detail-ts-chart { min-height: 280px; }
.period-toggle { display: inline-flex; gap: 4px; }
.period-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

@media (max-width: 1200px) {
  .blend-grid {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto;
  }
  .big-card { grid-column: 1 / -1; grid-row: auto; }
  .kpi-card:nth-of-type(2), .kpi-card:nth-of-type(3) { grid-column: auto; grid-row: auto; }
  .price-card, .chart-card { grid-column: auto; grid-row: auto; }
  .sensor-grid { grid-template-columns: 1fr; }
}
