:root {
  --font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  
  /* Light Theme */
  --bg-app: #f4f6fa;
  --bg-card: #ffffff;
  --bg-card-hover: #fcfdfe;
  --bg-muted: #f1f4f9;
  --border-color: #e2e8f0;
  --border-subtle: #edf2f7;
  
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --primary-border: #bfdbfe;
  
  --success: #10b981;
  --success-hover: #059669;
  --success-light: #ecfdf5;
  --success-border: #a7f3d0;
  --success-text: #065f46;
  
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --danger-light: #fef2f2;
  --danger-border: #fecaca;
  --danger-text: #991b1b;
  
  --warning: #f59e0b;
  --warning-hover: #d97706;
  --warning-light: #fffbeb;
  --warning-border: #fde68a;
  --warning-text: #92400e;
  
  --purple: #8b5cf6;
  --purple-light: #f5f3ff;
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.15), 0 8px 10px -6px rgba(0, 0, 0, 0.08);
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;
  
  --table-row-hover: #f8fafc;
  --table-stripe: #fafbfc;
}

[data-theme="dark"] {
  --bg-app: #0f172a;
  --bg-card: #1e293b;
  --bg-card-hover: #243248;
  --bg-muted: #141f33;
  --border-color: #334155;
  --border-subtle: #293548;
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-light: rgba(59, 130, 246, 0.15);
  --primary-border: #1d4ed8;
  
  --success: #10b981;
  --success-hover: #059669;
  --success-light: rgba(16, 185, 129, 0.15);
  --success-border: #047857;
  --success-text: #34d399;
  
  --danger: #f87171;
  --danger-hover: #ef4444;
  --danger-light: rgba(239, 68, 68, 0.15);
  --danger-border: #b91c1c;
  --danger-text: #fca5a5;
  
  --warning: #fbbf24;
  --warning-hover: #f59e0b;
  --warning-light: rgba(245, 158, 11, 0.15);
  --warning-border: #b45309;
  --warning-text: #fcd34d;
  
  --purple: #a78bfa;
  --purple-light: rgba(139, 92, 246, 0.15);
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -2px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
  
  --table-row-hover: #24344d;
  --table-stripe: #192437;
}

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

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

/* Header & Navbar */
.app-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  padding: 0.75rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}

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

.brand-section {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-logo {
  width: 42px;
  height: 42px;
  background: linear-gradient(135deg, #1d4ed8, #3b82f6);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.35rem;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.3);
}

.brand-text h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.brand-badge {
  font-size: 0.65rem;
  text-transform: uppercase;
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-full);
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 700;
  border: 1px solid var(--primary-border);
}

.brand-text p {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* Account Selector */
.account-switcher {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--bg-muted);
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.account-switcher label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.account-switcher select {
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius-sm);
  outline: none;
  cursor: pointer;
}

.account-switcher select:focus {
  border-color: var(--primary);
}

/* Header Actions */
.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.55rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.18s ease;
  font-family: inherit;
  text-decoration: none;
  white-space: nowrap;
}

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

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}
.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.35);
  transform: translateY(-1px);
}

.btn-success {
  background: var(--success);
  color: #ffffff;
}
.btn-success:hover {
  background: var(--success-hover);
  box-shadow: 0 4px 10px rgba(16, 185, 129, 0.35);
  transform: translateY(-1px);
}

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

.btn-outline {
  background: transparent;
  border-color: var(--border-color);
  color: var(--text-primary);
}
.btn-outline:hover {
  background: var(--bg-muted);
  border-color: var(--text-muted);
}

.btn-icon {
  width: 38px;
  height: 38px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background: var(--bg-muted);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.18s ease;
}
.btn-icon:hover {
  background: var(--border-color);
  color: var(--text-primary);
}

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

/* Navigation Tabs */
.tabs-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-bottom: 2px solid var(--border-color);
  margin-bottom: 1.5rem;
  overflow-x: auto;
  padding-bottom: 2px;
}

.tab-btn {
  background: transparent;
  border: none;
  font-family: inherit;
  font-size: 0.925rem;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 0.65rem 1.15rem;
  cursor: pointer;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  position: relative;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.tab-btn:hover {
  color: var(--text-primary);
  background: var(--bg-muted);
}

.tab-btn.active {
  color: var(--primary);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-bottom: 2px solid var(--bg-card);
  margin-bottom: -2px;
}

.tab-badge {
  font-size: 0.75rem;
  padding: 0.1rem 0.45rem;
  border-radius: var(--radius-full);
  background: var(--border-color);
  color: var(--text-secondary);
}

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

/* Stat Cards Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.15rem;
  margin-bottom: 1.75rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  position: relative;
  overflow: hidden;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.stat-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
}

.stat-card.card-balance::before { background: linear-gradient(90deg, #2563eb, #3b82f6); }
.stat-card.card-reconciled::before { background: linear-gradient(90deg, #10b981, #34d399); }
.stat-card.card-pending::before { background: linear-gradient(90deg, #f59e0b, #fbbf24); }
.stat-card.card-flow::before { background: linear-gradient(90deg, #8b5cf6, #ec4899); }

.stat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.stat-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.stat-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

.card-balance .stat-icon { background: var(--primary-light); color: var(--primary); }
.card-reconciled .stat-icon { background: var(--success-light); color: var(--success); }
.card-pending .stat-icon { background: var(--warning-light); color: var(--warning); }
.card-flow .stat-icon { background: var(--purple-light); color: var(--purple); }

.stat-value {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
  letter-spacing: -0.02em;
}

.stat-subtext {
  font-size: 0.8rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.stat-subtext span.badge-pill {
  font-size: 0.7rem;
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-full);
  font-weight: 700;
}

/* Sections */
.tab-content {
  display: none;
}
.tab-content.active {
  display: block;
  animation: fadeIn 0.25s ease;
}

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

/* Filter Toolbar */
.toolbar-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow-sm);
}

.toolbar-grid {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-wrap: wrap;
}

.search-box {
  flex: 1;
  min-width: 240px;
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 0.75rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.search-input {
  width: 100%;
  padding: 0.5rem 0.75rem 0.5rem 2.25rem;
  font-family: inherit;
  font-size: 0.875rem;
  background: var(--bg-muted);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s ease;
}

.search-input:focus {
  border-color: var(--primary);
  background: var(--bg-card);
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.filter-select {
  padding: 0.5rem 0.75rem;
  font-family: inherit;
  font-size: 0.85rem;
  background: var(--bg-muted);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  outline: none;
  cursor: pointer;
}

.filter-select:focus {
  border-color: var(--primary);
}

/* Table Styles */
.table-container {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  margin-bottom: 1.5rem;
}

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

.table-header-title {
  font-weight: 700;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
  max-height: 600px;
}

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

.data-table th {
  background: var(--bg-card);
  padding: 0.75rem 1rem;
  font-weight: 700;
  font-size: 0.775rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 10;
  white-space: nowrap;
}

.data-table td {
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
  vertical-align: middle;
}

.data-table tbody tr {
  transition: background-color 0.15s ease;
}

.data-table tbody tr:hover {
  background-color: var(--table-row-hover);
}

.data-table tbody tr.row-unreconciled {
  border-left: 3px solid var(--warning);
}

.data-table tbody tr.row-reconciled {
  border-left: 3px solid var(--success);
}

/* Amount typography */
.amount-income {
  color: var(--success);
  font-weight: 700;
  white-space: nowrap;
}

.amount-expense {
  color: var(--danger);
  font-weight: 700;
  white-space: nowrap;
}

.running-balance {
  font-weight: 700;
  white-space: nowrap;
  font-family: 'Courier New', Courier, monospace, sans-serif;
  font-size: 0.9rem;
}

/* Status Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: capitalize;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform 0.15s ease;
}

.badge:hover {
  transform: scale(1.04);
}

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

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

.badge-category {
  background: var(--bg-muted);
  color: var(--text-secondary);
  border-color: var(--border-color);
  font-size: 0.75rem;
}

.badge-debt-payable {
  background: var(--danger-light);
  color: var(--danger-text);
  border-color: var(--danger-border);
}

.badge-debt-receivable {
  background: var(--success-light);
  color: var(--success-text);
  border-color: var(--success-border);
}

.badge-status-settled {
  background: var(--success-light);
  color: var(--success-text);
  border-color: var(--success-border);
}

.badge-status-partial {
  background: var(--warning-light);
  color: var(--warning-text);
  border-color: var(--warning-border);
}

.badge-status-pending {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary-border);
}

.badge-status-overdue {
  background: #fee2e2;
  color: #991b1b;
  border-color: #f87171;
}

.badge-iess-deposited {
  background: #e0f2fe;
  color: #0369a1;
  border-color: #7dd3fc;
}

.badge-iess-cancelled {
  background: #ecfdf5;
  color: #065f46;
  border-color: #6ee7b7;
}

/* Debt Progress Bar */
.debt-progress-bar {
  width: 100%;
  height: 5px;
  background: var(--border-color);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-top: 4px;
}

.debt-progress-fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 0.3s ease;
}

/* Row Action Buttons */
.action-buttons {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.btn-table-action {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.3rem 0.45rem;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}

.btn-table-action:hover {
  color: var(--text-primary);
  background: var(--bg-muted);
}

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

/* Empty State */
.empty-state {
  text-align: center;
  padding: 3.5rem 1.5rem;
  color: var(--text-secondary);
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 0.75rem;
  opacity: 0.7;
}

.empty-state h3 {
  font-size: 1.1rem;
  color: var(--text-primary);
  margin-bottom: 0.35rem;
}

.empty-state p {
  font-size: 0.875rem;
  max-width: 420px;
  margin: 0 auto 1.25rem;
}

/* Reconciliation View */
.reconciliation-grid {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 1.5rem;
  align-items: start;
}

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

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

.reconcile-panel h3 {
  font-size: 1.05rem;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.reconcile-calc-box {
  background: var(--bg-muted);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  margin: 1rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.calc-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.calc-row.total-row {
  border-top: 1px dashed var(--border-color);
  padding-top: 0.5rem;
  font-weight: 700;
  color: var(--text-primary);
  font-size: 0.95rem;
}

.calc-row.difference-row {
  border-top: 2px solid var(--border-color);
  padding-top: 0.65rem;
  font-weight: 800;
  font-size: 1.05rem;
}

.difference-tag {
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 0.95rem;
}

.diff-balanced {
  background: var(--success-light);
  color: var(--success-text);
  border: 1px solid var(--success-border);
}

.diff-unbalanced {
  background: var(--danger-light);
  color: var(--danger-text);
  border: 1px solid var(--danger-border);
}

/* Charts Grid */
.charts-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

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

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

.chart-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.chart-card-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.chart-wrapper {
  position: relative;
  width: 100%;
  min-height: 260px;
  flex: 1;
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 1rem;
}

.modal-overlay.active {
  display: flex !important;
  animation: fadeIn 0.2s ease;
}

.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 580px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
  display: flex;
  flex-direction: column;
  animation: modalSlideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-box.modal-lg {
  max-width: 820px;
}

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

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

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 1.4rem;
  color: var(--text-secondary);
  cursor: pointer;
  line-height: 1;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}

.modal-close:hover {
  background: var(--bg-muted);
  color: var(--text-primary);
}

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

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  background: var(--bg-muted);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
}

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

@media (max-width: 540px) {
  .form-group.col-span-2 {
    grid-column: span 1;
  }
}

.form-label {
  font-size: 0.825rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-label .required {
  color: var(--danger);
}

.form-control {
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0.55rem 0.85rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-muted);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s ease;
}

.form-control:focus {
  border-color: var(--primary);
  background: var(--bg-card);
}

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

/* Radio Group / Toggle Segment */
.segmented-control {
  display: flex;
  background: var(--bg-muted);
  padding: 0.25rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  gap: 0.25rem;
}

.segmented-control label {
  flex: 1;
  text-align: center;
  font-size: 0.825rem;
  font-weight: 600;
  padding: 0.45rem 0.5rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
}

.segmented-control input[type="radio"] {
  display: none;
}

.segmented-control label:has(input[type="radio"]:checked) {
  background: var(--bg-card);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

.segmented-control label.opt-income:has(input[type="radio"]:checked) {
  color: var(--success);
  font-weight: 700;
}

.segmented-control label.opt-expense:has(input[type="radio"]:checked) {
  color: var(--danger);
  font-weight: 700;
}

.segmented-control label.opt-fee:has(input[type="radio"]:checked) {
  color: var(--warning);
  font-weight: 700;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  z-index: 1000;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.85rem 1.15rem;
  box-shadow: var(--shadow-lg);
  font-size: 0.875rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 280px;
  max-width: 420px;
  animation: toastIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  color: var(--text-primary);
}

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

.toast-success { border-left: 4px solid var(--success); }
.toast-danger { border-left: 4px solid var(--danger); }
.toast-info { border-left: 4px solid var(--primary); }
.toast-warning { border-left: 4px solid var(--warning); }

/* Print Stylesheet for Reports */
@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
  }
  
  .app-header,
  .tabs-nav,
  .toolbar-card,
  .header-actions,
  .action-buttons,
  .btn,
  .toast-container,
  .modal-overlay {
    display: none !important;
  }
  
  .main-wrapper {
    margin: 0 !important;
    padding: 0 !important;
    max-width: 100% !important;
  }
  
  .tab-content {
    display: block !important;
  }
  
  .stats-grid {
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 10px !important;
  }
  
  .stat-card {
    border: 1px solid #ccc !important;
    box-shadow: none !important;
  }
  
  .data-table {
    font-size: 9pt !important;
  }
  
  .print-only-header {
    display: block !important;
    margin-bottom: 20px;
    border-bottom: 2px solid #000;
    padding-bottom: 10px;
  }
}

.print-only-header {
  display: none;
}

/* ==========================================================================
   Drag and Drop Styles (Reordenamiento Interactivo en todas las secciones)
   ========================================================================== */
tr[draggable="true"], .draggable-item {
  transition: background-color 0.15s ease, opacity 0.15s ease, box-shadow 0.15s ease;
}

.drag-handle-cell, .drag-handle {
  cursor: grab !important;
  user-select: none;
  color: var(--text-muted);
  font-size: 1.15rem;
  letter-spacing: -2px;
  text-align: center;
  transition: color 0.15s ease, transform 0.15s ease;
}

.drag-handle-cell:hover, .drag-handle:hover {
  color: var(--primary) !important;
  transform: scale(1.2);
}

.drag-handle-cell:active, .drag-handle:active,
tr.dragging .drag-handle-cell, .draggable-item.dragging .drag-handle {
  cursor: grabbing !important;
}

tr.dragging, .draggable-item.dragging {
  opacity: 0.35 !important;
  background-color: var(--primary-light) !important;
  outline: 2px dashed var(--primary);
}

tr.drag-over-top, .draggable-item.drag-over-top {
  border-top: 3px solid var(--primary) !important;
  box-shadow: 0 -3px 8px rgba(37, 99, 235, 0.25) !important;
}

tr.drag-over-bottom, .draggable-item.drag-over-bottom {
  border-bottom: 3px solid var(--primary) !important;
  box-shadow: 0 3px 8px rgba(37, 99, 235, 0.25) !important;
}

/* Sub-navegación para Contabilidad Core NIIF */
.accounting-subtabs-nav {
  display: flex;
  gap: 0.5rem;
  border-bottom: 2px solid var(--border-color);
  margin-bottom: 1.5rem;
  overflow-x: auto;
  padding-bottom: 2px;
}

.accounting-subtab-btn {
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 0.65rem 1.15rem;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  white-space: nowrap;
  transition: all 0.15s ease;
  margin-bottom: -2px;
}

.accounting-subtab-btn:hover {
  color: var(--primary);
  background: var(--bg-muted);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.accounting-subtab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 700;
}

.accounting-subtab-content {
  display: none;
}

.accounting-subtab-content.active {
  display: block;
  animation: fadeIn 0.2s ease;
}

/* SRI Subtabs Navigation */
.sri-subtabs-nav {
  display: flex;
  gap: 0.5rem;
  border-bottom: 2px solid var(--border-color);
  margin-bottom: 1.5rem;
  overflow-x: auto;
  padding-bottom: 2px;
}

.sri-subtab-btn {
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 0.65rem 1.15rem;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  white-space: nowrap;
  transition: all 0.15s ease;
  margin-bottom: -2px;
}

.sri-subtab-btn:hover {
  color: var(--primary);
  background: var(--bg-muted);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.sri-subtab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 700;
}

.sri-subtab-panel {
  display: none;
}

.sri-subtab-panel.active {
  display: block;
  animation: fadeIn 0.2s ease;
}

/* XML Preformatted Box */
.xml-code-box {
  background: #0f172a;
  color: #38bdf8;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 0.82rem;
  padding: 1.25rem;
  border-radius: var(--radius-md);
  max-height: 480px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
  border: 1px solid #1e293b;
}

[data-theme="light"] .xml-code-box {
  background: #f8fafc;
  color: #0369a1;
  border: 1px solid #cbd5e1;
}

/* Estilos de Impresión de Volante de Rol de Pagos */
@media print {
  body * {
    visibility: hidden;
  }
  #modalPaySlipView, #modalPaySlipView * {
    visibility: visible;
  }
  #modalPaySlipView {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    margin: 0;
    padding: 0;
    background: #ffffff !important;
  }
  .modal-overlay {
    background: transparent !important;
  }
  .modal-header, .modal-footer, .btn {
    display: none !important;
  }
  #paySlipViewContent {
    box-shadow: none !important;
    border: none !important;
    padding: 0 !important;
  }
}

/* ==========================================================================
   PORTAL DE AUTENTICACIÓN Y REGISTRO DE USUARIOS (CLOUDFLARE D1 + PBKDF2)
   ========================================================================== */
body.auth-locked {
  overflow: hidden !important;
}

.auth-gate-overlay {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: radial-gradient(circle at 20% 20%, rgba(15, 23, 42, 0.94) 0%, rgba(2, 6, 23, 0.98) 100%);
  backdrop-filter: blur(12px);
}

.auth-gate-overlay.active {
  display: flex;
}

.auth-card {
  width: 100%;
  max-width: 500px;
  max-height: 94vh;
  overflow-y: auto;
  background: var(--bg-card, #ffffff);
  color: var(--text-primary, #0f172a);
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 16px;
  padding: 2rem;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.55);
  animation: authFadeIn 0.25s ease-out;
}

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

.auth-brand-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.4rem;
  padding-bottom: 1.15rem;
  border-bottom: 1px solid var(--border-color, #e2e8f0);
}

.auth-logo-circle {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  color: #ffffff;
  font-size: 1.65rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 8px 16px rgba(37, 99, 235, 0.28);
}

.auth-title {
  margin: 0;
  font-size: 1.28rem;
  font-weight: 800;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.auth-subtitle {
  margin: 0.25rem 0 0;
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.35;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
  background: var(--bg-surface, #f1f5f9);
  padding: 0.35rem;
  border-radius: 10px;
  border: 1px solid var(--border-color, #e2e8f0);
  margin-bottom: 1.25rem;
}

.auth-tab-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.86rem;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.18s ease;
}

.auth-tab-btn:hover {
  color: var(--text-primary);
}

.auth-tab-btn.active {
  background: var(--bg-card, #ffffff);
  color: var(--primary, #2563eb);
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.08);
  font-weight: 700;
}

.auth-feedback-alert {
  padding: 0.75rem 0.95rem;
  border-radius: 8px;
  font-size: 0.83rem;
  font-weight: 600;
  margin-bottom: 1rem;
  line-height: 1.4;
}

.auth-feedback-alert.danger {
  background: rgba(239, 68, 68, 0.12);
  color: #dc2626;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.auth-feedback-alert.success {
  background: rgba(16, 185, 129, 0.12);
  color: #059669;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.auth-form .form-group {
  margin-bottom: 0.95rem;
}

.auth-submit-btn {
  width: 100%;
  justify-content: center;
  padding: 0.75rem 1rem;
  font-size: 0.95rem;
  font-weight: 700;
  margin-top: 0.35rem;
}

.auth-footer-note {
  margin-top: 1.1rem;
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-secondary);
  display: flex;
  justify-content: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.auth-footer-note a {
  color: var(--primary, #2563eb);
  font-weight: 700;
  text-decoration: none;
}

.auth-footer-note a:hover {
  text-decoration: underline;
}

.auth-security-badge {
  margin-top: 1.35rem;
  padding-top: 0.95rem;
  border-top: 1px dashed var(--border-color, #e2e8f0);
  text-align: center;
  font-size: 0.73rem;
  color: var(--text-secondary);
  line-height: 1.4;
}



