/* ==========================================================================
   Fast Receipt Pro — Modern, Privacy-First Invoice & Receipt Generator
   Design System & Comprehensive Stylesheet
   ========================================================================== */

:root {
  /* Core Base Colors */
  --bg-app: #0f172a;
  --bg-surface: #1e293b;
  --bg-card: #ffffff;
  --bg-subtle: #f8fafc;
  --bg-input: #ffffff;
  
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --text-inverse: #ffffff;

  --border-color: #e2e8f0;
  --border-focus: #3b82f6;
  --border-dark: #334155;

  /* Brand Accents */
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --primary-border: #bfdbfe;

  --accent: #f59e0b;
  --accent-pro: #8b5cf6;
  
  /* Status Colors */
  --success: #16a34a;
  --success-bg: #dcfce7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --warning: #d97706;
  --warning-bg: #fef3c7;

  /* Typography */
  --font-sans: 'Plus Jakarta Sans', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  /* Shadows & Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  --shadow-sheet: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

/* Template Themes */
body[data-theme="slate"] {
  --theme-primary: #1e293b;
  --theme-accent: #3b82f6;
  --theme-bg-light: #f8fafc;
}
body[data-theme="minimal"] {
  --theme-primary: #18181b;
  --theme-accent: #71717a;
  --theme-bg-light: #fafafa;
}
body[data-theme="emerald"] {
  --theme-primary: #065f46;
  --theme-accent: #059669;
  --theme-bg-light: #f0fdf4;
}
body[data-theme="sand"] {
  --theme-primary: #78350f;
  --theme-accent: #d97706;
  --theme-bg-light: #fffbeb;
}
body[data-theme="indigo"] {
  --theme-primary: #3730a3;
  --theme-accent: #6366f1;
  --theme-bg-light: #eef2ff;
}
body[data-theme="mono"] {
  --theme-primary: #000000;
  --theme-accent: #52525b;
  --theme-bg-light: #f4f4f5;
}
body[data-theme="terracotta"] {
  --theme-primary: #9a3412;
  --theme-accent: #ea580c;
  --theme-bg-light: #fff7ed;
}
body[data-theme="burgundy"] {
  --theme-primary: #881337;
  --theme-accent: #be123c;
  --theme-bg-light: #fff1f2;
}
body[data-theme="teal"] {
  --theme-primary: #115e59;
  --theme-accent: #0d9488;
  --theme-bg-light: #f0fdfa;
}
body[data-theme="rose"] {
  --theme-primary: #9d174d;
  --theme-accent: #db2777;
  --theme-bg-light: #fdf2f8;
}
body[data-theme="forest"] {
  --theme-primary: #14532d;
  --theme-accent: #16a34a;
  --theme-bg-light: #f0fdf4;
}
body[data-theme="gold"] {
  --theme-primary: #1e293b;
  --theme-accent: #d97706;
  --theme-bg-light: #fefce8;
}

/* Base Resets */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 15px;
  scroll-behavior: smooth;
  box-sizing: border-box;
  overflow-x: clip;
  width: 100%;
}
*, *:before, *:after {
  box-sizing: inherit;
}

body {
  font-family: var(--font-sans);
  background-color: #f1f5f9;
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 100%;
  overflow-x: clip;
  margin: 0;
  padding: 0;
  position: relative;
}

/* Utility Classes */
.font-mono { font-family: var(--font-mono); }
.font-bold { font-weight: 700; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-muted { color: var(--text-muted); }

/* ==========================================================================
   Header Navigation Bar (Fixed / Sticky & Full-Width)
   ========================================================================== */
.app-header {
  background-color: #0f172a;
  color: #ffffff;
  position: sticky;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  min-width: 100%;
  z-index: 1000;
  border-bottom: 1px solid #1e293b;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  box-sizing: border-box;
}

.header-container {
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  box-sizing: border-box;
}

.brand-area {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  text-decoration: none;
  color: #ffffff;
  font-weight: 800;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}

.brand-icon {
  font-size: 1.35rem;
  filter: drop-shadow(0 0 8px rgba(250, 204, 21, 0.4));
}

.brand-pro {
  background: linear-gradient(135deg, #8b5cf6, #3b82f6);
  color: #ffffff;
  font-size: 0.7rem;
  font-weight: 800;
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-full);
  letter-spacing: 0.05em;
  margin-left: 0.2rem;
}

.brand-tagline {
  font-size: 0.75rem;
  color: #94a3b8;
  border-left: 1px solid #334155;
  padding-left: 0.75rem;
  display: none;
}

@media (min-width: 900px) {
  .brand-tagline { display: inline-block; }
}

/* Nav Tabs */
.nav-tabs {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background-color: #1e293b;
  padding: 0.25rem;
  border-radius: var(--radius-md);
  border: 1px solid #334155;
}

.nav-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.85rem;
  background: none;
  border: none;
  color: #94a3b8;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.nav-tab:hover {
  color: #ffffff;
  background-color: rgba(255, 255, 255, 0.05);
}

.nav-tab.active {
  background-color: var(--primary);
  color: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.badge-count {
  background-color: #334155;
  color: #ffffff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.1rem 0.4rem;
  border-radius: var(--radius-full);
}
.nav-tab.active .badge-count {
  background-color: rgba(0, 0, 0, 0.3);
}

/* Header Global Controls */
.header-controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.control-select-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  background-color: #1e293b;
  border: 1px solid #334155;
  border-radius: var(--radius-md);
  padding: 0 0.5rem;
  max-width: 100%;
}

.control-icon {
  font-size: 0.9rem;
  margin-right: 0.25rem;
  flex-shrink: 0;
}

.header-select {
  background: transparent;
  color: #ffffff;
  border: none;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.45rem 0.25rem;
  cursor: pointer;
  outline: none;
  max-width: 220px;
}
.header-select option {
  background-color: #1e293b;
  color: #ffffff;
  font-weight: 500;
}

/* Pro / Usage Counter Badge & Subscription Button */
.pro-badge-wrap {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.usage-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.15), rgba(139, 92, 246, 0.15));
  border: 1px solid rgba(139, 92, 246, 0.4);
  color: #e0e7ff;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-full);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.usage-badge:hover {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.3), rgba(139, 92, 246, 0.3));
  border-color: #8b5cf6;
  transform: translateY(-1px);
}

.usage-badge.unlocked {
  background: #dcfce7;
  border-color: #86efac;
  color: #166534;
}

.usage-dot {
  width: 7px;
  height: 7px;
  background-color: #38bdf8;
  border-radius: 50%;
  box-shadow: 0 0 6px #38bdf8;
  flex-shrink: 0;
}
.usage-badge.unlocked .usage-dot {
  background-color: #22c55e;
  box-shadow: 0 0 6px #22c55e;
}

.btn-header-subscription {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: linear-gradient(135deg, #8b5cf6, #3b82f6);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-full);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(139, 92, 246, 0.35);
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-header-subscription:hover {
  background: linear-gradient(135deg, #7c3aed, #2563eb);
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.5);
  transform: translateY(-1px);
}

.btn-header-subscription.pro-active {
  background: linear-gradient(135deg, #10b981, #059669);
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.35);
}

.sub-spark {
  font-size: 0.85rem;
}

/* Responsive Header Layout for Mobile and Tablet */
@media (max-width: 960px) {
  .header-container {
    padding: 0.5rem 0.65rem;
    gap: 0.45rem;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow: hidden;
  }
  .brand-area {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .nav-tabs {
    width: 100%;
    display: flex;
    justify-content: space-between;
    box-sizing: border-box;
  }
  .nav-tab {
    flex: 1 1 0;
    justify-content: center;
    padding: 0.45rem 0.2rem;
    font-size: 0.76rem;
    white-space: nowrap;
    min-width: 0;
  }
  .nav-tab svg {
    flex-shrink: 0;
    width: 15px;
    height: 15px;
  }
  .header-controls {
    width: 100%;
    max-width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 0.35rem;
    box-sizing: border-box;
  }
  .control-select-wrap {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
    overflow: hidden;
    padding: 0 0.35rem;
  }
  .header-select {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    font-size: 0.72rem;
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
    box-sizing: border-box;
  }
  .usage-badge {
    grid-column: 1 / -1;
    width: 100%;
    justify-content: center;
    padding: 0.4rem 0.75rem;
    box-sizing: border-box;
    font-size: 0.75rem;
  }
}

/* ==========================================================================
   Main Layout & Panes
   ========================================================================== */
.main-wrapper {
  flex: 1;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem;
  box-sizing: border-box;
}

@media (max-width: 768px) {
  .main-wrapper {
    padding: 0.75rem;
  }
}

.tab-pane {
  display: none;
  animation: fadeIn 0.2s ease-in-out;
}
.tab-pane.active {
  display: block;
}

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

/* ==========================================================================
   Builder Layout (2-Column Grid)
   ========================================================================== */
.builder-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
  align-items: start;
}

@media (min-width: 1024px) {
  .builder-layout {
    grid-template-columns: minmax(480px, 1fr) minmax(500px, 1.05fr);
    gap: 2rem;
  }
}

/* Editor Form Card */
.builder-editor-card {
  background-color: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* Top Action Bar (Mode Switcher) */
.action-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.doc-mode-toggle {
  display: inline-flex;
  background-color: #f1f5f9;
  padding: 0.25rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.mode-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.85rem;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.mode-check {
  display: none;
  font-size: 0.8rem;
  font-weight: 900;
  color: #ffffff;
  background-color: rgba(255, 255, 255, 0.25);
  border-radius: 50%;
  width: 16px;
  height: 16px;
  line-height: 16px;
  text-align: center;
}

.mode-btn.active {
  background-color: var(--theme-primary, #1e293b);
  color: #ffffff;
  box-shadow: var(--shadow-sm);
}

.mode-btn.active .mode-check {
  display: inline-block;
}

.topbar-actions {
  display: flex;
  gap: 0.5rem;
}

/* Document Meta Grid */
.doc-meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.75rem;
  background-color: var(--bg-subtle);
  padding: 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

/* Form Controls & Inputs */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  width: 100%;
}

.form-group label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.form-input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9rem;
  background-color: #ffffff;
  color: var(--text-main);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.form-input.input-bold {
  font-weight: 700;
  font-size: 1rem;
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

@media (max-width: 500px) {
  .form-row-2 { grid-template-columns: 1fr; }
}

.input-with-action {
  display: flex;
  gap: 0.35rem;
}

.btn-input-action {
  background-color: #ffffff;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0 0.65rem;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn-input-action:hover {
  background-color: #f1f5f9;
  border-color: var(--primary);
}

/* Accordion Sections */
.editor-section {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.section-title {
  background-color: var(--bg-subtle);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  gap: 0.5rem;
}

.section-title h3 {
  font-size: 0.95rem;
  font-weight: 700;
  flex: 1;
}

.section-number {
  background-color: var(--theme-primary, #1e293b);
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 800;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.section-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.section-toggle {
  background: none;
  border: none;
  font-size: 1.1rem;
  color: var(--text-muted);
  cursor: pointer;
}

.section-body {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background-color: #ffffff;
}
.section-body.collapsed {
  display: none;
}

.section-visibility-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-muted, #64748b);
  cursor: pointer;
  user-select: none;
  background-color: #f8fafc;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-sm, 4px);
  border: 1px solid var(--border-color, #e2e8f0);
  transition: all 0.15s ease;
}
.section-visibility-toggle:hover {
  background-color: #f1f5f9;
  color: var(--text-main, #0f172a);
}
.section-visibility-toggle input[type="checkbox"] {
  cursor: pointer;
  accent-color: var(--primary, #2563eb);
}

.branding-option-card {
  background-color: #ffffff;
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: var(--radius-md, 8px);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  margin-top: 0.25rem;
}
.branding-checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main, #0f172a);
  cursor: pointer;
  width: 100%;
}
.branding-checkbox-label input[type="checkbox"] {
  cursor: pointer;
  accent-color: var(--primary, #2563eb);
  width: 16px;
  height: 16px;
}
.branding-label-text {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.badge-pro-pill {
  background: linear-gradient(135deg, #8b5cf6, #3b82f6);
  color: #ffffff;
  font-size: 0.65rem;
  font-weight: 800;
  padding: 0.12rem 0.45rem;
  border-radius: 9999px;
  letter-spacing: 0.05em;
}

/* Logo Dropzone & From Grid */
.from-grid {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 1rem;
}

@media (max-width: 540px) {
  .from-grid { grid-template-columns: 1fr; }
}

.logo-dropzone {
  border: 2px dashed #cbd5e1;
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0.75rem;
  cursor: pointer;
  background-color: #f8fafc;
  transition: all 0.15s ease;
  min-height: 120px;
  position: relative;
}

.logo-dropzone:hover {
  border-color: var(--primary);
  background-color: var(--primary-light);
}

.logo-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.logo-icon { font-size: 1.5rem; }
.logo-text { font-size: 0.8rem; font-weight: 700; color: var(--text-main); }
.logo-hint { font-size: 0.65rem; color: var(--text-muted); }

.logo-preview-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo-preview-wrap img {
  max-width: 100%;
  max-height: 100px;
  object-fit: contain;
  border-radius: var(--radius-sm);
}

.logo-remove-btn {
  position: absolute;
  top: -8px;
  right: -8px;
  background-color: var(--danger);
  color: #ffffff;
  border: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 0.9rem;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
}

.from-fields {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Client Quick Select */
.client-quick-select {
  font-size: 0.75rem;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background-color: #ffffff;
  color: var(--text-main);
  max-width: 200px;
}

.save-client-checkbox {
  margin-top: 0.25rem;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  cursor: pointer;
}

/* Line Items Table */
.line-items-container {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 100%;
}

.items-table-header {
  display: grid;
  grid-template-columns: minmax(130px, 3fr) 60px 85px 65px 85px 35px;
  gap: 0.4rem;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0 0.25rem;
}

.item-row {
  display: grid;
  grid-template-columns: minmax(130px, 3fr) 60px 85px 65px 85px 35px;
  gap: 0.4rem;
  align-items: center;
  background-color: #f8fafc;
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  transition: border-color 0.15s ease;
}

.item-row:hover {
  border-color: #cbd5e1;
}

.item-total-col {
  font-size: 0.85rem;
  font-weight: 700;
  text-align: right;
  padding-right: 0.25rem;
}

.btn-remove-row {
  background: none;
  border: none;
  color: var(--text-light);
  font-size: 1.1rem;
  cursor: pointer;
  transition: color 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-remove-row:hover {
  color: var(--danger);
}

@media (max-width: 600px) {
  .items-table-header { display: none; }
  .item-row {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto auto;
    gap: 0.5rem;
    padding: 0.75rem;
  }
  .item-row .row-desc { grid-column: 1 / -1; }
  .item-row .row-qty { grid-column: 1 / 2; }
  .item-row .row-rate { grid-column: 2 / 3; }
  .item-row .row-tax { grid-column: 1 / 2; }
  .item-row .item-total-col { grid-column: 2 / 3; text-align: left; }
  .item-row .btn-remove-row { grid-column: 2 / 3; justify-self: end; }
}

/* Quick Items Shelf */
.quick-items-shelf {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  padding-top: 0.5rem;
}

.shelf-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
}

.chip-btn {
  background-color: #f1f5f9;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  padding: 0.25rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.15s ease;
}
.chip-btn:hover {
  background-color: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

/* Summary Calculations Box */
.invoice-summary-box {
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 0.5rem;
}

.summary-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
}

.summary-control-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.control-label-group {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.control-input-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.small-select, .small-text-input, .small-number-input {
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  background-color: #ffffff;
}
.small-number-input {
  width: 75px;
  text-align: right;
  font-family: var(--font-mono);
}
.small-text-input {
  width: 90px;
}

.summary-grand-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 0.75rem;
  border-top: 2px solid var(--text-main);
  margin-top: 0.25rem;
}

.grand-total-label {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text-main);
}

.grand-total-amount {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--theme-primary, #1e293b);
}

/* Payment & QR Grid */
.payment-grid {
  display: grid;
  grid-template-columns: 1fr 140px;
  gap: 1rem;
}

@media (max-width: 520px) {
  .payment-grid { grid-template-columns: 1fr; }
}

.payment-inputs {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.qr-preview-card {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-color: #ffffff;
  text-align: center;
}

.qr-box {
  width: 100px;
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.qr-box img {
  width: 100% !important;
  height: 100% !important;
}

.qr-caption {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 0.4rem;
}

/* ==========================================================================
   Right Column: Export Toolbar & Live Preview
   ========================================================================== */
.builder-preview-col {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.export-toolbar-card {
  background-color: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.export-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.export-heading h4 {
  font-size: 1.05rem;
  font-weight: 800;
}

.export-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.preview-layout-pills {
  display: inline-flex;
  background-color: #f1f5f9;
  padding: 0.25rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.pill-check {
  display: none;
  font-size: 0.75rem;
  font-weight: 900;
  color: #ffffff;
  background-color: rgba(255, 255, 255, 0.25);
  border-radius: 50%;
  width: 15px;
  height: 15px;
  line-height: 15px;
  text-align: center;
}

.pill-btn.active {
  background-color: #0f172a;
  color: #ffffff;
}

.pill-btn.active .pill-check {
  display: inline-block;
}

.export-buttons-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.6rem;
}

.btn-export {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem 0.85rem;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border-color);
  background-color: #ffffff;
  color: var(--text-main);
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s ease;
}

.btn-export:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.btn-export-text {
  display: flex;
  flex-direction: column;
}

.btn-export-text strong {
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1.2;
}

.btn-export-text small {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.btn-export-pdf {
  background: linear-gradient(135deg, #1e293b, #0f172a);
  color: #ffffff;
  border-color: #0f172a;
}
.btn-export-pdf small { color: #94a3b8; }

.btn-export-thermal {
  background: #f8fafc;
  border-color: #334155;
}

.btn-export-docx {
  border-color: #bfdbfe;
  background-color: #eff6ff;
  color: #1e40af;
}

.btn-export-csv {
  border-color: #bbf7d0;
  background-color: #f0fdf4;
  color: #166534;
}

.btn-export-print {
  border-color: #fed7aa;
  background-color: #fff7ed;
  color: #9a3412;
}

/* Live Preview Outer Wrapper */
.live-preview-wrapper {
  display: flex;
  justify-content: center;
  background-color: #cbd5e1;
  padding: 1.5rem;
  border-radius: var(--radius-lg);
  overflow-x: auto;
  min-height: 600px;
}

/* ==========================================================================
   1. STANDARD A4 INVOICE SHEET (Pixel-Perfect High-Res Rendering)
   ========================================================================== */
.invoice-sheet {
  background-color: #ffffff;
  width: 100%;
  max-width: 780px;
  min-height: 950px;
  padding: 3rem 2.5rem;
  border-radius: 4px;
  box-shadow: var(--shadow-sheet);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  color: #1e293b;
  font-size: 0.95rem;
}

/* Watermark Rubber Stamp */
.stamp-watermark {
  position: absolute;
  top: 35%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-15deg);
  border: 5px solid #dc2626;
  color: #dc2626;
  font-size: 3.5rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  padding: 0.5rem 2rem;
  border-radius: 12px;
  opacity: 0.22;
  pointer-events: none;
  user-select: none;
  z-index: 10;
}

.stamp-watermark.stamp-paid { border-color: #16a34a; color: #16a34a; }
.stamp-watermark.stamp-overdue { border-color: #dc2626; color: #dc2626; }
.stamp-watermark.stamp-draft { border-color: #64748b; color: #64748b; }
.stamp-watermark.stamp-void { border-color: #000000; color: #000000; }

.sheet-header {
  display: flex;
  justify-content: space-between;
  gap: 2rem;
  padding-bottom: 2rem;
  border-bottom: 2px solid var(--theme-primary, #1e293b);
}

.sheet-logo-col {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-width: 60%;
}

.sheet-logo {
  max-width: 160px;
  max-height: 70px;
  object-fit: contain;
}

.sheet-biz-name {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--theme-primary, #1e293b);
  line-height: 1.2;
}

.sheet-text-muted {
  font-size: 0.85rem;
  color: #64748b;
  line-height: 1.4;
}

.sheet-doc-meta {
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.sheet-doc-title {
  font-size: 2.2rem;
  font-weight: 900;
  letter-spacing: -0.03em;
  color: var(--theme-primary, #1e293b);
  line-height: 1;
  margin-bottom: 0.75rem;
}

.meta-table {
  border-collapse: collapse;
  font-size: 0.9rem;
}
.meta-table th {
  text-align: right;
  padding: 0.2rem 0.5rem;
  color: #64748b;
  font-weight: 600;
}
.meta-table td {
  text-align: right;
  padding: 0.2rem 0;
}

.sheet-parties-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  margin: 2rem 0;
  padding: 1.25rem;
  background-color: var(--theme-bg-light, #f8fafc);
  border-radius: var(--radius-sm);
  border-left: 4px solid var(--theme-primary, #1e293b);
}

.sheet-section-label {
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #64748b;
  margin-bottom: 0.35rem;
}

.sheet-client-name {
  font-size: 1.2rem;
  font-weight: 700;
  color: #0f172a;
}

.sheet-quick-summary {
  text-align: right;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-end;
}

.sheet-amount-callout {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--theme-primary, #1e293b);
}

.sheet-currency-badge {
  font-size: 0.75rem;
  font-weight: 700;
  color: #64748b;
}

/* Sheet Table */
.sheet-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
}

.sheet-table thead th {
  background-color: var(--theme-primary, #1e293b);
  color: #ffffff;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.65rem 0.75rem;
  text-align: left;
}

.sheet-table thead th.th-num { width: 35px; text-align: center; }
.sheet-table thead th.th-qty { width: 65px; text-align: center; }
.sheet-table thead th.th-rate { width: 90px; text-align: right; }
.sheet-table thead th.th-tax { width: 75px; text-align: center; }
.sheet-table thead th.th-amount { width: 100px; text-align: right; }

.sheet-table tbody td {
  padding: 0.75rem;
  border-bottom: 1px solid #e2e8f0;
  font-size: 0.9rem;
}

.sheet-table tbody tr:nth-child(even) {
  background-color: #fafbfc;
}

.sheet-table td.td-num { text-align: center; color: #94a3b8; font-weight: 600; }
.sheet-table td.td-qty { text-align: center; font-family: var(--font-mono); }
.sheet-table td.td-rate { text-align: right; font-family: var(--font-mono); }
.sheet-table td.td-tax { text-align: center; font-family: var(--font-mono); color: #64748b; }
.sheet-table td.td-amount { text-align: right; font-family: var(--font-mono); font-weight: 700; }

/* Totals & Notes Section */
.sheet-totals-section {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 2rem;
  margin-top: 1.5rem;
  padding-top: 1rem;
}

.sheet-payment-box {
  background-color: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  font-size: 0.8rem;
  line-height: 1.5;
  margin-bottom: 0.5rem;
}

.sheet-terms-box {
  font-size: 0.8rem;
  color: #64748b;
  font-style: italic;
}

.sheet-calculations-col {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.sheet-calc-table {
  width: 100%;
  border-collapse: collapse;
}

.sheet-calc-table th {
  text-align: right;
  padding: 0.35rem 0.75rem;
  font-size: 0.9rem;
  color: #64748b;
  font-weight: 600;
}

.sheet-calc-table td {
  text-align: right;
  padding: 0.35rem 0;
  font-size: 0.95rem;
}

.sheet-calc-table tr.sheet-calc-grand th {
  font-size: 1.15rem;
  font-weight: 800;
  color: #0f172a;
  border-top: 2px solid var(--theme-primary, #1e293b);
  padding-top: 0.6rem;
}

.sheet-calc-table tr.sheet-calc-grand td {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--theme-primary, #1e293b);
  border-top: 2px solid var(--theme-primary, #1e293b);
  padding-top: 0.6rem;
}

.sheet-qr-box {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  border: 1px solid #e2e8f0;
  padding: 0.5rem;
  border-radius: var(--radius-sm);
}

.sheet-footer {
  margin-top: auto;
  padding-top: 2rem;
  border-top: 1px solid #e2e8f0;
  text-align: center;
  font-size: 0.75rem;
  color: #94a3b8;
}

/* ==========================================================================
   2. THERMAL POS RECEIPT SHEET (80mm / 58mm Condensed Layout)
   ========================================================================== */
.thermal-receipt-sheet {
  background-color: #ffffff;
  width: 320px;
  padding: 1.5rem 1.25rem;
  border-radius: 4px;
  box-shadow: var(--shadow-sheet);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.4;
  color: #000000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.thermal-header {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
}

.thermal-logo {
  max-width: 90px;
  max-height: 45px;
  object-fit: contain;
  margin-bottom: 0.25rem;
  filter: grayscale(100%) contrast(150%);
}

.thermal-title {
  font-size: 1.1rem;
  font-weight: 800;
  text-transform: uppercase;
}

.thermal-muted {
  font-size: 0.72rem;
  color: #333333;
}

.thermal-divider-dashed {
  border-top: 1px dashed #000000;
  margin: 0.35rem 0;
}

.thermal-divider-double {
  border-top: 3px double #000000;
  margin: 0.35rem 0;
}

.thermal-meta-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
}

.thermal-items-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.thermal-item-row {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.thermal-item-desc {
  font-weight: 700;
  word-break: break-word;
}

.thermal-item-math {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
}

.thermal-summary {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.thermal-calc-row {
  display: flex;
  justify-content: space-between;
}

.thermal-calc-grand {
  display: flex;
  justify-content: space-between;
  font-size: 1rem;
}

.thermal-stamp-badge {
  text-align: center;
  font-size: 1.1rem;
  font-weight: 800;
  padding: 0.3rem;
  border: 2px dashed #000000;
  margin: 0.4rem 0;
}

.thermal-footer {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding-top: 0.25rem;
}

.thermal-payment-note {
  font-size: 0.72rem;
}

.thermal-qr-wrap {
  margin: 0.25rem 0;
}

.thermal-thanks {
  font-size: 0.75rem;
  font-weight: 700;
}

.thermal-tiny-id {
  font-size: 0.65rem;
  color: #666666;
}

/* ==========================================================================
   Bookkeeping Log & Ledger Tab
   ========================================================================== */
.ledger-container, .clients-container {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.ledger-header-card, .clients-header-card {
  background-color: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  padding: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.ledger-title-group h2, .clients-header-card h2 {
  font-size: 1.35rem;
  font-weight: 800;
}

.ledger-title-group p, .clients-header-card p {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.ledger-actions-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.ledger-reporting-box {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background-color: #f8fafc;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.35rem 0.65rem;
}

.reporting-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
}

.reporting-select {
  border: none;
  background: transparent;
  outline: none;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-main);
  cursor: pointer;
}

.ledger-search-box {
  display: flex;
  align-items: center;
  background-color: #f8fafc;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.45rem 0.75rem;
  gap: 0.4rem;
}

.ledger-search-box input {
  border: none;
  background: transparent;
  outline: none;
  font-family: inherit;
  font-size: 0.85rem;
  width: 200px;
}

/* Financial Stat Cards */
.ledger-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

.stat-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
}

.stat-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 800;
  margin-top: 0.35rem;
}

/* Table Card */
.ledger-table-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.ledger-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.ledger-table thead th {
  background-color: #f8fafc;
  border-bottom: 1.5px solid var(--border-color);
  padding: 0.85rem 1rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  text-align: left;
}

.ledger-table tbody td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border-color);
}

.ledger-table tbody tr:hover {
  background-color: #f1f5f9;
}

.status-badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}

.status-badge.paid { background-color: var(--success-bg); color: var(--success); }
.status-badge.draft { background-color: #f1f5f9; color: #64748b; }
.status-badge.overdue { background-color: var(--danger-bg); color: var(--danger); }
.status-badge.sent { background-color: #e0f2fe; color: #0284c7; }
.status-badge.none { background-color: #f1f5f9; color: #64748b; }

.table-actions-cell {
  display: flex;
  gap: 0.35rem;
}

.btn-table-action {
  padding: 0.3rem 0.55rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background-color: #ffffff;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-table-action:hover {
  background-color: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

.btn-table-action.delete:hover {
  background-color: var(--danger-bg);
  border-color: var(--danger);
  color: var(--danger);
}

/* Empty States */
.ledger-empty-state {
  padding: 4rem 1.5rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.empty-icon { font-size: 3rem; }
.ledger-empty-state h3 { font-size: 1.25rem; font-weight: 800; }
.ledger-empty-state p { font-size: 0.9rem; color: var(--text-muted); max-width: 400px; }

/* Clients Grid */
.clients-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.client-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 1rem;
  transition: all 0.15s ease;
}

.client-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
}

.client-card-name {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
}

.client-card-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.client-card-actions {
  display: flex;
  gap: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border-color);
}

/* ==========================================================================
   Buttons System
   ========================================================================== */
.btn-primary, .btn-secondary, .btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
}

.btn-primary {
  background-color: var(--primary);
  color: #ffffff;
  border: 1.5px solid var(--primary);
  box-shadow: 0 1px 3px rgba(37, 99, 235, 0.2);
}
.btn-primary:hover {
  background-color: var(--primary-hover);
  border-color: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  background-color: #ffffff;
  color: var(--text-main);
  border: 1.5px solid var(--border-color);
}
.btn-secondary:hover {
  background-color: #f8fafc;
  border-color: #cbd5e1;
}

.btn-ghost {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
}
.btn-ghost:hover {
  background-color: #f1f5f9;
  color: var(--text-main);
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.78rem;
}

.btn-link {
  background: none;
  border: none;
  color: var(--primary);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}

/* ==========================================================================
   Modal Dialogs & Paywall
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(5px);
  z-index: 2147483647;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: calc(var(--header-height, 60px) + 2rem) 1rem 2.5rem;
  overflow-y: auto;
  animation: fadeIn 0.2s ease-in-out;
  box-sizing: border-box;
}

.modal-backdrop.active {
  display: flex !important;
  visibility: visible !important;
  opacity: 1 !important;
}

.modal-dialog {
  background-color: #ffffff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  max-width: 520px;
  width: 100%;
  padding: 2rem;
  position: relative;
  margin: 1rem auto 2rem;
  box-sizing: border-box;
}

.modal-close-btn {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
}

/* Paywall Specific Dialog */
.paywall-dialog {
  max-width: 960px;
  text-align: center;
  margin: 1rem auto 2rem;
}

.paywall-badge-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: linear-gradient(135deg, #8b5cf6, #3b82f6);
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  padding: 0.3rem 0.85rem;
  border-radius: var(--radius-full);
  margin-bottom: 0.75rem;
}

.paywall-title {
  font-size: 1.75rem;
  font-weight: 900;
  color: #0f172a;
}

.paywall-subtitle {
  font-size: 0.95rem;
  color: var(--text-muted);
  max-width: 680px;
  margin: 0.5rem auto 1.75rem;
  line-height: 1.5;
}

.pricing-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.pricing-cards-grid.two-cards {
  grid-template-columns: 1fr 1fr;
}

.pricing-cards-grid.three-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.25rem;
  margin-bottom: 1.5rem;
  align-items: stretch;
}

@media (max-width: 860px) {
  .pricing-cards-grid.three-cards {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .pricing-cards-grid.two-cards {
    grid-template-columns: 1fr;
  }
}

.pricing-card {
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  background-color: #ffffff;
  display: flex;
  flex-direction: column;
  text-align: left;
  position: relative;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.pricing-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}

.pricing-card.featured {
  border: 2px solid var(--primary);
  background: linear-gradient(180deg, #f0f9ff 0%, #ffffff 100%);
  box-shadow: 0 4px 20px rgba(14, 165, 233, 0.12);
}

.pricing-card.free-tier-card {
  background-color: #f8fafc;
  border-color: #e2e8f0;
}

.card-featured-badge {
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  background-color: var(--primary);
  color: #ffffff;
  font-size: 0.68rem;
  font-weight: 800;
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-full);
  letter-spacing: 0.05em;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(14, 165, 233, 0.3);
}

.plan-name {
  font-size: 1.15rem;
  font-weight: 800;
  color: #0f172a;
}

.plan-price {
  font-size: 2.2rem;
  font-weight: 900;
  color: #0f172a;
  margin: 0.4rem 0 1rem;
}

.plan-price .currency { font-size: 1.2rem; vertical-align: top; }
.plan-price .period { font-size: 0.9rem; font-weight: 500; color: var(--text-muted); margin-left: 0.25rem; }

.plan-features-checklist {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  font-size: 0.82rem;
  color: #334155;
  margin-bottom: 1.5rem;
  flex: 1;
  padding: 0;
}

.plan-features-checklist li {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  line-height: 1.35;
}

.plan-features-checklist .check-icon {
  color: var(--success);
  font-weight: 800;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.plan-features-checklist .cross-icon {
  color: #94a3b8;
  font-weight: 800;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.plan-btn-container {
  margin-top: auto;
}

.btn-current-plan {
  background-color: #e2e8f0 !important;
  color: #475569 !important;
  border: 1px solid #cbd5e1 !important;
  cursor: default !important;
  font-weight: 700 !important;
  opacity: 0.9;
}

.paywall-free-note {
  background-color: #f8fafc;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1.5rem;
  text-align: left;
}

.paywall-free-note .free-badge {
  background-color: #e2e8f0;
  color: #475569;
  font-size: 0.65rem;
  font-weight: 800;
  padding: 0.15rem 0.4rem;
  border-radius: var(--radius-sm);
  letter-spacing: 0.05em;
  flex-shrink: 0;
}

.btn-plan {
  width: 100%;
  padding: 0.75rem;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 700;
}

/* Label with Action Button */
.label-with-action {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.35rem;
}

.label-with-action label {
  margin-bottom: 0;
}

.btn-text-action {
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  transition: all 0.15s ease;
}

.btn-text-action:hover {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

/* Header Usage Badge Variants */
.usage-badge.trial-ended {
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  color: #92400e;
  border-color: #f59e0b;
}

.usage-badge.trial-ended .usage-dot {
  background-color: #f59e0b;
}

/* Ledger Paused Banner */
.ledger-paused-banner {
  background: #fffbeb;
  border: 1.5px solid #fde68a;
  border-radius: var(--radius-md);
  padding: 0.9rem 1.25rem;
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.ledger-paused-banner .banner-content {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  text-align: left;
}

.ledger-paused-banner .banner-icon {
  font-size: 1.4rem;
}

.ledger-paused-banner strong {
  font-size: 0.88rem;
  color: #92400e;
  display: block;
}

.ledger-paused-banner p {
  font-size: 0.8rem;
  color: #b45309;
  margin: 0.15rem 0 0 0;
}

@media (max-width: 720px) {
  .ledger-paused-banner {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* Currency Conversion Modal */
.fx-dialog {
  max-width: 500px;
}

.fx-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  text-align: left;
}

.fx-icon {
  font-size: 1.8rem;
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  flex-shrink: 0;
}

.fx-header h3 {
  font-size: 1.2rem;
  font-weight: 800;
  color: #0f172a;
  margin: 0;
}

.fx-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0.15rem 0 0 0;
}

.fx-body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  text-align: left;
}

.fx-row {
  display: flex;
  gap: 0.75rem;
}

.flex-1 { flex: 1; }

.fx-source-chip {
  background: #f8fafc;
  border: 1px solid var(--border-color);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  color: #1e293b;
}

.margin-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.35rem;
}

.margin-badge {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #166534;
  font-size: 0.75rem;
  font-weight: 800;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
}

.form-range {
  width: 100%;
  accent-color: var(--primary);
  cursor: pointer;
}

.form-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
  display: block;
  line-height: 1.35;
}

.fx-preview-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.fx-rate-row, .fx-calc-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
}

.fx-rate-label, .fx-calc-label {
  color: var(--text-muted);
  font-size: 0.82rem;
}

.fx-calc-total {
  font-size: 1.15rem;
  color: var(--primary);
}

.fx-date-row {
  font-size: 0.72rem;
  color: #94a3b8;
  border-top: 1px dashed #e2e8f0;
  padding-top: 0.35rem;
  margin-top: 0.2rem;
}

.fx-offline-notice {
  background: #f1f5f9;
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
  color: #475569;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* Document Conversion Transparency Notes */
.sheet-conversion-note {
  margin-top: 0.6rem;
  padding: 0.4rem 0.6rem;
  background: #f8fafc;
  border-radius: var(--radius-sm);
  border: 1px solid #e2e8f0;
  font-size: 0.72rem;
  font-style: italic;
  color: #64748b;
  text-align: right;
  line-height: 1.35;
}

.thermal-conversion-note {
  margin-top: 0.4rem;
  font-size: 0.68rem;
  font-style: italic;
  color: #475569;
  text-align: center;
  padding: 0.25rem 0;
  border-top: 1px dashed #cbd5e1;
  line-height: 1.3;
}

/* Restore Box */
.restore-access-box {
  padding-top: 1.25rem;
  border-top: 1px dashed var(--border-color);
}

.restore-form {
  margin-top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.restore-input-group {
  display: flex;
  gap: 0.5rem;
}

.restore-input-group input {
  flex: 1 1 auto;
  min-width: 0;
}

.restore-status {
  font-size: 0.85rem;
  margin-top: 0.35rem;
}
.restore-status.success { color: var(--success); font-weight: 700; }
.restore-status.error { color: var(--danger); font-weight: 700; }

.modal-footer-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

/* Toast Container */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  background-color: #0f172a;
  color: #ffffff;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  animation: slideUp 0.2s ease-out;
}
.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }

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

/* Mobile and Tablet Layout Optimization */
@media (max-width: 768px) {
  .live-preview-wrapper {
    padding: 0.75rem 0.5rem;
    min-height: auto;
    justify-content: flex-start;
  }

  .invoice-sheet {
    padding: 1.5rem 1rem;
    font-size: 0.82rem;
    min-height: auto;
  }

  .sheet-header {
    flex-direction: column;
    gap: 1rem;
  }

  .sheet-logo-col {
    max-width: 100%;
  }

  .sheet-doc-meta {
    text-align: left;
    align-items: flex-start;
  }

  .sheet-doc-title {
    font-size: 1.75rem;
  }

  .meta-table th, .meta-table td {
    text-align: left;
    padding: 0.15rem 0.4rem 0.15rem 0;
  }

  .sheet-parties-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
    margin: 1.25rem 0;
    padding: 0.85rem;
  }

  .sheet-quick-summary {
    text-align: left;
    align-items: flex-start;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px dashed #cbd5e1;
  }

  .sheet-table thead th {
    padding: 0.45rem 0.4rem;
    font-size: 0.72rem;
  }

  .sheet-table tbody td {
    padding: 0.5rem 0.4rem;
    font-size: 0.8rem;
  }

  .sheet-totals-section {
    grid-template-columns: 1fr;
    gap: 1.25rem;
  }

  .sheet-calculations-col {
    align-items: stretch;
  }

  .export-buttons-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* ==========================================================================
   Print Styles (@media print)
   ========================================================================== */
@media print {
  body {
    background-color: #ffffff !important;
    color: #000000 !important;
    padding: 0 !important;
  }

  .app-header, .builder-editor-card, .export-toolbar-card, .modal-backdrop, .toast-container, .nav-tabs {
    display: none !important;
  }

  .main-wrapper {
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .builder-layout {
    display: block !important;
  }

  .live-preview-wrapper {
    background: none !important;
    padding: 0 !important;
  }

  .invoice-sheet {
    box-shadow: none !important;
    max-width: 100% !important;
    min-height: auto !important;
    padding: 0 !important;
  }

  .thermal-receipt-sheet {
    box-shadow: none !important;
    width: 100% !important;
    padding: 0 !important;
  }
}

/* ==========================================================================
   Locked Branding & New Features Styling
   ========================================================================== */

/* Locked Branding Option Card */
.branding-option-card.locked {
  background-color: #f8fafc;
  border-color: #cbd5e1;
  cursor: pointer;
}
.branding-option-card.locked .branding-checkbox-label {
  cursor: pointer;
  color: #64748b;
}
.branding-option-card.locked input[type="checkbox"] {
  cursor: not-allowed;
  opacity: 0.5;
}
.branding-lock-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.75rem;
}

/* FX Offline / Historical Estimate Warning */
.fx-estimate-warning {
  background-color: #fef3c7;
  border: 1px solid #fde68a;
  color: #92400e;
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  font-size: 0.78rem;
  line-height: 1.4;
  margin: 0.5rem 0;
}

/* Status Badges */
.status-badge.overdue {
  background-color: #fee2e2;
  color: #b91c1c;
  border: 1px solid #fca5a5;
  font-weight: 700;
}
.status-badge.partial {
  background-color: #fef3c7;
  color: #92400e;
  border: 1px solid #fde68a;
  font-weight: 700;
}

/* Catalog Modal & Shelf */
.catalog-dialog {
  max-width: 580px;
}
.catalog-chips-list {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.chip-btn.catalog-chip {
  background-color: #e0e7ff;
  color: #3730a3;
  border-color: #c7d2fe;
}
.chip-btn.catalog-chip:hover {
  background-color: #c7d2fe;
  color: #1e1b4b;
}
.chip-manage-catalog {
  background-color: #f1f5f9;
  border: 1px dashed #cbd5e1;
  color: #475569;
}
.chip-manage-catalog:hover {
  background-color: #e2e8f0;
  color: #0f172a;
}
.catalog-add-form {
  background-color: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1.25rem;
}
.catalog-add-form h4 {
  margin: 0 0 0.75rem 0;
  font-size: 0.9rem;
  color: #1e293b;
}
.form-row-3 {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.catalog-form-actions {
  display: flex;
  justify-content: flex-end;
}
.catalog-items-grid {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 220px;
  overflow-y: auto;
  margin-top: 0.5rem;
}
.catalog-item-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.85rem;
  background-color: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
}
.catalog-item-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.catalog-item-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: #0f172a;
}
.catalog-item-pricing {
  font-size: 0.75rem;
  color: #64748b;
}
.catalog-item-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* Send & Share Modal */
.send-dialog {
  max-width: 520px;
}
.modal-header-with-icon {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}
.modal-header-with-icon .header-icon {
  font-size: 2rem;
}
.modal-header-with-icon h3 {
  margin: 0 0 0.25rem 0;
  font-size: 1.2rem;
  color: #0f172a;
}
.modal-header-with-icon p {
  margin: 0;
  font-size: 0.85rem;
  color: #64748b;
}
.send-options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.send-option-card {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.85rem;
  background-color: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s ease;
}
.send-option-card:hover {
  background-color: #eff6ff;
  border-color: #3b82f6;
  transform: translateY(-1px);
}
.send-option-card .option-icon {
  font-size: 1.4rem;
}
.send-option-card .option-details {
  display: flex;
  flex-direction: column;
  flex: 1;
}
.send-option-card strong {
  font-size: 0.82rem;
  color: #0f172a;
}
.send-option-card small {
  font-size: 0.7rem;
  color: #64748b;
}
.send-option-card .option-arrow {
  color: #94a3b8;
  font-weight: bold;
}
.send-preview-box {
  margin-top: 0.5rem;
}
.send-preview-box label {
  font-size: 0.75rem;
  font-weight: 600;
  color: #64748b;
  margin-bottom: 0.25rem;
  display: block;
}
.btn-export-send {
  background: linear-gradient(135deg, #059669, #10b981) !important;
  color: #ffffff !important;
  border: none !important;
}
.btn-export-send:hover {
  background: linear-gradient(135deg, #047857, #059669) !important;
  transform: translateY(-2px);
}

/* Standalone Save to Ledger Button in Export Bar */
.btn-export-save {
  background: linear-gradient(135deg, #475569, #334155) !important;
  color: #ffffff !important;
  border: none !important;
}
.btn-export-save:hover {
  background: linear-gradient(135deg, #334155, #1e293b) !important;
  transform: translateY(-2px);
}

/* Save Client Row in Bill To section */
.save-client-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.75rem;
  padding-top: 0.5rem;
  border-top: 1px dashed var(--border-color);
  flex-wrap: wrap;
}

/* Custom Quick Add Items Shelf */
.quick-items-shelf {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
  margin-top: 0.75rem;
}
.chip-custom {
  background-color: #f0fdf4 !important;
  border-color: #86efac !important;
  color: #166534 !important;
  display: inline-flex !important;
  align-items: center !important;
  gap: 0.35rem !important;
}
.chip-custom:hover {
  background-color: #dcfce7 !important;
  border-color: #4ade80 !important;
}
.chip-delete-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background-color: #bbf7d0;
  color: #15803d;
  font-size: 0.75rem;
  font-weight: bold;
  line-height: 1;
  margin-left: 0.2rem;
  transition: all 0.15s ease;
}
.chip-delete-btn:hover {
  background-color: #ef4444;
  color: #ffffff;
}

/* Contextual Help Tooltips (❓) */
.tooltip-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: help;
  margin-left: 0.3rem;
  vertical-align: middle;
  outline: none;
}
.tooltip-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background-color: #e2e8f0;
  color: #475569;
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 1;
  user-select: none;
  transition: all 0.15s ease;
}
.tooltip-wrap:hover .tooltip-icon,
.tooltip-wrap:focus .tooltip-icon,
.tooltip-wrap:active .tooltip-icon {
  background-color: var(--primary);
  color: #ffffff;
  transform: scale(1.1);
}
.tooltip-box {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background-color: #0f172a;
  color: #f8fafc;
  padding: 0.45rem 0.65rem;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 400;
  line-height: 1.35;
  width: max-content;
  max-width: 220px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  z-index: 9999;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s ease, visibility 0.15s ease;
  text-align: left;
}
.tooltip-box::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border-width: 4px;
  border-style: solid;
  border-color: #0f172a transparent transparent transparent;
}
.tooltip-wrap:hover .tooltip-box,
.tooltip-wrap:focus .tooltip-box,
.tooltip-wrap:active .tooltip-box,
.tooltip-wrap.active .tooltip-box,
.tooltip-wrap:focus-within .tooltip-box {
  opacity: 1;
  visibility: visible;
}

/* Distinct Preview Info Blocks */
.sheet-info-block {
  margin-bottom: 0.65rem;
}
.sheet-info-block:last-child {
  margin-bottom: 0;
}

/* ----------------------------------------------------
   FLOATING AI ASSISTANT CHATBOT WIDGET
   ---------------------------------------------------- */
.ai-chat-widget {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-family: inherit;
}

.btn-ai-chat-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.7rem 1.15rem;
  border-radius: 9999px;
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  color: #ffffff;
  border: 1.5px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.3), 0 2px 6px rgba(0, 0, 0, 0.1);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  user-select: none;
}

.btn-ai-chat-toggle:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.4), 0 4px 10px rgba(0, 0, 0, 0.15);
  border-color: rgba(255, 255, 255, 0.3);
  background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
}

.btn-ai-chat-toggle.active {
  background: #0f172a;
  border-color: #3b82f6;
}

.ai-toggle-icon {
  font-size: 1.1rem;
  line-height: 1;
}

.ai-chat-panel {
  position: fixed;
  bottom: 5.25rem;
  right: 1.5rem;
  width: 370px;
  max-width: calc(100vw - 2rem);
  height: 520px;
  max-height: calc(100vh - 7rem);
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.22), 0 4px 12px rgba(0, 0, 0, 0.08);
  border: 1px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: aiPanelSlideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 10001;
}

@keyframes aiPanelSlideUp {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.ai-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  color: #ffffff;
}

.ai-header-info {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.ai-avatar-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  font-size: 1.1rem;
}

.ai-header-title {
  font-size: 0.92rem;
  font-weight: 700;
  line-height: 1.2;
}

.ai-header-status {
  font-size: 0.72rem;
  color: #94a3b8;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: #22c55e;
  box-shadow: 0 0 6px #22c55e;
}

.ai-chat-close-btn {
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: 6px;
  transition: all 0.15s ease;
}

.ai-chat-close-btn:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
}

.ai-chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  background-color: #f8fafc;
}

.ai-msg {
  display: flex;
  gap: 0.5rem;
  max-width: 88%;
  font-size: 0.85rem;
  line-height: 1.45;
}

.ai-msg-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.ai-msg-assistant {
  align-self: flex-start;
}

.ai-msg-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  flex-shrink: 0;
  margin-top: 2px;
}

.ai-msg-bubble {
  padding: 0.65rem 0.85rem;
  border-radius: 12px;
  word-break: break-word;
}

.ai-msg-user .ai-msg-bubble {
  background: #2563eb;
  color: #ffffff;
  border-bottom-right-radius: 3px;
}

.ai-msg-assistant .ai-msg-bubble {
  background: #ffffff;
  color: #1e293b;
  border: 1px solid #e2e8f0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  border-bottom-left-radius: 3px;
}

.ai-msg-bubble p {
  margin: 0 0 0.4rem 0;
}
.ai-msg-bubble p:last-child {
  margin-bottom: 0;
}

/* Rate Limit Assistant Bubble */
.rate-limit-bubble {
  background: #fffbeb !important;
  border-color: #fde68a !important;
  color: #92400e !important;
}

.rate-limit-title {
  font-weight: 700;
  font-size: 0.85rem;
  margin-bottom: 0.35rem;
  color: #b45309;
}

.btn-upgrade-chat {
  margin-top: 0.55rem;
  display: inline-block;
  padding: 0.45rem 0.8rem;
  background: #2563eb;
  color: #ffffff;
  border: none;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn-upgrade-chat:hover {
  background: #1d4ed8;
}

/* Suggestions / Chips */
.ai-chat-suggestions {
  margin-top: 0.5rem;
  padding: 0.75rem;
  background: #ffffff;
  border-radius: 10px;
  border: 1px dashed #cbd5e1;
}

.ai-suggestion-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: #64748b;
  margin-bottom: 0.5rem;
}

.ai-prompt-chips {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.ai-prompt-chip {
  text-align: left;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  font-size: 0.78rem;
  color: #334155;
  cursor: pointer;
  transition: all 0.15s ease;
}

.ai-prompt-chip:hover {
  background: #e2e8f0;
  color: #0f172a;
  border-color: #cbd5e1;
}

/* Typing indicator */
.ai-typing-bubble {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0.6rem 0.8rem;
}

.ai-typing-bubble .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: #94a3b8;
  animation: aiTypingBounce 1.2s infinite ease-in-out;
}

.ai-typing-bubble .dot:nth-child(2) {
  animation-delay: 0.2s;
}

.ai-typing-bubble .dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes aiTypingBounce {
  0%, 80%, 100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-4px);
  }
}

/* Chat Footer */
.ai-chat-footer {
  padding: 0.65rem 0.85rem;
  background: #ffffff;
  border-top: 1px solid #e2e8f0;
}

.ai-chat-quota-bar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.4rem;
}

.ai-chat-quota-badge {
  font-size: 0.68rem;
  font-weight: 500;
  color: #64748b;
  background: #f1f5f9;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
}

.ai-chat-input-row {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.ai-chat-input {
  flex: 1;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  font-size: 0.85rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s ease;
}

.ai-chat-input:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.btn-ai-chat-send {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #2563eb;
  color: #ffffff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.95rem;
  transition: background 0.15s ease;
  flex-shrink: 0;
}

.btn-ai-chat-send:hover {
  background: #1d4ed8;
}

@media (max-width: 640px) {
  .ai-chat-panel {
    bottom: 0;
    right: 0;
    width: 100vw;
    max-width: 100vw;
    height: 80vh;
    border-radius: 16px 16px 0 0;
  }
}

/* ==========================================================================
   Tooltips & Help Icons (LTR & RTL Supported)
   ========================================================================== */
.tooltip-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  margin-left: 0.35rem;
  cursor: pointer;
  vertical-align: middle;
}
[dir="rtl"] .tooltip-wrap {
  margin-left: 0;
  margin-right: 0.35rem;
}
.tooltip-icon {
  font-size: 0.8rem;
  opacity: 0.65;
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.tooltip-wrap:hover .tooltip-icon,
.tooltip-wrap.active .tooltip-icon {
  opacity: 1;
  transform: scale(1.15);
}
.tooltip-box {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background-color: #0f172a;
  color: #f8fafc;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.35;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  width: max-content;
  max-width: 260px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  z-index: 1000;
  pointer-events: none;
  text-align: left;
  text-transform: none;
  letter-spacing: normal;
}
[dir="rtl"] .tooltip-box {
  text-align: right;
  left: auto;
  right: 50%;
  transform: translateX(50%);
}
.tooltip-wrap:hover .tooltip-box,
.tooltip-wrap:focus-within .tooltip-box,
.tooltip-wrap.active .tooltip-box {
  display: block;
  animation: fadeIn 0.15s ease-in-out;
}

/* ==========================================================================
   Doc Meta Grid Label Alignment Fix (Part 6)
   ========================================================================== */
.doc-meta-grid .form-group label,
.doc-meta-grid .label-with-action {
  min-height: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.2rem;
}
.label-with-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}
.btn-text-action {
  background: none;
  border: none;
  color: var(--primary, #2563eb);
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  padding: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
}
.btn-text-action:hover {
  text-decoration: underline;
}

/* ==========================================================================
   Line Items Table & Mobile Reflow (Part 8)
   ========================================================================== */
.line-items-container {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.items-table-header {
  display: grid;
  grid-template-columns: 3.5fr 1fr 1.2fr 1fr 1.2fr 40px;
  gap: 0.5rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted, #64748b);
  padding: 0 0.5rem;
}
.item-row {
  display: grid;
  grid-template-columns: 3.5fr 1fr 1.2fr 1fr 1.2fr 40px;
  gap: 0.5rem;
  align-items: center;
  background-color: #f8fafc;
  padding: 0.5rem;
  border-radius: var(--radius-sm, 6px);
  border: 1px solid var(--border-color, #e2e8f0);
}
.item-total-col {
  display: flex;
  align-items: center;
  font-size: 0.85rem;
}
.item-action-col {
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-remove-item, .btn-remove-row {
  background: transparent;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  color: #ef4444;
  font-size: 1.1rem;
  line-height: 1;
  width: 28px;
  height: 28px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}
.btn-remove-item:hover, .btn-remove-row:hover {
  background: #fee2e2;
  border-color: #fca5a5;
}

@media (max-width: 600px) {
  .items-table-header {
    display: none;
  }
  .item-row {
    grid-template-columns: 1fr 1fr 1fr 32px;
    grid-template-rows: auto auto;
    gap: 0.4rem;
    padding: 0.75rem;
  }
  .item-desc-col {
    grid-column: 1 / -1;
  }
  .item-qty-col {
    grid-column: 1 / 2;
  }
  .item-rate-col {
    grid-column: 2 / 3;
  }
  .item-tax-col {
    display: none;
  }
  .item-total-col {
    grid-column: 3 / 4;
    font-size: 0.85rem;
    align-self: center;
  }
  .item-action-col {
    grid-column: 4 / 5;
    align-self: center;
  }
}

/* ==========================================================================
   Local Storage Notice Banner & Ledger Privacy Callout (Part 9)
   ========================================================================== */
.local-storage-notice-banner {
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  color: #f8fafc;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-md, 8px);
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}
.local-storage-notice-banner .notice-content {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  font-size: 0.85rem;
  line-height: 1.4;
}
.local-storage-notice-banner .notice-icon {
  font-size: 1.2rem;
}
.btn-notice-dismiss {
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 6px;
  padding: 0.35rem 0.75rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}
.btn-notice-dismiss:hover {
  background: rgba(255, 255, 255, 0.25);
}

.ledger-privacy-callout {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 0.5rem 0.85rem;
  font-size: 0.8rem;
  color: #475569;
  margin-bottom: 1rem;
}
.ledger-privacy-callout .callout-icon {
  font-size: 1rem;
}

/* ==========================================================================
   Header Support Button (Part 10)
   ========================================================================== */
.btn-header-support {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  color: #334155;
  padding: 0.35rem 0.65rem;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 700;
  text-decoration: none;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.btn-header-support:hover {
  background: #e2e8f0;
  color: #0f172a;
}



