:root {
  --bg: #f3ece0;
  --surface: #faf6ef;
  --border: #e8ddc8;
  --text-primary: #1a0f08;
  --text-secondary: #5C4A3A;
  --text-muted: #c4a882;
  --accent: #8b1a1a;
  --accent-light: rgba(139,26,26,0.06);
  --gold: #c9a84c;
  --gold-light: #f5ecd4;
  --accent-hover: #b5312a;
  --cat-active: #8b1a1a;
  --cat-bg: #faf6ef;
  --success: #2D7A4F;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(26,15,8,0.07), 0 1px 2px rgba(26,15,8,0.05);
  --shadow-md: 0 4px 16px rgba(26,15,8,0.12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Noto Sans TC', sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
}

/* ── Layout ── */
#app { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  background: #8b1a1a;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  z-index: 10;
  position: relative;
}
.topbar::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, #8b1a1a 0%, #c9a84c 50%, #8b1a1a 100%);
}

.topbar-title {
  font-family: 'Noto Serif TC', serif;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.18em;
  color: #f5e6c0;
}

.topbar-nav {
  display: flex;
  gap: 4px;
}

.nav-btn {
  padding: 6px 14px;
  border-radius: 5px;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 400;
  color: #e8d5a0;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.03em;
}
.nav-btn:hover { background: rgba(201,168,76,0.18); color: #faf6ef; }
.nav-btn.active { background: #c9a84c; color: #1a0f08; font-weight: 600; }

.main { display: flex; flex: 1; overflow: hidden; }

/* ── POS View ── */
#pos-view { display: flex; flex-direction: row; width: 100%; overflow: hidden; }

/* Categories tab bar */
.cat-panel {
  flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.cat-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-family: inherit;
  font-size: 13px;
  font-weight: 400;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}
.cat-btn:hover { border-color: var(--gold); color: var(--text-primary); background: var(--gold-light); }
.cat-btn.active { border-color: var(--accent); background: var(--accent); color: #faf6ef; font-weight: 600; }

.cat-count {
  font-size: 11px;
  font-family: 'DM Mono', monospace;
  opacity: 0.8;
  background: rgba(255,255,255,0.25);
  padding: 1px 5px;
  border-radius: 8px;
  margin-left: 6px;
}
.cat-btn:not(.active) .cat-count { background: var(--gold-light); color: var(--text-muted); opacity: 1; }

/* Center: products */
.product-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.search-bar {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.search-input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 13px;
  background: var(--bg);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23c4a882' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 10px center;
}
.search-input:focus { border-color: var(--gold); background-color: var(--surface); }

.product-grid {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
  align-content: start;
}

.product-btn {
  padding: 12px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  transition: all 0.15s;
  box-shadow: var(--shadow);
  position: relative;
}
.fav-star {
  position: absolute;
  top: 6px;
  right: 7px;
  font-size: 13px;
  line-height: 1;
  color: var(--border);
  cursor: pointer;
  transition: color 0.15s, transform 0.15s;
  user-select: none;
}
.fav-star:hover { color: var(--gold); transform: scale(1.2); }
.fav-star.active { color: var(--gold); }
.product-btn:hover {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(201,168,76,0.15);
  transform: translateY(-1px);
}
.product-btn.selected {
  border-color: var(--accent);
  background: var(--accent-light);
  box-shadow: 0 0 0 2px rgba(139,26,26,0.2);
}
.product-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.4;
  margin-bottom: 4px;
}
.product-sub {
  font-size: 11px;
  color: var(--text-muted);
}
.product-code {
  font-size: 10px;
  font-family: 'DM Mono', monospace;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Right: print panel */
.print-panel {
  width: 260px;
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.print-header {
  padding: 14px 16px 12px;
  background: #8b1a1a;
  position: relative;
}
.print-header::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, #8b1a1a 0%, #c9a84c 50%, #8b1a1a 100%);
}

.print-header h3 {
  font-family: 'Noto Serif TC', serif;
  font-size: 13px;
  font-weight: 500;
  color: #f5e6c0;
  letter-spacing: 0.18em;
}

.print-body { flex: 1; overflow-y: auto; padding: 16px; }

.selected-product-info {
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 14px;
  margin-bottom: 16px;
}

.selected-product-info .name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
  line-height: 1.4;
}
.selected-product-info .sub {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.selected-product-info .barcode {
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  color: var(--text-muted);
}

.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.label-type-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.label-type-btn {
  padding: 12px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  font-family: inherit;
  text-align: center;
  transition: all 0.15s;
}
.label-type-btn:hover { border-color: var(--gold); background: var(--gold-light); }
.label-type-btn.active {
  border-color: var(--accent);
  background: var(--accent-light);
  box-shadow: 0 0 0 1px rgba(139,26,26,0.15);
}
.label-type-btn .size-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  display: block;
  margin-bottom: 2px;
}
.label-type-btn .size-dim {
  font-size: 10px;
  color: var(--text-muted);
  font-family: 'DM Mono', monospace;
}

.qty-control {
  display: flex;
  align-items: center;
  gap: 10px;
}
.qty-btn {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  font-size: 18px;
  font-weight: 300;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  transition: all 0.15s;
  line-height: 1;
}
.qty-btn:hover { background: var(--bg); border-color: var(--gold); }
.qty-input {
  width: 60px;
  height: 32px;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: 'DM Mono', monospace;
  font-size: 15px;
  font-weight: 500;
  color: var(--text-primary);
  background: var(--bg);
  outline: none;
}
.qty-input:focus { border-color: var(--gold); background: var(--surface); }

.print-footer { padding: 16px; border-top: 1px solid var(--border); }

.print-btn {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: #faf6ef;
  border: none;
  border-radius: var(--radius);
  font-family: 'Noto Serif TC', serif;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.2em;
}
.print-btn:hover { background: var(--accent-hover); }
.print-btn:disabled {
  background: var(--border);
  color: var(--text-muted);
  cursor: not-allowed;
}


.empty-state {
  grid-column: 1/-1;
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: 14px;
}

/* ── Admin View ── */
#admin-view {
  display: none;
  flex-direction: column;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
}

.admin-toolbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  box-shadow: 0 1px 0 var(--border);
}

.admin-search {
  padding: 7px 12px 7px 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 13px;
  background: var(--bg);
  outline: none;
  width: 240px;
  color: var(--text-primary);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23c4a882' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 10px center;
}
.admin-search:focus { border-color: var(--gold); background-color: var(--surface); }

.admin-spacer { flex: 1; }

.btn {
  padding: 7px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  font-family: inherit;
  font-size: 13px;
  font-weight: 400;
  cursor: pointer;
  transition: all 0.15s;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}
.btn:hover { background: var(--bg); border-color: var(--gold); color: var(--text-primary); }
.btn-primary { background: var(--accent); color: #faf6ef; border-color: var(--accent); font-family: 'Noto Serif TC', serif; letter-spacing: 0.1em; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.admin-table-wrap {
  flex: 1;
  overflow: auto;
  padding: 16px 24px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 12px;
}
.data-table thead tr:first-child th:first-child { border-radius: 8px 0 0 0; }
.data-table thead tr:first-child th:last-child  { border-radius: 0 8px 0 0; }
.data-table tbody tr:last-child td:first-child  { border-radius: 0 0 0 8px; }
.data-table tbody tr:last-child td:last-child   { border-radius: 0 0 8px 0; }
.data-table th {
  background: #8b1a1a;
  color: #f5e6c0;
  padding: 9px 12px;
  text-align: left;
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 0.06em;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 2;
}
/* Column group coloring for readability */
.data-table th:nth-child(n+5):nth-child(-n+11) { background: #7a1818; }
.data-table th:nth-child(n+12):nth-child(-n+16) { background: #6b4a12; }
.data-table th:nth-child(n+17):nth-child(-n+26) { background: #3d5c28; }
.data-table th:nth-child(n+27):nth-child(-n+35) { background: #836624; }
.data-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  white-space: nowrap;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--gold-light); }

/* 凍結前兩欄：商品編號、商品名稱 */
.data-table th:nth-child(1),
.data-table td:nth-child(1) {
  position: sticky;
  left: 0;
  min-width: 68px;
  background: var(--surface);
  z-index: 3;
}
.data-table th:nth-child(2),
.data-table td:nth-child(2) {
  position: sticky;
  left: 68px;
  min-width: 140px;
  background: var(--surface);
  z-index: 3;
  box-shadow: 2px 0 5px rgba(26,15,8,0.07);
}
.data-table th:nth-child(1) { background: #8b1a1a; z-index: 4; }
.data-table th:nth-child(2) { background: #8b1a1a; z-index: 4; }
.data-table tr:hover td:nth-child(1),
.data-table tr:hover td:nth-child(2) { background: var(--gold-light); }

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 400;
}
.tag-cat { background: var(--gold-light); color: #6b4a12; border: 1px solid rgba(201,168,76,0.3); }
.tag-pork { background: #fef3c7; color: #92400e; border: 1px solid rgba(146,64,14,0.2); }

/* Toggle switch */
.toggle-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.toggle {
  position: relative;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}
.toggle input { display: none; }
.toggle-track {
  position: absolute;
  inset: 0;
  border-radius: 20px;
  background: var(--border);
  transition: background 0.2s;
}
.toggle input:checked + .toggle-track { background: var(--accent); }
.toggle-thumb {
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: left 0.2s;
}
.toggle input:checked ~ .toggle-thumb { left: 18px; }
.toggle-label { font-size: 11px; color: var(--text-secondary); white-space: nowrap; }

.edit-btn {
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.15s;
}
.edit-btn:hover { background: var(--gold-light); border-color: var(--gold); color: var(--text-primary); }

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border-radius: 8px;
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 40px rgba(26,15,8,0.18), 0 2px 8px rgba(26,15,8,0.08);
  border: 1px solid var(--border);
  overflow: hidden;
  position: relative;
}
.modal::before {
  content: '';
  display: block;
  height: 3px;
  background: linear-gradient(90deg, #8b1a1a 0%, #c9a84c 50%, #8b1a1a 100%);
  flex-shrink: 0;
}

.modal-header {
  padding: 18px 24px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title { font-family: 'Noto Serif TC', serif; font-size: 15px; font-weight: 500; letter-spacing: 0.08em; color: var(--text-primary); }
.modal-close {
  width: 32px; height: 32px;
  border: 1px solid var(--border); background: var(--bg);
  border-radius: 5px;
  cursor: pointer;
  font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  transition: all 0.15s;
}
.modal-close:hover { background: var(--border); color: var(--text-primary); }

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
}

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

/* Edit form */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.form-grid .full { grid-column: 1/-1; }

.field-group { display: flex; flex-direction: column; gap: 5px; }
.field-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.04em;
}
.field-input, .field-select, .field-textarea {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text-primary);
  background: var(--bg);
  outline: none;
  transition: border-color 0.15s;
}
.field-input:focus, .field-select:focus, .field-textarea:focus {
  border-color: var(--gold);
  background: var(--surface);
}
.field-textarea { resize: vertical; min-height: 60px; }

/* Section divider in modal */
.section-divider {
  grid-column: 1/-1;
  padding: 8px 0 4px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

/* Print preview overlay */
.preview-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
  box-sizing: border-box;
}
.preview-overlay.open { display: flex; }

.preview-container {
  background: var(--surface);
  border-radius: 8px;
  box-shadow: 0 8px 40px rgba(26,15,8,0.18), 0 2px 8px rgba(26,15,8,0.08);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  width: 420px;
  max-width: 95vw;
  max-height: 90vh;
  overflow: hidden;
  position: relative;
}
.preview-container::before {
  content: '';
  display: block;
  height: 3px;
  background: linear-gradient(90deg, #8b1a1a 0%, #c9a84c 50%, #8b1a1a 100%);
  flex-shrink: 0;
}
.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 14px;
  border-bottom: 1px solid var(--border);
}
.preview-product-name {
  font-family: 'Noto Serif TC', serif;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.05em;
  color: var(--text-primary);
}
.preview-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
}
#preview-labels-wrap {
  display: flex;
  justify-content: center;
}
.preview-info {
  display: flex;
  align-items: center;
  gap: 0;
  width: 100%;
  background: var(--bg);
  border-radius: 6px;
  border: 1px solid var(--border);
  overflow: hidden;
}
.preview-info-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 16px;
  gap: 4px;
}
.preview-info-divider {
  width: 1px;
  height: 40px;
  background: var(--border);
  flex-shrink: 0;
}
.preview-info-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.04em;
}
.preview-info-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}
.preview-info-qty {
  font-size: 22px;
  font-weight: 800;
  color: var(--accent);
}
.preview-footer {
  display: flex;
  gap: 10px;
  padding: 10px 20px;
  border-top: 1px solid var(--border);
  justify-content: flex-end;
}

/* Label styles for print */
.label-wrapper {
  background: white;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
  overflow: hidden;
}

/* ── Label base ── */
.label-large {
  width: 208px;
  height: 208px;
  padding: 6px;
  font-family: 'Noto Sans TC', sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-sizing: border-box;
}

/* Small label: 35mm x 25mm = 132px x 94px at 96dpi (landscape, 94px < 94.49px threshold) */
.label-small {
  width: 132px;
  height: 94px;
  padding: 4px 6px;
  font-family: 'Noto Sans TC', sans-serif;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  box-sizing: border-box;
}

/* Small label content */
.label-small .sl-text {
  display: flex;
  flex-direction: column;
}
.label-small .sl-name {
  font-size: 13px;
  font-weight: 900;
  line-height: 1.2;
  color: #000;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.label-small .sl-sub {
  font-size: 9px;
  color: #333;
  line-height: 1.3;
}
.label-small .sl-info {
  font-size: 9px;
  color: #000;
  line-height: 1.35;
  white-space: nowrap;
}
.label-small .sl-barcode-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
}
.label-small .sl-barcode-num {
  font-family: 'DM Mono', monospace;
  font-size: 6.5px;
  color: #000;
  letter-spacing: 0.5px;
  margin-top: 1px;
}

/* ── Large label 50x50mm = 189x189px ── */
.label-large {
  font-family: 'Noto Sans TC', sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-sizing: border-box;
}
.ll-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 2px;
}
.ll-name { font-size: 13px; font-weight: 400; color: #000; line-height: 1.2; }
.ll-sub  { font-size: 10px; color: #000; font-weight: 400; }
.ll-body { display: flex; gap: 3px; flex: 1; min-height: 0; overflow: hidden; }

/* Left column */
.ll-left {
  flex: 1;
  display: flex;
  flex-direction: column;
  font-size: 8px;
  color: #000;
  line-height: 1.25;
  min-width: 0;
  overflow: hidden;
}
.ll-left .ll-row { display: flex; flex-wrap: wrap; min-width: 0; }
.ll-left .ll-label { font-weight: 400; white-space: nowrap; flex-shrink: 0; }
.ll-left .ll-val { word-break: break-all; min-width: 0; flex: 1; }
.ll-divider { border: none; border-top: 0.5px solid #000; margin: 2px 0; }

/* Right column — nutrition */
.ll-right {
  width: 115px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}
.ll-nt-box {
  flex: 1;
  display: flex;
  flex-direction: column;
  border: 1px solid #000;
  min-height: 0;
}
.ll-nt-title {
  font-size: 9px;
  font-weight: 400;
  text-align: center;
  letter-spacing: 2px;
  padding: 1px 2px;
  border-bottom: 1px solid #000;
}
.ll-nt-serving {
  font-size: 8px;
  padding: 1px 3px;
  line-height: 1.35;
  border-bottom: 1px solid #000;
  white-space: nowrap;
}
.ll-nt-table {
  width: 100%;
  border-collapse: collapse;
  flex: 1;
  table-layout: fixed;
}
.ll-nt-table th:nth-child(1),
.ll-nt-table td:nth-child(1) { width: 42px; }
.ll-nt-table th:nth-child(2),
.ll-nt-table td:nth-child(2) { width: 35px; }
/* nth-child(3) gets remaining ~39px automatically */
.ll-nt-table tr { border-bottom: none; }
.ll-nt-table .nt-header-row { border-bottom: 0.5px solid #000; }
.ll-nt-table th {
  font-size: 8px;
  font-weight: 400;
  text-align: center;
  padding: 0.5px 1px;
  line-height: 1.25;
  white-space: nowrap;
}
.ll-nt-table .nt-header-row { border-bottom: 0.5px solid #000; }
.ll-nt-table td {
  font-size: 8px;
  padding: 0.5px 1px;
  line-height: 1.25;
  vertical-align: middle;
  white-space: nowrap;
}
.ll-nt-table .nt-label { font-weight: 400; white-space: nowrap; }
.ll-nt-table .nt-indent { padding-left: 6px; font-weight: 400; }
.ll-nt-table .nt-val { text-align: right; white-space: nowrap; }

/* Barcode — below nutrition box, no surrounding border */
.ll-barcode-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2px 0 1px;
  flex-shrink: 0;
}
.ll-barcode-num {
  font-family: 'DM Mono', monospace;
  font-size: 7px;
  letter-spacing: 0.5px;
  margin-top: 1px;
}


/* Upload modal */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
}
.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--gold);
  background: var(--gold-light);
}
.upload-icon { font-size: 36px; margin-bottom: 12px; }
.upload-text { font-size: 14px; color: var(--text-secondary); }
.upload-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #8b1a1a;
  color: #faf6ef;
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0.03em;
  box-shadow: var(--shadow-md);
  z-index: 999;
  opacity: 0;
  transform: translateY(8px);
  transition: all 0.2s;
  pointer-events: none;
  border: 1px solid rgba(201,168,76,0.3);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { background: var(--success); border-color: rgba(255,255,255,0.2); }
.toast.error { background: #b5312a; border-color: rgba(255,255,255,0.2); }

/* ── Print CSS ── */
@media print {
  @page { margin: 0; }
  body > * { display: none !important; }
  #print-area {
    display: flex !important;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 0;
    padding: 0;
    background: white;
    width: 100%;
    box-sizing: border-box;
  }
  #print-area * { visibility: visible !important; }
  .label-wrapper { box-shadow: none !important; page-break-inside: avoid; }

}

/* ── Responsive (mobile) ── */
@media (max-width: 600px) {
  #pos-view {
    flex-direction: column;
  }
  .print-panel {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    max-height: 200px;
  }
  .print-body {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px;
    align-items: center;
  }
  .selected-product-info { flex: 1; min-width: 100px; }
  .size-toggle { flex-shrink: 0; }
  .qty-row { flex-shrink: 0; }
  .print-actions {
    display: flex;
    gap: 8px;
    width: 100%;
  }
  .print-actions .btn-primary { flex: 1; }
  .cat-panel { grid-template-columns: repeat(4, 1fr); }
  .print-footer {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
  }
  .print-btn { flex: 1; }
  .print-body { overflow-y: auto; }
}
/* ── Settings View ── */
#settings-view { display: none; flex: 1; overflow: hidden; flex-direction: column; }

.settings-mode-bar {
  display: flex;
  gap: 0;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.settings-mode-btn {
  padding: 10px 22px;
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  margin-bottom: -1px;
}
.settings-mode-btn:hover { color: var(--text-primary); }
.settings-mode-btn.active {
  color: var(--accent);
  font-weight: 600;
  border-bottom-color: var(--accent);
}

.settings-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.settings-panel {
  width: 300px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.settings-tabs {
  display: flex;
  gap: 8px;
  padding: 14px 16px 0;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.settings-tab-btn {
  padding: 7px 22px;
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  background: var(--bg);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  margin-bottom: -1px;
}
.settings-tab-btn.active {
  background: var(--surface);
  color: var(--accent);
  font-weight: 600;
  border-color: var(--border);
  border-bottom: 1px solid var(--surface);
}

.settings-form-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.settings-section { margin-bottom: 22px; }

.settings-section-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 0;
  min-height: 32px;
}

.settings-label {
  font-size: 13px;
  color: var(--text-primary);
}

.settings-input {
  width: 72px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-family: 'DM Mono', monospace;
  font-size: 13px;
  text-align: right;
  color: var(--text-primary);
  background: var(--bg);
  transition: border-color 0.15s;
}
.settings-input:focus {
  outline: none;
  border-color: var(--gold);
}

.settings-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

.settings-preview-panel {
  flex: 1;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.settings-preview-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.settings-zoom-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.settings-preview-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 20px;
  align-self: flex-start;
  flex-shrink: 0;
}

.preview-scale-wrap {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 200px;
}

.preview-size-info {
  margin-top: 16px;
  font-size: 12px;
  color: var(--text-muted);
  font-family: 'DM Mono', monospace;
  letter-spacing: 0.03em;
}

.pv-line { margin-bottom: 1px; line-height: 1.3; }

.preview-zoom-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
  width: 100%;
  max-width: 380px;
}
.preview-zoom-label {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}
.preview-zoom-slider {
  flex: 1;
  accent-color: var(--accent);
  cursor: pointer;
  height: 4px;
}
.preview-zoom-pct {
  font-size: 12px;
  font-family: 'DM Mono', monospace;
  color: var(--text-secondary);
  width: 36px;
  text-align: right;
}

.settings-zone-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.06em;
  padding: 6px 0 2px;
  margin-top: 4px;
  border-top: 1px solid var(--border);
}
.settings-zone-label:first-of-type { border-top: none; margin-top: 0; }

.order-btns { display: flex; flex-direction: column; gap: 1px; }
.order-btn {
  width: 20px;
  height: 16px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg);
  font-size: 10px;
  line-height: 1;
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.1s;
}
.order-btn:hover:not(:disabled) { background: var(--border); }
.order-btn:disabled { opacity: 0.3; cursor: default; }

/* ── Login Screen ── */
#login-screen {
  position: fixed;
  inset: 0;
  background: #f3ece0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-card {
  background: #faf6ef;
  width: 380px;
  border: 1px solid #e8ddc8;
  box-shadow: 0 2px 40px rgba(26,15,8,0.10), 0 1px 4px rgba(26,15,8,0.06);
  position: relative;
  overflow: hidden;
}
.auth-card::before {
  content: '';
  display: block;
  height: 3px;
  background: linear-gradient(90deg, #8b1a1a 0%, #c9a84c 50%, #8b1a1a 100%);
}

.auth-card-inner { padding: 40px 40px 36px; }

.auth-brand { text-align: center; margin-bottom: 32px; }
.auth-brand-mark {
  width: 52px; height: 52px; margin: 0 auto 12px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid rgba(201,168,76,0.6);
  position: relative;
}
.auth-brand-mark::after {
  content: '';
  position: absolute;
  inset: 4px;
  border: 0.8px solid rgba(139,26,26,0.4);
  pointer-events: none;
}
.auth-brand-mark img {
  width: 36px; height: 36px;
  mix-blend-mode: multiply;
}
.auth-brand-logo {
  width: 160px;
  display: block;
  margin: 0 auto 4px;
  mix-blend-mode: multiply;
}
.auth-brand-sub { font-size: 11px; color: #c4a882; letter-spacing: 0.25em; margin-top: 4px; text-transform: uppercase; }

.auth-divider { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; }
.auth-divider-line { flex: 1; height: 1px; background: #e8ddc8; }
.auth-divider-diamond { width: 6px; height: 6px; background: #c9a84c; transform: rotate(45deg); flex-shrink: 0; }

.auth-field { margin-bottom: 16px; }
.auth-field label {
  display: block; font-size: 11px; color: #c4a882;
  letter-spacing: 0.15em; text-transform: uppercase; margin-bottom: 6px;
}
.auth-field input {
  width: 100%; height: 42px; border: 1px solid #e8ddc8; background: #faf6ef;
  padding: 0 14px; font-family: 'Noto Sans TC', sans-serif; font-size: 14px;
  color: #1a0f08; outline: none; transition: border-color 0.2s;
}
.auth-field input:focus { border-color: #c9a84c; }
.auth-field input::placeholder { color: #ddd5c2; }

.auth-btn {
  width: 100%; height: 44px; background: #8b1a1a; color: #faf6ef; border: none;
  cursor: pointer; font-family: 'Noto Serif TC', serif; font-size: 15px;
  letter-spacing: 0.3em; margin-top: 8px; transition: background 0.2s;
  display: flex; align-items: center; justify-content: center; gap: 10px; position: relative;
}
.auth-btn:hover:not(:disabled) { background: #b5312a; }
.auth-btn:disabled { cursor: default; opacity: 0.85; }

.auth-btn-spinner { width: 16px; height: 16px; flex-shrink: 0; opacity: 0; transition: opacity 0.2s; }
.auth-btn-spinner circle { stroke: rgba(250,246,239,0.35); }
.auth-btn-spinner path   { stroke: #faf6ef; }
.auth-loading .auth-btn-spinner { opacity: 1; animation: auth-spin 0.9s linear infinite; }

.auth-progress-track {
  position: absolute; bottom: 0; left: 0; right: 0;
  height: 2px; background: rgba(250,246,239,0.2); overflow: hidden;
}
.auth-progress-fill { height: 100%; width: 0; background: #c9a84c; transition: width 0s; }
.auth-loading .auth-progress-fill { transition: width 2.8s cubic-bezier(0.4,0,0.2,1); width: 88%; }

.auth-overlay {
  position: absolute; inset: 0; background: rgba(250,246,239,0.94);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 20px; opacity: 0; pointer-events: none; transition: opacity 0.35s ease; z-index: 10;
}
.auth-overlay-visible { opacity: 1 !important; pointer-events: all; }

.auth-seal-ring {
  position: relative; width: 80px; height: 80px;
  display: flex; align-items: center; justify-content: center;
}
.auth-ring { position: absolute; inset: 0; animation: auth-spin 3s linear infinite; }
.auth-seal-inner { position: relative; z-index: 1; animation: auth-breathe 2s ease-in-out infinite; }

.auth-overlay-text {
  font-family: 'Noto Serif TC', serif; font-size: 14px; color: #8b1a1a;
  letter-spacing: 0.35em; animation: auth-fade-pulse 1.6s ease-in-out infinite;
  transition: opacity 0.3s;
}
.auth-overlay-sub { font-size: 11px; color: #c4a882; letter-spacing: 0.2em; margin-top: -12px; }

.auth-corner { position: absolute; width: 14px; height: 14px; opacity: 0.35; }
.auth-corner-tl { top: 8px; left: 8px; border-top: 1.5px solid #c9a84c; border-left: 1.5px solid #c9a84c; }
.auth-corner-tr { top: 8px; right: 8px; border-top: 1.5px solid #c9a84c; border-right: 1.5px solid #c9a84c; }
.auth-corner-bl { bottom: 8px; left: 8px; border-bottom: 1.5px solid #c9a84c; border-left: 1.5px solid #c9a84c; }
.auth-corner-br { bottom: 8px; right: 8px; border-bottom: 1.5px solid #c9a84c; border-right: 1.5px solid #c9a84c; }

@keyframes auth-spin      { to { transform: rotate(360deg); } }
@keyframes auth-breathe   { 0%,100% { transform: scale(1);   opacity: 0.8; } 50% { transform: scale(1.1); opacity: 1; } }
@keyframes auth-fade-pulse{ 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }

/* ── Topbar User / Logout ── */
.topbar-user { display: flex; align-items: center; gap: 10px; }
.topbar-username { font-size: 13px; color: #e8d5a0; font-weight: 400; letter-spacing: 0.05em; }
.topbar-logout-btn {
  padding: 5px 12px; border-radius: 4px;
  border: 1px solid rgba(201,168,76,0.4); background: transparent;
  color: #e8d5a0; font-family: inherit; font-size: 12px;
  cursor: pointer; transition: all 0.15s; letter-spacing: 0.03em;
}
.topbar-logout-btn:hover { background: rgba(201,168,76,0.15); border-color: #c9a84c; color: #faf6ef; }

/* override product-table column color banding */
.accounts-table th { background: #8b1a1a !important; }

/* ── Accounts View ── */
#accounts-view {
  display: none;
  flex-direction: column;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
}
