:root {
  color-scheme: light;
  --surface-1:      #fcfcfb;
  --page-plane:     #f9f9f7;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --gridline:       #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11,11,11,0.10);
  --series-1:       #2a78d6;
  --good:           #006300;
  --critical:       #d03b3b;
  --card-shadow:       0 1px 2px rgba(11,11,11,0.04), 0 2px 8px rgba(11,11,11,0.04);
  --card-shadow-hover: 0 2px 4px rgba(11,11,11,0.05), 0 8px 20px rgba(11,11,11,0.08);
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --cat-2: #eb6834; --cat-3: #1baf7a; --cat-4: #eda100;
  --cat-5: #e87ba4; --cat-6: #008300; --cat-7: #4a3aa7; --cat-8: #e34948;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --surface-1:      #1a1a19;
    --page-plane:     #0d0d0d;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --gridline:       #2c2c2a;
    --baseline:       #383835;
    --border:         rgba(255,255,255,0.10);
    --series-1:       #3987e5;
    --good:           #0ca30c;
    --critical:       #e66767;
    --card-shadow:       0 1px 2px rgba(0,0,0,0.3), 0 2px 10px rgba(0,0,0,0.24);
    --card-shadow-hover: 0 2px 4px rgba(0,0,0,0.35), 0 10px 24px rgba(0,0,0,0.36);
    --cat-2: #d95926; --cat-3: #199e70; --cat-4: #c98500;
    --cat-5: #d55181; --cat-6: #008300; --cat-7: #9085e9; --cat-8: #e66767;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page-plane);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.page {
  max-width: 980px;
  margin: 0 auto;
  padding: 24px 20px 64px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.topbar h1 {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 4px;
}

.subtitle {
  margin: 0;
  color: var(--text-secondary);
  font-size: 14px;
}

.subtitle a {
  color: var(--text-secondary);
  text-decoration: none;
}
.subtitle a:hover { color: var(--series-1); }

.topbar-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

input[type="month"], input[type="text"], input[type="number"], input[type="date"], input[type="password"] {
  font: inherit;
  color: var(--text-primary);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  transition: border-color .15s ease;
}

input:focus-visible, select:focus-visible, .btn:focus-visible, .nav-button:focus-visible,
.nav-button-sm:focus-visible, .home-hero:focus-visible, .icon-btn:focus-visible {
  outline: 2px solid var(--series-1);
  outline-offset: 2px;
}

.btn {
  font: inherit;
  font-weight: 600;
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  border: 1px solid var(--border);
  cursor: pointer;
  background: var(--surface-1);
  color: var(--text-primary);
  text-decoration: none;
  display: inline-block;
  transition: border-color .15s ease, background-color .15s ease, filter .15s ease, transform .1s ease;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

.btn-primary {
  background: var(--series-1);
  color: #ffffff;
  border-color: transparent;
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: default;
}

.btn-secondary:hover, .btn:hover:not(:disabled) {
  filter: brightness(0.97);
}
.btn:active:not(:disabled) { transform: translateY(1px); }

.btn-muted {
  background: var(--gridline);
  color: var(--text-secondary);
  border-color: transparent;
}

.smp-panel, .customers-panel {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--card-shadow);
  padding: 22px 24px;
  margin-bottom: 22px;
}

/* ---- 보조 참고용 패널: 바로 아래 오는 본 모니터링 패널보다 한 단계 낮은 위계로 보이게 ---- */
.reference-panel {
  background: var(--page-plane);
  border: 1px solid var(--gridline);
  box-shadow: none;
  padding: 14px 18px;
  margin-bottom: 28px;
}
.reference-panel .panel-header { margin-bottom: 10px; }
.reference-panel .panel-header h2 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}
.reference-panel table { font-size: 13px; }
.reference-panel thead th,
.reference-panel thead th:first-child {
  padding: 6px 8px;
  font-size: 13px;
  text-align: center;
}
.reference-panel tbody td,
.reference-panel tbody td:first-child {
  padding: 6px 8px;
  text-align: center;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.stat-tile {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  background: var(--page-plane);
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.stat-value {
  font-size: 22px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.chart-card { margin-top: 4px; }

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.chart-title {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 600;
}

.chart-wrap {
  position: relative;
  width: 100%;
}

/* Daily CfD / 포지션 모니터링의 SMP 산술평균 추이 차트만 좌우로 조금 더 넓게 */
#chartWrap {
  margin-left: -24px;
  margin-right: -24px;
  width: calc(100% + 48px);
}

.smp-chart {
  width: 100%;
  height: 220px;
  display: block;
  overflow: visible;
}

.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 12px;
  box-shadow: var(--card-shadow-hover);
  transform: translate(-50%, -110%);
  white-space: nowrap;
  color: var(--text-primary);
}

.chart-tooltip .tt-date { color: var(--text-muted); margin-bottom: 2px; }
.chart-tooltip .tt-value { font-weight: 600; font-variant-numeric: tabular-nums; }

.chart-empty {
  color: var(--text-muted);
  font-size: 14px;
  padding: 24px 0;
  text-align: center;
}

.section-group-title {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  margin: 40px 0 16px;
  padding-left: 14px;
  border-left: 5px solid var(--series-1);
}
.section-group-title:first-of-type { margin-top: 8px; }

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  gap: 12px;
}

.panel-header h2 {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
}

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

thead th {
  text-align: right;
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 11px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  padding: 10px;
  border-bottom: 1px solid var(--baseline);
  white-space: nowrap;
}

#settlementTable thead th { font-size: 13px; }

thead th:first-child { text-align: left; }

.th-unit { color: var(--text-muted); font-weight: 400; text-transform: none; letter-spacing: normal; }

tbody td, tfoot td {
  padding: 10px;
  text-align: right;
  border-bottom: 1px solid var(--gridline);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

tbody td:first-child { text-align: left; font-variant-numeric: normal; }

tbody tr { transition: background-color .1s ease; }
tbody tr:hover { background: var(--page-plane); }

tbody input[type="number"] {
  width: 110px;
  text-align: right;
}

.settlement-positive { color: var(--good); font-weight: 600; }
.settlement-negative { color: var(--critical); font-weight: 600; }
.settlement-na { color: var(--text-muted); }

.row-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.icon-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  padding: 4px 6px;
  border-radius: 6px;
  transition: background-color .15s ease, color .15s ease;
}
.icon-btn:hover { background: var(--gridline); color: var(--text-primary); }
.icon-btn.danger:hover { color: var(--critical); }

tfoot .total-label {
  text-align: right;
  color: var(--text-secondary);
  font-weight: 600;
  border-bottom: none;
}
tfoot .total-value {
  font-weight: 700;
  font-size: 16px;
  border-bottom: none;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11,11,11,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  background: var(--surface-1);
  border-radius: var(--radius-md);
  padding: 20px;
  width: 320px;
  box-shadow: var(--card-shadow-hover);
}

.modal h3 { margin: 0 0 14px; font-size: 16px; }

.field {
  display: block;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--text-secondary);
}
.field > span { display: block; margin-bottom: 4px; }
.field input { width: 100%; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.modal-error {
  color: var(--critical);
  font-size: 12px;
  margin-top: 8px;
}

@media (max-width: 640px) {
  .stat-row { grid-template-columns: 1fr; }
}

/* ---- 공용: 카드형 이동 버튼 ---- */
.nav-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.nav-button {
  display: block;
  text-decoration: none;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  box-shadow: var(--card-shadow);
  color: var(--text-primary);
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.nav-button:hover { border-color: var(--series-1); box-shadow: var(--card-shadow-hover); transform: translateY(-1px); }
.nav-button .nb-title { font-size: 15px; font-weight: 700; margin-bottom: 4px; }
.nav-button .nb-desc { font-size: 12px; color: var(--text-muted); }

/* ---- 홈: 모니터링(메인) 히어로 카드 ---- */
.home-hero {
  display: block;
  text-decoration: none;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-left: 4px solid var(--series-1);
  border-radius: var(--radius-lg);
  padding: 28px 32px;
  box-shadow: var(--card-shadow);
  margin: 24px 0 36px;
  color: var(--text-primary);
  transition: box-shadow .15s ease, transform .15s ease;
}
.home-hero:hover { box-shadow: var(--card-shadow-hover); transform: translateY(-1px); }
.home-hero-eyebrow {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--series-1);
  margin-bottom: 10px;
}
.home-hero-title {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: 6px;
}
.home-hero-desc {
  font-size: 14px;
  color: var(--text-secondary);
}

/* ---- 홈: 보조(데이터 입력/조회) 영역 ---- */
.home-secondary-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  text-transform: uppercase;
  margin: 0 0 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--gridline);
}
.home-secondary-group + .home-secondary-group { margin-top: 22px; }
.home-secondary-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 0 0 10px;
}
.home-secondary-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}
.nav-button-sm {
  display: block;
  text-decoration: none;
  background: var(--page-plane);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text-primary);
  transition: border-color .15s ease, transform .15s ease;
}
.nav-button-sm:hover { border-color: var(--series-1); transform: translateY(-1px); }
.nav-button-sm .nb-title-sm { font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.nav-button-sm .nb-desc-sm { font-size: 11px; color: var(--text-muted); }

/* ---- 헤드라인 정산금액 카드 ---- */
.headline-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 20px;
}
.headline-tile {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  background: var(--page-plane);
}
.headline-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.headline-value {
  font-size: 28px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
@media (max-width: 640px) {
  .headline-row { grid-template-columns: 1fr; }
}

/* ---- 차트 범례 ---- */
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-secondary);
}
.chart-legend .legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.chart-legend .swatch {
  width: 14px;
  height: 0;
  border-top-width: 2px;
  border-top-style: solid;
  display: inline-block;
}
.chart-legend .swatch.dashed { border-top-style: dashed; }

/* ---- 산업체 정보 입력 폼 ---- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px 16px;
}
.form-grid .field { margin-bottom: 0; }
select {
  font: inherit;
  color: var(--text-primary);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  width: 100%;
  transition: border-color .15s ease;
}

.month-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
  margin-top: 10px;
  padding: 14px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
}
.month-grid .month-field { font-size: 12px; color: var(--text-secondary); }
.month-grid .month-field span { display: block; margin-bottom: 4px; }
.month-grid input { width: 100%; }
.month-grid-empty { color: var(--text-muted); font-size: 13px; }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

/* ---- SMP 실적 상세 테이블 ---- */
.smp-table { font-size: 12px; }
.smp-table th, .smp-table td { padding: 6px 8px; }
.smp-table td.mean-col { font-weight: 600; }
.smp-table td.month-mean-col { color: var(--text-secondary); }
