/* ====== BASE / VARIABLES ====== */
:root {
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.6;
  font-weight: 400;
  color-scheme: light;
  color: var(--text-primary);
  background-color: var(--bg-page);

  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: rgba(37, 99, 235, 0.06);
  --primary-subtle: rgba(37, 99, 235, 0.08);
  --success: #16a34a;
  --success-hover: #15803d;
  --warning: #ca8a04;
  --warning-hover: #a16207;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --green-600: #16a34a;
  --amber-600: #d97706;
  --red-600: #dc2626;
  --card-bg: #ffffff;
  --border-color: #e2e8f0;
  --border-subtle: #f1f5f9;
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --text-tertiary: #94a3b8;
  --sidebar-bg: #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-active: #3b82f6;
  --sidebar-hover: rgba(255, 255, 255, 0.04);
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 10px;
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.08);

  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

*, *::before, *::after { box-sizing: border-box; }

a { font-weight: 500; color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }

body { margin: 0; min-width: 320px; min-height: 100vh; }

h1 { font-size: 1.625rem; line-height: 1.25; font-weight: 600; letter-spacing: -0.02em; }

#app { width: 100%; min-height: 100vh; }

button {
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  padding: 0.5em 1em;
  font-size: 0.8125rem;
  font-weight: 500;
  font-family: inherit;
  background-color: var(--primary);
  color: white;
  cursor: pointer;
  transition: background-color 0.15s ease, box-shadow 0.15s ease;
}
button:hover { background-color: var(--primary-hover); }
button:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Status badges */
.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.175rem 0.55rem;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.status-pending { background: #fef9c3; color: #854d0e; }
.status-paid { background: #dcfce7; color: #166534; }
.status-overdue { background: #fee2e2; color: #991b1b; }
.status-draft { background: #f1f5f9; color: #475569; }
.status-validated { background: #dbeafe; color: #1e40af; }
.status-unpaid { background: #fef2f2; color: #991b1b; }
.status-canceled { background: #f1f5f9; color: #94a3b8; text-decoration: line-through; }

/* Form group */
.form-group { margin-bottom: 1.25rem; }
.form-group label {
  display: block;
  color: var(--text-primary);
  margin-bottom: 0.375rem;
  font-weight: 500;
  font-size: 0.8125rem;
}
.form-group input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text-primary);
  font-size: 0.875rem;
  box-sizing: border-box;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.form-group input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.08);
}

/* View button */
.btn-view {
  background: transparent;
  border: none;
  padding: 0.35rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-tertiary);
  transition: color 0.15s ease, background 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-view:hover { color: var(--primary); background: var(--primary-light); }

/* Loading */
.loading, .error, .no-invoices, .no-clients {
  padding: 3rem;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.9rem;
}
.error { color: var(--danger); }

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1.25rem;
  padding: 0.75rem 1rem;
  background: var(--card-bg);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}
.pagination-info {
  font-weight: 500;
  color: var(--text-secondary);
  font-size: 0.8125rem;
  display: flex;
  gap: 0.3rem;
  align-items: center;
}
.pagination-info .current-page,
.pagination-info .total-pages {
  font-weight: 600;
  color: var(--text-primary);
  min-width: 20px;
  text-align: center;
}
.btn-pagination {
  padding: 0.4rem 0.9rem;
  background: var(--card-bg);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 500;
  font-size: 0.8125rem;
  transition: all 0.15s ease;
}
.btn-pagination:hover:not(:disabled) {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-pagination:disabled {
  background: #f8fafc;
  color: #cbd5e1;
  cursor: not-allowed;
}

@media (max-width: 768px) {
  .pagination { flex-wrap: wrap; gap: 0.5rem; }
  .btn-pagination { flex: 1; min-width: 90px; }
  .pagination-info { order: 3; width: 100%; justify-content: center; }
}

/* Skeleton */
@keyframes skeleton-shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
.skeleton {
  background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.8s ease-in-out infinite;
  border-radius: 4px;
}
.skeleton-row {
  display: flex; gap: 1rem;
  padding: 0.875rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
}
.skeleton-cell { height: 14px; border-radius: 3px; }
.skeleton-cell.w-sm { width: 60px; }
.skeleton-cell.w-md { width: 120px; }
.skeleton-cell.w-lg { width: 200px; }
.skeleton-cell.w-xl { width: 100%; }

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 3.5rem 2rem;
  text-align: center;
  color: var(--text-secondary);
}
.empty-state-icon {
  width: 56px; height: 56px;
  border-radius: 14px;
  background: var(--primary-light);
  display: flex;
  align-items: center; justify-content: center;
  margin-bottom: 1rem;
  color: var(--primary);
}
.empty-state h3 {
  margin: 0 0 0.25rem;
  color: var(--text-primary);
  font-size: 0.95rem;
  font-weight: 600;
}
.empty-state p {
  margin: 0 0 1rem;
  font-size: 0.8125rem;
  max-width: 320px;
  line-height: 1.5;
}
.empty-state .btn-empty-action {
  padding: 0.45rem 1rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 0.8125rem;
  cursor: pointer;
  transition: background 0.15s ease;
}
.empty-state .btn-empty-action:hover { background: var(--primary-hover); }

/* ── Page entrance animation ── */
.page-enter {
  animation: pageEnter 0.3s cubic-bezier(0.22, 1, 0.36, 1) both;
}

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

/* ── Stagger animation for KPI cards ── */
.db-kpi-card { animation: fadeInUp 0.4s cubic-bezier(0.22, 1, 0.36, 1) both; }
.db-kpi-card:nth-child(1) { animation-delay: 0ms; }
.db-kpi-card:nth-child(2) { animation-delay: 80ms; }
.db-kpi-card:nth-child(3) { animation-delay: 160ms; }
.db-kpi-card:nth-child(4) { animation-delay: 240ms; }

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

/* ── Hover lift for cards ── */
.db-kpi-card,
.settings-card,
.db-chart-card,
.db-recent-card,
.db-table-card {
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.db-kpi-card:hover,
.db-chart-card:hover,
.db-recent-card:hover,
.db-table-card:hover {
  transform: translateY(-1px);
}

/* ── Status badge enhanced ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  line-height: 1.6;
}

.badge::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  flex-shrink: 0;
}

.badge-draft {
  background: var(--gray-100);
  color: var(--gray-600);
}
.badge-draft::before { background: var(--gray-400); }

.badge-unpaid {
  background: var(--amber-50);
  color: var(--amber-600);
}
.badge-unpaid::before { background: var(--amber-600); }

.badge-paid {
  background: var(--green-50);
  color: var(--green-600);
}
.badge-paid::before { background: var(--green-600); }

:root[data-theme='dark'] .badge-draft {
  background: rgba(148, 163, 184, 0.14);
  color: #cbd5e1;
}
:root[data-theme='dark'] .badge-draft::before { background: #64748b; }
:root[data-theme='dark'] .badge-unpaid {
  background: rgba(245, 158, 11, 0.15);
  color: #fcd34d;
}
:root[data-theme='dark'] .badge-unpaid::before { background: #fcd34d; }
:root[data-theme='dark'] .badge-paid {
  background: rgba(34, 197, 94, 0.18);
  color: #86efac;
}
:root[data-theme='dark'] .badge-paid::before { background: #86efac; }

/* Fix select dropdown visibility in dark mode:
   Native <select> dropdowns render with OS background — force color-scheme
   so the browser renders options with the correct light/dark contrast */
:root[data-theme='dark'] {
  color-scheme: dark;
  --green-600: #86efac;
  --amber-600: #fcd34d;
  --red-600: #fca5a5;
}

select {
  color-scheme: inherit;
}

select option {
  background: var(--card-bg, #fff);
  color: var(--text-primary, #1e293b);
}
