:root {
  --bg-color: #0F172A; /* Deep Night */
  --surface-color: rgba(30, 41, 59, 0.7);
  --primary-color: #10B981; /* Emerald Green */
  --text-primary: #F8FAFC;
  --text-secondary: #94A3B8;
  --border-color: rgba(255, 255, 255, 0.1);
  --danger-color: #EF4444;
  --warning-color: #EAB308;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Inter', -apple-system, sans-serif; }
body { background: #000; color: var(--text-primary); overflow: hidden; /* Prevent bounce on mobile view */ }

.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  max-width: 500px; /* Constrain for desktop viewing */
  margin: 0 auto;
  background: var(--bg-color);
  position: relative;
}

/* --- Scanner Zone (Top 45%) --- */
.scanner-zone {
  flex: 0 0 45vh;
  background: #000;
  position: relative;
  overflow: hidden;
}

video#preview {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  z-index: 1;
}

.scanner-overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.header {
  position: absolute; top: 0; left: 0; width: 100%;
  padding: 1rem; display: flex; justify-content: space-between;
  background: linear-gradient(to bottom, rgba(0,0,0,0.8), transparent);
  z-index: 10;
}
.header-left { display: flex; flex-direction: column; }
.shop-name { font-weight: 600; letter-spacing: 0.5px; }
.status.online { color: var(--primary-color); font-size: 0.8rem; font-weight: 600; text-shadow: 0 0 8px currentColor; }

.sync-status {
  background: rgba(255,255,255,0.05); padding: 0.4rem 0.8rem; border-radius: 99px;
  display: flex; align-items: center; gap: 0.5rem; border: 1px solid var(--border-color);
}
.sync-icon { font-size: 0.9rem; }
.sync-status.pending .sync-icon { animation: pulse 2s infinite; color: var(--warning-color); }
.sync-text { font-size: 0.75rem; color: var(--text-secondary); font-weight: 500; }
@keyframes pulse { 0% { opacity: 1; } 50% { opacity: 0.4; } 100% { opacity: 1; } }

.scanner-reticle {
  width: 60%; aspect-ratio: 1;
  border: 2px dashed rgba(255,255,255,0.3);
  border-radius: 20px;
  position: relative; /* Maintain relative for scan-line anchoring if needed */
  transition: all 0.2s ease;
  z-index: 6;
}
.scanner-reticle.success {
  border-color: var(--primary-color);
  background: rgba(16, 185, 129, 0.15);
  transform: scale(1.05);
}
.scanner-reticle.fail {
  border-color: var(--warning-color);
  background: rgba(234, 179, 8, 0.1);
}

.scan-text { color: rgba(255,255,255,0.5); font-size: 0.9rem; }
.scan-line {
  position: absolute;
  top: 15%; width: 100%; height: 2px;
  background: rgba(16, 185, 129, 0.5);
  box-shadow: 0 0 10px rgba(16, 185, 129, 1);
  animation: scanAnim 2s infinite linear;
}
@keyframes scanAnim { 0% { top: 15%; opacity: 0; } 10% { opacity: 1; } 90% { opacity: 1; } 100% { top: 85%; opacity: 0; } }

/* --- Cart Zone (Middle) --- */
.cart-zone {
  flex: 1;
  background: var(--bg-color);
  overflow-y: auto;
  padding: 1rem;
  padding-bottom: 100px; /* Space for checkout bar */
}

/* Quick Actions Scroll */
.quick-actions {
  display: flex; gap: 0.5rem; overflow-x: auto; padding-bottom: 0.8rem;
  scrollbar-width: none; /* Firefox */
}
.quick-actions::-webkit-scrollbar { display: none; } /* Chrome/Safari */

.quick-btn {
  background: var(--surface-color); color: var(--text-primary);
  border: 1px solid var(--border-color);
  padding: 0.6rem 1rem; border-radius: 99px;
  white-space: nowrap; font-size: 0.85rem; font-weight: 500;
  backdrop-filter: blur(10px); cursor: pointer;
  transition: background 0.2s;
}
.quick-btn:active { background: rgba(255,255,255,0.1); }

/* Onboarding Card (Zero-friction Add) */
.onboarding-card {
  background: rgba(234, 179, 8, 0.15);
  border: 1px solid rgba(234, 179, 8, 0.4);
  border-radius: 12px; padding: 1rem; margin-bottom: 1rem;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  animation: slideDown 0.3s ease-out;
}
@keyframes slideDown { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
.onboarding-header { color: var(--warning-color); font-size: 0.9rem; font-weight: 600; margin-bottom: 0.8rem; }
.onboarding-inputs { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.onboarding-inputs input {
  flex: 1; min-width: 100px;
  background: rgba(0,0,0,0.4); border: 1px solid var(--border-color);
  color: white; padding: 0.8rem; border-radius: 8px; font-size: 0.95rem;
}
.onboarding-inputs input:focus { outline: none; border-color: var(--warning-color); }
.save-btn {
  background: var(--warning-color); color: #000; font-weight: 600;
  border: none; padding: 0.8rem 1rem; border-radius: 8px; cursor: pointer;
  transition: transform 0.1s;
}
.save-btn:active { transform: scale(0.95); }

/* Cart List & Three-Column Layout (User Requested) */
.cart-list { display: flex; flex-direction: column; gap: 0.6rem; }
.cart-item {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: 12px; padding: 0.8rem 1rem; 
  display: flex; justify-content: space-between; align-items: stretch;
  backdrop-filter: blur(10px); transition: background 0.3s;
  gap: 0.8rem;
}

/* 左側：品名與單價 */
.item-main {
  flex: 1; /* 佔據剩餘空間 */
  min-width: 0; /* 讓截斷或自動換行生效 */
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.item-main h3 { 
  font-size: 0.95rem; 
  font-weight: 600; 
  line-height: 1.3;
  word-break: break-all; 
}
.item-main h3.long-text {
  font-size: 0.75rem; 
  color: rgba(255, 255, 255, 0.85);
}
.item-main .unit-price { 
  font-size: 0.85rem; 
  color: var(--text-secondary); 
  margin-top: 0.2rem; 
}

/* 中左：數量控制 (方案三：極簡膠囊) */
.item-qty {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.2rem;
}
/* 方案四：原地展開的 qty-control */
.qty-control {
  display: flex; align-items: center; gap: 0.6rem;
  background: rgba(0,0,0,0.4); border-radius: 8px; padding: 4px; border: 1px solid var(--border-color);
}
.qty-control.expanded {
  animation: expandWidth 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes expandWidth {
  0% { opacity: 0; transform: scaleX(0.5); }
  100% { opacity: 1; transform: scaleX(1); }
}

.qty-btn {
  width: 28px; height: 28px; background: rgba(255,255,255,0.1);
  border: none; border-radius: 6px; color: white; font-weight: bold; cursor: pointer;
}
.qty-btn:active { background: rgba(255,255,255,0.2); }
.qty-val { font-size: 0.95rem; font-weight: 600; width: 20px; text-align: center; }

.qty-pill {
  display: flex;
  align-items: baseline;
  gap: 2px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 20px;
  padding: 0.4rem 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--primary-color);
}
.qty-pill:active { 
  background: rgba(255, 255, 255, 0.2); 
  transform: scale(0.95);
}
.qty-pill .qty-label { font-size: 0.75rem; font-weight: 500; opacity: 0.8; }
.qty-pill .qty-val { font-size: 1.1rem; font-weight: 700; width: auto; text-align: center; }

/* 數量編輯器特定樣式 */
.qty-editor-display {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.03); border: 1px solid var(--border-color);
  border-radius: 16px; padding: 1.5rem; margin-bottom: 1rem;
}
.qty-editor-label { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 0.5rem; }
.qty-editor-value { font-size: 3rem; font-weight: 800; color: var(--primary-color); line-height: 1; }

.qty-quick-actions {
  display: flex; gap: 0.5rem; margin-bottom: 1rem;
}
.qty-quick-btn {
  flex: 1; background: rgba(16, 185, 129, 0.1); border: 1px solid rgba(16, 185, 129, 0.3);
  color: var(--primary-color); border-radius: 12px; padding: 0.8rem;
  font-size: 1.1rem; font-weight: 600; cursor: pointer; transition: all 0.1s;
}
.qty-quick-btn:active { background: rgba(16, 185, 129, 0.2); transform: scale(0.95); }

/* 中右：小計金額 */
.item-subtotal {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 65px; /* 給予合理寬度防止不同金額長度跳動 */
  padding-right: 0.5rem;
}
.item-subtotal .price { 
  font-weight: 600; font-size: 1.05rem; color: var(--text-primary); 
}

/* 右側：刪除按鈕 */
.item-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  padding-left: 0.5rem;
  border-left: 1px solid rgba(255,255,255,0.05); /* 微弱的分割線增加結構感 */
}
.delete-btn {
  background: rgba(239, 68, 68, 0.1); color: var(--danger-color);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: 8px; width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; cursor: pointer; transition: all 0.2s;
}
.delete-btn:active { background: rgba(239, 68, 68, 0.3); transform: scale(0.95); }

.cart-item.highlight { background: rgba(16, 185, 129, 0.2); border-color: var(--primary-color); }

/* --- Checkout Bar (Bottom) --- */
.checkout-bar {
  position: absolute; bottom: 0; left: 0; width: 100%;
  background: rgba(15, 23, 42, 0.85);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--border-color);
  padding: 1rem; display: flex; justify-content: flex-end; align-items: center; gap: 0.8rem;
  z-index: 20;
}
.total-display { flex: 1; display: flex; flex-direction: column; }
.total-display .label { font-size: 0.75rem; color: var(--text-secondary); font-weight: 600; }
.total-display .amount { font-size: 1.6rem; font-weight: 700; color: var(--primary-color); line-height: 1.2; }
.checkout-btn {
  background: linear-gradient(135deg, #10B981, #059669);
  color: white; border: none; padding: 0 1.5rem; height: 50px; border-radius: 14px;
  font-size: 1.05rem; font-weight: 700; box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
  cursor: pointer; transition: transform 0.1s;
}
.checkout-btn:active { transform: scale(0.97); }

.cancel-btn {
  width: 50px; height: 50px; border-radius: 14px;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: var(--danger-color);
  font-size: 1.2rem;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  transition: all 0.2s;
}

.cancel-btn:active {
  background: rgba(239, 68, 68, 0.3);
  transform: scale(0.95);
}

.cancel-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* --- Checkout Overlay --- */
.checkout-overlay {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.7); backdrop-filter: blur(5px);
  z-index: 30; display: none; flex-direction: column; justify-content: flex-end;
}
.checkout-modal {
  background: var(--bg-color); border-top-left-radius: 24px; border-top-right-radius: 24px;
  padding: 1.5rem; animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  border-top: 1px solid var(--border-color); box-shadow: 0 -10px 40px rgba(0,0,0,0.5);
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.2rem; }
.modal-header h2 { font-size: 1.3rem; font-weight: 600; }
.close-btn { background: rgba(255,255,255,0.1); border: none; border-radius: 50%; color: var(--text-secondary); width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; cursor: pointer; }

.modal-list-container {
  margin-bottom: 1.5rem;
  padding: 0 0.5rem;
}

.modal-item-list {
  max-height: 120px;
  overflow-y: auto;
  border-bottom: 1px dashed var(--border-color);
  padding-bottom: 1rem;
}

.mini-item {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  color: var(--text-primary);
  margin-bottom: 0.4rem;
}

.summary-detailed {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 1.2rem;
  margin-bottom: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.summary-row .summary-label {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.summary-row .summary-value {
  font-size: 1.2rem;
  font-weight: 600;
}

.summary-row.primary .summary-label {
  color: var(--text-primary);
  font-weight: 600;
}

.summary-row.primary .input-container {
  display: flex;
  align-items: baseline;
  gap: 4px;
  color: var(--primary-color);
}

.summary-row.primary .currency-prefix {
  font-size: 1.2rem;
  font-weight: 700;
}

.summary-row.primary .input-value {
  font-size: 2.2rem;
  font-weight: 800;
}

.summary-row.highlight {
  border-top: 1px solid var(--border-color);
  padding-top: 1rem;
}

.summary-row.highlight .summary-label {
  font-weight: 600;
}

.summary-row.highlight .summary-value {
  font-size: 1.5rem;
  color: var(--primary-color);
}

.summary-row.highlight.insufficient .summary-value {
  color: var(--danger-color);
}

/* Keypad Grid */
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.8rem;
  margin-bottom: 1.5rem;
}

.key {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  height: 60px;
  border-radius: 12px;
  font-size: 1.4rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  transition: all 0.1s;
}

.key:active {
  background: rgba(255,255,255,0.15);
  transform: scale(0.95);
}

.key.action {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-secondary);
}

.action-buttons { display: flex; flex-direction: column; gap: 0.8rem; }

.confirm-btn {
  width: 100%; background: linear-gradient(135deg, var(--primary-color), #059669); color: white;
  border: none; padding: 1.2rem; border-radius: 16px; font-size: 1.2rem; font-weight: 700;
  cursor: pointer; box-shadow: 0 4px 15px rgba(16, 185, 129, 0.4);
}
.confirm-btn:active { transform: scale(0.98); }

.continue-btn {
  width: 100%; background: var(--surface-color); color: var(--text-primary);
  border: 1px solid var(--border-color); padding: 1.2rem; border-radius: 16px; font-size: 1.1rem; font-weight: 600;
  cursor: pointer;
}
.continue-btn:active { background: rgba(255,255,255,0.1); }

/* --- Success State Styles --- */
.success-modal { text-align: center; display: flex; flex-direction: column; align-items: center; padding-bottom: 2rem; }
.success-modal h2 { margin-bottom: 1.5rem; }
.success-icon {
  width: 80px; height: 80px; background: rgba(16, 185, 129, 0.2);
  color: var(--primary-color); border-radius: 50%; font-size: 2.5rem;
  display: flex; align-items: center; justify-content: center; margin-bottom: 1rem;
  border: 2px solid var(--primary-color);
}
.success-msg { color: var(--text-secondary); margin-bottom: 1.5rem; font-size: 0.95rem; }
.success-summary { width: 100%; }

.print-btn {
  width: 100%; background: #3B82F6; color: white; border: none; padding: 1.2rem;
  border-radius: 16px; font-size: 1.15rem; font-weight: 700; cursor: pointer;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}
.print-btn:active { transform: scale(0.98); }

.new-transaction-btn {
  width: 100%; background: var(--surface-color); color: var(--text-primary);
  border: 1px solid var(--border-color); padding: 1.2rem; border-radius: 16px; font-size: 1.1rem; font-weight: 600;
  cursor: pointer;
}
.new-transaction-btn:active { background: rgba(255,255,255,0.1); }
/* --- Printing Overlay --- */
.printing-overlay {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.85);
  -webkit-backdrop-filter: blur(15px);
  backdrop-filter: blur(15px);
  z-index: 100;
  display: flex; align-items: center; justify-content: center;
  text-align: center;
}

.printing-content {
  width: 80%;
  animation: fadeIn 0.5s ease-out;
}

.printer-icon {
  font-size: 4rem; margin-bottom: 1.5rem;
  animation: bounce 2s infinite ease-in-out;
}

.printing-content h2 { font-size: 1.5rem; margin-bottom: 0.5rem; color: var(--text-primary); }
.printing-content p { color: var(--text-secondary); font-size: 0.95rem; margin-bottom: 2rem; }

.progress-container {
  width: 100%; height: 8px; background: rgba(255,255,255,0.1);
  border-radius: 99px; overflow: hidden; margin-bottom: 1rem;
}

.progress-bar {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--primary-color), #3B82F6);
  border-radius: 99px;
  animation: printProgress 10s linear forwards;
}

.timer { font-size: 0.85rem; font-weight: 600; color: var(--primary-color); }

@keyframes printProgress {
  from { width: 0%; }
  to { width: 100%; }
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-15px); }
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

/* --- Cancel Success State --- */
#cancelSuccessOverlay { 
  background: rgba(127, 29, 29, 0.4); /* 深紅色毛玻璃底層 */
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  z-index: 100;
}

.cancel-success-modal { 
  text-align: center; display: flex; flex-direction: column; align-items: center; padding-bottom: 2rem; 
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.cancel-success-modal h2 { margin-bottom: 2rem; color: var(--text-primary); }

.cancel-icon {
  width: 80px; height: 80px; background: rgba(239, 68, 68, 0.1);
  color: var(--danger-color); border-radius: 50%; font-size: 2.5rem;
  display: flex; align-items: center; justify-content: center; margin-bottom: 1.5rem;
  border: 2px solid var(--danger-color);
  animation: modalPop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modalPop {
  0% { transform: scale(0.5); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
