:root {
  --bg-app: #0b0f19;
  --bg-sidebar: #111827;
  --bg-card: #1f2937;
  --bg-input: #374151;
  --text-main: #f9fafb;
  --text-muted: #9ca3af;
  --text-dark: #1f2937;
  
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --secondary: #4b5563;
  --secondary-hover: #374151;
  --success: #10b981;
  --success-hover: #059669;
  --warning: #f59e0b;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  
  --border: #374151;
  --border-light: #e5e7eb;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.3), 0 2px 4px -1px rgba(0,0,0,0.2);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.4), 0 4px 6px -2px rgba(0,0,0,0.3);
  
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Premium custom scrollbar styling */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-app);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Reset and Globals */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-main);
  height: 100vh;
  overflow: hidden;
}

/* App Container Layout */
.app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* Sidebar navigation */
.sidebar {
  width: 260px;
  min-width: 260px;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 100;
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              min-width 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
  position: relative;
}

/* Collapsed sidebar */
.sidebar.collapsed {
  width: 0;
  min-width: 0;
  border-right: none;
}

/* Sidebar overlay backdrop for mobile */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
  display: block;
  opacity: 1;
}

/* All sidebar inner content hides smoothly when collapsed */
.sidebar.collapsed .sidebar-brand,
.sidebar.collapsed .sidebar-menu,
.sidebar.collapsed .sidebar-footer {
  opacity: 0;
  pointer-events: none;
}

.sidebar-brand,
.sidebar-menu,
.sidebar-footer {
  transition: opacity 0.2s ease;
  white-space: nowrap;
}

.sidebar-brand {
  padding: 24px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  width: 32px;
  height: 32px;
  border-radius: 8px;
}

.brand-name {
  font-size: 18px;
  font-weight: 800;
  background: linear-gradient(135deg, #60a5fa, #c084fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.025em;
}

.sidebar-menu {
  flex-grow: 1;
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: var(--transition);
}

.menu-item svg {
  color: var(--text-muted);
  transition: var(--transition);
}

.menu-item:hover {
  background-color: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
}

.menu-item:hover svg {
  color: var(--text-main);
}

.menu-item.active {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.15), rgba(139, 92, 246, 0.15));
  border: 1px solid rgba(59, 130, 246, 0.3);
  color: #60a5fa;
}

.menu-item.active svg {
  color: #60a5fa;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border-radius: var(--radius-md);
  background-color: rgba(255, 255, 255, 0.02);
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #a855f7);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: white;
}

.user-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.user-company {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.user-currency {
  font-size: 11px;
  color: var(--text-muted);
}

/* Main Content Area */
.main-content {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow-y: auto;
  position: relative;
}

/* Top Bar */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background-color: rgba(11, 15, 25, 0.8);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 9;
  gap: 12px;
}

.top-bar-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.top-bar-left h2 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* Sidebar Toggle Button (Hamburger) */
.sidebar-toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
  flex-shrink: 0;
}

.sidebar-toggle-btn:hover {
  background: rgba(59, 130, 246, 0.15);
  border-color: rgba(59, 130, 246, 0.4);
  color: #60a5fa;
}

/* Content Sections */
.content-section {
  display: none;
  padding: 32px;
  flex-grow: 1;
  animation: fadeIn 0.3s ease-in-out;
  overflow-y: auto;
}

.content-section.active {
  display: block;
}

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

/* Dashboard Elements */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 28px;
}

.kpi-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-md);
  transition: var(--transition);
}

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: rgba(59, 130, 246, 0.4);
}

.kpi-icon-wrapper {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.kpi-content {
  display: flex;
  flex-direction: column;
}

.kpi-title {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.05em;
}

.kpi-value {
  font-size: 20px;
  font-weight: 700;
  margin-top: 4px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(450px, 1fr));
  gap: 24px;
}

.card {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  margin-bottom: 24px;
}

.card-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.card-title {
  font-size: 16px;
  font-weight: 700;
}

.card-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.card-body {
  padding: 20px;
}

/* Analytics Chart */
.chart-container {
  height: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 10px 0;
}

.analytics-chart {
  width: 100%;
  height: 100%;
}

.chart-grid-line {
  stroke: var(--border);
  stroke-width: 1;
}

.chart-line {
  fill: none;
  stroke: url(#chart-gradient);
  stroke-width: 3.5;
  stroke-linecap: round;
}

.chart-area {
  fill: url(#chart-bg-gradient);
  opacity: 0.15;
}

.chart-point {
  fill: var(--primary);
  stroke: var(--bg-card);
  stroke-width: 2.5;
  cursor: pointer;
  transition: r 0.2s ease;
}

.chart-point:hover {
  r: 6;
}

.chart-axis-text {
  fill: var(--text-muted);
  font-size: 9px;
  font-weight: 500;
}

/* Data Table UI */
.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.data-table th {
  padding: 12px 16px;
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  letter-spacing: 0.05em;
}

.data-table td {
  padding: 14px 16px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  color: var(--text-main);
  vertical-align: middle;
}

.data-table tbody tr:hover {
  background-color: rgba(255, 255, 255, 0.02);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 50px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.status-badge.paid {
  background-color: rgba(16, 185, 129, 0.15);
  color: #34d399;
}

.status-badge.pending {
  background-color: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
}

/* Reprint counter badge inside button */
.reprint-badge {
  display: inline-flex;
  align-items: center;
  background: rgba(255,255,255,0.2);
  border-radius: 20px;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 700;
  font-family: monospace;
  letter-spacing: 0.05em;
  margin-left: 4px;
}

/* Paid rows: subtle green-tinted background */
tr.row-paid {
  background-color: rgba(16, 185, 129, 0.04);
}

tr.row-paid td {
  opacity: 0.85;
}

/* Action cell: wrap buttons on small screens */
.d-flex.flex-wrap {
  flex-wrap: wrap;
  gap: 4px;
}


/* Forms & Editor Layout */
.editor-layout {
  display: grid;
  grid-template-columns: 500px 1fr;
  gap: 32px;
  height: calc(100vh - 140px);
  position: relative;
}

.form-pane {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
  box-shadow: var(--shadow-lg);
}

.pane-section {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.pane-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.pane-section-header h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
  border-left: 3px solid var(--primary);
  padding-left: 8px;
}

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

.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.form-control, .addon-select {
  background-color: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  padding: 10px 12px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: var(--transition);
  width: 100%;
  min-width: 0;
}

.form-control:focus, .addon-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.form-control-sm {
  background-color: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  padding: 6px 10px;
  font-size: 12px;
  outline: none;
}

.form-row-two {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.form-row-three {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

/* Color Accent Picker */
.color-palette-picker {
  display: flex;
  align-items: center;
  gap: 8px;
}

.palette-option {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: var(--transition);
}

.palette-option.active {
  border-color: white;
  transform: scale(1.1);
}

.custom-color-input {
  border: none;
  background: none;
  width: 24px;
  height: 24px;
  cursor: pointer;
  border-radius: 50%;
}

/* Logo uploading elements */
.logo-upload-zone {
  display: flex;
  align-items: center;
  gap: 16px;
  background-color: rgba(255, 255, 255, 0.01);
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px dashed var(--border);
}

.logo-preview-box {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-sm);
  background-color: var(--bg-input);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 1px solid var(--border);
  position: relative;
}

.logo-preview-box img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.logo-upload-controls {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.upload-hint {
  font-size: 10px;
  color: var(--text-muted);
}

/* Line items editor rows */
.line-items-editor-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.item-editor-row {
  display: grid;
  grid-template-columns: 1fr 60px 80px 65px 36px;
  gap: 8px;
  align-items: end;
  background-color: rgba(255,255,255,0.01);
  padding: 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.item-editor-col-header {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 4px;
}

.input-addon-group {
  display: flex;
}

.input-addon-group input {
  flex-grow: 1;
  border-top-right-radius: 0 !important;
  border-bottom-right-radius: 0 !important;
  border-right: none;
}

.input-addon-group .addon-select {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  padding: 8px;
}

/* Dual Signature Grid (Customer + Seller side by side) */
.dual-signature-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* Individual signature box */
.sig-box {
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
}

.sig-box-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 10px;
}

.sig-box-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 2px;
}

.sig-box-hint {
  font-size: 10px;
  color: var(--text-muted);
}

/* Signature Canvas */
.signature-canvas-container {
  border: 2px dashed var(--border);
  background-color: white;
  border-radius: var(--radius-md);
  overflow: hidden;
  position: relative;
  height: 130px;
  transition: border-color 0.2s;
}

.signature-canvas-container:hover {
  border-color: var(--primary);
}

.signature-canvas {
  width: 100%;
  height: 100%;
  cursor: crosshair;
  background-color: white;
  touch-action: none;
  display: block;
}

.signature-instructions {
  position: absolute;
  bottom: 6px;
  right: 8px;
  font-size: 9px;
  color: rgba(0, 0, 0, 0.4);
  pointer-events: none;
  background-color: rgba(255,255,255,0.9);
  padding: 2px 6px;
  border-radius: 4px;
}

/* Responsive: stack signatures on small screens */
@media (max-width: 640px) {
  .dual-signature-grid {
    grid-template-columns: 1fr;
  }
}

/* Buttons Styling */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: var(--transition);
  outline: none;
  text-decoration: none;
}

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

.btn-primary {
  background-color: var(--primary);
  color: white;
}

.btn-primary:hover {
  background-color: var(--primary-hover);
}

.btn-secondary {
  background-color: var(--secondary);
  color: var(--text-main);
}

.btn-secondary:hover {
  background-color: var(--secondary-hover);
}

.btn-success {
  background-color: var(--success);
  color: white;
}

.btn-success:hover {
  background-color: var(--success-hover);
}

.btn-danger {
  background-color: var(--danger);
  color: white;
}

.btn-danger:hover {
  background-color: var(--danger-hover);
}

.btn-text {
  background: none;
  border: none;
  font-weight: 600;
  cursor: pointer;
  outline: none;
}

.btn-icon-only {
  padding: 8px;
  background-color: transparent;
  color: var(--text-muted);
  border-radius: 4px;
}

.btn-icon-only:hover {
  background-color: rgba(255,255,255,0.05);
  color: var(--danger);
}

.pane-actions-container {
  display: flex;
  gap: 12px;
  padding-top: 10px;
}

/* Preview Pane Area */
.preview-pane {
  display: flex;
  flex-direction: column;
  gap: 20px;
  height: 100%;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  padding: 12px 20px;
  border-radius: var(--radius-md);
  flex-wrap: wrap;
  gap: 12px;
}

.preview-mode-tag {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  color: var(--success);
  display: flex;
  align-items: center;
  gap: 6px;
}

.preview-mode-tag::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--success);
  box-shadow: 0 0 8px var(--success);
}

.preview-actions {
  display: flex;
  gap: 10px;
}

/* Page Preview Sheet */
.a4-sheet-container {
  flex-grow: 1;
  background-color: #1e293b;
  border-radius: var(--radius-lg);
  padding: 20px 10px;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.5);
}

/* Templates base */
.template-renderer {
  width: 210mm; /* A4 width */
  min-height: 297mm; /* A4 height */
  background-color: white;
  color: #111827;
  padding: 20mm;
  box-shadow: 0 20px 25px -5px rgba(0,0,0,0.5), 0 10px 10px -5px rgba(0,0,0,0.4);
  font-size: 13px;
  line-height: 1.5;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  position: relative;
  font-family: inherit;
}

/* RETAIL TEMPLATE (Detailed table) */
.template-renderer.retail {
  border-top: 8px solid var(--theme-color, #3b82f6);
}

/* CORPORATE TEMPLATE */
.template-renderer.corporate {
  border-left: 20px solid var(--theme-color, #3b82f6);
}

/* Dynamic styling elements in templates */
.tpl-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 30px;
}

.tpl-header-left {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tpl-logo {
  max-width: 80px;
  max-height: 80px;
  object-fit: contain;
  margin-bottom: 8px;
}

.tpl-company-name {
  font-size: 18px;
  font-weight: 800;
  color: #1f2937;
}

.tpl-company-details {
  font-size: 11px;
  color: #4b5563;
  line-height: 1.4;
}

.tpl-header-right {
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.tpl-inv-title {
  font-size: 26px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: -0.02em;
  color: var(--theme-color, #3b82f6);
  margin-bottom: 12px;
}

.tpl-meta-list {
  display: grid;
  grid-template-columns: auto auto;
  gap: 4px 16px;
  font-size: 12px;
}

.tpl-meta-label {
  color: #6b7280;
  font-weight: 500;
}

.tpl-meta-val {
  color: #1f2937;
  font-weight: 600;
  text-align: right;
}

.tpl-billing-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
  margin-bottom: 30px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border-light);
}

.tpl-bill-to {
  display: flex;
  flex-direction: column;
}

.tpl-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: #6b7280;
  margin-bottom: 8px;
  letter-spacing: 0.05em;
}

.tpl-client-name {
  font-size: 14px;
  font-weight: 700;
  color: #111827;
  margin-bottom: 4px;
}

.tpl-client-details {
  font-size: 11px;
  color: #4b5563;
  line-height: 1.4;
}

/* Items Render Table */
.tpl-items-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 30px;
}

.tpl-items-table th {
  padding: 10px 12px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: white;
  background-color: var(--theme-color, #3b82f6);
  text-align: left;
}

.tpl-items-table.minimalist-table th {
  background-color: transparent !important;
  color: #374151 !important;
  border-bottom: 2px solid #111827 !important;
  padding-left: 0;
}

.tpl-items-table td {
  padding: 12px;
  font-size: 12px;
  border-bottom: 1px solid var(--border-light);
  color: #374151;
}

.tpl-items-table.minimalist-table td {
  padding-left: 0;
  padding-right: 0;
}

.tpl-items-table.retail-table {
  border: 1px solid #d1d5db;
}

.tpl-items-table.retail-table td, .tpl-items-table.retail-table th {
  border: 1px solid #d1d5db;
}

.text-right {
  text-align: right !important;
}

.text-center {
  text-align: center !important;
}

/* Totals Summary Row */
.tpl-summary-section {
  display: flex;
  justify-content: justify-between;
  margin-top: auto; /* Push to bottom of content */
  padding-top: 20px;
  justify-content: space-between;
}

.tpl-payment-info {
  flex-grow: 1;
  max-width: 55%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tpl-qr-and-bank {
  display: flex;
  gap: 16px;
  align-items: center;
}

.tpl-qr-canvas {
  width: 80px;
  height: 80px;
  border: 1px solid #e5e7eb;
  padding: 2px;
  border-radius: 4px;
}

.tpl-bank-box {
  font-size: 11px;
  color: #4b5563;
  line-height: 1.4;
}

.tpl-bank-title {
  font-weight: 700;
  color: #374151;
  margin-bottom: 2px;
}

.tpl-terms-box {
  font-size: 10px;
  color: #9ca3af;
  line-height: 1.3;
}

.tpl-totals-block {
  width: 260px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
}

.tpl-totals-row {
  display: flex;
  justify-content: space-between;
  color: #4b5563;
}

.tpl-totals-row.grand-total {
  font-size: 15px;
  font-weight: 800;
  color: #111827;
  border-top: 1.5px solid #111827;
  padding-top: 6px;
  margin-top: 4px;
}

.tpl-totals-row.balance-due {
  font-size: 13px;
  font-weight: 800;
  color: #b45309;
  background-color: #fef3c7;
  padding: 4px 8px;
  border-radius: 4px;
  margin-top: 4px;
}

/* Dual signature row in invoice template (Customer Left | Seller Right) */
.tpl-dual-sig-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-top: 24px;
  gap: 12px;
}

.tpl-sig-col {
  display: flex;
  flex-direction: column;
}

/* Keep backward compat */
.tpl-signature-wrapper {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: right;
  margin-top: 24px;
}

.tpl-signature-img {
  max-width: 140px;
  max-height: 50px;
  object-fit: contain;
  margin-bottom: 4px;
  border-bottom: 1px solid #d1d5db;
}

.tpl-signature-lbl {
  font-size: 10px;
  color: #6b7280;
  font-weight: 600;
}

/* Utility Helpers */
.d-none { display: none !important; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.py-4 { padding-top: 16px; padding-bottom: 16px; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger { color: var(--danger); }
.text-xs { font-size: 11px; }
.cursor-pointer { cursor: pointer; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-wrap { flex-wrap: wrap; }
.gap-3 { gap: 12px; }
.w-48 { width: 192px; }
.justify-between { justify-content: space-between; }
.flex-grow { flex-grow: 1; }
.justify-center { justify-content: center; }

/* Settings structures */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 24px;
}

.danger-zone-box {
  border: 1px solid rgba(239, 68, 68, 0.3);
  background-color: rgba(239, 68, 68, 0.05);
  padding: 16px;
  border-radius: var(--radius-md);
}

/* ==========================================
   PRINT STYLES (@media print)
   ========================================== */
@media print {
  body {
    background: white !important;
    color: black !important;
    height: auto !important;
    overflow: visible !important;
  }
  
  /* Hide all app wrapper Chrome controls */
  .sidebar,
  .top-bar,
  .form-pane,
  .preview-toolbar,
  .content-section:not(#tab-editor) {
    display: none !important;
  }
  
  /* Re-configure sections so they expand without layout wrappers */
  .main-content {
    display: block !important;
    height: auto !important;
    overflow: visible !important;
    position: static !important;
  }
  
  .content-section#tab-editor {
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
  }
  
  .editor-layout {
    display: block !important;
    height: auto !important;
    grid-template-columns: none !important;
  }
  
  .preview-pane {
    display: block !important;
    height: auto !important;
  }
  
  .a4-sheet-container {
    background: transparent !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
    box-shadow: none !important;
    display: block !important;
  }
  
  .template-renderer {
    box-shadow: none !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    min-height: 0 !important;
    border: none !important;
    zoom: 1 !important;
    transform: none !important;
  }
  
  /* Retain brand colors in printing if browser permits */
  .tpl-inv-title,
  .tpl-items-table th {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}

/* ==========================================
   ADVANCED EXTENSIONS STYLES
   ========================================== */

/* Fullscreen Lock Screen Overlay */
.lock-screen-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(11, 15, 25, 0.85);
  backdrop-filter: blur(16px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99999;
  animation: fadeIn 0.3s ease;
}

.lock-card {
  background-color: #1e293b;
  border: 1px solid #334155;
  border-radius: var(--radius-lg);
  padding: 32px;
  width: 320px;
  text-align: center;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.lock-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
  box-shadow: 0 0 20px rgba(59, 130, 246, 0.4);
}

.lock-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 6px;
}

.lock-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 24px;
}

/* PIN Indicators */
.pin-indicator-row {
  display: flex;
  gap: 16px;
  margin-bottom: 28px;
}

.pin-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--border);
  transition: all 0.15s ease;
}

.pin-dot.filled {
  background-color: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 0 10px var(--primary);
  transform: scale(1.15);
}

/* Keypad Grid */
.keypad-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  width: 100%;
}

.keypad-btn {
  background-color: #334155;
  border: 1px solid var(--border);
  color: var(--text-main);
  border-radius: 50%;
  width: 56px;
  height: 56px;
  font-size: 20px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  justify-self: center;
  transition: var(--transition);
  outline: none;
}

.keypad-btn:hover {
  background-color: var(--border);
  transform: scale(1.05);
}

.keypad-btn:active {
  transform: scale(0.95);
  background-color: var(--primary);
  color: white;
}

/* Shake animation for errors */
.lock-card.shake {
  animation: shake 0.4s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

/* Stock status badges */
.stock-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 50px;
  font-size: 11px;
  font-weight: 600;
}

.stock-badge.in-stock {
  background-color: rgba(16, 185, 129, 0.15);
  color: #34d399;
}

.stock-badge.low-stock {
  background-color: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
}

.stock-badge.out-of-stock {
  background-color: rgba(239, 68, 68, 0.15);
  color: #f87171;
}

/* FAQ accordion style */
.faq-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.faq-item {
  background-color: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  transition: var(--transition);
}

.faq-question {
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-main);
  outline: none;
  list-style: none;
}

.faq-question::-webkit-details-marker {
  display: none;
}

.faq-answer {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
  line-height: 1.4;
}

.faq-item[open] {
  border-color: var(--primary);
}

/* Fonts Typography */
.template-renderer.font-sans {
  font-family: var(--font-sans) !important;
}
.template-renderer.font-serif {
  font-family: Georgia, 'Times New Roman', Times, serif !important;
}
.template-renderer.font-mono {
  font-family: Consolas, 'Courier New', Courier, monospace !important;
}
.template-renderer.font-playfair {
  font-family: Georgia, 'Times New Roman', serif !important;
  font-style: italic;
}

/* Font Size Helpers */
.template-renderer.fs-sm {
  font-size: 11px !important;
}
.template-renderer.fs-md {
  font-size: 13px !important;
}
.template-renderer.fs-lg {
  font-size: 14px !important;
}
.template-renderer.fs-xl {
  font-size: 16px !important;
}

/* Autocomplete suggestion styles in item name search */
.autocomplete-suggestions-box {
  position: absolute;
  background-color: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 150px;
  overflow-y: auto;
  z-index: 100;
  width: 100%;
  box-shadow: var(--shadow-lg);
  margin-top: 4px;
}

.suggestion-row {
  padding: 8px 12px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-main);
  display: flex;
  justify-content: space-between;
}

.suggestion-row:hover {
  background-color: var(--primary);
  color: white;
}

.suggestion-sku {
  color: var(--text-muted);
  font-size: 10px;
}

.suggestion-row:hover .suggestion-sku {
  color: rgba(255,255,255,0.7);
}

/* =====================================================
   MOBILE TAB SWITCHER (Edit / Preview) — hidden on desktop
   ===================================================== */
.mobile-tab-switcher {
  display: none; /* shown only via media query */
  gap: 0;
  margin-bottom: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  flex-shrink: 0;
}

.mobile-tab-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 12px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.mobile-tab-btn.active {
  background: var(--primary);
  color: #fff;
}

.mobile-tab-btn:not(.active):hover {
  background: rgba(255,255,255,0.05);
  color: var(--text-main);
}

/* =====================================================
   TABLET & MOBILE — SIDEBAR AS FIXED OVERLAY DRAWER
   ===================================================== */
@media (max-width: 1024px) {

  /* Body: allow scroll on mobile (keyboard-safe) */
  body {
    height: auto;
    overflow: auto;
  }

  /* App container: stay row, sidebar is now an overlay */
  .app-container {
    flex-direction: row;
    height: 100%;
    min-height: 100vh;
  }

  /* Sidebar: fixed left drawer, slides in/out */
  .sidebar {
    position: fixed !important;
    left: 0;
    top: 0;
    height: 100vh !important;
    width: 260px !important;
    min-width: 260px !important;
    transform: translateX(-270px);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    z-index: 200 !important;
    border-right: 1px solid var(--border) !important;
    overflow-y: auto;
  }

  /* Sidebar open: slide in from left */
  .sidebar.sidebar-open {
    transform: translateX(0) !important;
  }

  /* Override collapsed behavior on mobile — use transform instead */
  .sidebar.collapsed {
    width: 260px !important;
    min-width: 260px !important;
    border-right: 1px solid var(--border) !important;
    transform: translateX(-270px) !important;
  }

  /* Keep sidebar inner content fully visible (not faded) */
  .sidebar.collapsed .sidebar-brand,
  .sidebar.collapsed .sidebar-menu,
  .sidebar.collapsed .sidebar-footer {
    opacity: 1 !important;
    pointer-events: auto !important;
  }

  /* Sidebar menu: vertical (restored from old horizontal override) */
  .sidebar-menu {
    flex-direction: column !important;
    overflow-x: hidden !important;
    overflow-y: auto;
    padding: 20px 12px;
    gap: 6px;
  }

  /* Restore sidebar footer visibility */
  .sidebar-footer {
    display: flex !important;
  }

  /* Menu items: normal vertical layout */
  .menu-item {
    padding: 12px 16px;
    white-space: normal;
  }

  /* Main content: full width (sidebar doesn't push it) */
  .main-content {
    width: 100%;
    height: 100vh;
    overflow-y: auto;
  }

  /* Top bar */
  .top-bar {
    padding: 12px 16px;
  }

  /* Content sections */
  .content-section {
    padding: 16px;
  }

  /* Editor: stacked layout */
  .editor-layout {
    grid-template-columns: 1fr;
    height: auto;
    gap: 16px;
    padding-bottom: 20px;
  }

  .form-pane {
    height: auto;
    max-height: none;
    padding: 16px;
    overflow-y: visible;
  }

  .preview-pane {
    height: auto;
    min-height: 400px;
  }

  .a4-sheet-container {
    padding: 10px;
    min-height: 350px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Mobile tab switcher: show */
  .mobile-tab-switcher {
    display: flex;
  }

  /* Settings & dashboard */
  .settings-grid {
    grid-template-columns: 1fr;
  }
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  /* KPI: 2 columns on tablet */
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* =====================================================
   MOBILE PHONES — ≤ 768px
   ===================================================== */
@media (max-width: 768px) {

  /* Form 2-col rows → single column */
  .form-row-two {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  /* Slider rows: stack vertically */
  .form-row-two:has(input[type="range"]) {
    grid-template-columns: 1fr;
  }

  /* Top bar: tighter */
  .top-bar {
    padding: 10px 12px;
    gap: 8px;
  }

  .top-bar-left h2 {
    font-size: 17px;
  }

  /* Section padding */
  .content-section {
    padding: 12px;
  }

  .pane-section {
    padding: 12px;
  }

  /* Form pane */
  .form-pane {
    padding: 12px;
    gap: 16px;
  }

  /* A4 preview: full width scrollable */
  .a4-sheet-container {
    padding: 6px;
    overflow-x: auto;
  }

  /* Preview toolbar wraps */
  .preview-toolbar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
  }

  .preview-actions {
    gap: 6px;
  }

  .preview-actions .btn-sm {
    padding: 7px 10px;
    font-size: 11px;
  }

  /* Palette options wrap */
  .palette-options {
    flex-wrap: wrap;
  }

  /* Signature boxes stack */
  .dual-signature-grid {
    grid-template-columns: 1fr;
  }

  /* Invoice items table: tighter */
  .item-editor-row {
    grid-template-columns: 1fr 50px 75px 55px 32px;
    gap: 5px;
    padding: 6px;
  }

  /* Pane actions: full width */
  .pane-actions-container {
    flex-wrap: wrap;
    gap: 8px;
  }

  .pane-actions-container .btn {
    flex: 1;
    min-width: 120px;
  }
}

/* =====================================================
   SMALL PHONES — ≤ 480px
   ===================================================== */
@media (max-width: 480px) {

  /* KPI: single column */
  .kpi-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  /* Top bar title */
  .top-bar-left h2 {
    font-size: 15px;
  }

  /* Hide Quick Invoice button label, show only + icon */
  .btn-label {
    display: none;
  }

  /* Sidebar toggle button: slightly smaller */
  .sidebar-toggle-btn {
    width: 32px;
    height: 32px;
  }

  /* Item editor: compact */
  .item-editor-row {
    grid-template-columns: 1fr 44px 68px 48px 28px;
    gap: 4px;
    padding: 4px;
  }

  .item-editor-row .form-control {
    padding: 6px 8px;
    font-size: 12px;
  }

  /* Preview actions: icon only (hide text on small screens) */
  .preview-actions .btn-sm {
    font-size: 11px;
    padding: 6px 8px;
  }

  /* Section padding: minimal */
  .content-section {
    padding: 8px;
  }

  .a4-sheet-container {
    padding: 4px;
  }
}


