/* ============================================
   Design Tokens
   ============================================ */
:root {
  /* Typography */
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  font-weight: 400;

  /* Color tokens */
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;

  --blue-50: #eff6ff;
  --blue-100: #dbeafe;
  --blue-500: #3b82f6;
  --blue-600: #2563eb;
  --blue-700: #1d4ed8;

  --green-50: #f0fdf4;
  --green-100: #dcfce7;
  --green-600: #16a34a;
  --green-700: #15803d;

  --amber-50: #fffbeb;
  --amber-100: #fef3c7;
  --amber-600: #d97706;

  --red-50: #fef2f2;
  --red-100: #fee2e2;
  --red-500: #ef4444;
  --red-600: #dc2626;
  --red-700: #b91c1c;

  --primary: var(--blue-600);
  --primary-hover: var(--blue-700);
  --primary-light: rgba(37, 99, 235, 0.06);
  --primary-subtle: rgba(37, 99, 235, 0.08);
  --success: var(--green-600);
  --success-hover: var(--green-700);
  --warning: var(--amber-600);
  --warning-hover: #a16207;
  --danger: var(--red-500);
  --danger-hover: var(--red-600);

  --card-bg: #ffffff;
  --border-color: var(--gray-200);
  --border-subtle: var(--gray-100);
  --text-primary: var(--gray-900);
  --text-secondary: var(--gray-500);
  --text-tertiary: var(--gray-400);
  --bg-page: var(--gray-50);
  --bg-subtle: var(--gray-100);

  /* Spacing (4px grid) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;

  /* Radius */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;

  /* Shadows */
  --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 6px -1px rgba(0, 0, 0, 0.06), 0 2px 4px -2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.06), 0 4px 6px -4px rgba(0, 0, 0, 0.04);

  /* Transitions */
  --transition-fast: 120ms ease;
  --transition-base: 150ms ease;

  color-scheme: light;
  color: var(--text-primary);
  background-color: var(--bg-page);

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

/* ── Large / Presentation Displays ── */
@media (min-width: 1600px) {
  :root {
    font-size: 15px;
  }
}

@media (min-width: 2200px) {
  :root {
    font-size: 16px;
  }
}

:root[data-theme='dark'] {
  --gray-50: #0f172a;
  --gray-100: #111827;
  --gray-200: #1f2937;
  --gray-300: #374151;
  --gray-400: #94a3b8;
  --gray-500: #cbd5e1;
  --gray-600: #e2e8f0;
  --gray-700: #f1f5f9;
  --gray-800: #f8fafc;
  --gray-900: #ffffff;

  --card-bg: #0b1220;
  --border-color: #1f2a3d;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-tertiary: #64748b;
  --bg-page: #070d18;
  --bg-subtle: #0f172a;
  --border-subtle: #1f2a3d;
  color-scheme: dark;
}

:root[data-theme='dark'] .status-paid,
:root[data-theme='dark'] .status-badge-client.status-active {
  background-color: #15803d;
  color: #fff;
}

:root[data-theme='dark'] .status-overdue,
:root[data-theme='dark'] .status-unpaid,
:root[data-theme='dark'] .status-badge-client.status-inactive {
  background-color: #c2410c;
  color: #fff;
}

:root[data-theme='dark'] .status-pending {
  background-color: #b45309;
  color: #fff;
}

:root[data-theme='dark'] .status-draft,
:root[data-theme='dark'] .status-badge-client.status-unknown {
  background-color: #475569;
  color: #fff;
}

:root[data-theme='dark'] .status-canceled {
  background-color: #991b1b;
  color: #fff;
  opacity: 0.75;
}

:root[data-theme='dark'] .status-validated {
  background-color: #1d4ed8;
  color: #fff;
}

:root[data-theme='dark'] .invoices-table thead,
:root[data-theme='dark'] .clients-table thead,
:root[data-theme='dark'] .db-monitoring-table thead th {
  background: rgba(15, 23, 42, 0.85);
}

:root[data-theme='dark'] .db-recent-item:hover,
:root[data-theme='dark'] .invoices-table tbody tr:hover,
:root[data-theme='dark'] .clients-table tbody tr:hover {
  background-color: rgba(30, 41, 59, 0.65);
}

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

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

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

a:hover {
  color: var(--primary-hover);
}

h1,
h2,
h3,
h4,
h5,
h6 {
  margin: 0;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

h1 {
  font-size: 1.5rem;
}

h2 {
  font-size: 1.25rem;
}

h3 {
  font-size: 1rem;
}

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

/* ============================================
   Buttons
   ============================================ */
button {
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  padding: var(--space-2) var(--space-4);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  background-color: var(--primary);
  color: white;
  cursor: pointer;
  transition: background-color var(--transition-fast);
  line-height: 1.4;
}

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

button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ============================================
   Status Badges
   ============================================ */
.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
  letter-spacing: 0.02em;
  border: none;
}

.status-pending {
  background-color: #d97706;
  color: #fff;
}

.status-paid {
  background-color: #16a34a;
  color: #fff;
}

.status-overdue,
.status-unpaid {
  background-color: #ea580c;
  color: #fff;
}

.status-draft {
  background-color: #64748b;
  color: #fff;
}

.status-validated {
  background-color: #2563eb;
  color: #fff;
}

.status-canceled {
  background-color: #dc2626;
  color: #fff;
  opacity: 0.7;
}

/* ============================================
   Amount & Stats
   ============================================ */
.amount-display {
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  color: var(--text-primary);
}

.card-stat {
  background: var(--card-bg);
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
}

.card-stat-label {
  color: var(--text-secondary);
  font-size: 12px;
  margin-bottom: var(--space-1);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.card-stat-value {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.card-stat.positive .card-stat-value {
  color: var(--success);
}

.card-stat.negative .card-stat-value {
  color: var(--danger);
}


/* ============================================
   Voice Input
   ============================================ */
.search-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1;
  max-width: 320px;
}

.search-wrapper .search-input {
  width: 100%;
  max-width: 100%;
  flex: none;
  padding-right: 34px;
}

.clientes-filters .search-wrapper {
  max-width: 400px;
}

.voice-btn {
  position: absolute;
  right: 6px;
  background: none;
  border: none;
  padding: 4px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--gray-400);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  transition: color var(--transition-fast), background-color var(--transition-fast);
  flex-shrink: 0;
}

.voice-btn:hover:not(:disabled) {
  color: var(--primary);
  background: var(--blue-50);
  border-color: transparent;
}

.voice-btn:disabled {
  cursor: default;
  opacity: 0.7;
}

/* Estado: grabando */
.voice-btn--recording {
  color: var(--red-500);
  animation: voice-pulse 1.1s ease-in-out infinite;
}

/* Estado: procesando */
.voice-btn--processing .voice-spin {
  transform-origin: center;
  animation: voice-spin 0.8s linear infinite;
}

@keyframes voice-pulse {
  0%, 100% { opacity: 1;   transform: scale(1);    }
  50%       { opacity: 0.6; transform: scale(1.25); }
}

@keyframes voice-spin {
  to { transform: rotate(360deg); }
}

/* Tooltip flotante del botón de voz */
.voice-tip {
  position: absolute;
  bottom: calc(100% + 7px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--gray-900);
  color: #fff;
  font-size: 11px;
  white-space: nowrap;
  padding: 3px 8px;
  border-radius: 4px;
  pointer-events: none;
  z-index: 9999;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.logout-button {
  background-color: transparent;
  color: var(--text-secondary);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: color var(--transition-fast), border-color var(--transition-fast);
}

.logout-button:hover {
  color: var(--danger);
  border-color: var(--danger);
  background-color: var(--red-50);
}
