:root {
  color-scheme: light;
  --page: #f5f7f8;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #64707d;
  --line: #dce3e8;
  --line-strong: #c7d1d8;
  --green: #1f8a5b;
  --green-soft: #e7f4ed;
  --orange: #d66b21;
  --orange-soft: #fff0df;
  --red: #c43131;
  --red-soft: #ffe8e8;
  --blue: #2e6ccf;
  --blue-soft: #e9f0ff;
  --shadow: 0 12px 28px rgba(29, 45, 57, .08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-width: 320px;
  background: var(--page);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans KR", sans-serif;
  letter-spacing: 0;
}
button, input, select, textarea { font: inherit; }
button { border: 0; cursor: pointer; }
input, select, textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
  color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: 3px solid rgba(46, 108, 207, .18);
  border-color: var(--blue);
}
textarea { min-height: 88px; resize: vertical; }

.app { max-width: 1180px; margin: 0 auto; padding: 18px; }
.app-header { padding: 8px 0 16px; }
h1 { margin: 0; font-size: clamp(25px, 4vw, 36px); line-height: 1.15; }
.app-header p { margin: 8px 0 0; color: var(--muted); }

.tabs {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 0 14px;
  background: var(--page);
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  font-weight: 800;
  white-space: nowrap;
}
.tab.active { background: #1f2b37; border-color: #1f2b37; color: #fff; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel + .panel { margin-top: 14px; }
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 15px 16px;
  border-bottom: 1px solid var(--line);
}
.panel-head h2 { margin: 0; font-size: 18px; line-height: 1.25; }
.dashboard-grid, .two-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, .9fr);
  gap: 14px;
  align-items: start;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}
.pill.green, .badge.normal { color: var(--green); background: var(--green-soft); }
.pill.blue, .badge.order { color: var(--blue); background: var(--blue-soft); }
.badge.low { color: var(--orange); background: var(--orange-soft); }
.badge.urgent { color: var(--red); background: var(--red-soft); }
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.risk-list, .list, .quick-list { display: grid; gap: 10px; padding: 16px; }
.list { max-height: 360px; overflow: auto; }
.risk-item, .list-item, .quick-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}
.risk-item.low { border-color: #f0c18c; background: var(--orange-soft); }
.risk-item.urgent { border-color: #e8aaaa; background: var(--red-soft); }
.title-line { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; font-weight: 900; }
.meta { margin-top: 5px; color: var(--muted); font-size: 13px; line-height: 1.45; }

.stock-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(70px, 1fr));
  gap: 8px;
  min-width: 250px;
}
.stock-chip {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  text-align: right;
}
.stock-chip span { display: block; color: var(--muted); font-size: 11px; font-weight: 900; }
.stock-chip strong { display: block; margin-top: 3px; font-size: 22px; line-height: 1; }

.filter-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(150px, .4fr);
  gap: 10px;
  padding: 16px 16px 0;
}
.filter-stack { display: grid; gap: 10px; padding: 16px 16px 0; }
.form { display: grid; gap: 12px; padding: 16px; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; font-weight: 800; }

.actions { display: flex; gap: 8px; padding: 0 16px 16px; }
.actions.no-pad { padding: 0; }
.primary, .secondary, .danger {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 46px;
  padding: 0 16px;
  border-radius: 8px;
  font-weight: 900;
  white-space: nowrap;
}
.primary { flex: 1; color: #fff; background: var(--green); }
.secondary { color: var(--ink); background: #e9eef1; }
.danger { color: #fff; background: var(--red); }
.compact { min-height: 36px; padding: 0 12px; }

.stepper { display: grid; grid-template-columns: 42px 72px 42px; gap: 6px; align-items: center; }
.stepper button {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #e9eef1;
  font-size: 22px;
  font-weight: 900;
}
.stepper input { text-align: center; font-weight: 900; }

.table-wrap { max-height: 430px; overflow: auto; }
table { width: 100%; min-width: 780px; border-collapse: collapse; }
th, td { padding: 13px 16px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}
#inventoryRows tr { cursor: pointer; }
#inventoryRows tr:hover { background: #f4f7fa; }
#inventoryRows tr.selected-row { background: var(--blue-soft); }
.inline-stock { display: flex; flex-wrap: wrap; gap: 6px; }
.mini {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  min-height: 28px;
  padding: 0 8px;
  border-radius: 8px;
  background: #eef3f6;
  font-weight: 900;
}
.mini span { color: var(--muted); font-size: 11px; }

.order-check {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 2px solid #9aa6b2;
  border-radius: 6px;
  background: #fff;
  color: transparent;
  font-size: 22px;
  font-weight: 900;
}
.order-check.checked { border-color: var(--green); color: var(--green); background: var(--green-soft); }
.row-actions, .order-actions { display: flex; gap: 6px; justify-content: flex-end; align-items: center; }
.small-action, .icon-btn {
  min-height: 34px;
  padding: 0 10px;
  border-radius: 8px;
  background: #e9eef1;
  color: var(--ink);
  font-size: 12px;
  font-weight: 900;
}
.icon-btn { width: 36px; padding: 0; font-size: 17px; }
.icon-btn.danger { color: #fff; background: var(--red); }

.stats-panel { margin-top: 14px; }
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 16px 16px 0;
}
.metric {
  min-height: 88px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}
.metric span { color: var(--muted); font-size: 13px; font-weight: 900; }
.metric strong { display: block; margin-top: 6px; font-size: 27px; line-height: 1; }
.chart-wrap {
  margin: 16px;
  min-height: 340px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}
#statsChart { width: 100%; height: 320px; display: block; }
.stats-list { margin: 0 16px 16px; padding: 0; }

.suggestions { display: grid; gap: 8px; }
.suggestion-btn {
  display: grid;
  gap: 4px;
  width: 100%;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  color: var(--ink);
  text-align: left;
}
.suggestion-btn.selected { border-color: var(--blue); background: var(--blue-soft); }

.empty {
  padding: 18px;
  border: 1px dashed #cbd5dc;
  border-radius: 8px;
  background: #fbfcfd;
  color: var(--muted);
  text-align: center;
}
.hidden { display: none !important; }
.notice {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}
.lock-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 18px;
  background: linear-gradient(180deg, #f5f7f8 0%, #e9eef1 100%);
}
.lock-card {
  display: grid;
  gap: 14px;
  width: min(420px, 100%);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.lock-card h2 {
  margin: 0;
  font-size: 24px;
}
.lock-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}
.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 120;
  transform: translateX(-50%) translateY(16px);
  opacity: 0;
  pointer-events: none;
  min-width: min(420px, calc(100vw - 32px));
  padding: 13px 16px;
  border-radius: 8px;
  color: #fff;
  background: #1f2b37;
  box-shadow: var(--shadow);
  transition: 180ms ease;
  font-weight: 900;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
dialog { width: min(420px, calc(100vw - 28px)); border: 1px solid var(--line); border-radius: 8px; padding: 0; }
dialog::backdrop { background: rgba(23, 32, 42, .38); }
.dialog-card { display: grid; gap: 14px; padding: 18px; }
.dialog-card h2 { margin: 0; }

@media (max-width: 880px) {
  .app { padding: 12px; }
  .dashboard-grid, .two-grid { grid-template-columns: 1fr; }
  .filter-bar, .stats-grid { grid-template-columns: 1fr; }
  .risk-item, .quick-row, .list-item { grid-template-columns: 1fr; }
  .stock-metrics { min-width: 0; }
  .list, .risk-list, .quick-list, .form { padding: 12px; }
  .actions { padding: 0 12px 12px; }
}

@media (max-width: 520px) {
  h1 { font-size: 24px; }
  .panel-head { align-items: flex-start; flex-direction: column; }
  .stock-metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stock-chip strong { font-size: 19px; }
}
