/* ---- Layout ---------------------------------------------------------------- */
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, sans-serif; color: #222; }

/* The `hidden` attribute must win over the display rules on these classed elements
   (ID/attr specificity beats a bare class selector — no !important needed). */
#loginScreen[hidden], #locationPickerScreen[hidden], #posApp[hidden], #cashInputButtons[hidden],
.subcategory[hidden], [hidden].location-switcher { display: none; }

.pos { display: flex; align-items: stretch; min-height: 100vh; }
.menu-pane { flex: 1; padding: 10px;
  background: linear-gradient(180deg, #3a4654 0%, #2b3540 100%); }
.cart-pane { width: 38%; min-width: 320px; background: #e0e0e0; display: flex; flex-direction: column; }

/* ---- Toolbar / nav --------------------------------------------------------- */
.toolbar { display: flex; align-items: center; gap: 14px; color: #fff; padding: 6px 4px; }
.toolbar .icon { cursor: pointer; font-size: 18px; }
.topnav { margin-left: auto; display: flex; gap: 18px; align-items: center; }
.topnav a, .topnav .brand { color: #fff; text-decoration: none; font-weight: 600; }
.location-switcher { padding: 6px 10px; border-radius: 5px; border: none; font-size: 15px; }
.current-user { font-weight: 600; opacity: 0.9; }

/* ---- Login screen ---------------------------------------------------------- */
.login-screen {
  position: fixed; inset: 0; z-index: 2000; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(180deg, #3a4654 0%, #2b3540 100%);
}
.login-box {
  background: #fff; padding: 32px; border-radius: 10px; width: 320px;
  display: flex; flex-direction: column; gap: 14px; box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}
.login-box h2 { margin: 0 0 6px; text-align: center; color: #303D4E; }
.login-box input { padding: 12px; font-size: 16px; border: 1px solid #ccc; border-radius: 6px; }
.login-box button {
  padding: 14px; font-size: 16px; background: #4CAF50; color: #fff; border: none;
  border-radius: 6px; cursor: pointer; text-transform: uppercase;
}
.login-box button:hover { background: #2e7d32; }
.login-error { color: #c62828; text-align: center; font-size: 14px; }
.forgot-link { text-align: center; font-size: 13px; color: #1970a6; text-decoration: none; }
.forgot-link:hover { text-decoration: underline; }

/* ---- Categories ------------------------------------------------------------ */
.main-category { display: flex; flex-wrap: wrap; gap: 10px; padding: 10px 4px; }
.main-category button {
  background: #494949; border: none; cursor: pointer; font-size: 18px;
  padding: 10px 16px; color: #fff; border-radius: 5px;
}
.main-category button.active { background: #4CAF50; }

/* ---- Items ----------------------------------------------------------------- */
/* 4-wide grid that flows as many rows as needed — no inner scrollbar. */
.subcategory { display: none; }
.subcategory.active {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; padding: 4px;
}
.item { position: relative; cursor: pointer; }
.item-image { position: relative; border-radius: 6px; overflow: hidden; }
.item img { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; display: block; }
.item-overlay {
  position: absolute; bottom: 0; left: 0; width: 100%;
  background: rgba(0, 0, 0, 0.55); color: #fff; text-align: center;
  padding: 8px; height: 90px;
  display: flex; flex-direction: column; justify-content: space-between; align-items: center;
}
.item-overlay-top {
  flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center;
  gap: 3px; min-height: 0; overflow: hidden;
}
.item-title {
  font-weight: bold; line-height: 1.2em; text-align: center;
}
.item-subtitle {
  font-size: 11px; color: #ddd; line-height: 1.3; text-align: center; white-space: pre-wrap; word-break: break-word;
}
.item-price { line-height: 1.2; color: lightblue; flex-shrink: 0; }
.item.draggable-card { cursor: grab; }
.item.draggable-card:active { cursor: grabbing; }
.item.card-dragging { opacity: .3; }
.item.card-drag-over { outline: 2px solid #97CCE8; outline-offset: -2px; border-radius: 6px; }
#categoryTabs button.draggable-tab { cursor: grab; }
#categoryTabs button.draggable-tab:active { cursor: grabbing; }
#categoryTabs button.tab-dragging { opacity: .35; }
#categoryTabs button.tab-drag-over { outline: 2px solid #97CCE8; outline-offset: -2px; border-radius: 5px; }
.item.sold-out { opacity: 0.75; cursor: default; }
.sold-out-banner {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.72); color: #ff6b6b; font-weight: 900;
  font-size: 15px; letter-spacing: 2px; padding: 6px 14px;
  border-radius: 4px; border: 2px solid #ff6b6b; white-space: nowrap;
  pointer-events: none;
}

/* Options modal — every choice a big tap target, laid out so nothing scrolls. */
.options-modal-content { width: 60%; max-width: 700px; }
.options-modal-content h3 { margin: 0 0 14px; text-align: center; }
.options-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.option-toggle {
  padding: 18px 10px; font-size: 16px; background: #494949; color: #fff;
  border: none; border-radius: 6px; cursor: pointer;
}
.option-toggle.selected { background: blue; }
.add-to-cart {
  display: block; width: 100%; margin-top: 16px; padding: 16px; font-size: 18px;
  background: green; color: #fff; border: none; border-radius: 6px;
  cursor: pointer; text-transform: uppercase;
}
.add-to-cart:hover { background: #2e7d32; }

/* ---- Cart ------------------------------------------------------------------ */
.cart-header { padding: 14px; display: flex; justify-content: space-between; align-items: center; }
.pos-shift-group { display: flex; align-items: center; gap: 10px; }
#terminalId { color: #1970a6; cursor: pointer; font-weight: bold; }
#shiftDisplay { color: #1970a6; cursor: pointer; font-weight: bold; padding-left: 10px; border-left: 1px solid #bbb; }
.cart-total { font-weight: bold; }
#qrBalanceDisplay { text-align: right; }

.cart-error { margin: 0 14px 8px; padding: 8px 12px; background: #fff3cd; color: #856404; border: 1px solid #ffc107; border-radius: 6px; font-size: 13px; text-align: center; }

#paymentButtons { text-align: center; padding-bottom: 10px; }
#paymentButtons button {
  background: #4CAF50; border: none; color: #fff; padding: 10px 25px;
  font-size: 16px; margin: 4px 2px; cursor: pointer; border-radius: 10px;
}

.cart-container { flex: 1; overflow-y: auto; padding: 14px; }
.cart { background: #fff; padding: 10px; border-radius: 5px; margin-bottom: 10px; display: flex; gap: 10px; }
.cart-item-title { flex: 1.8; }
.cart-item-quantity { flex: 0.9; display: flex; align-items: center; gap: 4px; }
.cart-item-total { flex: 0.6; text-align: right; }
.cart-item-options { font-size: 13px; font-style: italic; line-height: 1em; }
.cart-button { cursor: pointer; border: none; background: #ddd; border-radius: 4px; padding: 2px 8px; }
.quantity-input { width: 50px; height: 25px; text-align: center; }

/* ---- Modals ---------------------------------------------------------------- */
.modal, .terminal-modal {
  display: none; position: fixed; inset: 0; z-index: 1000;
  background: rgba(0, 0, 0, 0.4); overflow: auto;
}
.modal-content { background: #fff; margin: 7% auto; padding: 20px; border: 1px solid #888; width: 40%; }

/* ---- Backdate (manager after-outage order entry) ---- */
.backdate-banner {
  display: flex; align-items: center; justify-content: center; gap: 14px;
  background: #b8860b; color: #fff; padding: 8px 14px; font-weight: 700; font-size: 15px;
}
/* The author display:flex above would otherwise defeat the [hidden] attribute. */
.backdate-banner[hidden] { display: none; }
.backdate-banner button {
  background: #fff; color: #7a5900; border: none; border-radius: 4px;
  padding: 4px 12px; font-weight: 700; cursor: pointer;
}
.backdate-modal-content { text-align: left; }
.backdate-hint { font-size: 13px; color: #666; margin: 6px 0 14px; }
.backdate-input { width: 100%; padding: 10px; font-size: 16px; border: 1px solid #ccc; border-radius: 5px; }
.backdate-actions { display: flex; gap: 10px; margin-top: 16px; }
.backdate-actions button { flex: 1; padding: 10px; font-size: 15px; border: none; border-radius: 5px; cursor: pointer; }
#backdateSet { background: #1970a6; color: #fff; }
#backdateOff { background: #b8860b; color: #fff; }
#backdateCancel { background: #eee; color: #333; }
.terminal-modal-content { width: 80%; max-width: 400px; margin: 15% auto; text-align: center; }
.close { color: #aaa; float: right; font-size: 28px; font-weight: bold; cursor: pointer; }
.close:hover { color: #000; }

#paymentContent { margin-bottom: 20px; }
.button-container { text-align: center; margin-top: 12px; }
#cashboxBtn, #completeButton, #printReceipt, #applyCashBtn, #applyQrBtn {
  padding: 10px 20px; background: #4CAF50; color: #fff; border: none; border-radius: 5px; cursor: pointer;
}

.number-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 20px 0; }
.cashNumberButton, #clearButton {
  padding: 10px; font-size: 15px; background: #ddd; border: none; border-radius: 5px; cursor: pointer;
}
.cashNumberButton:hover, #clearButton:hover { background: #ccc; }

.card-actions { display: flex; align-items: center; gap: 16px; margin-top: 12px; }
#simulateCardBtn { padding: 8px 14px; border: 1px dashed #888; background: #f3f3f3; border-radius: 6px; cursor: pointer; }
#cardRetryBtn { padding: 10px 18px; border: none; background: #1565c0; color: #fff; font-weight: 600; border-radius: 6px; cursor: pointer; }
#cardRetryBtn:hover { background: #0d47a1; }

/* Customer email — shown for every payment type when enabled at /config/. */
#customerEmailRow { margin: 10px 0; }
#customerEmailRow label { display: block; font-size: 13px; font-weight: 600; color: #444; margin-bottom: 4px; }
#customerEmailField {
  width: 100%; padding: 10px 12px; font-size: 15px;
  border: 1px solid #ccc; border-radius: 6px;
}
#customerEmailField:focus { outline: none; border-color: #1970a6; }
#customerEmailRow.invalid #customerEmailField { border-color: #c62828; background: #fffafa; }
#customerEmailError { margin-top: 4px; font-size: 12px; color: #c62828; }

#appliedList { margin: 8px 0; padding: 8px 10px; background: #f0f7f0; border-radius: 6px; border: 1px solid #c8e6c9; }
.applied-payment-row { font-size: 13px; color: #2e7d32; padding: 2px 0; }
.split-next-label { margin: 0 0 8px; font-weight: 600; font-size: 14px; color: #444; }
.split-method-btns { display: flex; gap: 8px; }
.choose-method-btn {
  flex: 1; padding: 10px; font-size: 14px; font-weight: 600;
  background: #1970a6; color: #fff; border: none; border-radius: 6px; cursor: pointer;
}
.choose-method-btn:hover { background: #145a8a; }

.voucher-type-selector { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.voucher-type-btn {
  width: 100%; padding: 12px; font-size: 14px; font-weight: 600; text-align: left;
  background: #f0f4f8; color: #333; border: 2px solid #ccc; border-radius: 6px; cursor: pointer;
}
.voucher-type-btn:hover { background: #dce8f5; border-color: #1970a6; }
.voucher-type-btn.selected { background: #1970a6; color: #fff; border-color: #1970a6; }
#voucherNumberSection { margin-top: 4px; }
#voucherStatus { font-size: 13px; color: #555; margin-bottom: 8px; }

.qr-code-balance { position: relative; }
.qr-code-input, #cashInputField {
  width: 100%; padding: 10px 12px; font-size: 16px;
  border: 1px solid #ccc; border-radius: 6px; box-sizing: border-box;
  margin-bottom: 8px;
}
.qr-code-input { padding-right: 40px; }
.clear-button { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); border: none; background: none; cursor: pointer; }

.terminal-button {
  margin: 5px; padding: 10px 20px; font-size: 16px; cursor: pointer;
  background: #007bff; color: #fff; border: none; border-radius: 4px;
}
.terminal-button:hover { background: #0056b3; }
.terminal-button.shift-default { outline: 3px solid #ffca28; outline-offset: 2px; }

/* ---- Order history panel --------------------------------------------------- */
.order-history { border-top: 2px solid #ccc; background: #f5f5f5; flex-shrink: 0; }
.order-history-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px; cursor: default;
}
.order-history-bar span { font-size: 13px; font-weight: 600; color: #444; }
.order-history-toggle {
  background: none; border: 1px solid #bbb; border-radius: 4px;
  font-size: 18px; line-height: 1; padding: 2px 8px; cursor: pointer; color: #555;
}
.order-history-toggle:hover { background: #e0e0e0; }
.order-history-toggle.open { transform: rotate(180deg); }
.order-history-list { max-height: 280px; overflow-y: auto; border-top: 1px solid #ddd; }
.order-history-item {
  padding: 8px 14px; border-bottom: 1px solid #e8e8e8; font-size: 13px;
  display: flex; align-items: flex-start; gap: 10px;
}
.order-history-item:last-child { border-bottom: none; }
.order-history-info { flex: 1; }
.order-history-info strong { font-size: 14px; color: #222; }
.order-history-info .oh-meta { color: #666; margin-top: 2px; }
.order-history-info .oh-email { color: #1970a6; margin-top: 2px; word-break: break-all; }
.order-history-actions { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.oh-reprint { font-size: 12px; color: #1970a6; cursor: pointer; text-decoration: none; white-space: nowrap; }
.oh-reprint:hover { text-decoration: underline; }

/* ---- Responsive ------------------------------------------------------------ */
@media (max-width: 768px) {
  .pos { flex-direction: column; }
  .cart-pane { width: 100%; }
  .modal-content { width: 90%; }
}
