﻿/* HS EnergyDashboard - 다크 네이비 테마 (설계서 7.1)
   레이아웃: CSS Grid, 100vh, 페이지 스크롤 없음(1920x1080 / 1600x900 기준) */
:root {
  --bg: #0b1530;
  --bg2: #0e1a3a;
  --panel: #111d3f;
  --panel2: #16244d;
  --line: #22325f;
  --line2: #2c3e72;
  --text: #e6ecff;
  --text2: #a9b6db;
  --muted: #6f7fa8;
  --blue: #4c8dff;
  --blue2: #8db6ff;
  --green: #2fd18b;
  --purple: #b28cff;
  --orange: #ffa53a;
  --red: #ff5d6c;
  --gray: #56638a;
  --radius: 10px;
  --font: "Malgun Gothic", "맑은 고딕", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  overflow: hidden;
  display: grid;
  grid-template-rows: 56px minmax(0, 1fr);
}
a { color: var(--blue2); text-decoration: none; }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* ---------- 헤더 ---------- */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 0 20px;
  background: linear-gradient(180deg, #0f1c40, #0c1735);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: .2px; white-space: nowrap; }
.brand .logo { width: 22px; height: 22px; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a {
  color: var(--text2); padding: 8px 14px; border-radius: 8px; font-weight: 600; white-space: nowrap;
}
.nav a:hover { background: var(--panel2); color: var(--text); }
.nav a.active { background: var(--blue); color: #fff; }
.nav a.admin { margin-left: auto; color: var(--muted); font-weight: 500; }
.nav a.admin.active { color: #fff; }
.top-right { display: flex; align-items: center; gap: 14px; white-space: nowrap; }
.clock { font-size: 18px; font-weight: 600; }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: var(--panel2); color: var(--text2); border: 1px solid var(--line2);
}
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--gray); }
.badge.ok { color: var(--green); border-color: rgba(47,209,139,.4); }
.badge.ok::before { background: var(--green); box-shadow: 0 0 6px var(--green); }
.badge.warn { color: var(--orange); border-color: rgba(255,165,58,.4); }
.badge.warn::before { background: var(--orange); }
.badge.err { color: var(--red); border-color: rgba(255,93,108,.45); }
.badge.err::before { background: var(--red); }

.banner {
  position: fixed; top: 56px; left: 0; right: 0; z-index: 50;
  background: #4a1d27; color: #ffd0d5; text-align: center; padding: 6px; font-weight: 600;
  border-bottom: 1px solid #7a2d3a; box-shadow: 0 4px 12px rgba(0,0,0,.4);
}
.stale .value, .stale td { opacity: .45; }

/* ---------- 공통 패널 ---------- */
.page { min-height: 0; padding: 14px 18px 16px; display: grid; gap: 12px; }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; min-height: 0; min-width: 0; display: flex; flex-direction: column;
}
.panel-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.panel-title { font-weight: 700; font-size: 15px; }
.panel-note { color: var(--muted); font-size: 12px; }
.chart-box { position: relative; flex: 1; min-height: 0; }

.toolbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 14px;
}
.toolbar label { color: var(--text2); display: inline-flex; align-items: center; gap: 8px; }
.toolbar .spacer { flex: 1; }

select, input[type=text], input[type=number], input[type=datetime-local], input[type=search] {
  background: var(--bg2); color: var(--text); border: 1px solid var(--line2); border-radius: 7px;
  padding: 6px 9px; font-family: var(--font); font-size: 14px;
}
select:focus, input:focus { outline: 2px solid var(--blue); outline-offset: -1px; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--blue); }

button, .btn {
  background: var(--panel2); color: var(--text); border: 1px solid var(--line2); border-radius: 7px;
  padding: 6px 12px; font-family: var(--font); font-size: 13px; font-weight: 600; cursor: pointer;
}
button:hover { border-color: var(--blue); }
button.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
button:disabled { opacity: .5; cursor: default; }

.seg { display: inline-flex; border: 1px solid var(--line2); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: transparent; color: var(--text2); padding: 6px 12px; }
.seg button + button { border-left: 1px solid var(--line2); }
.seg button.on { background: var(--blue); color: #fff; }

/* ---------- KPI 카드 ---------- */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.kpi {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 18px; position: relative; overflow: hidden;
}
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--blue); }
.kpi.today::before { background: var(--green); }
.kpi.month::before { background: var(--purple); }
.kpi .label { color: var(--text2); font-weight: 600; display: flex; align-items: center; gap: 8px; }
.kpi .value { font-size: 38px; font-weight: 700; margin: 4px 0 2px; line-height: 1.15; }
.kpi .value .unit { font-size: 18px; color: var(--text2); margin-left: 6px; font-weight: 600; }
.kpi.rt .value { color: var(--blue2); }
.kpi.today .value { color: #7ff0bd; }
.kpi.month .value { color: #d3bcff; }
.kpi .sub { color: var(--muted); font-size: 13px; }
.tag {
  display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 4px;
  background: rgba(255,165,58,.15); color: var(--orange); border: 1px solid rgba(255,165,58,.35);
}
.tag.blue { background: rgba(76,141,255,.15); color: var(--blue2); border-color: rgba(76,141,255,.35); }

/* ---------- 종합 현황 ---------- */
.page-dashboard { grid-template-rows: auto auto minmax(0, 46fr) minmax(0, 36fr); }
.dash-bottom { display: grid; grid-template-columns: 1fr 300px; gap: 12px; min-height: 0; }
.chips { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 4px 3px 10px; border-radius: 999px;
  background: var(--panel2); border: 1px solid var(--line2); font-size: 12px;
}
.chip i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.chip button { padding: 0 6px; border: 0; background: transparent; color: var(--muted); font-size: 14px; line-height: 1; }
.chip button:hover { color: var(--red); }
.info-list { display: grid; grid-template-columns: auto 1fr; gap: 9px 14px; margin: 4px 0 0; }
.info-list dt { color: var(--muted); }
.info-list dd { margin: 0; text-align: right; font-weight: 600; }
.legend-inline { display: inline-flex; gap: 12px; color: var(--muted); font-size: 12px; align-items: center; }
.legend-inline span::before {
  content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px;
}
.legend-inline .lg-ok::before { background: var(--blue); }
.legend-inline .lg-est::before { background: rgba(141,182,255,.45); border: 1px dashed var(--blue2); }
.legend-inline .lg-miss::before { background: repeating-linear-gradient(45deg, #56638a 0 2px, transparent 2px 4px); }
.legend-inline .lg-reset::before { border: 2px solid var(--orange); }

/* ---------- 표 ---------- */
.table-wrap { flex: 1; min-height: 0; overflow: auto; }
table.grid { width: 100%; border-collapse: collapse; }
table.grid th, table.grid td { padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.grid th {
  position: sticky; top: 0; background: var(--panel2); color: var(--text2); font-weight: 700; text-align: left; z-index: 1;
}
table.grid th.sortable { cursor: pointer; user-select: none; }
table.grid th.sortable:hover { color: var(--text); }
table.grid th .arrow { color: var(--blue2); margin-left: 4px; }
table.grid td.r, table.grid th.r { text-align: right; }
table.grid tbody tr:hover { background: rgba(76,141,255,.07); }
table.grid tbody tr.click { cursor: pointer; }
table.grid tr.virtual td { color: var(--text2); font-style: italic; background: rgba(178,140,255,.05); }
/* 설비별 모니터링: 현재 전력 비율 수평 막대 (수전 = 100%) */
table.grid td.wcell { width: 26%; min-width: 180px; }
.wbar { display: flex; align-items: center; gap: 8px; }
.wbar .track { flex: 1; height: 12px; background: var(--bg2); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.wbar .fill { height: 100%; background: var(--blue); border-radius: 5px 0 0 5px; }
.wbar.main .fill { background: var(--blue2); }
.wbar.phase .fill { background: var(--gray); }
.wbar.virtual .fill { background: var(--purple); opacity: .7; }
.wbar.over .fill { background: var(--orange); }
.wbar .pct { width: 42px; text-align: right; color: var(--text2); font-size: 12px; }
.st { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.st::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--gray); }
.st.normal { color: var(--green); } .st.normal::before { background: var(--green); }
.st.delay { color: var(--orange); } .st.delay::before { background: var(--orange); }
.st.lost { color: var(--red); } .st.lost::before { background: var(--red); }
.st.nodata { color: var(--muted); }
.over { color: var(--red); font-weight: 700; }
.role { font-size: 11px; padding: 1px 6px; border-radius: 4px; border: 1px solid var(--line2); color: var(--text2); margin-left: 6px; }

/* ---------- 설비별 모니터링 ---------- */
.page-meters { grid-template-rows: auto minmax(0, 1fr); }
.counts { display: inline-flex; gap: 14px; font-weight: 600; }
.counts .c-normal { color: var(--green); } .counts .c-delay { color: var(--orange); } .counts .c-lost { color: var(--red); }
.pager { display: flex; justify-content: center; align-items: center; gap: 6px; padding-top: 10px; color: var(--muted); }
.pager button.on { background: var(--blue); border-color: var(--blue); color: #fff; }

/* ---------- 기간별 분석 ---------- */
.page-analysis { grid-template-rows: auto auto minmax(0, 46fr) minmax(0, 34fr); }
.sum-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.sum-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 16px; }
.sum-card .label { color: var(--text2); font-weight: 600; font-size: 13px; }
.sum-card .value { font-size: 26px; font-weight: 700; margin-top: 2px; }
.sum-card .sub { color: var(--muted); font-size: 12px; }
[hidden] { display: none !important; }
.msg { color: var(--orange); font-weight: 600; }
.msg.err { color: var(--red); }

/* ---------- 설비 설정 ---------- */
.page-admin { grid-template-rows: auto minmax(0, 1fr) auto; }
.page-admin td input[type=text] { width: 100%; min-width: 90px; }
.page-admin td input[type=number] { width: 90px; }
.page-admin td select { max-width: 150px; }
.saved { color: var(--green); font-weight: 600; }

/* ---------- 오류 페이지 ---------- */
.page-error { place-content: center; text-align: center; }

@media (max-width: 1500px) {
  .kpi .value { font-size: 32px; }
  .dash-bottom { grid-template-columns: 1fr 260px; }
}

/* =====================================================================
   작은 화면(태블릿·스마트폰, 2026-11-13): 한 화면 고정 대신 세로 스크롤 배치
   - PC(폭 1100px 이상이고 높이 600px 이상)는 위의 한 화면 고정 배치 그대로
   - 그래프는 화면 높이에 맞춰 줄이지 않고 고정 높이로 표시
   ===================================================================== */
@media (max-width: 1100px), (max-height: 600px) {
  html, body { height: auto; min-height: 100%; }
  body { overflow-x: hidden; overflow-y: auto; grid-template-rows: auto auto; }
  .topbar { position: sticky; top: 0; z-index: 40; flex-wrap: wrap; gap: 6px 14px; padding: 8px 12px; }
  .nav { overflow-x: auto; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .banner { position: sticky; top: 0; }
  .page { padding: 10px; gap: 10px; grid-template-rows: none !important; }
  .panel { min-height: auto; }
  .chart-box { flex: none; height: 260px; }
  .page-dashboard > .panel .chart-box { height: 280px; }
  .dash-bottom { grid-template-columns: 1fr !important; }
  .dash-bottom .chart-box { height: 240px; }
  .info-list dd { white-space: nowrap; }
  .table-wrap { flex: none; overflow: auto; -webkit-overflow-scrolling: touch; }
  .page-analysis .table-wrap { max-height: 70vh; }
  .page-admin .table-wrap { max-height: none; }
}

/* 스마트폰 세로(폭 700px 이하) */
@media (max-width: 700px) {
  body { font-size: 13px; }
  .topbar { gap: 4px 10px; padding: 6px 10px; }
  .brand span { display: none; }                 /* 로고만 */
  .top-right { margin-left: auto; gap: 8px; }
  .clock { font-size: 15px; }
  .badge { padding: 3px 9px; font-size: 12px; }
  .nav { order: 3; flex: 1 0 100%; }
  .nav a { padding: 6px 10px; font-size: 13px; }
  .nav a.admin { margin-left: 0; }

  .page { padding: 8px; gap: 8px; }
  .panel { padding: 10px; }
  .toolbar { gap: 8px 10px; padding: 8px 10px; }
  .toolbar label { flex-wrap: wrap; }
  .toolbar .spacer { display: none; }
  .page-dashboard .toolbar label:first-child, .page-analysis .toolbar label:first-child { flex: 1 0 100%; }
  .page-dashboard #meterSel, .page-analysis #meterSel { flex: 1; min-width: 0; }
  .page-analysis input[type=datetime-local] { width: calc(50% - 22px); min-width: 0; font-size: 12px; padding: 6px; }
  .page-analysis .toolbar label:nth-child(3) { flex: 1 0 100%; gap: 6px; }
  .seg button { padding: 6px 9px; }
  .panel-head { gap: 6px 10px; }
  .panel-head .panel-note { flex: 1 0 100%; }

  .kpis { grid-template-columns: 1fr; gap: 8px; }
  .kpi { padding: 10px 14px; }
  .kpi .value { font-size: 30px; }
  .sum-cards { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .sum-card .value { font-size: 21px; }
  .chart-box { height: 230px; }
  .page-dashboard > .panel .chart-box { height: 250px; }
  .dash-bottom .chart-box { height: 220px; }

  table.grid th, table.grid td { padding: 8px 6px; }
  /* 설비별 모니터링: No, 그룹, 최종 수신 열 숨김 */
  .page-meters #tbl th:nth-child(1), .page-meters #tbl td:nth-child(1),
  .page-meters #tbl th:nth-child(3), .page-meters #tbl td:nth-child(3),
  .page-meters #tbl th:nth-child(9), .page-meters #tbl td:nth-child(9) { display: none; }
  .page-meters #tbl td[colspan] { display: table-cell; }
  /* 옆으로 밀어도 설비명은 왼쪽에 고정 */
  .page-meters #tbl td:nth-child(2) { position: sticky; left: 0; background: var(--panel); z-index: 1; }
  .page-meters #tbl th:nth-child(2) { position: sticky; left: 0; z-index: 2; }
  .page-meters #tbl tr.virtual td:nth-child(2) { background: #15204a; }
  .page-meters .role { display: none; }
  table.grid td.wcell { width: auto; min-width: 110px; }
  .wbar .pct { width: 34px; }
  .page-meters th .muted { display: none; }
  /* 기간별 분석: 구간 종료, 샘플 수 열 숨김 */
  .page-analysis #tbl th:nth-child(3), .page-analysis #tbl td:nth-child(3),
  .page-analysis #tbl th:nth-child(7), .page-analysis #tbl td:nth-child(7) { display: none; }
  .page-analysis #tbl td[colspan] { display: table-cell; }
}
