:root {
  --bg: #F7F8FA;
  --card: #FFFFFF;
  --border: #E4E7EC;
  --text: #111827;
  --text-muted: #6B7280;
  --accent: #2563EB;
  --accent-hover: #1d4ed8;
  --accent-soft: #eef2ff;
  --teal: #0D9488;
  --gray-light: #F3F4F6;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --sidebar-w: 220px;
  --sidebar-w-collapsed: 68px;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow-x: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Malgun Gothic", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

#app {
  display: flex;
  min-height: 100vh;
  max-width: 100vw;
}

/* ---------- 사이드바 ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  transition: width 0.15s ease;
  z-index: 10;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 18px 16px;
  font-size: 15px;
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.brand-logo {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--teal));
  color: #fff;
  font-weight: 800;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  min-width: 0;
}

.sidebar-toggle {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--gray-light);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-toggle:hover { background: var(--border); color: var(--text); }

.sidebar nav {
  flex: 1;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-radius: 8px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover { background: var(--bg); color: var(--text); }

.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.nav-icon { flex-shrink: 0; }
.nav-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar .admin-box {
  padding: 14px;
  border-top: 1px solid var(--border);
}

.admin-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.admin-status .admin-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 사이드바 접힘 상태 ---------- */
#app.sidebar-collapsed .sidebar { width: var(--sidebar-w-collapsed); }
#app.sidebar-collapsed .main { margin-left: var(--sidebar-w-collapsed); }
#app.sidebar-collapsed .brand { justify-content: center; padding: 16px 8px; gap: 0; }
#app.sidebar-collapsed .brand-text { display: none; }
#app.sidebar-collapsed .sidebar-toggle { display: none; }
#app.sidebar-collapsed .sidebar-toggle { display: flex; }
#app.sidebar-collapsed .nav-item { justify-content: center; padding: 11px 0; }
#app.sidebar-collapsed .nav-label { display: none; }
#app.sidebar-collapsed .admin-status .admin-label { display: none; }
#app.sidebar-collapsed .admin-status { justify-content: center; }
#app.sidebar-collapsed .admin-box .btn-sm { padding: 6px 8px; }

/* ---------- 메인 영역 ---------- */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 28px 32px 60px;
  transition: margin-left 0.15s ease;
}

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

.page-header h2 {
  font-size: 21px;
  margin: 0;
}

.page-header .sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* ---------- 버튼 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.btn:hover { background: #f0f1f3; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: #fff; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- 리스트 (공지사항/AS) ---------- */
.list {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.list-item:last-child { border-bottom: none; }
.list-item:hover { background: var(--accent-soft); }

.list-item .title {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}

.list-item .date {
  flex-shrink: 0;
  font-size: 12.5px;
  color: var(--text-muted);
}

.list-item .date-actions {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.badge-pin { background: var(--accent-soft); color: var(--accent); font-weight: 600; flex-shrink: 0; }

.list-item .row-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 60px 20px;
}

/* ---------- 상품목록 테이블 ---------- */
.table-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.table-toolbar select {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13.5px;
  background: #fff;
  color: var(--text);
  width: auto;
  min-width: 150px;
  max-width: 100%;
  flex-shrink: 0;
}

.table-toolbar input {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13.5px;
  background: #fff;
  color: var(--text);
  width: 100%;
}

.search-row {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  width: 520px;
  max-width: 100%;
}

.search-row input { flex: 1; min-width: 0; }
.search-row .btn { flex-shrink: 0; }

.table-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  table-layout: auto;
}

table.data-table thead th {
  text-align: center;
  padding: 11px 14px;
  background: #fafbfc;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12.5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

table.data-table tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  user-select: text;
  text-align: center;
  white-space: nowrap;
}

table.data-table tbody tr:last-child td { border-bottom: none; }
table.data-table tbody tr:hover { background: var(--accent-soft); }
table.data-table tbody tr.discontinued { color: #9aa1ac; }
table.data-table tbody tr.discontinued .price { text-decoration: line-through; }
table.data-table tbody tr.selected { background: var(--accent-soft); }
table.data-table tbody tr.selected:hover { background: #e0e9ff; }

.price { font-variant-numeric: tabular-nums; }

.badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  white-space: nowrap;
}

.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-warning { background: #fff7ed; color: #c2410c; }
.badge-sale { background: #fef2f2; color: #dc2626; font-weight: 600; }

.product-name-link {
  cursor: pointer;
  color: var(--accent);
  font-weight: 500;
}

.product-name-link:hover { text-decoration: underline; }

.memo-cell {
  max-width: none;
  white-space: nowrap;
}

.detail-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.detail-table th {
  text-align: left;
  width: 120px;
  padding: 9px 10px;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12.5px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.detail-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
}

.detail-table tr:last-child th, .detail-table tr:last-child td { border-bottom: none; }

/* ---------- 모달 ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 25, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 6vh 16px;
  z-index: 100;
  overflow-y: auto;
}

.modal {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 560px;
  padding: 24px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.15);
}

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

.modal-header h3 { margin: 0; font-size: 18px; }
.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
  padding: 2px 4px;
}

.post-meta {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.post-content {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14.5px;
  margin-bottom: 14px;
}

.post-image {
  max-width: 100%;
  border-radius: 8px;
  display: block;
  margin-bottom: 14px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.modal-actions.between { justify-content: space-between; }

/* ---------- 폼 ---------- */
.form-group { margin-bottom: 14px; }

label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-muted);
}

input[type="text"], input[type="password"], input[type="number"], input[type="date"],
textarea, select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}

textarea { min-height: 160px; resize: vertical; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.checkbox-row input { width: auto; }

.error-msg {
  color: var(--danger);
  font-size: 12.5px;
  margin-top: 6px;
  min-height: 16px;
}

.hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: -6px;
  margin-bottom: 12px;
}

.existing-images {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.existing-image-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 11.5px;
  color: var(--text-muted);
  cursor: pointer;
}

.existing-image-item img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.existing-image-item input { width: auto; }

/* ---------- 카드 (데이터 관리 등) ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.card-title {
  font-size: 15px;
  font-weight: 700;
}

.form-hint {
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.6;
}

/* ---------- 장바구니 ---------- */
.cart-fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 50;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 13px 20px;
  font-size: 14.5px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(37, 99, 235, 0.35);
  display: flex;
  align-items: center;
  gap: 6px;
}

.cart-fab:hover { background: var(--accent-hover); }

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

.cart-qty-input {
  width: 56px;
  padding: 6px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
}

.cart-qty-input:disabled { background: var(--bg); color: var(--text-muted); }

.cart-item-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.cart-item-row:last-child { border-bottom: none; }

.cart-item-info { flex: 1 1 auto; min-width: 0; }
.cart-item-name {
  font-weight: 600;
  font-size: 14px;
  word-break: keep-all;
  overflow-wrap: break-word;
}
.cart-item-option { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

input.cart-item-qty {
  flex: 0 0 64px;
  width: 64px;
  padding: 7px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13.5px;
  text-align: center;
}

.cart-remove-btn {
  flex: 0 0 auto;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  padding: 2px 6px;
}

.cart-remove-btn:hover { color: var(--danger); }

/* 캡처/인쇄용 발주서 */
.order-print {
  background: #fff;
}

.order-print h2 { font-size: 19px; margin: 0 0 4px; }
.order-print .order-meta { font-size: 12.5px; color: var(--text-muted); margin-bottom: 16px; }

.order-print table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  margin-bottom: 14px;
}

.order-print th, .order-print td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
}

.order-print th { color: var(--text-muted); font-size: 12px; font-weight: 600; }
.order-print .order-total { font-size: 13px; color: var(--text-muted); text-align: right; }

@media print {
  body * { visibility: hidden; }
  #orderPrintArea, #orderPrintArea * { visibility: visible; }
  #orderPrintArea {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    padding: 24px;
  }
  .no-print { display: none !important; }
}

/* ---------- 반응형: 태블릿 이하 (사이드바를 상단바로 전환) ---------- */
@media (max-width: 880px) {
  .sidebar {
    position: static;
    width: 100% !important;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .sidebar-toggle { display: none !important; }
  .brand-text { display: block !important; }
  .nav-label { display: inline !important; }
  .admin-status .admin-label { display: inline !important; }

  .sidebar .brand { padding: 16px 18px !important; justify-content: flex-start !important; gap: 10px !important; }
  .nav-item { justify-content: flex-start !important; }
  .admin-status { justify-content: space-between !important; }

  .sidebar nav {
    flex-direction: row;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 8px 12px;
    gap: 6px;
  }

  .nav-item {
    white-space: nowrap;
    flex-shrink: 0;
    width: auto;
    padding: 9px 13px;
    justify-content: flex-start;
  }

  .sidebar .admin-box {
    border-top: 1px solid var(--border);
    padding: 10px 14px;
  }

  #app { flex-direction: column; }
  #app.sidebar-collapsed .main { margin-left: 0; }

  .main {
    margin-left: 0;
    padding: 20px 20px 50px;
    max-width: 100%;
  }

  table.data-table { width: 100%; }
}

/* ---------- 반응형: 휴대폰 (≤560px) ---------- */
@media (max-width: 560px) {
  .brand-text { font-size: 15px; }
  .nav-item { font-size: 13px; padding: 8px 12px; }
  .admin-status { font-size: 11.5px; }

  .cart-fab { right: 14px; bottom: 14px; padding: 11px 16px; font-size: 13.5px; }

  .main { padding: 16px 14px 40px; }

  .page-header { gap: 10px; }
  .page-header h2 { font-size: 18px; }

  .btn { padding: 9px 13px; font-size: 13.5px; }

  /* 목록(공지사항/AS)은 좁은 화면에서 제목/날짜를 세로로 쌓음 */
  .list-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    padding: 12px 14px;
  }

  .list-item .title { max-width: 100%; }
  .list-item .date { font-size: 11.5px; }

  .table-toolbar { flex-direction: column; align-items: stretch; }
  .table-toolbar select { width: 100%; min-width: 0; }
  .search-row { width: 100%; }

  table.data-table { width: 100%; font-size: 12.5px; }
  table.data-table thead th, table.data-table tbody td { padding: 9px 10px; }

  /* 모달을 화면 가장자리까지 넓게, 여백은 줄여서 사용 */
  .modal-backdrop { padding: 0; align-items: stretch; }

  .modal {
    max-width: 100%;
    min-height: 100%;
    border-radius: 0;
    padding: 18px 16px 24px;
  }

  .modal-header h3 { font-size: 16px; }

  .form-row { grid-template-columns: 1fr; gap: 0; }

  .detail-table th { width: 96px; font-size: 11.5px; }
  .detail-table th, .detail-table td { padding: 8px 8px; }

  .existing-image-item img { width: 60px; height: 60px; }

  .card { padding: 16px; }

  .modal-actions { flex-wrap: wrap; }
  .modal-actions .btn { flex: 1; justify-content: center; }
}
