/* === Tokens === */
:root {
  --bg: #ffffff;
  --bg-elev: #fafafa;
  --surface: #ffffff;
  --surface-hover: #f4f4f5;
  --border: #e5e7eb;
  --border-strong: #d4d4d8;
  --text: #18181b;
  --text-muted: #71717a;
  --text-subtle: #a1a1aa;
  --accent: #03c75a;
  --accent-hover: #02b350;
  --accent-soft: rgba(3, 199, 90, 0.1);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.1);
  --warning: #f59e0b;
  --info: #3b82f6;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06), 0 2px 4px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.08), 0 4px 8px rgba(0, 0, 0, 0.04);
  --radius-sm: 6px;
  --radius: 8px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --sidebar-w: 232px;
}

[data-theme="dark"] {
  --bg: #0a0a0a;
  --bg-elev: #111113;
  --surface: #141416;
  --surface-hover: #1c1c1f;
  --border: #26262a;
  --border-strong: #3a3a3f;
  --text: #fafafa;
  --text-muted: #a1a1aa;
  --text-subtle: #71717a;
  --accent: #03c75a;
  --accent-hover: #04dd64;
  --accent-soft: rgba(3, 199, 90, 0.15);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.15);
  --warning: #fbbf24;
  --info: #60a5fa;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.5), 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.5), 0 2px 4px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.6), 0 4px 8px rgba(0, 0, 0, 0.4);
}

/* === Base === */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.01em;
  transition: background 0.2s, color 0.2s;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; padding: 0; }
input, select, textarea { font-family: inherit; }
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }

/* === Layout === */
.app { min-height: 100vh; display: flex; }
.sidebar {
  width: var(--sidebar-w);
  border-right: 1px solid var(--border);
  background: var(--bg-elev);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 30;
}
.sidebar-header {
  padding: 18px 16px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}
.logo-mark {
  width: 28px; height: 28px;
  background: var(--accent);
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 800; font-size: 14px;
  letter-spacing: -0.5px;
}
.brand-name { font-weight: 600; font-size: 14px; letter-spacing: -0.02em; }
.brand-sub { font-size: 11px; color: var(--text-muted); margin-top: 1px; }
.nav-section { padding: 12px 8px; flex: 1; overflow-y: auto; }
.nav-label {
  font-size: 11px;
  color: var(--text-subtle);
  font-weight: 500;
  padding: 8px 10px 4px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.12s;
  width: 100%;
  text-align: left;
  font-weight: 500;
}
.nav-item:hover { background: var(--surface-hover); color: var(--text); }
.nav-item.active { background: var(--surface-hover); color: var(--text); font-weight: 600; }
.nav-item.active .nav-icon { color: var(--accent); }
.nav-icon { width: 16px; height: 16px; flex-shrink: 0; }
.nav-badge {
  margin-left: auto;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 10px;
}
.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 12px;
}

.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-width: 0;
}
.topbar {
  height: 56px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-title { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.topbar-spacer { flex: 1; }
.crumbs {
  display: flex; align-items: center; gap: 6px;
  color: var(--text-muted); font-size: 13px;
}
.crumb-sep { color: var(--text-subtle); }
.page { padding: 28px 28px 80px; max-width: 1400px; }
.page-header { margin-bottom: 24px; }
.page-title { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 4px; }
.page-desc { color: var(--text-muted); font-size: 13px; margin: 0; }

/* === Components === */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 12px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500;
  transition: all 0.12s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-hover); border-color: var(--border-strong); }
.btn-primary {
  background: var(--accent); color: white; border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-hover); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn-lg { height: 38px; padding: 0 16px; font-size: 14px; }
.btn-icon { width: 32px; padding: 0; justify-content: center; }
.btn-icon.btn-sm { width: 28px; }

.input, .select, .textarea {
  height: 32px;
  padding: 0 10px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
  width: 100%;
}
.textarea { height: auto; padding: 8px 10px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input-with-icon { position: relative; }
.input-with-icon .input { padding-left: 32px; }
.input-icon {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  width: 14px; height: 14px; color: var(--text-subtle); pointer-events: none;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.card-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.card-title { font-weight: 600; font-size: 14px; }
.card-body { padding: 16px; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  background: var(--surface-hover);
  color: var(--text-muted);
}
.badge-success { background: var(--accent-soft); color: var(--accent); }
.badge-warn { background: rgba(245, 158, 11, 0.12); color: var(--warning); }
.badge-info { background: rgba(59, 130, 246, 0.12); color: var(--info); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-dot::before {
  content: ''; width: 5px; height: 5px; border-radius: 50%;
  background: currentColor; display: inline-block;
}

/* === Tables === */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left;
  font-weight: 500;
  font-size: 12px;
  color: var(--text-muted);
  padding: 10px 12px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background 0.1s; }
.table tbody tr:hover { background: var(--bg-elev); }
.table tbody tr.selected { background: var(--accent-soft); }
.table-checkbox { width: 36px; }
.table-thumb {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--bg-elev);
}
.product-cell { display: flex; align-items: center; gap: 10px; min-width: 240px; }
.product-name { font-weight: 500; color: var(--text); }
.product-meta { color: var(--text-subtle); font-size: 11px; margin-top: 1px; }

.numeric { font-variant-numeric: tabular-nums; text-align: right; }
.price-edit {
  font-variant-numeric: tabular-nums;
  text-align: right;
  width: 110px;
  height: 28px;
  padding: 0 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  outline: none;
  font-family: inherit;
}
.price-edit:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.price-edit.dirty { border-color: var(--warning); background: rgba(245, 158, 11, 0.05); }

/* === Checkbox === */
.checkbox {
  appearance: none;
  width: 16px; height: 16px;
  border: 1.5px solid var(--border-strong);
  border-radius: 4px;
  background: var(--surface);
  cursor: pointer;
  display: inline-flex;
  align-items: center; justify-content: center;
  transition: all 0.1s;
  position: relative;
}
.checkbox:hover { border-color: var(--accent); }
.checkbox:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.checkbox:checked::after {
  content: '';
  width: 8px; height: 4px;
  border-left: 2px solid white;
  border-bottom: 2px solid white;
  transform: rotate(-45deg) translate(1px, -1px);
}

/* === Stat tile === */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
}
.stat-label {
  font-size: 12px; color: var(--text-muted); font-weight: 500;
  display: flex; align-items: center; gap: 6px;
}
.stat-value {
  font-size: 24px; font-weight: 700; letter-spacing: -0.02em;
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}
.stat-delta {
  margin-top: 6px;
  font-size: 12px;
  display: flex; align-items: center; gap: 4px;
}
.stat-delta.up { color: var(--accent); }
.stat-delta.down { color: var(--danger); }

/* === Toolbar === */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.toolbar-group { display: flex; align-items: center; gap: 6px; }
.toolbar-divider { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }

/* === Filter chips === */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px;
  border-radius: 14px;
  font-size: 12px;
  background: var(--surface-hover);
  color: var(--text);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.12s;
}
.chip:hover { background: var(--bg-elev); border-color: var(--border); }
.chip.active { background: var(--accent-soft); color: var(--accent); border-color: transparent; font-weight: 500; }

/* === Modal === */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 24px;
  backdrop-filter: blur(2px);
  animation: fadeIn 0.15s;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 560px;
  width: 100%;
  max-height: 88vh;
  overflow: auto;
  animation: slideUp 0.2s;
}
.modal-lg { max-width: 880px; }
.modal-xl { max-width: 1100px; }
.modal-header {
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.modal-title { font-weight: 600; font-size: 16px; flex: 1; letter-spacing: -0.01em; }
.modal-body { padding: 20px; }
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex; gap: 8px; justify-content: flex-end;
  background: var(--bg-elev);
}

/* === Toast === */
.toast-stack {
  position: fixed; bottom: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 200;
}
.toast {
  background: var(--text);
  color: var(--bg);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 8px;
  min-width: 220px;
  animation: slideUp 0.2s;
}

/* === Empty state === */
.empty {
  padding: 48px 16px;
  text-align: center;
  color: var(--text-muted);
}
.empty-icon { width: 32px; height: 32px; margin: 0 auto 8px; color: var(--text-subtle); }

/* === Misc === */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; } .gap-6 { gap: 24px; }
.flex-1 { flex: 1; }
.muted { color: var(--text-muted); }
.subtle { color: var(--text-subtle); }
.text-sm { font-size: 12px; }
.text-xs { font-size: 11px; }
.text-lg { font-size: 16px; }
.font-mono { font-family: 'SF Mono', Menlo, Consolas, monospace; }
.tabular { font-variant-numeric: tabular-nums; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.row { display: flex; align-items: center; gap: 12px; }
.right { margin-left: auto; }

/* === Mobile === */
.mobile-toggle { display: none; }
@media (max-width: 880px) {
  :root { --sidebar-w: 220px; }
  .sidebar { transform: translateX(-100%); transition: transform 0.2s; }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .mobile-toggle { display: inline-flex; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .page { padding: 16px 16px 80px; }
  .topbar { padding: 0 12px; }
  .hide-mobile { display: none !important; }
}

/* === Print === */
@media print {
  body { background: white; color: black; }
  .sidebar, .topbar, .no-print { display: none !important; }
  .main { margin-left: 0; }
  .page { padding: 0; max-width: none; }
  .print-only { display: block !important; }
  .invoice-page { page-break-after: always; }
  .invoice-page:last-child { page-break-after: auto; }
}
.print-only { display: none; }

/* === Skeleton === */
.skeleton {
  background: linear-gradient(90deg, var(--surface-hover) 0%, var(--bg-elev) 50%, var(--surface-hover) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 4px;
}
@keyframes shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }

/* product image placeholder */
.thumb-ph {
  width: 100%;
  aspect-ratio: 1;
  border-radius: var(--radius);
  background: var(--bg-elev);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-subtle);
  border: 1px solid var(--border);
  font-size: 11px;
  position: relative;
  overflow: hidden;
}

/* segmented control */
.seg {
  display: inline-flex;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 2px;
  gap: 2px;
}
.seg-btn {
  padding: 4px 10px;
  border-radius: 5px;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  transition: all 0.1s;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}
