/* ---------------------------------------------------------------------
   KPI Dashboard — design tokens (values from the validated reference
   palette; see dataviz skill: references/palette.md)
--------------------------------------------------------------------- */
:root {
  color-scheme: light;
  --page:            #f9f9f7;
  --surface-1:       #fcfcfb;
  --surface-2:       #f2f1ed;
  --text-primary:    #0b0b0b;
  --text-secondary:  #52514e;
  --text-muted:      #898781;
  --gridline:        #e1e0d9;
  --baseline:        #c3c2b7;
  --border:          rgba(11,11,11,0.10);
  --series-1:        #2a78d6;   /* categorical slot 1 - blue (neutral/info) */
  --status-good:     #0ca30c;
  --status-warning:  #fab219;
  --status-serious:  #ec835a;
  --status-critical: #d03b3b;
  --success-text:    #006300;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-1: 0 1px 2px rgba(11,11,11,0.06), 0 4px 16px rgba(11,11,11,0.06);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page:            #0d0d0d;
    --surface-1:       #1a1a19;
    --surface-2:       #232322;
    --text-primary:    #ffffff;
    --text-secondary:  #c3c2b7;
    --text-muted:      #898781;
    --gridline:        #2c2c2a;
    --baseline:        #383835;
    --border:          rgba(255,255,255,0.10);
    --series-1:        #3987e5;
    --success-text:    #0ca30c;
    --shadow-1: 0 1px 2px rgba(0,0,0,0.3), 0 4px 16px rgba(0,0,0,0.3);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page:            #0d0d0d;
  --surface-1:       #1a1a19;
  --surface-2:       #232322;
  --text-primary:    #ffffff;
  --text-secondary:  #c3c2b7;
  --text-muted:      #898781;
  --gridline:        #2c2c2a;
  --baseline:        #383835;
  --border:          rgba(255,255,255,0.10);
  --series-1:        #3987e5;
  --success-text:    #0ca30c;
  --shadow-1: 0 1px 2px rgba(0,0,0,0.3), 0 4px 16px rgba(0,0,0,0.3);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

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

/* Header */
.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}
.app-header__title h1 {
  margin: 0 0 4px;
  font-size: 24px;
  font-weight: 600;
}
.app-header__subtitle {
  margin: 0;
  color: var(--text-secondary);
  font-size: 14px;
}
.app-header__actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease;
}
.btn--primary {
  background: var(--series-1);
  color: #ffffff;
}
.btn--primary:hover { filter: brightness(1.08); }
.btn--ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-primary);
}
.btn--ghost:hover { background: var(--surface-2); }
.btn--icon {
  padding: 6px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
}
.btn--icon:hover { background: var(--surface-2); }
.icon { display: block; flex-shrink: 0; }
#theme-toggle .icon--moon { display: none; }
:root[data-theme="dark"] #theme-toggle .icon--sun { display: none; }
:root[data-theme="dark"] #theme-toggle .icon--moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #theme-toggle .icon--sun { display: none; }
  :root:not([data-theme="light"]) #theme-toggle .icon--moon { display: block; }
}

/* Summary stat tiles */
.summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}
.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: var(--shadow-1);
}
.stat-tile__label {
  font-size: 13px;
  color: var(--text-secondary);
}
.stat-tile__value {
  font-size: 30px;
  font-weight: 600;
  line-height: 1.1;
  color: var(--text-primary);
}
.stat-tile--good .stat-tile__value { color: var(--status-good); }
.stat-tile--info .stat-tile__value { color: var(--series-1); }
.stat-tile--critical .stat-tile__value { color: var(--status-critical); }

/* Panel / table */
.panel {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}
.panel__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--gridline);
}
.panel__header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}
.panel__hint {
  font-size: 13px;
  color: var(--text-muted);
}
.table-scroll {
  overflow-x: auto;
}
.kpi-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.kpi-table th {
  text-align: left;
  padding: 10px 16px;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .02em;
  border-bottom: 1px solid var(--gridline);
  white-space: nowrap;
}
.kpi-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--gridline);
  color: var(--text-primary);
  vertical-align: middle;
  white-space: nowrap;
}
.kpi-table tbody tr:last-child td { border-bottom: none; }
.kpi-table tbody tr:hover { background: var(--surface-2); }
.cell-code { color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.cell-name { font-weight: 500; white-space: normal; min-width: 220px; }
.cell-group { color: var(--text-secondary); }
.cell-owner { color: var(--text-secondary); }
.cell-target, .cell-current { font-variant-numeric: tabular-nums; color: var(--text-secondary); }
.cell-progress { min-width: 160px; }

/* Meter */
.meter {
  display: flex;
  align-items: center;
  gap: 8px;
}
.meter__track {
  flex: 1;
  height: 8px;
  border-radius: 4px;
  background: var(--surface-2);
  overflow: hidden;
  min-width: 80px;
}
.meter__fill {
  height: 100%;
  border-radius: 4px;
  background: var(--series-1);
  transition: width .2s ease;
}
.meter__value {
  font-size: 12.5px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  width: 38px;
  text-align: right;
  flex-shrink: 0;
}
.meter--good .meter__fill { background: var(--status-good); }
.meter--critical .meter__fill { background: var(--status-critical); }

/* Status badge */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 8px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 500;
  background: var(--surface-2);
}
.badge__icon {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.badge--완료 .badge__icon { background: var(--status-good); }
.badge--진행중 .badge__icon { background: var(--series-1); }
.badge--지연 .badge__icon { background: var(--status-critical); }
.badge__label { color: var(--text-primary); }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(11,11,11,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--surface-1);
  color: var(--text-primary);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 40px rgba(0,0,0,0.25);
}
.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--gridline);
}
.modal__header h2 { margin: 0; font-size: 17px; font-weight: 600; }
.modal__body {
  padding: 20px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 20px;
  border-top: 1px solid var(--gridline);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  grid-column: span 2;
}
.field--half { grid-column: span 1; }
.field--progress-preview { grid-column: span 2; }
.field label, .field__label-static {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}
.required { color: var(--status-critical); }
.field input, .field select {
  font: inherit;
  font-size: 14px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--baseline);
  background: var(--surface-1);
  color: var(--text-primary);
}
.field input:focus, .field select:focus {
  outline: 2px solid var(--series-1);
  outline-offset: 1px;
}
.field__error {
  margin: 0;
  font-size: 12.5px;
  color: var(--status-critical);
}
.field__error[hidden] { display: none; }

@media (max-width: 640px) {
  .summary { grid-template-columns: repeat(2, 1fr); }
  .modal__body { grid-template-columns: 1fr; }
  .field, .field--half, .field--progress-preview { grid-column: span 1; }
}
