:root {
  /* Vibrant Purple Brand Palette (Default Light & Dark Accent) */
  --primary: #7c3aed;
  --primary-hover: #6d28d9;
  --primary-light: #f5f3ff;
  --primary-border: #ddd6fe;
  
  --secondary: #475569;
  --secondary-hover: #334155;
  
  --accent: #8b5cf6;
  --accent-light: #ede9fe;
  
  --danger: #ef4444;
  --danger-light: #fef2f2;
  --warning: #f59e0b;
  --warning-light: #fffbeb;
  --success: #10b981;
  --success-light: #ecfdf5;
  
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --gray-900: #0f172a;
  
  --bg-page: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-secondary: #f8fafc;
  --border-color: #e2e8f0;
  --border-subtle: #f1f5f9;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-label: #334155;
  --input-bg: #ffffff;
  --input-border: #cbd5e1;
  
  --radius-sm: 4px;
  --radius: 8px;
  --radius-lg: 12px;
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.04);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  --focus-ring: rgba(124, 58, 237, 0.2);
}

[data-theme="dark"] {
  color-scheme: dark;

  /* Purple accent palette (strictly for accents replacing the original red) */
  --primary: #8b5cf6;
  --primary-hover: #7c3aed;
  --primary-light: rgba(139, 92, 246, 0.14);
  --primary-border: rgba(139, 92, 246, 0.35);

  --secondary: #94a3b8;
  --secondary-hover: #cbd5e1;

  --accent: #a78bfa;
  --accent-light: rgba(167, 139, 250, 0.14);

  --danger: #ef4444;
  --danger-light: rgba(239, 68, 68, 0.16);
  --warning: #f59e0b;
  --warning-light: rgba(245, 158, 11, 0.16);
  --success: #10b981;
  --success-light: rgba(16, 185, 129, 0.16);

  /* Clean neutral slate/gray scale - zero purple tint */
  --gray-50: #0f172a;
  --gray-100: #1e293b;
  --gray-200: #334155;
  --gray-300: #475569;
  --gray-400: #64748b;
  --gray-500: #94a3b8;
  --gray-600: #cbd5e1;
  --gray-700: #e2e8f0;
  --gray-800: #f1f5f9;
  --gray-900: #ffffff;

  /* Clean neutral dark surfaces & page background */
  --bg-page: #0b0f17;
  --bg-surface: #1e293b;
  --bg-surface-secondary: #0f172a;
  --border-color: #334155;
  --border-subtle: #1e293b;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-label: #cbd5e1;
  --input-bg: #0f172a;
  --input-border: #334155;

  /* Standard neutral drop shadows - zero purple glow */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.35);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.45), 0 2px 4px -2px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.55), 0 4px 6px -4px rgba(0, 0, 0, 0.45);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.7), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
  --focus-ring: rgba(139, 92, 246, 0.3);
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.2s ease, color 0.2s ease;
}

/* =================================================== */
/* THEME TOGGLE BUTTON & AUTH CORNER                   */
/* =================================================== */
.auth-theme-corner {
  position: absolute;
  top: 1.25rem;
  right: 1.5rem;
  z-index: 20;
}

.btn-theme-toggle {
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}

.btn-theme-toggle:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  transform: scale(1.06);
  box-shadow: var(--shadow);
}

.btn-theme-toggle .theme-icon {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease;
}

/* Light mode: show moon icon (click to switch to dark), hide sun */
.btn-theme-toggle .sun-icon {
  display: none;
}
.btn-theme-toggle .moon-icon {
  display: block;
  color: var(--primary);
}

/* Dark mode: show sun icon (click to switch to light), hide moon */
[data-theme="dark"] .btn-theme-toggle .moon-icon {
  display: none;
}
[data-theme="dark"] .btn-theme-toggle .sun-icon {
  display: block;
  color: #fbbf24;
}

/* =================================================== */
/* DEDICATED FULL-SCREEN LOGIN PAGE (FIRST OPENING)   */
/* =================================================== */
.auth-page-wrapper {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 2rem 1rem;
  background: radial-gradient(circle at 50% 20%, #ffffff 0%, var(--bg-page) 80%);
  position: relative;
  transition: background 0.2s ease;
}

[data-theme="dark"] .auth-page-wrapper {
  background: radial-gradient(circle at 50% 20%, #1e293b 0%, #0b0f17 85%);
}

.auth-page-wrapper::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--primary);
}

.auth-card {
  width: 100%;
  max-width: 450px;
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  animation: authFadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
}

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

.auth-header {
  padding: 2.2rem 2rem 1.5rem 2rem;
  text-align: center;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-surface);
}

.auth-logo-badge {
  width: 52px;
  height: 52px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: #ffffff;
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1rem;
  box-shadow: 0 4px 14px rgba(139, 92, 246, 0.3);
}

.auth-logo-badge svg {
  width: 28px;
  height: 28px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

.auth-title {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.2;
}

.auth-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.4rem;
}

.auth-body {
  padding: 1.75rem 2rem;
}

.auth-remember-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 1rem 0 1.25rem 0;
  font-size: 0.825rem;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-label);
  font-weight: 500;
  cursor: pointer;
  user-select: none;
}

.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}

.auth-admin-hint {
  background: var(--bg-surface-secondary);
  border: 1px dashed var(--border-color);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  margin-top: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.auth-admin-hint-header {
  font-size: 0.725rem;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--primary);
  letter-spacing: 0.05em;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.auth-admin-pill {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.825rem;
  color: var(--text-main);
}

.auth-admin-pill code {
  background: var(--bg-surface);
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  border: 1px solid var(--border-color);
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--primary);
}

.btn-autofill-admin {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

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

/* App Header */
.app-header {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.header-container {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0.65rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

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

.logo-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--primary), #6d28d9);
  color: #fff;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(124, 58, 237, 0.25);
}

.logo-icon svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

.logo-text h1 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.2;
}

.logo-text span {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* Tab Navigation */
.nav-tabs {
  display: flex;
  gap: 0.25rem;
  background: var(--bg-surface-secondary);
  border: 1px solid var(--border-subtle);
  padding: 0.25rem;
  border-radius: var(--radius);
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.9rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.tab-btn svg {
  width: 16px;
  height: 16px;
}

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

.tab-btn.active {
  background: var(--bg-surface);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* Header User Profile Bar */
.user-menu-area {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.35rem 0.65rem;
  background: var(--bg-surface-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.user-badge:hover {
  background: var(--gray-100);
  border-color: var(--primary);
  transform: translateY(-1px);
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-info {
  display: flex;
  flex-direction: column;
  text-align: left;
}

.user-name {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.1;
}

.user-title {
  font-size: 0.675rem;
  color: var(--primary);
  font-weight: 600;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  line-height: 1.25;
  text-decoration: none;
}

.btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

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

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

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

.btn-secondary:hover {
  background-color: var(--bg-surface-secondary);
  border-color: var(--primary-border);
  color: var(--primary);
}

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

.btn-success:hover {
  background-color: #059669;
}

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

.btn-danger:hover {
  background-color: #dc2626;
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.75rem;
  border-radius: var(--radius-sm);
}

/* Main Layout */
.main-content {
  flex: 1;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem;
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
}

/* Split Layout for Single Invoice */
.workspace-grid {
  display: grid;
  grid-template-columns: minmax(480px, 1fr) minmax(560px, 1.2fr);
  gap: 1.5rem;
  align-items: start;
}

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

/* Card Containers */
.card {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-header {
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-surface);
  gap: 0.75rem;
}

.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.card-title svg {
  width: 18px;
  height: 18px;
  color: var(--primary);
}

.card-body {
  padding: 1.25rem;
}

/* Form Styles */
.form-section {
  background: var(--bg-surface-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1.25rem;
}

.form-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.section-label {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.form-row:last-child {
  margin-bottom: 0;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.form-group.col-span-2 {
  grid-column: span 2;
}

.form-group label {
  font-size: 0.775rem;
  font-weight: 600;
  color: var(--text-label);
  display: flex;
  justify-content: space-between;
}

.form-group label .required {
  color: var(--danger);
  margin-left: 2px;
}

.form-control {
  width: 100%;
  padding: 0.5rem 0.65rem;
  font-size: 0.85rem;
  color: var(--text-main);
  background-color: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
  font-family: inherit;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

textarea.form-control {
  resize: vertical;
  min-height: 58px;
}

select.form-control {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%237c3aed'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.65rem center;
  background-size: 1rem;
  padding-right: 2rem;
  appearance: none;
}

[data-theme="dark"] select.form-control {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%23a78bfa'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
}

/* =================================================== */
/* SEARCHABLE COMBOBOX (PRODUCT & CUSTOMER SEARCH)    */
/* =================================================== */
.searchable-combobox {
  position: relative;
  width: 100%;
}

.combobox-control {
  position: relative;
  display: flex;
  align-items: center;
}

.combobox-control .search-icon {
  position: absolute;
  left: 0.75rem;
  width: 15px;
  height: 15px;
  color: var(--gray-400);
  pointer-events: none;
  stroke: currentColor;
  fill: none;
}

.combobox-input {
  width: 100%;
  padding-left: 2.15rem !important;
  padding-right: 3.5rem !important;
  cursor: text;
}

.combobox-actions {
  position: absolute;
  right: 0.4rem;
  display: flex;
  align-items: center;
  gap: 0.2rem;
}

.combobox-btn {
  background: transparent;
  border: none;
  color: var(--gray-400);
  cursor: pointer;
  padding: 0.25rem 0.4rem;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

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

.combobox-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-height: 280px;
  overflow-y: auto;
  z-index: 500;
  animation: comboboxOpen 0.15s ease-out;
}

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

.combobox-option {
  padding: 0.6rem 0.85rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border-subtle);
  transition: all 0.1s ease;
}

.combobox-option:last-child {
  border-bottom: none;
}

.combobox-group-header {
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--primary);
  background: var(--bg-surface-secondary);
  padding: 0.35rem 0.85rem;
  margin: -0.6rem -0.85rem 0.45rem -0.85rem;
  border-bottom: 1px solid var(--border-color);
  border-top: 1px solid var(--border-color);
}

.combobox-option:first-child .combobox-group-header {
  border-top: none;
}

.combobox-option:hover,
.combobox-option.selected {
  background-color: var(--primary-light);
  border-left: 3px solid var(--primary);
  padding-left: calc(0.85rem - 3px);
}

.combobox-option-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.combobox-option-title mark {
  background-color: #fef08a;
  color: #1e1b4b;
  font-weight: 800;
  padding: 0 2px;
  border-radius: 2px;
}

.combobox-option-meta {
  font-size: 0.725rem;
  color: var(--text-muted);
  margin-top: 2px;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.combobox-option-meta code {
  background: var(--bg-surface-secondary);
  padding: 1px 4px;
  border-radius: 2px;
  font-family: var(--font-mono);
  color: var(--primary);
  font-size: 0.7rem;
}

.combobox-empty {
  padding: 1.25rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.825rem;
}

/* Quick Search Filters in Directory Tables */
.search-filter-input {
  width: 220px;
  padding: 0.35rem 0.65rem;
  font-size: 0.775rem;
}

/* Line Items Container */
.items-container {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.line-item-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  position: relative;
}

.line-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px dashed var(--border-color);
}

.line-item-number {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--primary);
}

/* Live Preview Panel */
.preview-panel {
  position: sticky;
  top: 4.5rem;
}

.preview-toolbar {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* Color Option Bar Just Above Live Preview */
.preview-color-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 1rem;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
}

.color-picker-group {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.color-picker-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-label);
}

.color-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.color-input-wrapper input[type="color"] {
  position: absolute;
  top: 0;
  left: 0;
  width: 28px;
  height: 28px;
  opacity: 0;
  cursor: pointer;
  z-index: 2;
}

.color-preview-swatch {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--bg-surface);
  box-shadow: 0 0 0 1px var(--border-color), var(--shadow-sm);
  background-color: var(--primary);
  display: inline-block;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.color-preview-swatch:hover {
  transform: scale(1.08);
  box-shadow: 0 0 0 1px var(--primary), var(--shadow);
}

.color-hex-text {
  width: 82px !important;
  height: 28px !important;
  padding: 0.2rem 0.4rem !important;
  font-family: var(--font-mono) !important;
  font-size: 0.78rem !important;
  font-weight: 700 !important;
  text-transform: uppercase !important;
  border-radius: var(--radius-sm) !important;
  text-align: center !important;
  letter-spacing: 0.04em;
}

.preset-colors {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.preset-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-right: 0.15rem;
}

.preset-btn {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--bg-surface);
  box-shadow: 0 0 0 1px var(--border-color);
  cursor: pointer;
  padding: 0;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.preset-btn:hover {
  transform: scale(1.2);
  box-shadow: 0 0 0 1.5px var(--primary);
}

.preset-btn.active {
  box-shadow: 0 0 0 2px var(--primary);
  transform: scale(1.15);
}

.preset-btn-reset {
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 0.15rem 0.45rem;
  cursor: pointer;
  margin-left: 0.25rem;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.preset-btn-reset:hover {
  background: var(--bg-surface-secondary);
  color: var(--primary);
  border-color: var(--primary);
}

.invoice-preview-wrapper {
  background: #334155;
  padding: 1.5rem;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  overflow-x: auto;
  display: flex;
  justify-content: center;
  transition: background-color 0.2s ease;
}

[data-theme="dark"] .invoice-preview-wrapper {
  background: #0b0f17;
}

.invoice-sheet {
  --inv-theme: var(--primary);
  background: #ffffff;
  width: 100%;
  max-width: 800px;
  min-height: 1020px;
  padding: 2.2rem 2.2rem;
  box-shadow: var(--shadow-lg);
  color: #111827;
  font-size: 9.5pt;
  line-height: 1.35;
  display: flex;
  flex-direction: column;
  position: relative;
}

[data-theme="dark"] .invoice-sheet {
  background: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-xl);
}

[data-theme="dark"] .inv-title-area p,
[data-theme="dark"] .inv-meta-label,
[data-theme="dark"] .party-address,
[data-theme="dark"] .party-tax-row,
[data-theme="dark"] .item-desc-cell span,
[data-theme="dark"] .inv-declaration-box,
[data-theme="dark"] .sign-line {
  color: var(--text-muted);
}

[data-theme="dark"] .inv-meta-val,
[data-theme="dark"] .party-name,
[data-theme="dark"] .item-desc-cell strong,
[data-theme="dark"] .inv-table td {
  color: var(--text-main);
}

[data-theme="dark"] .inv-company-logo {
  border-right-color: var(--border-color);
}

[data-theme="dark"] .party-box,
[data-theme="dark"] .logistics-totals-box {
  background: var(--bg-surface-secondary);
  border-color: var(--border-color);
}

[data-theme="dark"] .party-title {
  border-bottom-color: var(--border-color);
}

[data-theme="dark"] .party-tax-row {
  border-top-color: var(--border-color);
}

[data-theme="dark"] .shipment-bar {
  background: color-mix(in srgb, var(--inv-theme, var(--primary)) 15%, var(--bg-surface-secondary));
  border-color: color-mix(in srgb, var(--inv-theme, var(--primary)) 30%, transparent);
}

[data-theme="dark"] .shipment-bar-item:not(:last-child) {
  border-right-color: color-mix(in srgb, var(--inv-theme, var(--primary)) 30%, transparent);
}

[data-theme="dark"] .inv-table td {
  border-color: var(--border-color);
}

[data-theme="dark"] .inv-table tbody tr:nth-child(even) {
  background-color: color-mix(in srgb, var(--inv-theme, var(--primary)) 10%, var(--bg-surface));
}

[data-theme="dark"] .totals-row.strong {
  border-top-color: var(--border-color);
}

[data-theme="dark"] .financial-totals-table tr.grand-total {
  background: color-mix(in srgb, var(--inv-theme, var(--primary)) 15%, var(--bg-surface-secondary));
}

[data-theme="dark"] .inv-declaration-box,
[data-theme="dark"] .sign-line {
  border-top-color: var(--border-color);
}

.inv-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 2px solid var(--inv-theme, var(--primary));
  padding-bottom: 0.75rem;
  margin-bottom: 1rem;
}

.inv-title-area h2 {
  font-size: 18pt;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: var(--inv-theme, var(--primary));
  text-transform: uppercase;
}
.inv-title-area {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.inv-company-logo {
  max-height: 54px;
  max-width: 160px;
  object-fit: contain;
  flex-shrink: 0;
  border-right: 1.5px solid #e5e7eb;
  padding-right: 0.85rem;
}


.inv-title-area p {
  font-size: 8.5pt;
  color: #4b5563;
  margin-top: 2px;
}

.inv-meta-grid {
  display: grid;
  grid-template-columns: auto auto;
  gap: 0.25rem 1.25rem;
  font-size: 8.5pt;
}

.inv-meta-label {
  font-weight: 700;
  color: #374151;
}

.inv-meta-val {
  font-weight: 600;
  color: #111827;
}

/* Parties Grid (Shipper & Consignee) */
.inv-parties-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  margin-bottom: 1rem;
}

.party-box {
  border: 1px solid #9ca3af;
  padding: 0.65rem 0.8rem;
  border-radius: 2px;
  background: #fafafa;
}

.party-title {
  font-size: 8.5pt;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--inv-theme, var(--primary));
  border-bottom: 1px solid #d1d5db;
  padding-bottom: 0.25rem;
  margin-bottom: 0.4rem;
}

.party-name {
  font-size: 10pt;
  font-weight: 700;
  color: #111827;
  margin-bottom: 0.2rem;
}

.party-address {
  white-space: pre-line;
  font-size: 8.5pt;
  color: #374151;
  margin-bottom: 0.4rem;
  min-height: 2.8em;
}

.party-tax-row {
  display: flex;
  justify-content: space-between;
  font-size: 8pt;
  color: #374151;
  padding-top: 0.25rem;
  border-top: 1px dashed #e5e7eb;
}

/* Shipment info strip */
.shipment-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  background: color-mix(in srgb, var(--inv-theme, var(--primary)) 6%, #ffffff);
  border: 1px solid color-mix(in srgb, var(--inv-theme, var(--primary)) 25%, #ffffff);
  padding: 0.5rem 0.75rem;
  font-size: 8pt;
  margin-bottom: 1rem;
}

.shipment-bar-item {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.shipment-bar-item:not(:last-child) {
  border-right: 1px solid color-mix(in srgb, var(--inv-theme, var(--primary)) 20%, transparent);
}

.shipment-bar-item strong {
  display: block;
  font-size: 7pt;
  color: var(--inv-theme, var(--primary));
  text-transform: uppercase;
  margin-bottom: 2px;
}

/* Invoice Table */
.inv-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1rem;
  font-size: 8.5pt;
}

.inv-table th {
  background: var(--inv-theme, var(--primary));
  color: #ffffff;
  font-weight: 700;
  text-transform: uppercase;
  font-size: 7.5pt;
  letter-spacing: 0.03em;
  padding: 0.45rem 0.5rem;
  border: 1px solid var(--inv-theme, var(--primary));
  text-align: left;
}

.inv-table th.text-right,
.inv-table td.text-right {
  text-align: right;
}

.inv-table th.text-center,
.inv-table td.text-center {
  text-align: center;
}

.inv-table td {
  padding: 0.45rem 0.5rem;
  border: 1px solid #d1d5db;
  color: #1f2937;
  vertical-align: top;
}

.inv-table tbody tr:nth-child(even) {
  background-color: color-mix(in srgb, var(--inv-theme, var(--primary)) 3%, #ffffff);
}

.item-desc-cell strong {
  display: block;
  font-weight: 700;
  color: #111827;
}

.item-desc-cell span {
  font-size: 7.5pt;
  color: #6b7280;
}

/* Summary Grid */
.inv-summary-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 1.5rem;
  margin-bottom: 1rem;
}

.logistics-totals-box {
  border: 1px solid #d1d5db;
  padding: 0.5rem 0.75rem;
  font-size: 8.5pt;
  background: #f9fafb;
}

.totals-row {
  display: flex;
  justify-content: space-between;
  padding: 0.2rem 0;
}

.totals-row.strong {
  font-weight: 700;
  border-top: 1px solid #d1d5db;
  margin-top: 0.25rem;
  padding-top: 0.25rem;
}

.financial-totals-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 8.5pt;
}

.financial-totals-table td {
  padding: 0.25rem 0.4rem;
}

.financial-totals-table tr.grand-total {
  font-size: 10pt;
  font-weight: 800;
  border-top: 2px solid var(--inv-theme, var(--primary));
  border-bottom: 2px solid var(--inv-theme, var(--primary));
  background: color-mix(in srgb, var(--inv-theme, var(--primary)) 8%, #ffffff);
}

/* Declaration and Sign-off */
.inv-declaration-box {
  margin-top: auto;
  border-top: 1px solid #9ca3af;
  padding-top: 0.65rem;
  font-size: 7.5pt;
  color: #4b5563;
}

.declaration-statement {
  margin-bottom: 0.75rem;
  font-style: italic;
  line-height: 1.3;
}

.signoff-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-top: 0.5rem;
}

.sign-line {
  border-top: 1px solid #4b5563;
  padding-top: 0.25rem;
  font-size: 7.5pt;
  color: #374151;
  text-transform: uppercase;
}

/* Signature Pad & Canvas Styling */
.signature-box {
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius);
  background: #ffffff;
  padding: 0.75rem;
  text-align: center;
}

.signature-canvas {
  width: 100%;
  max-width: 360px;
  height: 120px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-sm);
  background: #ffffff;
  touch-action: none;
  cursor: crosshair;
  display: block;
  margin: 0 auto 0.5rem auto;
}

.signature-preview-img {
  max-height: 60px;
  max-width: 200px;
  object-fit: contain;
  background: #ffffff;
  border: 1px solid var(--gray-300);
  padding: 4px;
  border-radius: var(--radius-sm);
}

/* Batch Rollout View */
.batch-upload-zone {
  border: 2px dashed var(--primary-border);
  border-radius: var(--radius-lg);
  padding: 2.5rem 1.5rem;
  text-align: center;
  background: #ffffff;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}

.batch-upload-zone:hover,
.batch-upload-zone.dragover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.batch-upload-zone input[type="file"] {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.upload-icon {
  width: 48px;
  height: 48px;
  color: var(--primary);
  margin-bottom: 0.75rem;
}

.upload-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--gray-800);
  margin-bottom: 0.25rem;
}

.upload-subtitle {
  font-size: 0.85rem;
  color: var(--gray-500);
  margin-bottom: 1rem;
}

/* Batch Table */
.batch-data-table-container {
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--bg-surface);
  margin-top: 1rem;
  max-height: 500px;
}

.batch-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.batch-table th {
  position: sticky;
  top: 0;
  background: var(--bg-surface-secondary);
  color: var(--text-muted);
  font-weight: 700;
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border-color);
  text-align: left;
  white-space: nowrap;
  z-index: 10;
}

.batch-table td {
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-main);
  white-space: nowrap;
}

.batch-table tr:hover {
  background: var(--primary-light);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.5rem;
  font-size: 0.725rem;
  font-weight: 600;
  border-radius: 9999px;
  line-height: 1.2;
}

.badge-success {
  background: var(--success-light);
  color: var(--success);
}

.badge-warning {
  background: var(--warning-light);
  color: var(--warning);
}

.badge-danger {
  background: var(--danger-light);
  color: var(--danger);
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

[data-theme="dark"] .modal-overlay {
  background: rgba(0, 0, 0, 0.75);
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-container {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  max-width: 600px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
  font-size: 1.25rem;
  line-height: 1;
}

.modal-close:hover {
  color: var(--danger);
}

.modal-body {
  padding: 1.25rem;
}

.modal-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border-color);
  background: var(--bg-surface-secondary);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

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

.toast {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-main);
  min-width: 280px;
  transform: translateX(120%);
  transition: transform 0.25s ease-out;
}

.toast.show {
  transform: translateX(0);
}

.toast.toast-success {
  border-left-color: var(--success);
}

.toast.toast-warning {
  border-left-color: var(--warning);
}

.toast.toast-danger {
  border-left-color: var(--danger);
}

/* Directory Tables */
.directory-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

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

.list-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.list-table th {
  background: var(--bg-surface-secondary);
  border-bottom: 2px solid var(--border-color);
  padding: 0.6rem 0.75rem;
  text-align: left;
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--primary);
}

.list-table td {
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-main);
}

.empty-state {
  padding: 2.5rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

#printContainer {
  display: none;
}
