/* ==========================================================================
   FacturaFlow - Design System & Modern Aesthetics
   ========================================================================== */

:root {
  /* Color Palette - Deep Slate Dark Theme */
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-card: rgba(17, 24, 39, 0.75);
  --bg-card-hover: rgba(30, 41, 59, 0.85);
  --bg-elevated: #1f293d;
  --bg-input: rgba(15, 23, 42, 0.6);

  /* Borders & Dividers */
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-medium: rgba(255, 255, 255, 0.15);
  --border-focus: #6366f1;

  /* Typography Colors */
  --text-main: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-inverse: #0f172a;

  /* Brand Accents */
  --accent-primary: #6366f1;
  --accent-primary-hover: #4f46e5;
  --accent-primary-glow: rgba(99, 102, 241, 0.25);
  
  --accent-cyan: #06b6d4;
  --accent-cyan-glow: rgba(6, 182, 212, 0.2);

  /* Status Colors */
  --status-pending: #f59e0b;
  --status-pending-bg: rgba(245, 158, 11, 0.12);
  --status-pending-border: rgba(245, 158, 11, 0.3);

  --status-processed: #10b981;
  --status-processed-bg: rgba(16, 185, 129, 0.12);
  --status-processed-border: rgba(16, 185, 129, 0.3);

  --status-resubmit: #ef4444;
  --status-resubmit-bg: rgba(239, 68, 68, 0.15);
  --status-resubmit-border: rgba(239, 68, 68, 0.35);

  /* Shadows & Glass */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 8px 24px -4px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 20px 40px -8px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 30px rgba(99, 102, 241, 0.2);

  --glass-blur: blur(16px);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  /* Transitions */
  --trans-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --trans-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Light Theme Variables */
[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-card: rgba(255, 255, 255, 0.85);
  --bg-card-hover: rgba(241, 245, 249, 0.95);
  --bg-elevated: #ffffff;
  --bg-input: #f1f5f9;

  --border-subtle: rgba(0, 0, 0, 0.08);
  --border-medium: rgba(0, 0, 0, 0.15);
  --border-focus: #4f46e5;

  --text-main: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --text-inverse: #ffffff;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 8px 24px -4px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 20px 40px -8px rgba(0, 0, 0, 0.12);
  --shadow-glow: 0 0 30px rgba(99, 102, 241, 0.12);
}

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

body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-main);
  min-height: 100vh;
  line-height: 1.5;
  overflow-x: hidden;
  background-image: 
    radial-gradient(circle at 15% 10%, rgba(99, 102, 241, 0.08) 0%, transparent 40%),
    radial-gradient(circle at 85% 80%, rgba(6, 182, 212, 0.06) 0%, transparent 45%);
  background-attachment: fixed;
}

/* Typography Helpers */
h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.02em;
}

a {
  color: var(--accent-primary);
  text-decoration: none;
}

/* Icons */
.icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
}

.icon svg {
  width: 1.25em;
  height: 1.25em;
  fill: currentColor;
}

/* App Container */
.app-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ==========================================================================
   Header & Navigation
   ========================================================================== */
.main-header {
  position: sticky;
  top: 0;
  z-index: 40;
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  background-color: rgba(10, 14, 23, 0.85);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0.85rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

[data-theme="light"] .main-header {
  background-color: rgba(255, 255, 255, 0.85);
}

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

.brand-logo-icon {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, #6366f1, #06b6d4);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.35);
  color: white;
}

.brand-text h1 {
  font-size: 1.25rem;
  line-height: 1.2;
  background: linear-gradient(135deg, #ffffff 30%, #94a3b8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

[data-theme="light"] .brand-text h1 {
  background: linear-gradient(135deg, #0f172a 30%, #475569);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

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

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* User Profile Badge */
.user-profile-menu {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  padding: 0.35rem 0.75rem 0.35rem 0.4rem;
  border-radius: var(--radius-full);
}

.user-avatar-circle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: white;
  text-transform: uppercase;
}

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

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

.user-info-role {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 1px 6px;
  border-radius: 4px;
  margin-top: 2px;
  display: inline-block;
  width: fit-content;
}

.role-admin {
  background: rgba(99, 102, 241, 0.15);
  color: #818cf8;
  border: 1px solid rgba(99, 102, 241, 0.3);
}

.role-user {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

/* Theme Toggle & Ghost Buttons */
.btn-icon {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--trans-fast);
}

.btn-icon:hover {
  background: var(--bg-card-hover);
  color: var(--text-main);
  border-color: var(--border-medium);
}

/* ==========================================================================
   Buttons & Form Controls
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--trans-fast);
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: white;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #4f46e5, #4338ca);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

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

.btn-secondary:hover {
  background: var(--bg-elevated);
  border-color: var(--text-muted);
}

.btn-success {
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.3);
}

.btn-success:hover {
  background: linear-gradient(135deg, #059669, #047857);
}

.btn-warning {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: white;
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.3);
}

.btn-danger {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: white;
  box-shadow: 0 4px 14px rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
  background: linear-gradient(135deg, #dc2626, #b91c1c);
}

.btn-sm {
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
}

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

/* Hero & KPI Metrics Section */
.hero-section {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 2rem;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.hero-title-area h2 {
  font-size: 1.75rem;
  margin-bottom: 0.25rem;
}

.hero-title-area p {
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.metric-card {
  background: var(--bg-card);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  transition: transform var(--trans-fast), border-color var(--trans-fast);
}

.metric-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-medium);
}

.metric-icon-box {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  flex-shrink: 0;
}

.metric-pending .metric-icon-box {
  background: var(--status-pending-bg);
  color: var(--status-pending);
  border: 1px solid var(--status-pending-border);
}

.metric-processed .metric-icon-box {
  background: var(--status-processed-bg);
  color: var(--status-processed);
  border: 1px solid var(--status-processed-border);
}

.metric-resubmit .metric-icon-box {
  background: var(--status-resubmit-bg);
  color: var(--status-resubmit);
  border: 1px solid var(--status-resubmit-border);
}

.metric-total .metric-icon-box {
  background: rgba(99, 102, 241, 0.15);
  color: var(--accent-primary);
  border: 1px solid rgba(99, 102, 241, 0.3);
}

.metric-info h4 {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.2rem;
}

.metric-number {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1;
}

.metric-subtext {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* ==========================================================================
   Filter & Toolbar Bar
   ========================================================================== */
.toolbar-container {
  background: var(--bg-card);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.status-tabs {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 2px;
}

.status-tab-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: all var(--trans-fast);
  white-space: nowrap;
}

.status-tab-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.04);
}

.status-tab-btn.active {
  background: var(--bg-elevated);
  color: var(--text-main);
  border-color: var(--border-medium);
  box-shadow: var(--shadow-sm);
}

.tab-badge {
  font-size: 0.72rem;
  padding: 1px 7px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-secondary);
}

.status-tab-btn.active .tab-badge {
  background: var(--accent-primary);
  color: white;
}

.toolbar-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.search-box-wrapper {
  position: relative;
  min-width: 240px;
}

.search-box-wrapper input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.55rem 0.85rem 0.55rem 2.25rem;
  font-family: inherit;
  font-size: 0.875rem;
  color: var(--text-main);
  outline: none;
  transition: border-color var(--trans-fast);
}

.search-box-wrapper input:focus {
  border-color: var(--border-focus);
}

.search-icon-pos {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.select-filter {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.55rem 0.85rem;
  font-family: inherit;
  font-size: 0.875rem;
  color: var(--text-main);
  outline: none;
  cursor: pointer;
}

.view-toggle-group {
  display: flex;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 2px;
}

.view-toggle-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--trans-fast);
}

.view-toggle-btn.active {
  background: var(--bg-elevated);
  color: var(--text-main);
}

/* ==========================================================================
   Invoices Grid & Cards
   ========================================================================== */
.invoices-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 1.5rem;
}

.invoice-card {
  background: var(--bg-card);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: all var(--trans-normal);
  position: relative;
}

.invoice-card:hover {
  transform: translateY(-4px);
  border-color: var(--border-medium);
  box-shadow: var(--shadow-md);
}

/* Card Header & Thumbnail */
.card-media-wrapper {
  position: relative;
  width: 100%;
  height: 220px;
  background: #0f172a;
  overflow: hidden;
  cursor: pointer;
}

.card-invoice-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  transition: transform 0.4s ease;
}

.card-media-wrapper:hover .card-invoice-img {
  transform: scale(1.05);
}

.card-overlay-hover {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--trans-fast);
  backdrop-filter: blur(2px);
}

.card-media-wrapper:hover .card-overlay-hover {
  opacity: 1;
}

.inspect-pill {
  background: rgba(255, 255, 255, 0.95);
  color: #0f172a;
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Status Badges */
.status-badge-floating {
  position: absolute;
  top: 0.85rem;
  left: 0.85rem;
  z-index: 2;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  backdrop-filter: blur(10px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}

.badge-pending {
  background: rgba(245, 158, 11, 0.9);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.badge-processed {
  background: rgba(16, 185, 129, 0.9);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.badge-resubmit {
  background: rgba(239, 68, 68, 0.92);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  animation: pulseAlert 2.5s infinite;
}

@keyframes pulseAlert {
  0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5); }
  70% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.version-chip {
  position: absolute;
  top: 0.85rem;
  right: 0.85rem;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  backdrop-filter: blur(8px);
}

/* Card Body */
.card-content {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.card-top-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.5rem;
}

.invoice-number-tag {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent-cyan);
  background: rgba(6, 182, 212, 0.1);
  padding: 2px 8px;
  border-radius: 4px;
}

.invoice-date {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.vendor-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.3;
  margin-bottom: 0.5rem;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-category-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
}

/* Reason Alert Box when Re-upload is requested */
.resubmit-alert-box {
  background: rgba(239, 68, 68, 0.1);
  border-left: 3px solid var(--status-resubmit);
  padding: 0.65rem 0.85rem;
  border-radius: 4px var(--radius-sm) var(--radius-sm) 4px;
  margin-bottom: 1rem;
}

.resubmit-alert-header {
  font-size: 0.75rem;
  font-weight: 700;
  color: #f87171;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.25rem;
}

.resubmit-alert-text {
  font-size: 0.8rem;
  color: #fecaca;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Card Price Row */
.card-price-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-top: auto;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border-subtle);
}

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

.amount-value {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text-main);
}

.amount-currency {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-cyan);
  margin-right: 2px;
}

/* Card Footer Action Bar */
.card-actions-bar {
  padding: 0.85rem 1.25rem;
  background: rgba(15, 23, 42, 0.4);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

/* Table View Mode */
.invoices-table-container {
  background: var(--bg-card);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow-x: auto;
}

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

.invoices-table th {
  padding: 1rem 1.25rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(15, 23, 42, 0.3);
}

.invoices-table td {
  padding: 1rem 1.25rem;
  font-size: 0.875rem;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-main);
  vertical-align: middle;
}

.invoices-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.table-thumb-preview {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  cursor: pointer;
  border: 1px solid var(--border-subtle);
}

/* ==========================================================================
   Modals & Overlays
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 15, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  opacity: 0;
  visibility: hidden;
  transition: all var(--trans-normal);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-dialog {
  background: var(--bg-secondary);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  transform: scale(0.95);
  transition: transform var(--trans-normal);
  overflow: hidden;
}

.modal-overlay.active .modal-dialog {
  transform: scale(1);
}

.modal-dialog-large {
  max-width: 1100px;
  height: 88vh;
}

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

.modal-header h3 {
  font-size: 1.25rem;
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 6px;
  display: flex;
  transition: color var(--trans-fast);
}

.modal-close-btn:hover {
  color: var(--text-main);
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 1.25rem 1.5rem;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  background: rgba(15, 23, 42, 0.3);
}

/* Form Styles */
.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
}

.form-label .required-star {
  color: #ef4444;
}

.form-control {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.65rem 0.9rem;
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--text-main);
  outline: none;
  transition: border-color var(--trans-fast), box-shadow var(--trans-fast);
}

.form-control:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

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

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

/* Drag and Drop Upload Area */
.upload-dropzone {
  border: 2px dashed rgba(99, 102, 241, 0.4);
  background: rgba(99, 102, 241, 0.03);
  border-radius: var(--radius-lg);
  padding: 2rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: all var(--trans-fast);
  position: relative;
  overflow: hidden;
}

.upload-dropzone:hover, .upload-dropzone.dragover {
  border-color: var(--accent-primary);
  background: rgba(99, 102, 241, 0.08);
}

.dropzone-icon-circle {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: rgba(99, 102, 241, 0.15);
  color: var(--accent-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
  margin: 0 auto 1rem;
}

.dropzone-prompt h4 {
  font-size: 1rem;
  margin-bottom: 0.25rem;
}

.dropzone-prompt p {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.dropzone-options {
  margin-top: 1rem;
  display: flex;
  justify-content: center;
  gap: 0.75rem;
}

.upload-preview-wrapper {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-medium);
  margin-top: 1rem;
  max-height: 280px;
  display: flex;
  justify-content: center;
  background: #000;
}

.upload-preview-img {
  max-width: 100%;
  max-height: 280px;
  object-fit: contain;
}

.btn-remove-preview {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: rgba(239, 68, 68, 0.85);
  color: white;
  border: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ==========================================================================
   Full Invoice Inspector Modal (Side-by-Side)
   ========================================================================== */
.inspector-layout {
  display: grid;
  grid-template-columns: 1fr 400px;
  height: calc(88vh - 70px);
}

.inspector-image-pane {
  background: #05080f;
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--border-subtle);
}

.inspector-viewport {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  cursor: grab;
}

.inspector-viewport:active {
  cursor: grabbing;
}

.inspector-img {
  max-width: 90%;
  max-height: 90%;
  object-fit: contain;
  transition: transform 0.2s ease, filter 0.2s ease;
  transform-origin: center center;
}

/* Thermal receipt filter */
.inspector-img.filter-contrast {
  filter: contrast(180%) brightness(110%);
}

.inspector-img.filter-invert {
  filter: invert(100%) contrast(150%);
}

.image-toolbar {
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(12px);
  padding: 0.65rem 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  border-top: 1px solid var(--border-subtle);
}

.inspector-details-pane {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  background: var(--bg-secondary);
}

.inspector-details-content {
  padding: 1.5rem;
  flex: 1;
}

.detail-section {
  margin-bottom: 1.5rem;
}

.detail-section h4 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0.35rem;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.detail-item-label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.detail-item-val {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-main);
}

/* Audit History Timeline */
.timeline-list {
  list-style: none;
  position: relative;
  padding-left: 1.25rem;
}

.timeline-list::before {
  content: '';
  position: absolute;
  left: 4px;
  top: 6px;
  bottom: 6px;
  width: 2px;
  background: var(--border-medium);
}

.timeline-item {
  position: relative;
  margin-bottom: 1rem;
}

.timeline-item:last-child {
  margin-bottom: 0;
}

.timeline-dot {
  position: absolute;
  left: -1.25rem;
  top: 4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-primary);
  border: 2px solid var(--bg-secondary);
}

.timeline-action {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-main);
}

.timeline-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.timeline-detail {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-top: 4px;
  background: rgba(255, 255, 255, 0.03);
  padding: 4px 8px;
  border-radius: 4px;
}

/* Version Navigator in Inspector */
.version-picker {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.version-btn {
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.version-btn.active {
  background: var(--accent-primary);
  color: white;
  border-color: var(--accent-primary);
}

/* ==========================================================================
   Auth Modal & Screen
   ========================================================================== */
.auth-wrapper {
  max-width: 440px;
  width: 100%;
  margin: 4rem auto;
  padding: 1.5rem;
}

.auth-card {
  background: var(--bg-card);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-xl);
  padding: 2.25rem;
  box-shadow: var(--shadow-lg);
}

.auth-header {
  text-align: center;
  margin-bottom: 1.75rem;
}

.auth-header .brand-logo-icon {
  margin: 0 auto 1rem;
  width: 48px;
  height: 48px;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  background: var(--bg-input);
  padding: 4px;
  border-radius: var(--radius-md);
  margin-bottom: 1.5rem;
}

.auth-tab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 0.6rem;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  transition: all var(--trans-fast);
}

.auth-tab-btn.active {
  background: var(--bg-elevated);
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
}

.quick-demo-accounts {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border-subtle);
}

.demo-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 700;
  letter-spacing: 0.05em;
  margin-bottom: 0.75rem;
  text-align: center;
}

.demo-buttons-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.demo-login-chip {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.65rem 0.75rem;
  text-align: left;
  cursor: pointer;
  transition: all var(--trans-fast);
}

.demo-login-chip:hover {
  background: rgba(99, 102, 241, 0.1);
  border-color: var(--accent-primary);
}

.demo-chip-role {
  font-size: 0.75rem;
  font-weight: 700;
  display: block;
}

.demo-chip-user {
  font-size: 0.7rem;
  color: var(--text-muted);
  display: block;
}

/* ==========================================================================
   Toast Notification System
   ========================================================================== */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  pointer-events: none;
}

.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border-medium);
  box-shadow: var(--shadow-lg);
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-size: 0.875rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 300px;
  max-width: 420px;
  pointer-events: auto;
  transform: translateY(20px);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast-success { border-left: 4px solid var(--status-processed); }
.toast-error { border-left: 4px solid var(--status-resubmit); }
.toast-warning { border-left: 4px solid var(--status-pending); }
.toast-info { border-left: 4px solid var(--accent-primary); }

/* Empty States */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  background: var(--bg-card);
  border: 1px dashed var(--border-medium);
  border-radius: var(--radius-xl);
}

.empty-icon {
  font-size: 3rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

/* Mobile Responsive */
@media (max-width: 900px) {
  .inspector-layout {
    grid-template-columns: 1fr;
    height: auto;
    overflow-y: auto;
  }

  .inspector-image-pane {
    height: 350px;
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
  }

  .modal-dialog-large {
    max-height: 95vh;
  }
}

@media (max-width: 640px) {
  html, body { min-width: 0; overflow-x: hidden; }
  .main-header {
    padding: 0.75rem 1rem;
  }

  .main-wrapper {
    padding: 1rem;
  }

  .hero-section {
    flex-direction: column;
    align-items: stretch;
  }

  .invoices-grid {
    grid-template-columns: 1fr;
  }

  .toolbar-container {
    flex-direction: column;
    align-items: stretch;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

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

  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal-dialog, .modal-dialog-large {
    width: 100%;
    max-width: none;
    max-height: 96vh;
    height: auto;
    border-radius: 1rem 1rem 0 0;
  }
  .modal-header { padding: .9rem 1rem; }
  .modal-header h3 { font-size: 1.05rem; }
  .modal-body { padding: 1rem; min-height: 0; }
  .modal-footer {
    position: sticky;
    bottom: 0;
    z-index: 2;
    padding: .75rem 1rem calc(.75rem + env(safe-area-inset-bottom));
    flex-direction: column-reverse;
    align-items: stretch;
  }
  .modal-footer .btn { width: 100%; min-height: 46px; justify-content: center; }
  .upload-dropzone { padding: 1.25rem .75rem; }
  .dropzone-options { flex-direction: column; width: 100%; }
  .dropzone-options .btn { width: 100%; min-height: 44px; justify-content: center; }
  #btn-save-invoice { display: flex !important; visibility: visible !important; }
  .modal-body .form-control { font-size: 16px; }
}

/* ==========================================================================
   Client Portal Specific Styles (Acceso Cliente)
   ========================================================================== */
.role-client {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.client-portal-banner {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.08) 0%, rgba(99, 102, 241, 0.08) 100%);
  border: 1px solid rgba(245, 158, 11, 0.25);
  border-radius: var(--radius-xl);
  padding: 1.5rem;
  margin-bottom: 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.client-banner-text h2 {
  font-size: 1.5rem;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 0.35rem;
}

.client-ruc-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(245, 158, 11, 0.18);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: #fbbf24;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.2rem 0.65rem;
  border-radius: var(--radius-full);
}

.client-banner-text p {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.client-banner-action {
  flex-shrink: 0;
}

.btn-client-camera {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: white;
  font-size: 1rem;
  padding: 0.85rem 1.75rem;
  border-radius: var(--radius-lg);
  box-shadow: 0 6px 20px rgba(245, 158, 11, 0.35);
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 700;
  border: none;
  cursor: pointer;
  transition: all var(--trans-fast);
}

.btn-client-camera:hover {
  background: linear-gradient(135deg, #d97706, #b45309);
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(245, 158, 11, 0.45);
}

.client-ruc-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.25);
  color: #fbbf24;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 4px;
}

.client-instructions-box {
  background: rgba(99, 102, 241, 0.06);
  border-left: 3px solid var(--accent-primary);
  padding: 0.75rem 1rem;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin-bottom: 1.25rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

