/* ===================================================================
   VIETEAM SMART INVOICE - DESIGN SYSTEM & APPLICATION STYLES
   Day Style (Light Theme) with Executive Dark Royal Purple Header
   Brand Colors: Royal Purple (#482169, #7C3AED), Lavender (#F4EFF8), Accent Gold (#D4AF37)
=================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;1,400&family=Playfair+Display:ital,wght@0,600;0,700;1,400&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  --primary-purple: #482169;
  --primary-dark: #35164f;
  --primary-light: #6a3498;
  --primary-vibrant: #7c3aed;
  --primary-hover: #5b21b6;
  --purple-glow: rgba(124, 58, 237, 0.18);
  --purple-soft: #f5f3ff;
  --purple-border: #ddd6fe;

  --accent-gold: #c59b27;
  --accent-gold-soft: #fffbeb;
  --accent-gold-hover: #b45309;

  /* DAY STYLE PALETTE (Clean, Modern, High Readability) */
  --bg-app: #f1f5f9;          /* Neutral workspace background */
  --bg-panel: #ffffff;        /* Form panel clean white */
  --bg-card: #ffffff;         /* Cards white */
  --bg-card-subtle: #f8fafc;  /* Nested rows & table headers */
  --bg-preview: #eaedf2;      /* Preview desk surface */
  --border-light: #e2e8f0;    /* Card & section borders */
  --border-input: #cbd5e1;    /* Form inputs border */

  --text-main: #0f172a;       /* Slate 900 */
  --text-muted: #64748b;      /* Slate 500 */
  --text-label: #475569;      /* Slate 600 */
  --text-subtle: #94a3b8;     /* Slate 400 */
  --text-light: #f8fafc;      /* For dark header only */
  --text-light-muted: #cbd5e1;/* For dark header only */

  /* Legacy variables mapped to Day Style so any remaining classes look perfect */
  --bg-dark: #ffffff;
  --border-dark: #e2e8f0;

  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;

  --font-sans: 'Montserrat', system-ui, -apple-system, sans-serif;
  --font-serif: 'Playfair Display', Georgia, serif;
  --font-mono: 'JetBrains Mono', Consolas, monospace;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05), 0 1px 2px rgba(0, 0, 0, 0.03);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
  --shadow-purple: 0 4px 14px rgba(106, 52, 152, 0.25);
  --shadow-paper: 0 12px 36px -8px rgba(15, 23, 42, 0.12), 0 4px 12px -2px rgba(15, 23, 42, 0.06), 0 0 0 1px rgba(15, 23, 42, 0.05);
}

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

body {
  font-family: var(--font-sans);
  background: var(--bg-app);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Scrollbar in Day Style */
::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* ===================================================================
   APP HEADER BAR (REMAINS SLEEK EXECUTIVE DARK ROYAL PURPLE)
=================================================================== */
.app-header {
  background: #181124;
  background: linear-gradient(180deg, #201335 0%, #150b22 100%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.09);
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.brand-badge {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-badge img {
  height: 38px;
  object-fit: contain;
}

.brand-info {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-title span.tag {
  background: linear-gradient(135deg, var(--primary-vibrant), var(--primary-purple));
  font-size: 10px;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 12px;
  font-weight: 700;
  letter-spacing: 0.8px;
  color: #fff;
  box-shadow: 0 2px 6px rgba(124, 58, 237, 0.4);
}

.brand-sub {
  font-size: 11px;
  color: #cbd5e1;
}

/* ===================================================================
   FORM STEPPER NAVIGATION (Tiến trình 4 bước đặt trong cột trái)
=================================================================== */
.form-stepper {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: #ffffff;
  border-bottom: 1px solid var(--border-light);
  padding: 8px 10px;
  gap: 6px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
}

.form-stepper .stepper-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 8px 4px 7px 4px;
  border-radius: 8px;
  background: #f8fafc;
  border: 1px solid var(--border-light);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  user-select: none;
}

.form-stepper .stepper-item:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.form-stepper .stepper-item.active {
  background: #f5f3ff;
  border-color: var(--primary-vibrant);
  box-shadow: 0 2px 8px rgba(124, 58, 237, 0.12);
}

.form-stepper .stepper-item .step-num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #e2e8f0;
  color: var(--text-label);
  font-size: 11px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
  transition: all 0.2s ease;
}

.form-stepper .stepper-item.active .step-num {
  background: linear-gradient(135deg, #8b5cf6, #6d28d9);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(124, 58, 237, 0.35);
}

.form-stepper .stepper-item.completed .step-num {
  background: #10b981;
  color: #ffffff;
}

.form-stepper .stepper-item .step-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.form-stepper .stepper-item .step-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.2;
}

.form-stepper .stepper-item.active .step-title {
  color: var(--primary-purple);
}

.form-stepper .stepper-item.completed .step-title {
  color: #059669;
}

.form-stepper .stepper-item .step-sub {
  font-size: 9px;
  color: var(--text-muted);
  line-height: 1.2;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 95px;
}

.form-stepper .stepper-item.active .step-sub {
  color: #6d28d9;
}

/* ===================================================================
   HEADER ACTIONS & USER BADGE
=================================================================== */
.app-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.cloud-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.35);
  color: #34d399;
  padding: 5px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}
.cloud-status-pill:hover {
  background: rgba(16, 185, 129, 0.25);
  border-color: #10b981;
}
.cloud-status-pill .pill-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 6px #10b981;
}
.cloud-status-pill.offline {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.35);
  color: #f87171;
}
.cloud-status-pill.offline .pill-dot {
  background: #ef4444;
  box-shadow: 0 0 6px #ef4444;
}

.app-header .btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: #f1f5f9;
  border-color: rgba(255, 255, 255, 0.15);
  box-shadow: none;
}
.app-header .btn-secondary:hover {
  background: rgba(255, 255, 255, 0.18);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.3);
}

.user-session-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 4px 10px 4px 6px;
  border-radius: 24px;
}

.user-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary-light), var(--primary-purple));
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid rgba(255, 255, 255, 0.4);
}

.user-name-text {
  font-size: 12px;
  font-weight: 700;
  color: #ffffff;
  max-width: 140px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role-badge {
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 10px;
  letter-spacing: 0.3px;
}
.user-role-badge.super_admin {
  background: rgba(212, 175, 55, 0.22);
  color: #fbbf24;
  border: 1px solid rgba(212, 175, 55, 0.4);
}
.user-role-badge.accountant {
  background: rgba(59, 130, 246, 0.22);
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.4);
}
.user-role-badge.staff {
  background: rgba(16, 185, 129, 0.22);
  color: #6ee7b7;
  border: 1px solid rgba(16, 185, 129, 0.4);
}

.btn-logout {
  background: none;
  border: none;
  color: #cbd5e1;
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  padding: 3px 6px;
  border-radius: 4px;
  transition: all 0.2s;
  margin-left: 4px;
}
.btn-logout:hover {
  color: #f87171;
  background: rgba(239, 68, 68, 0.15);
}

/* ===================================================================
   BUTTONS (DAY STYLE)
=================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid transparent;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, #7c3aed, #5b21b6);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(91, 33, 182, 0.25);
  border: 1px solid transparent;
}
.btn-primary:hover {
  background: linear-gradient(135deg, #6d28d9, #4c1d95);
  box-shadow: 0 4px 14px rgba(91, 33, 182, 0.35);
  transform: translateY(-1px);
}

.btn-secondary {
  background: #ffffff;
  color: #334155;
  border-color: #cbd5e1;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
.btn-secondary:hover {
  background: #f8fafc;
  border-color: #94a3b8;
  color: #0f172a;
}

.btn-gold {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #ffffff;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(217, 119, 6, 0.25);
}
.btn-gold:hover {
  background: linear-gradient(135deg, #fbbf24, #b45309);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(217, 119, 6, 0.35);
}

.btn-sm {
  padding: 5px 12px;
  font-size: 12px;
  border-radius: 6px;
}

.btn-icon {
  padding: 8px;
  border-radius: 8px;
  background: #ffffff;
  color: #475569;
  border: 1px solid #cbd5e1;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
.btn-icon:hover {
  color: #0f172a;
  background: #f8fafc;
  border-color: #94a3b8;
}

/* ===================================================================
   APP MAIN LAYOUT: SPLIT SCREEN (DAY STYLE)
=================================================================== */
.app-container {
  display: grid;
  grid-template-columns: 460px 1fr;
  flex: 1;
  height: calc(100vh - 65px);
  overflow: hidden;
  background: var(--bg-app);
}

/* Left Panel: Form Controller */
.form-panel {
  background: #ffffff;
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 2px 0 10px rgba(0, 0, 0, 0.02);
}

/* Quick Presets Bar */
.presets-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border-light);
  flex-wrap: wrap;
}

.presets-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 5px;
}

.preset-btn {
  background: #ffffff;
  border: 1px solid var(--border-input);
  color: var(--text-label);
  padding: 4px 11px;
  border-radius: 14px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}
.preset-btn:hover {
  background: #ede9fe;
  border-color: #a78bfa;
  color: #5b21b6;
}

.panel-content-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  background: #f8fafc;
}

.tab-pane {
  display: none;
  flex-direction: column;
  gap: 14px;
}
.tab-pane.active {
  display: flex;
}

/* Form Groups & Cards */
.form-card {
  background: #ffffff;
  border: 1px solid var(--border-light);
  border-radius: 10px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  transition: box-shadow 0.2s;
}
.form-card:hover {
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.05);
}

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

.card-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--primary-purple);
  display: flex;
  align-items: center;
  gap: 8px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group.full {
  grid-column: 1 / -1;
}

label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-label);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

input, select, textarea {
  width: 100%;
  padding: 8px 12px;
  background: #ffffff;
  border: 1px solid var(--border-input);
  border-radius: 6px;
  color: var(--text-main);
  font-family: inherit;
  font-size: 13px;
  transition: all 0.2s;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.02);
}

input::placeholder, textarea::placeholder {
  color: #94a3b8;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: #7c3aed;
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.15);
  background: #ffffff;
}

select {
  cursor: pointer;
}

textarea {
  resize: vertical;
  min-height: 50px;
}

.btn-text-action {
  background: none;
  border: none;
  color: #7c3aed;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  transition: all 0.15s;
}
.btn-text-action:hover {
  color: #5b21b6;
  background: #f5f3ff;
}

/* Items Editor List */
.items-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.item-row-edit {
  background: #ffffff;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
  transition: all 0.2s;
}
.item-row-edit:hover {
  border-color: #cbd5e1;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.05);
}

.item-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.item-num {
  font-size: 11px;
  font-weight: 700;
  color: var(--primary-purple);
  background: var(--purple-soft);
  border: 1px solid var(--purple-border);
  padding: 2px 8px;
  border-radius: 4px;
}

.item-delete-btn {
  background: #fee2e2;
  border: 1px solid #fecaca;
  color: #dc2626;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 600;
  transition: all 0.2s;
}
.item-delete-btn:hover {
  background: #ef4444;
  color: #ffffff;
  border-color: #ef4444;
}

.item-inputs-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: 8px;
}

/* Payment Method Selector */
.payment-method-selector {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 8px;
}

.payment-method-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  background: #ffffff;
  border: 1px solid var(--border-input);
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-label);
  transition: all 0.2s;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}
.payment-method-btn:hover {
  background: #f8fafc;
  border-color: #94a3b8;
}
.payment-method-btn input[type="radio"] {
  accent-color: var(--primary-vibrant);
}
.payment-method-btn.active {
  background: var(--purple-soft);
  border-color: var(--primary-light);
  color: var(--primary-purple);
  box-shadow: 0 0 0 2px rgba(106, 52, 152, 0.15);
}

/* Step Nav Footers */
.step-nav-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--border-light);
}

/* ===================================================================
   PREVIEW BOTTOM BAR (Tóm tắt tổng tiền & Tác vụ hóa đơn dưới A4)
=================================================================== */
.preview-bottom-bar,
.form-bottom-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 24px;
  background: #ffffff;
  border-top: 1px solid var(--border-light);
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.05);
  z-index: 20;
}

.bottom-summary-info {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12.5px;
}

.summary-items-count {
  color: var(--text-label);
  font-weight: 600;
}

.summary-divider {
  color: var(--border-input);
}

.summary-total-label {
  color: var(--text-muted);
  font-weight: 600;
}

.summary-total-val {
  font-weight: 800;
  color: #b45309;
  font-size: 15px;
  letter-spacing: 0.3px;
}

.summary-status-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: #059669;
  font-weight: 600;
  background: #ecfdf5;
  padding: 2px 8px;
  border-radius: 12px;
  border: 1px solid #a7f3d0;
}

.status-pulse-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #10b981;
}

.bottom-actions-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ===================================================================
   RIGHT PANEL: A4 LIVE PREVIEW AREA (DAY STYLE)
=================================================================== */
.preview-panel {
  background: #eaedf2;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.preview-toolbar {
  background: #ffffff;
  border-bottom: 1px solid var(--border-light);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 10;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
}

.preview-status {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--text-muted);
}
.preview-status strong {
  color: var(--text-main);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 10px var(--success);
}

.preview-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.zoom-ctrl {
  display: flex;
  align-items: center;
  background: #f1f5f9;
  border: 1px solid var(--border-input);
  border-radius: 6px;
  padding: 2px;
}

.zoom-btn {
  background: none;
  border: none;
  color: var(--text-label);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 4px;
  font-weight: 700;
  transition: all 0.15s;
}
.zoom-btn:hover {
  background: #e2e8f0;
  color: #0f172a;
}

.zoom-text {
  font-size: 12px;
  padding: 0 8px;
  color: var(--text-label);
  font-family: var(--font-mono);
  font-weight: 600;
}

.preview-viewport {
  flex: 1;
  overflow: auto;
  padding: 24px 20px 24px 20px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  background: #eaedf2;
}

/* ===================================================================
   A4 SHEET (THE PHYSICAL DOCUMENT DESIGN)
   Dimensions: 210mm x 297mm
=================================================================== */
.a4-sheet {
  width: 210mm;
  min-height: 297mm;
  height: auto;
  background: #ffffff;
  color: var(--text-main);
  box-shadow: 0 10px 30px -5px rgba(15, 23, 42, 0.12), 0 20px 45px -10px rgba(15, 23, 42, 0.08), 0 0 0 1px rgba(15, 23, 42, 0.05);
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 13mm 14mm 14mm 16mm;
  box-sizing: border-box;
  transform-origin: top center;
  transition: transform 0.2s ease-out;
}

/* 1. Repeating Vertical Branding Text at the OUTER LEFT EDGE */
.a4-left-vertical-brand {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 1.5mm;
  width: 4.5mm;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  pointer-events: none;
  z-index: 4;
  user-select: none;
}

.a4-left-vertical-brand span {
  writing-mode: vertical-rl;
  font-family: var(--font-sans);
  font-size: 6px;
  font-weight: 700;
  letter-spacing: 2.2px;
  text-transform: uppercase;
  color: #482169;
  opacity: 0.38;
  white-space: nowrap;
}

/* 2. Left Accent Purple Line (sits AFTER the text, moving inward) */
.a4-left-accent-bar {
  position: absolute;
  top: 0;
  left: 6.8mm;
  width: 1.2mm;
  height: 100%;
  background: var(--primary-purple);
  z-index: 5;
}

/* Center Watermark Logo - Very faint watermark, 100% readable text & data */
.a4-watermark {
  position: absolute !important;
  top: 0 !important;
  left: 50% !important;
  transform: translateX(-50%) !important;
  width: 155mm !important;
  max-width: 82% !important;
  opacity: 0.045 !important; /* Rất mờ (4.5%), hoàn toàn không che chữ/số */
  mix-blend-mode: multiply !important;
  pointer-events: none !important;
  z-index: 0 !important;
  user-select: none !important;
}

.a4-sheet > .a4-watermark {
  top: 96mm !important;
}

/* A4 Content Wrapper */
.a4-content {
  position: relative;
  z-index: 3;
  display: flex;
  flex-direction: column;
  flex: 1;
  justify-content: space-between;
}

/* A4 Header */
.doc-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding-bottom: 12px;
  border-bottom: 1px solid #ebe5f0;
}

.doc-logo-area {
  display: flex;
  align-items: center;
}

.doc-logo {
  height: 48px;
  width: auto;
  object-fit: contain;
}

.doc-header-subtitle {
  text-align: right;
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-top: 15px;
}

.doc-header-subtitle .title {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 1.8px;
  color: var(--primary-purple);
  text-transform: uppercase;
}

.doc-header-subtitle .tagline {
  font-size: 8.5px;
  letter-spacing: 2px;
  font-weight: 500;
  color: #7b8190;
  text-transform: uppercase;
}

/* Document Title & Meta Ribbon */
.doc-title-section {
  margin-top: 14px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding-bottom: 8px;
}

.doc-main-title {
  font-family: var(--font-sans);
  font-size: 24px;
  font-weight: 800;
  color: var(--primary-purple);
  letter-spacing: 1.5px;
  line-height: 1.1;
  text-transform: uppercase;
}

.doc-main-title small {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: #7a7f8d;
  letter-spacing: 0.8px;
  margin-top: 3px;
}

.doc-meta-badge {
  text-align: right;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.doc-meta-row {
  font-size: 12px;
  color: #4b5262;
}

.doc-meta-row strong {
  color: var(--text-main);
  font-weight: 700;
}

.doc-meta-row .badge-code {
  background: var(--purple-soft);
  color: var(--primary-purple);
  padding: 2px 7px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 11.5px;
  border: 1px solid var(--purple-border);
}

/* Party Info (Supplier & Bill To Grid) - 2 Distinct Separate Cards */
.doc-parties-grid {
  display: grid;
  grid-template-columns: 35% 1fr;
  gap: 12px;
  margin-top: 10px;
  background: transparent;
  padding: 0;
  border: none;
}

.party-box {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 10px;
  line-height: 1.38;
  padding: 8px 10px;
  border-radius: 6px;
}

.party-box-supplier {
  background: #fdfcfe;
  border: 1px solid #ebe4f3;
  font-size: 8.8px;
  line-height: 1.35;
}

.party-box-client {
  background: #f9f6fc;
  border: 1px solid #dfd1ec;
  box-shadow: 0 1px 4px rgba(72, 33, 105, 0.04);
}

.party-header {
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--primary-purple);
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.party-name {
  font-weight: 700;
  color: #1a1b20;
  font-size: 11px;
}

.party-detail {
  color: #4f5565;
  font-size: 9.5px;
}

.party-box-supplier .party-detail {
  font-size: 8.8px;
  line-height: 1.35;
}

/* Items Table */
.doc-table-wrapper {
  margin-top: 22px;
  flex: 1;
  position: relative;
}

.doc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11.5px;
  position: relative;
  z-index: 1;
}

.doc-table th {
  background: var(--primary-purple);
  color: #ffffff;
  padding: 8px 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  font-size: 10px;
  border: none;
}

.doc-table th:first-child {
  border-top-left-radius: 6px;
  border-bottom-left-radius: 6px;
}
.doc-table th:last-child {
  border-top-right-radius: 6px;
  border-bottom-right-radius: 6px;
}

.doc-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #eeebf2;
  color: #2d3139;
  vertical-align: top;
  line-height: 1.4;
}

.doc-table tr:nth-child(even) td {
  background: rgba(253, 252, 254, 0.4);
}

.col-no { width: 35px; text-align: center; }
.col-desc { }
.col-unit { width: 60px; text-align: center; }
.col-qty { width: 50px; text-align: center; }
.col-price { width: 95px; text-align: right; }
.col-total { width: 110px; text-align: right; font-weight: 700; color: #1a1b22; }

/* Totals & Amount in words */
.doc-calculation-section {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.totals-wrapper {
  display: flex;
  justify-content: flex-end;
}

.totals-table {
  width: 280px;
  border-collapse: collapse;
  font-size: 12px;
}

.totals-table td {
  padding: 4px 6px;
}

.totals-table .label {
  color: #5d6373;
  text-align: right;
}

.totals-table .value {
  text-align: right;
  font-weight: 600;
  color: #1a1b22;
  font-family: var(--font-mono);
}

.totals-table tr.grand-total td {
  padding-top: 6px;
  border-top: 2px solid var(--primary-purple);
  font-size: 14px;
}

.totals-table tr.grand-total .label {
  color: var(--primary-purple);
  font-weight: 800;
  text-transform: uppercase;
}

.totals-table tr.grand-total .value {
  color: var(--primary-purple);
  font-weight: 800;
  font-size: 15px;
}

/* Words Box - Right-aligned */
.words-box {
  background: #fbf9fd;
  border-right: 3px solid var(--primary-purple);
  padding: 7px 12px;
  border-radius: 6px 0 0 6px;
  font-size: 11px;
  color: #3b3f49;
  line-height: 1.45;
  text-align: right;
}

.words-box strong {
  color: var(--primary-purple);
  font-weight: 700;
}

/* Notes directly under Amount in words (Italic) */
.doc-notes-under-words {
  margin-top: 4px;
  font-size: 9.5px;
  color: #4f5565;
  font-style: italic;
  text-align: right;
  line-height: 1.4;
  padding-right: 2px;
}

.doc-notes-under-words strong {
  font-weight: 700;
  color: var(--primary-purple);
  font-style: normal;
}

/* In-app Toast Notification */
.toast-notice {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #0f172a;
  color: #ffffff;
  border: 1px solid var(--primary-vibrant);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  padding: 12px 18px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 9999;
  animation: toastSlideUp 0.25s ease-out;
  pointer-events: none;
}

@keyframes toastSlideUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Closing Section: Payment Info + Signatures kept together */
.doc-closing-section {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  page-break-inside: avoid !important;
  break-inside: avoid !important;
}

/* Full Width Single-Row Payment Notes Card */
.payment-notes-card {
  width: 100%;
  font-size: 9.5px;
  color: #4b5262;
  line-height: 1.4;
  background: #faf8fc;
  padding: 7px 12px;
  border-radius: 6px;
  border: 1px dashed #d8cde3;
  display: flex;
  flex-direction: column;
  gap: 3px;
  box-sizing: border-box;
}

.payment-card-header .title {
  font-weight: 700;
  font-size: 9px;
  color: var(--primary-purple);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.payment-inline-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 16px;
  font-size: 9.5px;
}

.payment-inline-row .payment-item {
  white-space: nowrap;
}

.payment-sub-note {
  margin-top: 1px;
  font-size: 8.5px;
  color: #68408a;
  line-height: 1.35;
}

.highlight-acc {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--primary-purple);
  font-size: 11px;
}

.highlight-memo {
  font-family: var(--font-mono);
  font-weight: 700;
  color: #b07817;
  font-size: 10.5px;
}

/* Row 2: Split 2 Columns (Col 1: QR Left | Col 2: Signature Right) */
.closing-split-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: flex-end;
  gap: 16px;
  width: 100%;
}

.qr-col {
  display: flex;
  align-items: flex-end;
}

.qr-horizontal-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #ffffff;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid #dfd1ec;
  box-shadow: 0 1px 4px rgba(72, 33, 105, 0.05);
}

.qr-img {
  width: 76px;
  height: 76px;
  object-fit: contain;
  border-radius: 4px;
  border: 1px solid #f0eaf5;
  flex-shrink: 0;
}

.qr-info-box {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.qr-brand-label {
  display: flex;
  align-items: center;
  gap: 5px;
}

.qr-tag {
  background: #ee0033;
  color: #fff;
  font-size: 8px;
  font-weight: 800;
  padding: 1px 5px;
  border-radius: 3px;
  letter-spacing: 0.5px;
}

.qr-napas {
  color: var(--primary-purple);
  font-size: 8.5px;
  font-weight: 800;
  letter-spacing: 0.5px;
}

.qr-guide-text {
  font-size: 8px;
  color: #6a707f;
  line-height: 1.35;
  max-width: 170px;
}

.signature-col {
  display: flex;
  justify-content: flex-end;
  padding-right: 15px;
}

.signature-area {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 220px;
}

.sign-title {
  font-size: 10px;
  font-weight: 700;
  color: var(--primary-purple);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sign-subtitle {
  font-size: 8px;
  color: #7b8190;
}

.sign-spacer {
  height: 38px;
}

.sign-name {
  font-size: 11.5px;
  font-weight: 700;
  color: #1a1b22;
}

.sign-pos {
  font-size: 9px;
  color: #6a707f;
}

/* Physical Document Footer - 3 Columns Layout */
.doc-legal-footer {
  margin-top: 14px;
  padding-top: 7px;
  border-top: 1px solid var(--primary-purple);
  display: grid;
  grid-template-columns: 1.15fr 0.95fr 1fr;
  gap: 12px;
  align-items: center;
  font-size: 9px;
  color: #4b5262;
}

.footer-col {
  display: flex;
  align-items: center;
  gap: 5px;
}

.footer-col svg {
  color: var(--primary-purple);
  flex-shrink: 0;
}

.footer-col-address {
  line-height: 1.25;
}

.footer-col-phone {
  white-space: nowrap;
  font-weight: 600;
}

.footer-col-online {
  display: flex;
  flex-direction: column;
  gap: 2px;
  line-height: 1.2;
}

.footer-online-item {
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.footer-online-item svg {
  color: var(--primary-purple);
  flex-shrink: 0;
}

/* ===================================================================
   MODALS (DAY STYLE)
=================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-overlay.active {
  display: flex;
}

.modal-card {
  background: #ffffff;
  border-radius: 12px;
  width: 90%;
  max-width: 520px;
  box-shadow: 0 20px 45px -10px rgba(15, 23, 42, 0.25), 0 0 0 1px rgba(15, 23, 42, 0.06);
  border: 1px solid var(--border-light);
  overflow: hidden;
  animation: modalPop 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  max-height: 88vh;
}

.stats-modal-card {
  max-width: 760px;
}

@keyframes modalPop {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

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

.modal-header h3 {
  font-size: 14px;
  font-weight: 700;
  color: #0f172a;
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-close-btn {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-muted);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: all 0.2s;
}
.modal-close-btn:hover {
  background: #fee2e2;
  color: #dc2626;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: #ffffff;
}

.modal-footer {
  padding: 12px 20px;
  background: #f8fafc;
  border-top: 1px solid var(--border-light);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.kpi-card {
  background: #f8fafc;
  border: 1px solid var(--border-light);
  border-radius: 10px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.kpi-card.kpi-highlight {
  border-color: #f59e0b;
  background: #fffbeb;
}

.kpi-title {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
}

.kpi-val {
  font-size: 18px;
  font-weight: 800;
  color: #0f172a;
}
.kpi-card.kpi-highlight .kpi-val {
  color: #b45309;
}

.kpi-sub {
  font-size: 10px;
  color: #64748b;
}

/* Stats & History Table */
.stats-table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  max-height: 280px;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.stats-table th {
  background: #f1f5f9;
  padding: 10px 12px;
  text-align: left;
  font-weight: 700;
  color: #475569;
  border-bottom: 1px solid var(--border-light);
  position: sticky;
  top: 0;
}
.stats-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-light);
  color: #1e293b;
}
.stats-table tr:hover td {
  background: #f8fafc;
}

/* Archive item cards */
.archive-item-card {
  background: #ffffff;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
  transition: all 0.2s;
}
.archive-item-card:hover {
  border-color: #cbd5e1;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.05);
}
.archive-item-no {
  font-weight: 700;
  color: var(--text-main);
  font-size: 13px;
}
.archive-item-meta {
  font-size: 11px;
  color: var(--text-muted);
}
.archive-item-amount {
  font-size: 12.5px;
  font-weight: 700;
  color: #b45309;
  margin-top: 2px;
}

/* ===================================================================
   AUTHENTICATION & LOGIN SCREEN (DAY STYLE / ELEGANT AMBIENCE)
=================================================================== */
.login-screen {
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: radial-gradient(circle at 50% 20%, #ede9fe 0%, #cbd5e1 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(10px);
}
.login-screen.hidden {
  display: none !important;
}

.login-card {
  background: #ffffff;
  border-radius: 16px;
  border: 1px solid var(--border-light);
  box-shadow: 0 20px 45px rgba(76, 29, 149, 0.12), 0 4px 12px rgba(0, 0, 0, 0.04);
  width: 100%;
  max-width: 440px;
  padding: 34px 30px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: modalPop 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.login-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
}

.login-logo {
  height: 52px;
  width: auto;
  object-fit: contain;
  margin-bottom: 6px;
}

.login-title {
  font-size: 17px;
  font-weight: 800;
  color: #3b0764;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.login-subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-input-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.login-input-group label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-label);
  text-transform: uppercase;
}

.login-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}
.login-input-wrapper svg {
  position: absolute;
  left: 12px;
  color: var(--text-muted);
  pointer-events: none;
}
.login-input-wrapper input {
  width: 100%;
  padding: 11px 14px 11px 38px;
  background: #f8fafc;
  border: 1px solid var(--border-input);
  border-radius: 8px;
  color: var(--text-main);
  font-size: 13px;
  font-family: inherit;
  transition: all 0.2s;
}
.login-input-wrapper input:focus {
  outline: none;
  background: #ffffff;
  border-color: #7c3aed;
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.15);
}

.login-btn-submit {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: linear-gradient(135deg, #7c3aed, #5b21b6);
  color: #fff;
  border: none;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(124, 58, 237, 0.35);
  transition: all 0.2s;
  margin-top: 6px;
}
.login-btn-submit:hover {
  background: linear-gradient(135deg, #6d28d9, #4c1d95);
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(124, 58, 237, 0.45);
}

.login-error-banner {
  background: #fee2e2;
  border: 1px solid #fecaca;
  color: #dc2626;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  display: none;
  align-items: center;
  gap: 8px;
}
.login-error-banner.active {
  display: flex;
}

/* ===================================================================
   RESPONSIVE ADJUSTMENTS
=================================================================== */
@media (max-width: 1080px) {
  .app-container {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }
  .form-panel {
    border-right: none;
    border-bottom: 1px solid var(--border-light);
    height: auto;
    max-height: 75vh;
  }
  .header-stepper {
    display: none;
  }
}

@media (max-width: 768px) {
  .app-header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 10px 14px;
  }
  .app-actions {
    overflow-x: auto;
    padding-bottom: 6px;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
  }
  .preview-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .preview-status {
    font-size: 11px;
    flex-wrap: wrap;
  }
  .preview-viewport {
    padding: 15px 5px 60px 5px;
  }
}
