:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-2: #f8faf8;
  --line: #e5e9ec;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #03c75a;
  --primary-dark: #02b351;
  --primary-soft: #eafaf1;
  --good: #03c75a;
  --warn: #f59e0b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "Noto Sans KR", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--primary);
  color: #ffffff;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

button.secondary,
button.preset {
  background: #ffffff;
  color: var(--text);
}

button:hover {
  background: var(--primary-dark);
}

button.secondary:hover,
button.preset:hover {
  background: #f5f7f8;
}

button:disabled {
  opacity: 0.6;
  cursor: wait;
}

.page-shell {
  width: 100%;
  min-height: 100vh;
  margin: 0;
  padding: 18px 20px 24px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 16px;
}

.page-header h1 {
  margin: 4px 0 8px;
  font-size: 28px;
  color: #1b1d1f;
}

.eyebrow,
.meta-line,
.subtle,
.card-sub,
.mini-sub,
.item-sub {
  color: var(--muted);
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0.08em;
}

.meta-line {
  margin: 0;
  font-size: 13px;
}

.header-actions {
  display: flex;
  gap: 10px;
}

.layout-grid {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
}

.control-panel {
  display: grid;
  gap: 12px;
  position: sticky;
  top: 16px;
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.section-title-row h2,
.section-title-row h3,
.panel h3 {
  margin: 0;
  font-size: 16px;
}

.preset-buttons {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

button.preset.active {
  outline: 2px solid var(--primary);
  background: var(--primary-soft);
  color: #067a3a;
}

.field-grid {
  display: grid;
  gap: 10px;
}

.compact-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

label {
  display: grid;
  gap: 6px;
  font-size: 13px;
}

input[type="number"] {
  width: 100%;
  background: #ffffff;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
}

.checkbox-row {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 10px;
}

.checkbox-row input {
  width: 18px;
  height: 18px;
}

.muted-panel {
  background: var(--panel-2);
}

.params-list,
.guide-list {
  display: grid;
  gap: 8px;
}

.param-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}

.guide-list {
  margin: 8px 0 0;
  padding-left: 18px;
  font-size: 13px;
}

.main-column {
  display: grid;
  gap: 16px;
}

.mobile-list-panel {
  display: none;
}

.mobile-card-list {
  display: grid;
  gap: 12px;
}

.mobile-sku-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  background: #ffffff;
}

.mobile-card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 12px;
}

.mobile-badge-stack {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.mobile-metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.mobile-metric,
.mobile-plan-box,
.mobile-reason-block,
.mobile-empty {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: #fbfcfd;
}

.mobile-plan-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.mobile-reason-block {
  margin-top: 10px;
}

.mobile-label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  align-items: start;
}

.summary-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
}

.summary-card.primary {
  border-color: rgba(3, 199, 90, 0.45);
  background: #f6fef9;
}

.summary-card.good {
  border-color: rgba(3, 199, 90, 0.4);
}

.summary-card.warn {
  border-color: rgba(245, 158, 11, 0.6);
}

.card-title {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--muted);
}

.card-value {
  display: block;
  font-size: 28px;
  margin-bottom: 6px;
}

.table-panel {
  padding-bottom: 8px;
}

.table-wrap {
  overflow: auto;
  border-radius: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  min-width: 1560px;
}

th,
td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  font-size: 13px;
  line-height: 1.35;
}

th {
  position: sticky;
  top: 0;
  background: #f9fbfb;
  z-index: 1;
  text-align: left;
  white-space: nowrap;
  font-size: 12px;
}

.col-select {
  width: 44px;
  text-align: center;
}

.th-check-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.selector-cell {
  text-align: center;
  vertical-align: middle;
}

.row-selector {
  display: block;
  width: 15px;
  height: 15px;
  margin: 0 auto;
  accent-color: var(--primary);
  cursor: pointer;
}

.master-selector {
  margin: 0;
}

.th-help-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.help-trigger {
  width: 16px;
  height: 16px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid rgba(3, 199, 90, 0.25);
  background: rgba(3, 199, 90, 0.08);
  color: #067a3a;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: help;
}

.help-trigger:hover,
.help-trigger:focus-visible {
  background: rgba(3, 199, 90, 0.16);
  border-color: rgba(3, 199, 90, 0.45);
  outline: none;
}

.help-tooltip {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  width: min(280px, 36vw);
  min-width: 220px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(3, 199, 90, 0.18);
  background: #f4fbf6;
  color: #166534;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.12);
  white-space: normal;
  line-height: 1.45;
  font-size: 12px;
  font-weight: 500;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity 0.16s ease, transform 0.16s ease, visibility 0.16s ease;
  pointer-events: none;
  z-index: 20;
}

.th-help-wrap.align-right .help-tooltip {
  left: auto;
  right: 0;
}

.th-help-wrap:hover .help-tooltip,
.th-help-wrap:focus-within .help-tooltip {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.col-item {
  width: 28%;
}

.col-stock {
  width: 5.2%;
}

.col-need {
  width: 5.2%;
}

.col-tail {
  width: 5.2%;
}

.col-weeks {
  width: 6.3%;
}

.col-ratio {
  width: 4.8%;
}

.col-current,
.col-simulated {
  width: 6%;
}

.col-final-weeks {
  width: 6.3%;
}

.col-delta {
  width: 4.3%;
}

.col-bucket {
  width: 5.2%;
}

.col-note {
  width: 12%;
}

tr.changed-row {
  background: rgba(3, 199, 90, 0.05);
}

tr.selected-row {
  box-shadow: inset 4px 0 0 rgba(3, 199, 90, 0.9);
  background: rgba(3, 199, 90, 0.09);
}

tr.selected-row.changed-row {
  background: rgba(3, 199, 90, 0.12);
}

.item-name {
  font-weight: 700;
  margin-bottom: 2px;
  line-height: 1.3;
  word-break: keep-all;
}

.item-sub {
  font-size: 12px;
  line-height: 1.3;
  word-break: auto-phrase;
}

.item-cell,
.note-cell {
  overflow-wrap: anywhere;
}

.note-cell {
  font-size: 12.5px;
}

.delta {
  font-weight: 700;
}

.good-text {
  color: var(--good);
}

.warn-text {
  color: var(--warn);
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  border: 1px solid var(--line);
  white-space: nowrap;
}

.badge.primary {
  background: rgba(3, 199, 90, 0.12);
  color: #067a3a;
}

.badge.warn {
  background: rgba(245, 158, 11, 0.14);
  color: #b45309;
}

.badge.neutral {
  background: #f3f4f6;
  color: #4b5563;
}

.excluded-divider-row td {
  padding: 6px 12px;
  background: #f6f8f9;
}

.excluded-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #ffffff;
  color: #067a3a;
  border: 1px solid rgba(3, 199, 90, 0.2);
  padding: 6px 10px;
  font-size: 12px;
}

.excluded-toggle::before {
  content: '▸';
  font-size: 10px;
  transition: transform 0.16s ease;
}

.excluded-toggle.open::before {
  transform: rotate(90deg);
}

.row-collapsed {
  display: none;
}

@media (max-width: 1280px) {
  .layout-grid {
    grid-template-columns: 1fr;
  }

  .control-panel {
    position: static;
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 800px) {
  .page-header {
    flex-direction: column;
  }

  .header-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .header-actions button {
    width: 100%;
  }

  .compact-grid,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .mobile-list-panel {
    display: block;
  }

  .table-panel {
    display: none;
  }

  .mobile-card-head,
  .mobile-plan-row,
  .mobile-metric-grid {
    grid-template-columns: 1fr;
    display: grid;
  }

  .mobile-card-head {
    display: grid;
  }

  .mobile-badge-stack {
    justify-content: flex-start;
  }
}
