:root {
  --bg-base:    #1a1a2e;
  --bg-card:    #16213e;
  --bg-group:   #1e2540;
  --bg-deep:    #0d1b2e;
  --bd-dim:     #2a3560;
  --bd-dark:    #334;
  --tx-primary: #eee;
  --tx-dim:     #556;
  --tx-mid:     #778;
  --tx-power:   #a8dadc;
  --tx-ess:     #34d399;
  --tx-solar:   #fbbf24;
  --tx-lasee:   #a78bfa;
  --tx-blue:    #60a5fa;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg-base); color: var(--tx-primary); font-family: 'Segoe UI', sans-serif; padding: 10px; overflow-x: hidden; }
.container { max-width: 95vw; margin: 0 auto; position: relative; padding-top: 55px; }

/* 로고 */
.logo       { position: absolute; top: 6px; right: 0; height: 82px; width: auto; object-fit: contain; pointer-events: none; transition: opacity 0.2s; }
.logo-left  { position: absolute; top: 6px; left: 0; height: 41px; width: auto; object-fit: contain; pointer-events: none; }
.logo-left-link { position: absolute; top: 0; left: 0; width: 240px; height: 60px; z-index: 10; }
.logo-btn   { position: absolute; top: 0; right: 0; width: 280px; height: 60px; cursor: pointer; background: transparent; border: none; padding: 0; }
.logo-btn:hover + .logo { opacity: 0.85; }

/* 라이트 모드 */
body.light-mode { background: #f0f4f8; color: #1e293b; }
body.light-mode .group-box { background: #ffffff; border-color: #cbd5e1; }
body.light-mode .device,
body.light-mode .ess-card,
body.light-mode .solar-card,
body.light-mode .hour-chart { background: #f1f5f9; }
body.light-mode .device-name { color: #0e7490; }
body.light-mode .device-kw .unit,
body.light-mode .updated,
body.light-mode .hour-yaxis span,
body.light-mode .hour-lbl { color: #94a3b8; }
body.light-mode .device-kwh,
body.light-mode .ess-card .e-lbl,
body.light-mode .ess-card .e-sub,
body.light-mode .solar-card .s-lbl,
body.light-mode .hour-chart h3 { color: #64748b; }
body.light-mode .bar-wrap,
body.light-mode .ess-soc-wrap { background: #dde3ec; }
body.light-mode .group-title.power { color: #0e7490; }
body.light-mode .group-title.ess   { color: #059669; }
body.light-mode .group-title.solar { color: #d97706; }
body.light-mode .group-title.lasee { color: #7c3aed; }

/* 전력 모니터링 레이아웃 */
.layout     { display: flex; gap: 6px; align-items: stretch; margin-bottom: 4px; }
.left-col   { flex: 0 0 200px; display: flex; flex-direction: column; }
.right-grid { flex: 1; display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 6px; align-content: start; }

/* 공통 카드 베이스 */
.device,
.ess-card   { background: var(--bg-card); border-radius: 10px; padding: 16px 14px; border-left: 4px solid var(--bd-dark); }
.solar-card { background: var(--bg-card); border-radius: 10px; padding: 16px 14px; border-left: 4px solid var(--tx-solar); }
.device.active { border-left-color: var(--tx-blue); }
.device.medium { border-left-color: #facc15; }
.device.high   { border-left-color: #f87171; }
.left-col .device { flex: 1; display: flex; flex-direction: column; justify-content: center; }

/* 카드 내부 공통 */
.device-name,
.ess-card .e-lbl,
.solar-card .s-lbl { font-size: 1rem; margin-bottom: 6px; }
.device-name        { color: var(--tx-power); }
.ess-card .e-lbl,
.solar-card .s-lbl  { color: var(--tx-mid); }

.device-kw,
.ess-card .e-val,
.solar-card .s-val  { font-size: 2rem; font-weight: bold; line-height: 1; }
.device-kw          { color: var(--tx-primary); }
.solar-card .s-val  { color: var(--tx-solar); }

.device-kw .unit,
.ess-card .e-unit,
.solar-card .s-unit { font-size: 0.82rem; color: var(--tx-dim); margin-left: 3px; }

.device-kwh,
.ess-card .e-sub,
.solar-card .s-sub  { font-size: 0.7rem; color: var(--tx-dim); margin-top: 5px; }

.bar-wrap,
.ess-soc-wrap { background: var(--bg-deep); border-radius: 4px; height: 5px; margin-top: 8px; overflow: hidden; }
.bar,
.ess-soc-bar  { height: 100%; border-radius: 4px; transition: width 0.5s ease; }

.device.main-card .device-kw   { font-size: 2.6rem; }
.device.main-card .device-name { font-size: 1.1rem; }
.updated { text-align: center; font-size: 0.7rem; color: var(--bd-dark); margin-top: 12px; }

/* 태양광 카드 색상 변형 */
.solar-card.green  { border-left-color: #4ade80; }
.solar-card.green  .s-val { color: #4ade80; }
.solar-card.blue   { border-left-color: var(--tx-blue); }
.solar-card.blue   .s-val { color: var(--tx-blue); }
.solar-card.purple { border-left-color: var(--tx-lasee); }
.solar-card.purple .s-val { color: var(--tx-lasee); }

/* 4분할 그룹 그리드 */
.groups-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(520px, 1fr)); gap: 14px; }
.group-box   { background: var(--bg-group); border: 1px solid var(--bd-dim); border-radius: 14px; padding: 16px; }
.group-title { font-size: 1.4rem; font-weight: 600; margin-bottom: 12px; letter-spacing: 0.03em; }
.group-title.power { color: var(--tx-power); display: flex; align-items: center; justify-content: space-between; }
.group-title.ess   { color: var(--tx-ess); }
.group-title.solar { color: var(--tx-solar); }
.group-title.lasee { color: var(--tx-lasee); }

/* ESS / 태양광 그리드 */
.ess-grid   { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 6px; }
.solar-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 6px; margin-bottom: 6px; }

/* 시간별 발전 바 차트 */
.hour-chart       { background: var(--bg-card); border-radius: 10px; padding: 12px 14px; }
.hour-chart h3    { font-size: 0.75rem; color: var(--tx-dim); margin-bottom: 8px; }
.hour-chart-inner { display: flex; align-items: flex-end; gap: 4px; }
.hour-yaxis       { display: flex; flex-direction: column; justify-content: space-between; align-items: flex-end; height: 200px; margin-bottom: 12px; padding-right: 3px; flex-shrink: 0; }
.hour-yaxis span  { font-size: 0.75rem; color: #667; line-height: 1; }
.hour-bars        { display: flex; align-items: flex-end; gap: 2px; height: 250px; flex: 1; }
.hour-bar-wrap    { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; }
@keyframes barGrow {
  from { transform: scaleY(0); opacity: 0; }
  to   { transform: scaleY(1); opacity: 1; }
}
.hour-bar         { width: 100%; background: #fbbf2466; border-radius: 2px 2px 0 0; position: relative;
                    transform-origin: bottom; animation: barGrow 0.45s cubic-bezier(0.22,1,0.36,1) both; }
.hour-bar.active  { background: var(--tx-solar); }
.hour-lbl         { font-size: 0.8rem; color: #445; margin-top: 2px; }

/* 툴팁 (바 차트용) */
.has-tip { position: relative; cursor: default; }
.has-tip .tip {
  display: none; position: absolute;
  bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  background: var(--bg-deep); color: #ccd; font-size: 0.85rem;
  white-space: nowrap; padding: 5px 9px; border-radius: 6px;
  border: 1px solid var(--bd-dim); z-index: 100; pointer-events: none;
}
.has-tip .tip::after {
  content: ''; position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
  border: 5px solid transparent; border-top-color: var(--bd-dim);
}
.has-tip:hover .tip,
.has-tip.tip-open .tip { display: block; }

/* 카드형 인라인 tip 숨김 — floating tip이 담당 */
.device .tip, .ess-card .tip, .solar-card .tip, .hour-bar .tip { display: none !important; }
.device.has-tip, .ess-card.has-tip, .solar-card.has-tip { cursor: pointer; -webkit-tap-highlight-color: transparent; }

/* floating tip */
#float-tip {
  display: none; position: fixed; z-index: 9999;
  background: #e0e2e5; color: #1e293b; font-size: 0.85rem; line-height: 1.7;
  padding: 7px 12px; border-radius: 7px; box-shadow: 0 6px 18px rgba(0,0,0,0.38);
  white-space: nowrap; pointer-events: none;
}
#float-tip::before {
  content: ''; position: absolute; top: 100%; left: 14px;
  border: 6px solid transparent; border-top-color: #e0e2e5;
}

/* 팝업 공통 베이스 */
#ess-table-popup,
#usage-popup,
#lasee-monthly-popup,
#bipv-monthly-popup {
  display: none; position: fixed;
  background: var(--bg-deep); border: 1px solid var(--bd-dim); border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.65); overflow: hidden; cursor: default;
}
#ess-table-popup     { z-index: 9997; max-width: min(680px, 95vw); overflow-x: auto; }
#usage-popup         { z-index: 9996; min-width: 200px; }
#lasee-monthly-popup { z-index: 9995; min-width: 260px; }
#bipv-monthly-popup  { z-index: 9994; min-width: 260px; }

body.light-mode #usage-popup,
body.light-mode #lasee-monthly-popup,
body.light-mode #bipv-monthly-popup { border-color: #cbd5e1; }

/* 월별 사용량 테이블 */
.usage-table { border-collapse: collapse; font-size: 0.78rem; width: 100%; white-space: nowrap; }
.usage-table caption {
  caption-side: top; background: #111d35; color: var(--tx-blue);
  font-size: 0.8rem; font-weight: 700; padding: 7px 12px;
  text-align: left; border-bottom: 1px solid var(--bd-dim);
}
.usage-table th { background: #1a3a6e; color: #ccd; font-weight: 600; padding: 5px 12px; border: 1px solid var(--bd-dim); }
.usage-table td { background: var(--bg-deep); color: #aab; padding: 4px 12px; border: 1px solid #1a2540; }
.usage-table td:last-child { text-align: right; }
.usage-table td.month-cell { position: relative; overflow: hidden; }
.u-bar     { position: absolute; left: 0; top: 0; bottom: 0; background: rgba(56,112,200,0.32); transition: width 0.3s; }
.month-lbl { position: relative; z-index: 1; }
.usage-table tr.cur .u-bar { background: rgba(180,120,0,0.38); }
.usage-table tr.cur td     { color: #fcd34d; font-weight: 600; }

#lasee-monthly-popup .usage-table caption { color: var(--tx-lasee); }
#bipv-monthly-popup  .usage-table caption { color: var(--tx-solar); }

/* 테이블 라이트모드 */
body.light-mode .usage-table caption       { background: #f0f6ff; color: #1a4d8f; border-bottom-color: #cbd5e1; }
body.light-mode .usage-table th            { background: #1a4d8f; color: #fff; border-color: #cfd8e3; }
body.light-mode .usage-table td            { background: #fff; color: #333; border-color: #e2e8f0; }
body.light-mode .u-bar                     { background: rgba(96,165,250,0.22); }
body.light-mode .usage-table tr.cur .u-bar { background: rgba(217,119,6,0.22); }
body.light-mode .usage-table tr.cur td     { color: #b45309; }
body.light-mode #lasee-monthly-popup .usage-table caption { color: #7c3aed; }
body.light-mode #bipv-monthly-popup  .usage-table caption { color: #d97706; }

/* 한전 요금표 버튼 */
#kepcoRateBtn {
  background: linear-gradient(135deg, #1e3a5f, #1a2a4a);
  border: 1px solid rgba(96,165,250,0.35); border-radius: 8px;
  color: #7dd3fc; cursor: pointer; padding: 5px 12px; font-size: 0.82em;
  display: flex; align-items: center; gap: 5px; line-height: 1;
  transition: border-color 0.2s, color 0.2s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3); flex-shrink: 0;
}
#kepcoRateBtn:hover { border-color: rgba(96,165,250,0.7); color: #bae6fd; }
#kepcoRateBtn .ti   { font-size: 1.2em; }

/* 한전 요금표 모달 */
#kepcoModal {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.65); backdrop-filter: blur(5px);
  z-index: 9999; align-items: center; justify-content: center;
}
.kepco-modal-inner {
  background: linear-gradient(160deg, #0f1c35 0%, #162040 100%);
  border: 1px solid rgba(96,165,250,0.25); border-radius: 16px;
  width: min(800px, 95vw); max-height: 88vh;
  display: flex; flex-direction: column;
  box-shadow: 0 24px 60px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.05);
  overflow: hidden;
}
.kepco-modal-header {
  flex-shrink: 0; display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  background: linear-gradient(90deg, rgba(37,99,235,0.2), rgba(96,165,250,0.05));
  border-bottom: 1px solid rgba(96,165,250,0.15);
}
.kepco-modal-title-wrap { display: flex; align-items: center; gap: 10px; }
.kepco-modal-icon {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, #1d4ed8, #3b82f6);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 14px rgba(59,130,246,0.45); flex-shrink: 0;
}
.kepco-modal-icon .ti  { font-size: 1.25em; color: #fff; }
.kepco-modal-title     { font-size: 1em; font-weight: 700; color: #e2e8f0; letter-spacing: 0.02em; }
.kepco-modal-subtitle  { font-size: 0.72em; color: #64748b; margin-top: 2px; }
.kepco-modal-close {
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 7px; color: #94a3b8; cursor: pointer;
  width: 30px; height: 30px; display: flex; align-items: center; justify-content: center;
  font-size: 1em; flex-shrink: 0;
}
.kepco-modal-close:hover { background: rgba(255,255,255,0.13); color: #e2e8f0; }
.kepco-modal-body {
  overflow-y: auto; flex: 1;
  scrollbar-color: rgba(96,165,250,0.35) rgba(255,255,255,0.04); scrollbar-width: thin;
}

/* 반응형 */
@media (max-width: 1399px) and (min-width: 701px) {
  .layout   { flex-direction: column; }
  .left-col { flex: none; width: 100%; }
}
@media (min-width: 1400px) {
  html, body   { height: 100%; overflow: hidden; }
  body         { display: flex; flex-direction: column; }
  .container   { flex: 1; min-height: 0; width: 100%; display: flex; flex-direction: column; }
  .groups-grid { flex: 1; min-height: 0; grid-template-columns: repeat(2, 1fr); grid-template-rows: minmax(0, 2fr) minmax(0, 3fr); }
  .group-box   { min-height: 0; overflow: hidden; }
  .group-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .right-grid  { grid-template-columns: repeat(4, 1fr); }
  .ess-grid    { grid-template-columns: repeat(5, 1fr); }
}
