/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #2c3e50;
  --primary-light: #34495e;
  --accent: #c0956c;
  --accent-light: #d4a97a;
  --accent-dark: #a07850;
  --bg: #f8f6f3;
  --bg-card: #ffffff;
  --bg-hover: #faf8f5;
  --text: #2c3e50;
  --text-light: #7f8c8d;
  --text-muted: #bdc3c7;
  --border: #e8e4df;
  --border-light: #f0ece7;
  --success: #27ae60;
  --danger: #e74c3c;
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.10);
  --radius: 8px;
  --radius-lg: 12px;
  --transition: 0.2s ease;
}

body {
  font-family: 'Noto Sans KR', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ===== Header ===== */
.header {
  background: var(--primary);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  height: 64px;
  gap: 32px;
}

.logo { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.logo-icon { font-size: 24px; color: var(--accent); }
.logo h1 { font-size: 20px; font-weight: 700; letter-spacing: -0.5px; }
.logo-sub { font-size: 12px; opacity: 0.6; margin-top: 2px; }

.nav { display: flex; gap: 4px; }
.nav-btn {
  background: none; border: none; color: rgba(255,255,255,0.6);
  padding: 8px 20px; border-radius: 6px; cursor: pointer;
  font-size: 14px; font-weight: 500; transition: var(--transition); font-family: inherit;
}
.nav-btn:hover { color: #fff; background: rgba(255,255,255,0.1); }
.nav-btn.active { color: #fff; background: rgba(255,255,255,0.15); }

.header-actions { margin-left: auto; display: flex; gap: 8px; }
.btn-settings { color: rgba(255,255,255,0.8) !important; border-color: rgba(255,255,255,0.3) !important; }
.btn-settings:hover { color: #fff !important; border-color: var(--accent) !important; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 18px; border-radius: 6px; border: none;
  font-size: 13px; font-weight: 500; cursor: pointer;
  transition: var(--transition); font-family: inherit; white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-outline { background: none; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }
.btn-accent { background: var(--primary); color: #fff; }
.btn-accent:hover { background: var(--primary-light); }
.btn-danger { background: none; border: 1px solid var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-icon {
  width: 32px; height: 32px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 6px; border: 1px solid var(--border);
  background: #fff; cursor: pointer; transition: var(--transition);
}
.btn-icon:hover { border-color: var(--accent); color: var(--accent); }
.btn-icon.btn-del { border-color: var(--danger); color: var(--danger); }
.btn-icon.btn-del:hover { background: var(--danger); color: #fff; }

/* ===== Main ===== */
.main { max-width: 1400px; margin: 0 auto; padding: 24px; }
.view { display: none; }
.view.active { display: block; }

/* ===== Filter Bar ===== */
.filter-bar {
  display: flex; align-items: flex-end; gap: 20px; flex-wrap: wrap;
  padding: 20px 24px; background: var(--bg-card);
  border-radius: var(--radius-lg); box-shadow: var(--shadow); margin-bottom: 20px;
}
.filter-group label {
  display: block; font-size: 11px; font-weight: 600;
  color: var(--text-light); text-transform: uppercase;
  letter-spacing: 0.5px; margin-bottom: 6px;
}
.filter-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  padding: 6px 14px; border-radius: 20px; border: 1px solid var(--border);
  background: #fff; font-size: 13px; cursor: pointer;
  transition: var(--transition); font-family: inherit; color: var(--text-light);
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

select, input[type="text"], input[type="number"], input[type="date"], textarea {
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px;
  font-size: 13px; font-family: inherit; color: var(--text);
  background: #fff; transition: var(--transition); width: 100%;
}
select:focus, input:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(192,149,108,0.15);
}

.search-group { flex: 1; min-width: 200px; }
.search-group input { width: 100%; }

.view-toggle { display: flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.toggle-btn {
  padding: 6px 12px; border: none; background: #fff; cursor: pointer;
  font-size: 16px; color: var(--text-light); transition: var(--transition);
}
.toggle-btn.active { background: var(--accent); color: #fff; }
.toggle-btn:hover:not(.active) { background: var(--bg); }

/* ===== Stats Bar ===== */
.stats-bar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 4px; font-size: 13px; color: var(--text-light); margin-bottom: 16px;
}
.stats-left { display: flex; align-items: center; gap: 12px; }

/* ===== Product Grid ===== */
.product-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px;
}
.product-card {
  background: var(--bg-card); border-radius: var(--radius-lg); overflow: hidden;
  box-shadow: var(--shadow); cursor: pointer; transition: var(--transition);
  border: 1px solid var(--border-light); position: relative;
}
.product-card:hover {
  transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: var(--accent);
}
.product-card-check {
  position: absolute; top: 10px; right: 10px; z-index: 5;
  width: 22px; height: 22px; cursor: pointer; accent-color: var(--accent);
}
.product-card-img {
  width: 100%; height: 200px;
  background: #ffffff;
  display: flex; align-items: center; justify-content: center;
  position: relative; overflow: hidden;
}
.product-card-img img { width: 100%; height: 100%; object-fit: contain; background: #fff; padding: 12px; }
.product-card-img .placeholder-icon { font-size: 48px; color: var(--text-muted); opacity: 0.4; }
.product-card-badge {
  position: absolute; top: 10px; left: 10px;
  padding: 3px 10px; background: var(--primary); color: #fff;
  border-radius: 12px; font-size: 11px; font-weight: 600;
}
.product-card-body { padding: 16px; }
.product-card-name { font-size: 14px; font-weight: 600; margin-bottom: 8px; line-height: 1.4; color: var(--text); }
.product-card-meta { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-light); }
.product-card-meta .meta-row { display: flex; justify-content: space-between; }
.product-card-price {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border-light);
}
.price-consumer { font-size: 11px; color: var(--text-muted); text-decoration: line-through; }
.price-supply { font-size: 16px; font-weight: 700; color: var(--accent-dark); }

/* ===== Product Table ===== */
.product-table-wrap {
  background: var(--bg-card); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); overflow-x: auto;
}
.product-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.product-table th {
  background: var(--primary); color: #fff;
  padding: 12px 12px; text-align: center; font-weight: 500;
  white-space: nowrap; position: sticky; top: 0;
  border-left: 1px solid rgba(255,255,255,0.15);
}
.product-table th:first-child { border-left: none; }
.product-table th.sortable { cursor: pointer; }
.product-table th.sortable:hover { background: var(--primary-light); }
.product-table th.th-check { width: 40px; }

.product-table td {
  padding: 10px 12px; text-align: center; vertical-align: middle;
  border-bottom: 1px solid var(--border-light);
  border-left: 1px solid var(--border-light);
}
.product-table td:first-child { border-left: none; }
.product-table tr:hover { background: var(--bg-hover); }

.product-table .thumb {
  width: 48px; height: 48px; border-radius: 6px;
  background: #ffffff; border: 1px solid var(--border-light);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; color: var(--text-muted); overflow: hidden;
  cursor: pointer; margin: 0 auto;
}
.product-table .thumb img { width: 100%; height: 100%; object-fit: contain; background: #fff; padding: 2px; }

.hidden { display: none !important; }

/* ===== Order View ===== */
.order-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.order-header h2 { font-size: 20px; font-weight: 700; }
.order-actions { display: flex; gap: 8px; }
.order-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 24px; }
.summary-card { background: var(--bg-card); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); text-align: center; }
.summary-label { font-size: 12px; color: var(--text-light); display: block; margin-bottom: 8px; }
.summary-value { font-size: 24px; font-weight: 700; color: var(--accent-dark); }

.order-table {
  width: 100%; border-collapse: collapse; background: var(--bg-card);
  border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow); font-size: 13px;
}
.order-table th {
  background: var(--primary); color: #fff;
  padding: 12px 12px; text-align: center; font-weight: 500;
  border-left: 1px solid rgba(255,255,255,0.15);
}
.order-table th:first-child { border-left: none; }
.order-table td {
  padding: 10px 12px; text-align: center; vertical-align: middle;
  border-bottom: 1px solid var(--border-light);
  border-left: 1px solid var(--border-light);
}
.order-table td:first-child { border-left: none; }
.order-table input[type="number"] { width: 70px; text-align: center; padding: 4px 8px; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-light); }
.empty-state p:first-child { font-size: 16px; margin-bottom: 8px; }

/* ===== Invoice ===== */
.invoice-controls { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.invoice-controls h2 { font-size: 20px; font-weight: 700; }
.invoice-actions { display: flex; gap: 8px; }
.invoice-preview {
  background: #e8e4df; padding: 32px;
  border-radius: var(--radius-lg); display: flex; justify-content: center;
}
.invoice-doc {
  background: #fff; width: 210mm; min-height: 297mm;
  padding: 40px; box-shadow: var(--shadow-lg); font-size: 12px;
}
.invoice-title {
  text-align: center; font-size: 28px; font-weight: 700;
  margin-bottom: 24px; letter-spacing: 8px; color: var(--primary);
}
.invoice-header-row {
  display: flex; justify-content: space-between; gap: 40px;
  margin-bottom: 20px; padding-bottom: 20px; border-bottom: 2px solid var(--primary);
}
.invoice-recipient { flex: 1; }
.invoice-field { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.invoice-field label { font-weight: 600; white-space: nowrap; min-width: 70px; }
.invoice-field input {
  flex: 1; border: none; border-bottom: 1px solid var(--border);
  border-radius: 0; padding: 4px 0; font-size: 13px;
}
.invoice-field input:focus { box-shadow: none; border-bottom-color: var(--accent); }
.invoice-sender { text-align: right; font-size: 12px; color: var(--text-light); }
.invoice-sender .sender-name { font-size: 16px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.invoice-amount-bar {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--bg); padding: 12px 20px; border-radius: 6px;
  margin-bottom: 20px; font-weight: 600;
}
.invoice-grand-total { font-size: 20px; color: var(--accent-dark); }

.invoice-table { width: 100%; border-collapse: collapse; margin-bottom: 24px; font-size: 12px; }
.invoice-table th {
  background: var(--primary); color: #fff; padding: 8px 12px;
  text-align: center; font-weight: 500; font-size: 11px;
  border-left: 1px solid rgba(255,255,255,0.15);
}
.invoice-table th:first-child { border-left: none; }
.invoice-table td {
  padding: 6px 12px; text-align: center;
  border-bottom: 1px solid var(--border-light);
  border-left: 1px solid var(--border-light);
}
.invoice-table td:first-child { border-left: none; }
.invoice-table td:nth-child(3) { text-align: left; }
.invoice-footer-totals { margin-top: 20px; border-top: 2px solid var(--primary); padding-top: 16px; }
.invoice-total-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 13px; }
.invoice-total-row.grand {
  font-size: 16px; font-weight: 700; color: var(--accent-dark);
  border-top: 1px solid var(--border); padding-top: 10px; margin-top: 6px;
}

/* ===== Modals ===== */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.5); z-index: 1000;
  justify-content: center; align-items: center;
  padding: 20px; backdrop-filter: blur(4px);
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--bg-card); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); width: 100%;
  max-height: 90vh; overflow-y: auto; animation: modalIn 0.25s ease;
}
.modal-sm { max-width: 420px; }
.modal-md { max-width: 540px; }
.modal-lg { max-width: 640px; }
.modal-img { max-width: 800px; background: #ffffff; overflow: visible; }

@keyframes modalIn {
  from { opacity: 0; transform: translateY(20px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 20px 24px; border-bottom: 1px solid var(--border-light);
}
.modal-header h3 { font-size: 18px; font-weight: 700; }
.modal-close {
  width: 32px; height: 32px; border: none; background: none;
  font-size: 24px; color: var(--text-light); cursor: pointer;
  border-radius: 6px; transition: var(--transition);
  display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-close-float {
  position: absolute; top: -40px; right: 0;
  color: #fff; background: rgba(0,0,0,0.5); border-radius: 50%;
  width: 36px; height: 36px; font-size: 22px;
}
.modal-close-float:hover { background: rgba(0,0,0,0.8); color: #fff; }

.modal-body { padding: 24px; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 16px 24px; border-top: 1px solid var(--border-light);
}

/* Image Zoom Modal */
.img-zoom-body {
  padding: 0; display: flex; align-items: center; justify-content: center;
}
.img-zoom-body img {
  max-width: 100%; max-height: 80vh; border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); background: #ffffff; padding: 24px;
}

/* ===== Form ===== */
.form-row { display: flex; gap: 16px; margin-bottom: 16px; }
.form-group { flex: 1; display: flex; flex-direction: column; }
.form-group.full { flex: 1 1 100%; }
.form-group label { font-size: 12px; font-weight: 600; color: var(--text-light); margin-bottom: 6px; }

.image-upload-area {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 24px; text-align: center; cursor: pointer;
  transition: var(--transition); min-height: 120px;
  display: flex; align-items: center; justify-content: center;
}
.image-upload-area:hover { border-color: var(--accent); background: var(--bg); }
.upload-placeholder { color: var(--text-muted); }
.upload-placeholder span { font-size: 32px; display: block; margin-bottom: 8px; }
#imagePreview { max-width: 100%; max-height: 200px; border-radius: var(--radius); }

.hint { font-size: 12px; color: var(--text-light); margin-top: 8px; }
.mb-1 { margin-bottom: 8px; }

/* ===== Detail Modal ===== */
.detail-content { display: flex; gap: 24px; }
.detail-image {
  flex: 0 0 240px; height: 240px;
  background: #ffffff; border: 1px solid var(--border-light);
  border-radius: var(--radius); display: flex; align-items: center;
  justify-content: center; overflow: hidden; cursor: pointer;
}
.detail-image img { width: 100%; height: 100%; object-fit: contain; background: #fff; padding: 12px; }
.detail-image .placeholder-icon { font-size: 64px; color: var(--text-muted); opacity: 0.3; }
.detail-info { flex: 1; }
.detail-info h4 { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.detail-category {
  display: inline-block; padding: 2px 10px; background: var(--primary);
  color: #fff; border-radius: 12px; font-size: 11px; font-weight: 600; margin-bottom: 16px;
}
.detail-specs { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.detail-spec { display: flex; flex-direction: column; }
.detail-spec .spec-label { font-size: 11px; color: var(--text-light); font-weight: 600; text-transform: uppercase; }
.detail-spec .spec-value { font-size: 15px; font-weight: 600; color: var(--text); }
.detail-spec .spec-value.highlight { color: var(--accent-dark); font-size: 18px; }

/* ===== Settings Page ===== */
.settings-page-title {
  font-size: 20px; font-weight: 700; margin-bottom: 20px;
}
.settings-subtabs {
  display: flex; gap: 4px; margin-bottom: 24px;
  border-bottom: 2px solid var(--border-light); padding-bottom: 0;
}
.subtab {
  padding: 10px 20px; border: none; background: none;
  font-size: 14px; font-weight: 500; color: var(--text-light);
  cursor: pointer; transition: var(--transition); font-family: inherit;
  border-bottom: 2px solid transparent; margin-bottom: -2px; border-radius: 6px 6px 0 0;
}
.subtab:hover { color: var(--text); background: var(--bg-hover); }
.subtab.active {
  color: var(--accent-dark); border-bottom-color: var(--accent);
  font-weight: 600;
}
.settings-panel-wrap { }
.settings-panel { display: none; }
.settings-panel.active { display: block; }
.settings-card {
  background: var(--bg-card); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); padding: 24px;
  border: 1px solid var(--border-light);
}
.settings-card h4 { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.settings-desc { font-size: 13px; color: var(--text-light); margin-bottom: 16px; }

.settings-columns {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.checkbox-label {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--text); cursor: pointer;
  padding: 6px 8px; border-radius: 6px; transition: var(--transition);
}
.checkbox-label:hover { background: var(--bg); }
.checkbox-label input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }

/* Settings Add Row */
.settings-add-row {
  display: flex; gap: 8px; align-items: center; margin-bottom: 16px;
}

/* Settings Item List */
.settings-item-list { display: flex; flex-direction: column; gap: 4px; }
.settings-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; background: var(--bg);
  border-radius: 6px; font-size: 13px;
  border: 1px solid var(--border-light);
  transition: var(--transition);
}
.settings-item:hover { border-color: var(--border); }
.settings-item-name { font-weight: 500; min-width: 100px; }
.settings-item-detail { color: var(--text-light); flex: 1; }
.settings-item-count {
  font-size: 11px; color: var(--text-muted);
  background: var(--bg-card); padding: 2px 8px; border-radius: 10px;
  border: 1px solid var(--border-light);
}
.settings-item-actions { display: flex; gap: 4px; margin-left: auto; }
.settings-item-edit {
  display: none; gap: 6px; align-items: center; flex: 1;
}
.settings-item-edit input { max-width: 160px; padding: 4px 8px; font-size: 12px; }
.settings-item.editing .settings-item-name,
.settings-item.editing .settings-item-detail,
.settings-item.editing .settings-item-count { display: none; }
.settings-item.editing .settings-item-edit { display: flex; }

/* Image Upload Drag Over */
.image-upload-area.drag-over {
  border-color: var(--accent); background: rgba(192,149,108,0.08);
  box-shadow: 0 0 0 3px rgba(192,149,108,0.15);
}

/* ===== Print Styles ===== */
@media print {
  body { background: #fff; }
  .header, .filter-bar, .stats-bar, .invoice-controls, .nav,
  .invoice-field input { border: none; }
  .invoice-preview { background: none; padding: 0; }
  .invoice-doc { box-shadow: none; padding: 20px; }
  .main { padding: 0; }
  .view:not(.active) { display: none !important; }
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .header-inner { padding: 0 16px; gap: 16px; }
  .logo-sub { display: none; }
  .nav-btn { padding: 6px 12px; font-size: 12px; }
  .main { padding: 16px; }
  .filter-bar { padding: 16px; gap: 12px; }
  .product-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
  .detail-content { flex-direction: column; }
  .detail-image { flex: none; height: 200px; }
  .order-summary { grid-template-columns: 1fr; }
  .invoice-doc { width: 100%; padding: 20px; }
  .form-row { flex-direction: column; gap: 12px; }
  .invoice-preview { padding: 16px; }
}

@media (max-width: 480px) {
  .header-inner { flex-wrap: wrap; height: auto; padding: 12px 16px; }
  .header-actions { display: none; }
  .filter-chips { flex-wrap: wrap; }
}
