:root {
  --red: #c0272d;
  --red-dark: #8f1c21;
  --green: #1f7a3f;
  --yellow: #f2b705;
  --cream: #fdf7ec;
  --ink: #241b16;
  --muted: #7a6c60;
  --card: #ffffff;
  --border: #ece2d2;
  --shadow: 0 10px 30px rgba(36, 27, 22, 0.08);
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: 'Segoe UI', Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button {
  font-family: inherit;
  cursor: pointer;
}

input {
  font-family: inherit;
}

.app-shell {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px 28px 40px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-image {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid var(--yellow);
  flex-shrink: 0;
  background: #fff;
}

.brand-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.eyebrow {
  margin: 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--red);
  text-transform: uppercase;
}

.topbar h1 {
  margin: 2px 0 0;
  font-size: 26px;
  font-weight: 800;
  color: var(--ink);
  letter-spacing: 0.01em;
}

.topbar h1 span { color: var(--red); }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.offline-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: #eef7ef;
  border: 1px solid #bfe3c6;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  color: var(--green);
}

.offline-pill i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  display: inline-block;
}

.icon-button {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- Info cards ---------- */
.info-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.info-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow);
}

.info-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: #fbe9d7;
  color: var(--red);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.info-body { flex: 1; min-width: 0; }
.info-body h3 { margin: 2px 0; font-size: 17px; }
.info-body p { margin: 0; font-size: 12px; color: var(--muted); }

.printer-actions, .info-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.outline-button {
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
}

.outline-button:disabled { opacity: .45; cursor: not-allowed; }

.file-button { position: relative; overflow: hidden; }

/* ---------- Workspace ---------- */
.workspace {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 18px;
  align-items: start;
}

.catalog-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.catalog-toolbar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}

.search-field {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--cream);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
}

.search-field input {
  border: none;
  background: transparent;
  outline: none;
  width: 100%;
  font-size: 14px;
}

.category-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.category-tab {
  flex-shrink: 0;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.category-tab.is-active {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 13px;
}

.product-card {
  position: relative;
  background: var(--cream);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  min-height: 140px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
  transition: transform .12s ease, box-shadow .12s ease;
}

.product-card:not(:disabled):active {
  transform: scale(0.97);
}

.product-card:not(:disabled):hover {
  box-shadow: 0 6px 18px rgba(192, 39, 45, 0.15);
  border-color: var(--red);
}

.product-card.is-sold-out {
  opacity: .5;
  cursor: not-allowed;
}

.sold-out-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  background: var(--ink);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
}

.product-icon { font-size: 26px; }
.product-name { font-size: 13px; font-weight: 700; line-height: 1.25; }
.product-desc { font-size: 11px; color: var(--muted); }
.product-price {
  margin-top: auto;
  font-size: 15px;
  font-weight: 800;
  color: var(--red);
}

/* ---------- Order panel ---------- */
.order-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  min-height: 600px;
  position: sticky;
  top: 20px;
  height: calc(100vh - 40px);
  max-height: calc(100vh - 40px);
  box-shadow: var(--shadow);
}

.order-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.order-header h2 { margin: 2px 0 10px; font-size: 20px; }

.customer-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}

.customer-field input {
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
  outline: none;
  min-width: 190px;
}

.customer-field input:focus { border-color: var(--red); }

.ghost-button {
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.cart-items {
  flex: 1;
  overflow-y: auto;
  padding: 10px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cart-line {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: var(--cream);
  border-radius: 12px;
}

.cart-line-name { margin: 0; font-size: 13px; font-weight: 700; }
.cart-line-variant { margin: 0; font-size: 11px; color: var(--muted); }

.cart-line-qty {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
}

.qty-btn {
  width: 24px;
  height: 24px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cart-line-price { font-size: 13px; font-weight: 800; color: var(--red); white-space: nowrap; }

.cart-line-remove {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  padding: 4px;
}

.order-footer {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.payment-row { display: flex; flex-direction: column; gap: 6px; }
.payment-label { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.payment-methods { display: flex; gap: 8px; }

.payment-chip {
  flex: 1;
  padding: 9px 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.payment-chip.is-active {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.cash-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.cash-row label { font-size: 12px; font-weight: 600; color: var(--muted); }

.cash-row input {
  flex: 1;
  min-width: 80px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  outline: none;
}

.change-due { margin: 0; font-size: 12px; font-weight: 700; color: var(--green); width: 100%; }
.change-due.is-negative { color: var(--red); }

.totals-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 15px;
  font-weight: 700;
  padding-top: 4px;
}

.totals-row strong { font-size: 26px; color: var(--red); }

.order-buttons { display: flex; gap: 10px; }

.primary-button {
  flex: 1;
  padding: 14px;
  border-radius: 14px;
  border: none;
  background: var(--red);
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.primary-button:disabled { opacity: .45; cursor: not-allowed; }

.danger-button {
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid #f1b4b4;
  background: #fff5f5;
  color: var(--red-dark);
  font-weight: 700;
  font-size: 13px;
  align-self: flex-start;
}

.danger-link {
  border: none;
  background: transparent;
  color: var(--red-dark);
  font-size: 12px;
  font-weight: 700;
  text-decoration: underline;
}

/* ---------- Empty state ---------- */
.empty-state {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
}

.empty-state strong { color: var(--ink); font-size: 15px; }
.empty-state span { font-size: 12px; }

/* ---------- Variant picker sheet ---------- */
.variant-sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(36, 27, 22, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  padding: 0;
}

.variant-sheet {
  background: #fff;
  width: 100%;
  max-width: 480px;
  border-radius: 20px 20px 0 0;
  padding: 22px 20px 26px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: slide-up .18s ease-out;
}

@keyframes slide-up {
  from { transform: translateY(16px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.variant-sheet h3 { margin: 0; font-size: 17px; }

.variant-options { display: flex; flex-direction: column; gap: 8px; }

.variant-option {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--cream);
  font-size: 14px;
  font-weight: 700;
}

.variant-option:active { background: #fbe9d7; }
.variant-option strong { color: var(--red); font-size: 16px; }

.variant-note-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.variant-note-field input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
  outline: none;
}

.variant-cancel { align-self: center; }

/* ---------- Modals ---------- */
.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(36, 27, 22, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 20px;
}

.modal-card {
  background: #fff;
  border-radius: 20px;
  width: 100%;
  max-width: 560px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.admin-card { max-width: 720px; }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { margin: 0; font-size: 17px; }

.sales-history {
  padding: 12px 20px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--cream);
  border-radius: 12px;
}

.history-row strong { font-size: 13px; }
.history-row p { margin: 2px 0 0; font-size: 11px; color: var(--muted); }
.history-total { font-weight: 800; color: var(--red); font-size: 14px; }

.reprint-button {
  padding: 7px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 11px;
  font-weight: 700;
}

/* ---------- Admin panel ---------- */
.admin-lock {
  padding: 40px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}

.admin-lock input {
  width: 160px;
  padding: 12px;
  text-align: center;
  font-size: 20px;
  letter-spacing: 0.3em;
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
}

.admin-pin-error { color: var(--red); font-size: 12px; min-height: 16px; margin: 0; }

.admin-content { display: flex; flex-direction: column; overflow: hidden; flex: 1; }

.admin-tabs {
  display: flex;
  gap: 6px;
  padding: 12px 20px 0;
  border-bottom: 1px solid var(--border);
}

.admin-tab {
  padding: 10px 14px;
  border: none;
  background: transparent;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  border-bottom: 2px solid transparent;
}

.admin-tab.is-active { color: var(--red); border-color: var(--red); }

.admin-panel {
  padding: 16px 20px 24px;
  overflow-y: auto;
  flex: 1;
}

.admin-category { margin-bottom: 18px; }
.admin-category h4 { margin: 0 0 10px; font-size: 13px; color: var(--red); text-transform: uppercase; letter-spacing: .04em; }

.admin-product {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 10px;
  background: var(--cream);
}

.admin-product-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.admin-product-name {
  flex: 1;
  min-width: 140px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
}

.admin-soldout { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }

.admin-variants { display: flex; flex-direction: column; gap: 6px; }

.admin-variant {
  display: flex;
  align-items: center;
  gap: 6px;
}

.admin-variant-label {
  flex: 1;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
}

.admin-variant-price {
  width: 80px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
}

.admin-quick-add {
  margin-top: 16px;
  padding: 14px;
  border: 1px dashed var(--border);
  border-radius: 14px;
}

.admin-quick-add h4 { margin: 0 0 10px; font-size: 13px; }

.quick-add-row { display: flex; gap: 8px; flex-wrap: wrap; }

.quick-add-row input {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
}

.quick-add-row input#qa-name { flex: 2; min-width: 160px; }
.quick-add-row input#qa-category { flex: 1; min-width: 120px; }
.quick-add-row input#qa-price { width: 90px; }

.admin-hint { font-size: 12px; color: var(--muted); margin: 0 0 14px; }
.admin-actions-row { display: flex; gap: 10px; margin-bottom: 22px; flex-wrap: wrap; }

.admin-panel h4 { margin: 0 0 10px; font-size: 13px; color: var(--red); text-transform: uppercase; }

#admin-panel-security label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin: 10px 0 4px; }
#admin-panel-security input {
  width: 160px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
}
#admin-panel-security button { margin-top: 14px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  background: var(--ink);
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 100;
  max-width: 90%;
  text-align: center;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  .workspace { grid-template-columns: 1fr 340px; }
}

@media (max-width: 760px) {
  .app-shell { padding: 18px 16px 30px; }
  .info-row { grid-template-columns: 1fr; }
  .workspace { grid-template-columns: 1fr; }
  .order-panel {
    position: relative;
    top: auto;
    height: auto;
    max-height: none;
    min-height: 460px;
  }
  .product-grid { grid-template-columns: repeat(3, 1fr); }
  .printer-actions, .info-actions { width: 100%; }
}

@media (max-width: 600px) {
  .topbar h1 { font-size: 20px; }
  .product-grid { grid-template-columns: repeat(2, 1fr); gap: 9px; }
  .product-card { padding: 13px; min-height: 128px; }
  .product-name { font-size: 12px; }
  .product-desc { font-size: 10px; }
  .product-price { font-size: 14px; }
  .order-panel { padding: 18px; border-radius: 18px; }
  .customer-field input { min-width: 0; width: 100%; }
}

@media (max-width: 420px) {
  .cart-line { grid-template-columns: 1fr auto; grid-template-areas: 'name price' 'qty remove'; }
  .cart-line-main { grid-area: name; }
  .cart-line-price { grid-area: price; }
  .cart-line-qty { grid-area: qty; }
  .cart-line-remove { grid-area: remove; justify-self: end; }
}
