/* ========================================================
   STYLESHEET CHO PHIEUTHU.INI.VN
   Thiết kế giao diện hiện đại, tối ưu mobile & bản in
   ======================================================== */

:root {
  --primary: #059669;
  --primary-dark: #047857;
  --primary-light: #d1fae5;
  --secondary: #2563eb;
  --secondary-dark: #1d4ed8;
  --accent: #f59e0b;
  --surface: #f8fafc;
  --card-bg: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
}

/* Hiệu ứng mượt mà & tối ưu cảm ứng Mobile */
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

button, a, input, select, textarea, label {
  touch-action: manipulation;
}

/* UI Pro Max: Accessibility Focus Rings (WCAG 2.1 AA) */
button:focus-visible,
a:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* UI Pro Max: Button Active State & Tactile Feedback */
button:active:not(:disabled),
.preset-chip:active {
  transform: scale(0.97);
  transition: transform 0.08s ease;
}

/* UI Pro Max: Respect Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  *, ::before, ::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Custom sleek scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 9999px;
}
::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

html, body {
  overflow-x: hidden;
  max-width: 100vw;
  width: 100%;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', 'Plus Jakarta Sans', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: #f1f5f9;
  color: #0f172a;
  letter-spacing: -0.011em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  padding-bottom: 84px; /* Chừa không gian cho Mobile Sticky Bar + Safe Area */
}

#mobileStickyBar {
  padding-bottom: calc(0.625rem + env(safe-area-inset-bottom, 0px));
}

@media (max-width: 767px) {
  .brand-badge {
    display: none !important;
  }
  /* Chống tự động phóng to (Auto-Zoom) trên iPhone / iOS Safari khi bấm vào ô nhập liệu */
  .form-input,
  input[type="text"],
  input[type="number"],
  input[type="tel"],
  select.form-input {
    font-size: 16px !important;
  }
  .preset-chip {
    padding: 0.35rem 0.65rem !important;
    font-size: 0.75rem !important;
  }
  .room-slot-btn {
    padding: 0.45rem 0.85rem !important;
    font-size: 0.8rem !important;
  }
}

@media (max-width: 639px) {
  .hidden-mobile {
    display: none !important;
  }
  .visible-mobile {
    display: inline-block !important;
  }
}

@media (min-width: 640px) {
  .visible-mobile {
    display: none !important;
  }
}

@media (min-width: 1024px) {
  body {
    padding-bottom: 0;
  }
}

/* Glassmorphism nav */
.glass-header {
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(226, 232, 240, 0.8);
}

/* Badge & Card shadows */
.card-shadow {
  box-shadow: 0 4px 20px -2px rgba(15, 23, 42, 0.06), 0 2px 6px -2px rgba(15, 23, 42, 0.04);
}

.preview-shadow {
  box-shadow: 0 10px 30px -4px rgba(15, 23, 42, 0.12), 0 4px 10px -2px rgba(15, 23, 42, 0.06);
}

/* Tab styles (Segmented Control style) */
.tab-btn {
  background-color: transparent;
  color: #334155 !important;
  font-weight: 700 !important;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.tab-btn:hover {
  color: #0f172a !important;
  background-color: rgba(255, 255, 255, 0.85) !important;
}
.tab-btn.active {
  background-color: #ffffff !important;
  color: #065f46 !important;
  box-shadow: 0 4px 14px rgba(5, 150, 105, 0.12), 0 1px 3px rgba(15, 23, 42, 0.08) !important;
  font-weight: 800 !important;
  border: 1.5px solid #059669 !important;
}

/* Input styles */
.form-input {
  width: 100%;
  padding: 0.625rem 0.875rem;
  border-radius: 0.5rem;
  border: 1px solid #cbd5e1;
  background-color: #ffffff;
  font-size: 0.875rem;
  color: #0f172a;
  transition: all 0.2s ease;
}

.form-input:focus {
  outline: none;
  border-color: #059669;
  box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.15);
}

/* Chips gợi ý nhanh */
.preset-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  background-color: #f1f5f9;
  color: #475569;
  border: 1px solid #e2e8f0;
  transition: all 0.15s ease;
  user-select: none;
}

.preset-chip:hover {
  background-color: #d1fae5;
  color: #065f46;
  border-color: #a7f3d0;
  transform: translateY(-1px);
}

/* Room Switcher Tabs */
.room-slot-btn {
  padding: 0.35rem 0.75rem;
  border-radius: 0.6rem;
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid #e2e8f0;
  background-color: #ffffff;
  color: #475569;
  transition: all 0.15s ease;
  cursor: pointer;
  white-space: nowrap;
}

.room-slot-btn.active {
  background-color: #ecfdf5;
  border-color: #10b981;
  color: #065f46;
  box-shadow: 0 1px 3px rgba(16, 185, 129, 0.15);
}

/* Custom scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: #f1f5f9;
}
::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 9999px;
}
::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* ========================================================
   CÁC PHONG CÁCH PHIẾU THU (PREVIEW TEMPLATES)
   ======================================================== */

#receiptToExport {
  background-color: #ffffff;
  color: #0f172a;
  position: relative;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  transition: all 0.3s ease;
}

/* Định dạng số tiền và chỉ số tabular để thẳng hàng chuẩn xác */
.font-mono, .receipt-amount, [data-currency] {
  font-family: 'JetBrains Mono', 'Courier Prime', monospace !important;
  font-feature-settings: "tnum" 1, "cv05" 1;
}

/* Mẫu 1: Modern Fintech */
.theme-modern {
  border-radius: 1rem;
  border: 1px solid #e2e8f0;
  background: #ffffff;
  font-family: 'Inter', system-ui, sans-serif;
}

.theme-modern .receipt-header-badge {
  background: linear-gradient(135deg, #059669 0%, #047857 100%);
  color: #ffffff;
}

/* Mẫu 2: Doanh Nghiệp (Regular Corporate Invoice) */
.theme-corporate {
  border-radius: 0.75rem;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #0f172a;
  font-family: 'Inter', system-ui, sans-serif;
}

.theme-corporate .corp-header-bar {
  border-bottom: 2px solid var(--primary-accent, #0f172a);
}

.theme-corporate .corp-table th {
  background-color: var(--primary-accent, #0f172a);
  color: #ffffff;
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  padding: 0.6rem 0.5rem;
}

.theme-corporate .corp-table td {
  padding: 0.6rem 0.5rem;
  border-bottom: 1px solid #e2e8f0;
}

@media (max-width: 639px) {
  .theme-corporate .corp-table th,
  .theme-corporate .corp-table td {
    padding: 0.45rem 0.35rem;
    font-size: 0.68rem;
  }
}

.theme-corporate .corp-table tr:nth-child(even) td {
  background-color: #f8fafc;
}

.theme-corporate .corp-card {
  border: 1px solid #e2e8f0;
  border-radius: 0.5rem;
  padding: 0.75rem;
  background-color: #f8fafc;
}

/* Mẫu 3: Chuẩn Kế toán Bộ Tài Chính (TT 133/200) */
.theme-accounting {
  font-family: 'Times New Roman', Times, serif;
  border: 2px solid #334155;
  border-radius: 0;
  padding: 1.5rem !important;
}

@media (max-width: 639px) {
  .theme-accounting {
    padding: 0.9rem !important;
  }
}

.theme-accounting h2 {
  font-family: 'Times New Roman', Times, serif;
  letter-spacing: 0.5px;
}

.theme-accounting table, .theme-accounting th, .theme-accounting td {
  border-color: #475569 !important;
}

/* Mẫu 4: Hóa đơn in nhiệt POS K80 (Chuẩn InitBill Receipt) */
.theme-pos {
  font-family: 'Courier New', Courier, monospace;
  max-width: 420px;
  margin: 0 auto;
  border: 1px dashed #cbd5e1;
  background: #ffffff;
  position: relative;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
}

/* Viền răng cưa giấy in nhiệt biên lai (Sawtooth Paper Tear) */
.pos-sawtooth-edge-top,
.pos-sawtooth-edge-bottom {
  height: 8px;
  width: 100%;
  background-repeat: repeat-x;
  background-size: 14px 8px;
  display: block;
}

.pos-sawtooth-edge-top {
  background-image: radial-gradient(circle at 7px 0px, transparent 5px, #f1f5f9 5.5px);
  margin-bottom: 0.5rem;
}

.pos-sawtooth-edge-bottom {
  background-image: radial-gradient(circle at 7px 8px, transparent 5px, #f1f5f9 5.5px);
  margin-top: 0.5rem;
}

.theme-pos .receipt-divider {
  border-top: 1px dashed #64748b;
}

.theme-pos .pos-barcode-line {
  letter-spacing: 2px;
  font-weight: 900;
  color: #1e293b;
}

/* ========================================================
   CÁC SẮC MÀU THƯƠNG HIỆU (BRAND ACCENT COLORS)
   ======================================================== */
.accent-emerald {
  --primary-accent: #059669;
  --primary-light: #ecfdf5;
  --primary-border: #a7f3d0;
  --primary-gradient: linear-gradient(135deg, #059669 0%, #0d9488 100%);
}
.accent-blue {
  --primary-accent: #2563eb;
  --primary-light: #eff6ff;
  --primary-border: #bfdbfe;
  --primary-gradient: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
}
.accent-purple {
  --primary-accent: #7c3aed;
  --primary-light: #f5f3ff;
  --primary-border: #ddd6fe;
  --primary-gradient: linear-gradient(135deg, #7c3aed 0%, #9333ea 100%);
}
.accent-orange {
  --primary-accent: #ea580c;
  --primary-light: #fff7ed;
  --primary-border: #fed7aa;
  --primary-gradient: linear-gradient(135deg, #ea580c 0%, #d97706 100%);
}
.accent-slate {
  --primary-accent: #334155;
  --primary-light: #f8fafc;
  --primary-border: #cbd5e1;
  --primary-gradient: linear-gradient(135deg, #334155 0%, #0f172a 100%);
}

.theme-accent-gradient {
  background: var(--primary-gradient, linear-gradient(135deg, #059669 0%, #0d9488 100%)) !important;
}

.theme-accent-badge {
  color: var(--primary-accent, #059669) !important;
  background-color: var(--primary-light, #ecfdf5) !important;
  border-color: var(--primary-border, #a7f3d0) !important;
}

.theme-accent-text {
  color: var(--primary-accent, #059669) !important;
}

/* ========================================================
   CON DẤU MỘC ĐỎ ĐIỆN TỬ (DIGITAL PAID STAMP - ELASTIC GSAP MOTION)
   ======================================================== */
@keyframes stampDrop {
  0% {
    opacity: 0;
    transform: scale(2.4) rotate(-32deg);
  }
  60% {
    opacity: 1;
    transform: scale(0.96) rotate(-10deg);
  }
  80% {
    transform: scale(1.04) rotate(-13deg);
  }
  100% {
    opacity: 1;
    transform: scale(1) rotate(-12deg);
  }
}

.stamp-paid-seal {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 3px double #dc2626;
  border-radius: 50%;
  width: 96px;
  height: 96px;
  color: #dc2626;
  font-family: 'Arial', system-ui, sans-serif;
  text-transform: uppercase;
  transform: rotate(-12deg);
  user-select: none;
  pointer-events: none;
  background-color: rgba(254, 242, 242, 0.45);
  box-shadow: 0 0 0 1px rgba(220, 38, 38, 0.25), inset 0 0 0 1px rgba(220, 38, 38, 0.25);
  position: relative;
  z-index: 10;
  animation: stampDrop 0.42s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@media (prefers-reduced-motion: reduce) {
  .stamp-paid-seal {
    animation: none !important;
    transform: rotate(-12deg) !important;
  }
}

.stamp-paid-seal::before {
  content: '';
  position: absolute;
  top: 4px;
  left: 4px;
  right: 4px;
  bottom: 4px;
  border: 1px dashed rgba(220, 38, 38, 0.45);
  border-radius: 50%;
}

/* ========================================================
   KHỔ GIẤY XEM TRƯỚC (PAPER SIZES)
   ======================================================== */
.paper-size-a4 {
  width: 100% !important;
  max-width: 100% !important;
}

.paper-size-a5 {
  width: 100% !important;
  max-width: 540px !important;
  margin: 0 auto;
}

.paper-size-k80 {
  width: 100% !important;
  max-width: 380px !important;
  margin: 0 auto;
}

/* ========================================================
   QR CODE & VIETQR STRICT 1:1 RATIO PROTECTION
   Guarantees QR is ALWAYS an exact square across all themes & devices
   ======================================================== */
.qr-container,
#previewQrContainer {
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  flex-shrink: 0 !important;
  align-self: center !important;
  background: #ffffff !important;
  border-radius: 0.75rem !important;
  padding: 0.5rem !important;
  box-sizing: border-box !important;
}

.qr-container img,
#previewQrContainer img {
  max-width: 175px !important;
  max-height: 215px !important;
  object-fit: contain !important;
  display: block !important;
  margin: 0 auto !important;
  flex-shrink: 0 !important;
}

/* Offline QR canvas & image container */
#offlineCanvasQr {
  width: 140px !important;
  height: 140px !important;
  min-width: 140px !important;
  min-height: 140px !important;
  max-width: 140px !important;
  max-height: 140px !important;
  aspect-ratio: 1 / 1 !important;
  background: #ffffff !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  box-sizing: border-box !important;
  flex-shrink: 0 !important;
  margin: 0 auto !important;
}

#offlineCanvasQr canvas {
  width: 140px;
  height: 140px;
  max-width: 140px;
  max-height: 140px;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  margin: 0 auto;
}

#offlineCanvasQr img {
  width: 140px !important;
  height: 140px !important;
  min-width: 140px !important;
  min-height: 140px !important;
  max-width: 140px !important;
  max-height: 140px !important;
  aspect-ratio: 1 / 1 !important;
  object-fit: contain !important;
  margin: 0 auto !important;
  flex-shrink: 0 !important;
}

/* Modal lead bounce */
@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-animate {
  animation: modalIn 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* Notification Toast */
#toastNotification {
  position: fixed;
  bottom: 5.5rem;
  right: 1rem;
  z-index: 9999;
  transition: all 0.3s ease;
}

@media (min-width: 1024px) {
  #toastNotification {
    bottom: 1.5rem;
    right: 1.5rem;
  }
}

/* ========================================================
   IN ẤN (@media print) TỐI ƯU HÓA HOÀN TOÀN
   ======================================================== */
@media print {
  @page {
    margin: 8mm;
    size: auto;
  }

  body * {
    visibility: hidden;
  }

  body {
    background: #ffffff !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  #receiptToExport, #receiptToExport * {
    visibility: visible;
  }

  #receiptToExport {
    position: absolute;
    left: 0;
    top: 0;
    width: 100% !important;
    max-width: 100% !important;
    box-shadow: none !important;
    border: none !important;
    padding: 6mm !important;
  }

  #receiptToExport.paper-size-k80 {
    width: 76mm !important;
    max-width: 76mm !important;
    margin: 0 auto !important;
    padding: 2mm !important;
  }

  #receiptToExport.paper-size-a5 {
    width: 148mm !important;
    max-width: 148mm !important;
    margin: 0 auto !important;
    padding: 5mm !important;
  }

  /* Tránh ngắt trang dở dang giữa các dòng bảng, con dấu, chữ ký và mã QR */
  table, tr, td, th, .stamp-container, #previewQrContainer, .receipt-break-inside-avoid {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  .no-print {
    display: none !important;
  }
}


/* ==========================================================================
   TAB 2 BƯỚC TRÊN ĐIỆN THOẠI (< 1024px): TAB THẬT - CHỈ HIỆN 1 CỘT MỖI LẦN
   ========================================================================== */
.mobile-step-tab {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.55rem 0.75rem;
  border-radius: 0.5rem;
  font-size: 0.75rem;
  font-weight: 700;
  color: #475569;
  background: #f8fafc;
  transition: background-color .2s ease, color .2s ease, box-shadow .2s ease, transform .1s ease;
  -webkit-tap-highlight-color: transparent;
}
.mobile-step-tab:active { transform: scale(0.97); }
.mobile-step-tab.is-active {
  background: #059669;
  color: #ffffff;
  font-weight: 800;
  box-shadow: 0 1px 3px rgba(5, 150, 105, .35);
}
.mobile-step-tab.is-active #mobileStepTotalBadge {
  background: rgba(255, 255, 255, .22);
  color: #ffffff;
}

@media screen and (max-width: 1023.98px) {
  #mainWorkspaceGrid[data-mobile-view="form"] #previewColumnContainer { display: none !important; }
  #mainWorkspaceGrid[data-mobile-view="preview"] #formColumnContainer { display: none !important; }
  #mainWorkspaceGrid[data-mobile-view] > #formColumnContainer,
  #mainWorkspaceGrid[data-mobile-view] > #previewColumnContainer {
    animation: mobileTabFadeIn .22s ease-out;
  }
}
@keyframes mobileTabFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  #mainWorkspaceGrid[data-mobile-view] > #formColumnContainer,
  #mainWorkspaceGrid[data-mobile-view] > #previewColumnContainer { animation: none; }
}