/* ===== Design Tokens ===== */
:root {
  --bg: #0b0f1a;
  --bg-elev: #11172a;
  --bg-elev-2: #161d36;
  --surface: rgba(255,255,255,0.03);
  --surface-2: rgba(255,255,255,0.06);
  --border: rgba(255,255,255,0.08);
  --border-strong: rgba(255,255,255,0.14);
  --text: #e7ecf3;
  --text-dim: #9aa3b4;
  --text-mute: #6c7588;
  --accent: #5b8def;
  --accent-2: #22d3ee;
  --accent-grad: linear-gradient(135deg, #5b8def 0%, #22d3ee 100%);
  --success: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow-1: 0 1px 2px rgba(0,0,0,0.4), 0 8px 24px rgba(0,0,0,0.25);
  --shadow-2: 0 1px 2px rgba(0,0,0,0.4), 0 24px 60px rgba(0,0,0,0.4);
  --ease: cubic-bezier(.2,.8,.2,1);
  --t: 220ms;
  --font: 'Pretendard', -apple-system, BlinkMacSystemFont, 'SF Pro KR', system-ui, sans-serif;
  --mono: 'JetBrains Mono', monospace;
  --row-h: 44px;
}
[data-theme="light"] {
  --bg: #f6f7fb;
  --bg-elev: #ffffff;
  --bg-elev-2: #ffffff;
  --surface: rgba(0,0,0,0.02);
  --surface-2: rgba(0,0,0,0.05);
  --border: rgba(0,0,0,0.08);
  --border-strong: rgba(0,0,0,0.16);
  --text: #14182a;
  --text-dim: #5a6479;
  --text-mute: #8893a8;
  --shadow-1: 0 1px 2px rgba(20,24,42,0.06), 0 8px 24px rgba(20,24,42,0.06);
  --shadow-2: 0 1px 2px rgba(20,24,42,0.08), 0 24px 60px rgba(20,24,42,0.10);
}

/* ===== Reset ===== */
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  height: 100vh; height: 100dvh;
  overflow: hidden;            /* B-1: no body scroll */
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
body::before {
  content: '';
  position: fixed; inset: 0;
  background: radial-gradient(1200px 600px at 80% -10%, rgba(34,211,238,0.12), transparent 60%),
              radial-gradient(900px 500px at -10% 110%, rgba(91,141,239,0.12), transparent 60%);
  pointer-events: none; z-index: 0;
}
[data-theme="light"] body::before { opacity: 0.6; }
button { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
input, select, textarea { font: inherit; color: inherit; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; }

/* ===== Layout ===== */
#app {
  position: relative; z-index: 1;
  display: grid;
  grid-template-columns: 248px 1fr;
  height: 100vh; height: 100dvh;
}

/* ===== Sidebar ===== */
.sidebar {
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.01));
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 18px 14px;
  backdrop-filter: blur(20px);
}
[data-theme="light"] .sidebar { background: linear-gradient(180deg, #ffffff, #fbfcfe); }

.brand {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 8px; margin-bottom: 18px;
  border-radius: var(--radius);
  cursor: pointer; user-select: none;
  transition: background var(--t) var(--ease);
}
.brand:hover { background: var(--surface); }
.brand-logo {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: var(--accent-grad);
  display: grid; place-items: center;
  color: #fff; font-weight: 800; font-size: 16px;
  box-shadow: 0 6px 14px rgba(91,141,239,0.4);
}
.brand-text { line-height: 1.15; }
.brand-name { font-weight: 700; font-size: 14.5px; letter-spacing: -0.02em; }
.brand-sub { color: var(--text-dim); font-size: 11.5px; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--text-dim);
  cursor: pointer;
  transition: all var(--t) var(--ease);
  font-weight: 500;
}
.nav-item svg { width: 18px; height: 18px; flex: 0 0 18px; }
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active {
  background: var(--surface-2);
  color: var(--text);
  position: relative;
}
.nav-item.active::before {
  content: '';
  position: absolute; left: -14px; top: 8px; bottom: 8px;
  width: 3px; border-radius: 3px;
  background: var(--accent-grad);
}
.sidebar-foot { margin-top: auto; }
.company-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--surface);
}
.company-name { font-weight: 700; }
.company-sub { color: var(--text-dim); font-size: 12px; }

/* ===== Topbar ===== */
.main {
  display: flex; flex-direction: column;
  min-width: 0;
  height: 100vh; height: 100dvh;
}
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.01);
  backdrop-filter: blur(12px);
}
.topbar-title { font-weight: 700; font-size: 18px; letter-spacing: -0.02em; }
.topbar-search {
  position: relative; flex: 1; max-width: 480px;
  display: flex; align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 10px;
  transition: border-color var(--t) var(--ease), background var(--t) var(--ease);
}
.topbar-search:focus-within { border-color: var(--accent); background: var(--surface-2); }
.topbar-search svg { width: 16px; height: 16px; color: var(--text-dim); }
.topbar-search input { flex: 1; border: 0; background: transparent; outline: none; padding: 10px; }
.topbar-search kbd {
  font-family: var(--mono); font-size: 11px;
  background: var(--surface-2);
  padding: 2px 6px; border-radius: 6px;
  color: var(--text-dim);
}
.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.btn-icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  display: grid; place-items: center;
  cursor: pointer;
  transition: all var(--t) var(--ease);
}
.btn-icon:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn-icon svg { width: 16px; height: 16px; }
.user-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 12px 6px 6px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.user-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent-grad);
  color: #fff; font-weight: 700;
  display: grid; place-items: center;
  font-size: 12.5px;
}
.user-meta { line-height: 1.1; }
.user-name { font-weight: 600; font-size: 13px; }
.user-role { font-size: 11px; color: var(--text-dim); }

/* ===== Content ===== */
.content {
  flex: 1; min-height: 0;
  padding: 20px;
  overflow: hidden; /* B-1: no body scroll, content area handles */
  display: flex; flex-direction: column;
  gap: 16px;
}

/* ===== Card ===== */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.card-title { font-weight: 700; font-size: 14.5px; letter-spacing: -0.01em; }
.card-sub { color: var(--text-dim); font-size: 12px; }
.card-body { padding: 18px; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-weight: 600; font-size: 13px;
  transition: all var(--t) var(--ease);
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn.primary {
  background: var(--accent-grad);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 6px 14px rgba(91,141,239,0.35);
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); border-color: rgba(248,113,113,0.3); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn svg { width: 14px; height: 14px; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* ===== Toolbar ===== */
.toolbar {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.toolbar .grow { flex: 1; }

/* ===== KPI ===== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}
.kpi {
  position: relative;
  padding: 18px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.kpi-label { color: var(--text-dim); font-size: 12.5px; font-weight: 500; }
.kpi-value {
  font-size: 28px; font-weight: 800;
  margin-top: 6px; letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.kpi-sub { color: var(--text-mute); font-size: 11.5px; margin-top: 4px; }
.kpi-glow {
  position: absolute; right: -20px; top: -20px;
  width: 100px; height: 100px;
  background: var(--accent-grad);
  opacity: 0.18;
  filter: blur(30px);
}

/* ===== Dashboard 2-col ===== */
.dash-grid {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 16px;
  flex: 1;
  min-height: 0;
}
.dash-col { display: flex; flex-direction: column; gap: 16px; min-height: 0; }

/* ===== Table ===== */
.table-wrap {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
}
.table-scroll {
  flex: 1; min-height: 0;
  overflow: auto;
  border-radius: 0;
}
table.data {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}
table.data thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--bg-elev-2);
  text-align: center;
  font-weight: 600; font-size: 12.5px;
  color: var(--text-dim);
  padding: 10px 8px;
  border-bottom: 1px solid var(--border-strong);
  border-right: 1px solid var(--border);  /* B-3 세로 구분선 */
  white-space: nowrap;
}
table.data thead th:last-child { border-right: 0; }
table.data tbody td {
  height: var(--row-h);                   /* B-3 행 높이 고정 */
  padding: 0 8px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13px;
}
table.data tbody td:last-child { border-right: 0; }
table.data tbody tr:hover td { background: var(--surface); }
.money { text-align: right !important; font-variant-numeric: tabular-nums; font-family: var(--mono); padding-right: 12px !important; }
.num { font-variant-numeric: tabular-nums; }

/* row actions */
.row-actions {
  display: inline-flex; gap: 6px; justify-content: center;
}
.row-actions button {
  width: 28px; height: 28px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  display: grid; place-items: center;
  color: var(--text-dim);
  transition: all var(--t) var(--ease);
}
.row-actions button:hover { background: var(--surface-2); color: var(--text); }
.row-actions button.danger:hover { color: var(--danger); border-color: rgba(248,113,113,0.3); }
.row-actions svg { width: 14px; height: 14px; }

/* status toggle */
.toggle {
  position: relative;
  width: 36px; height: 20px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--t) var(--ease);
}
.toggle::after {
  content: '';
  position: absolute; left: 2px; top: 50%;
  width: 14px; height: 14px;
  background: #fff;
  border-radius: 50%;
  transform: translateY(-50%);
  transition: left var(--t) var(--ease);
}
.toggle.on { background: var(--accent); border-color: transparent; }
.toggle.on::after { left: 18px; }

/* pagination */
.pagination {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.pagination .info { color: var(--text-dim); font-size: 12px; }
.pagination .spacer { flex: 1; }
.pagination button {
  width: 30px; height: 30px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  transition: all var(--t) var(--ease);
}
.pagination button:hover:not(:disabled) { background: var(--surface-2); }
.pagination button.active { background: var(--accent-grad); color: #fff; border-color: transparent; }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===== Form ===== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
.form-grid.cols-1 { grid-template-columns: 1fr; }
.form-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.form-grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field.col-span-2 { grid-column: span 2; }
.field.col-span-3 { grid-column: span 3; }
.field.col-span-4 { grid-column: span 4; }
.label {
  font-size: 12px; color: var(--text-dim);
  font-weight: 500; letter-spacing: 0.01em;
}
.required::after { content: ' *'; color: var(--danger); }
.input, .textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  transition: border-color var(--t) var(--ease), background var(--t) var(--ease);
}
.input:focus, .textarea:focus { border-color: var(--accent); background: var(--surface-2); }
.input.money-input { text-align: right; font-family: var(--mono); }
.input.num-input { text-align: center; font-variant-numeric: tabular-nums; }
.textarea { min-height: 60px; resize: vertical; }

/* combobox */
.combobox { position: relative; }
.combobox .menu {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--bg-elev-2);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  box-shadow: var(--shadow-2);
  max-height: 240px; overflow-y: auto;
  z-index: 20;
  padding: 6px;
  display: none;
  opacity: 0; transform: translateY(-4px);
  transition: opacity var(--t) var(--ease), transform var(--t) var(--ease);
}
.combobox.open .menu { display: block; opacity: 1; transform: translateY(0); }
.combobox .menu-item {
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}
.combobox .menu-item:hover, .combobox .menu-item.active { background: var(--surface-2); }
.combobox .menu-item.add-new { color: var(--accent); font-weight: 600; }

/* date picker */
.datepicker { position: relative; }
.datepicker .panel {
  position: absolute; top: calc(100% + 4px); left: 0;
  background: var(--bg-elev-2);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  box-shadow: var(--shadow-2);
  padding: 14px;
  z-index: 20;
  display: none;
  width: 280px;
  opacity: 0; transform: translateY(-4px);
  transition: opacity var(--t) var(--ease), transform var(--t) var(--ease);
}
.datepicker.open .panel { display: block; opacity: 1; transform: translateY(0); }
.dp-head { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.dp-head select {
  padding: 6px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
}
.dp-head button {
  width: 28px; height: 28px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  display: grid; place-items: center;
}
.dp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.dp-grid .dow { text-align: center; font-size: 11px; color: var(--text-dim); padding: 4px 0; }
.dp-grid .day {
  text-align: center;
  padding: 6px 0;
  border-radius: 6px;
  cursor: pointer;
  font-variant-numeric: tabular-nums; font-size: 12.5px;
  border: 1px solid transparent;
}
.dp-grid .day:hover { background: var(--surface-2); }
.dp-grid .day.other { color: var(--text-mute); }
.dp-grid .day.today { border-color: var(--accent); }
.dp-grid .day.selected { background: var(--accent-grad); color: #fff; }
.dp-foot { display: flex; gap: 6px; margin-top: 8px; }
.dp-foot button {
  flex: 1; padding: 6px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 12px;
}

/* ===== Modal ===== */
.modal-mask {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(6px);
  display: grid; place-items: center;
  padding: 20px;
  opacity: 0;
  transition: opacity var(--t) var(--ease);
}
.modal-mask.show { opacity: 1; }
.modal {
  width: min(820px, 100%);
  max-height: 90vh;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  box-shadow: var(--shadow-2);
  display: flex; flex-direction: column;
  transform: translateY(8px) scale(0.98);
  transition: transform var(--t) var(--ease);
}
.modal.lg { width: min(1080px, 100%); }
.modal-mask.show .modal { transform: translateY(0) scale(1); }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-weight: 700; font-size: 16px; letter-spacing: -0.02em; }
.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}
.modal-foot {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

/* ===== Tooltip ===== */
.tip-portal {
  position: fixed; z-index: 999;
  background: #1a2240;
  color: #fff;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 12px;
  pointer-events: none;
  box-shadow: var(--shadow-2);
  max-width: 360px;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity var(--t) var(--ease), transform var(--t) var(--ease);
}
.tip-portal.show { opacity: 1; transform: translateY(0); }

/* ===== Toast ===== */
.toast-root {
  position: fixed; bottom: 20px; right: 20px;
  z-index: 200;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  padding: 12px 16px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  box-shadow: var(--shadow-2);
  font-size: 13px;
  min-width: 240px;
  opacity: 0;
  transform: translateX(20px);
  transition: opacity var(--t) var(--ease), transform var(--t) var(--ease);
}
.toast.show { opacity: 1; transform: translateX(0); }
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }

/* ===== Badges ===== */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px; font-weight: 600;
  background: var(--surface-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.badge.source-직거래 { background: rgba(91,141,239,0.15); color: #a8c1ff; border-color: rgba(91,141,239,0.3); }
.badge.source-국립수산물품질관리원 { background: rgba(34,211,238,0.15); color: #8be9f4; border-color: rgba(34,211,238,0.3); }
.badge.source-식품안전나라 { background: rgba(251,191,36,0.15); color: #fcd47a; border-color: rgba(251,191,36,0.3); }
.badge.status-재고 { background: rgba(52,211,153,0.15); color: #79e7be; border-color: rgba(52,211,153,0.3); }
.badge.status-출고 { background: rgba(91,141,239,0.15); color: #a8c1ff; border-color: rgba(91,141,239,0.3); }
.badge.status-폐기 { background: rgba(248,113,113,0.15); color: #fca5a5; border-color: rgba(248,113,113,0.3); }

/* Empty/loading */
.empty {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-dim);
}
.empty-emoji { font-size: 36px; margin-bottom: 8px; opacity: 0.6; }
.skeleton {
  background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.06) 50%, transparent 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* chart wrapper - Chart.js requires position:relative parent with definite size */
.chart-wrap {
  position: relative;
  width: 100%; height: 100%;
}
.chart-wrap canvas { display: block; }

/* mini list */
.mini-list { display: flex; flex-direction: column; }
.mini-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.mini-row:last-child { border-bottom: 0; }
.mini-name { font-weight: 500; }
.mini-sub { color: var(--text-dim); font-size: 11.5px; }
.mini-amt { font-family: var(--mono); font-variant-numeric: tabular-nums; text-align: right; }

/* invoice items table inside modal */
.inv-items {
  width: 100%; border-collapse: collapse;
}
.inv-items th, .inv-items td {
  padding: 8px;
  border: 1px solid var(--border);
  text-align: center;
  font-size: 12.5px;
}
.inv-items th { background: var(--surface); color: var(--text-dim); font-weight: 600; }
.inv-items input { width: 100%; background: transparent; border: 0; outline: none; text-align: center; padding: 4px; }
.inv-items input.money { text-align: right; font-family: var(--mono); }

/* settings list */
.opt-list { display: flex; flex-direction: column; gap: 6px; }
.opt-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}
.opt-row .grip { color: var(--text-mute); cursor: grab; }
.opt-row .grow { flex: 1; }
.opt-row input { background: transparent; border: 0; outline: none; flex: 1; }

@media (max-width: 1100px) {
  #app { grid-template-columns: 72px 1fr; }
  .brand-text, .nav-item span, .sidebar-foot { display: none; }
  .nav-item { justify-content: center; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .dash-grid { grid-template-columns: 1fr; }
}
