/* ═══════════════════════════════════════════════════════════════════════════
   BillScan Design System  — v1.4
   Single source of truth for color tokens, typography scale, component
   classes, focus rings, and accessibility helpers.
   ═══════════════════════════════════════════════════════════════════════════ */


/* ── 1. Color Tokens ─────────────────────────────────────────────────────── */
:root {
  /* Module palette */
  --c-invoices:      79  70 229;   /* indigo-600  — Facturas */
  --c-invoices-bg:  238 242 255;   /* indigo-50   — Facturas bg */
  --c-expenses:       5 150 105;   /* emerald-600 — Gastos */
  --c-expenses-bg:  209 250 229;   /* emerald-100 — Gastos bg */
  --c-ai:           124  58 237;   /* violet-600  — Mapping IA */
  --c-ai-bg:        245 243 255;   /* violet-50   — AI bg */

  /* Semantic status */
  --c-success:       16 185 129;   /* emerald-500 */
  --c-success-bg:   209 250 229;   /* emerald-100 */
  --c-warning:      245 158  11;   /* amber-500   */
  --c-warning-bg:   254 243 199;   /* amber-100   */
  --c-danger:       239  68  68;   /* red-500     */
  --c-danger-bg:    254 226 226;   /* red-100     */
  --c-info:          59 130 246;   /* blue-500    */
  --c-info-bg:      219 234 254;   /* blue-100    */

  /* Neutral surface */
  --c-surface:      255 255 255;
  --c-raised:       248 250 252;   /* slate-50  */
  --c-border:       226 232 240;   /* slate-200 */
  --c-border-sub:   241 245 249;   /* slate-100 */

  /* Text hierarchy */
  --c-text-1:        30  41  59;   /* slate-800 — primary   */
  --c-text-2:        71  85 105;   /* slate-600 — secondary */
  --c-text-3:       100 116 139;   /* slate-500 — tertiary  */
  --c-text-4:       148 163 184;   /* slate-400 — muted     */

  /* Radius scale */
  --r-sm:  0.5rem;    /* 8px  — rounded-lg  */
  --r-md:  0.75rem;   /* 12px — rounded-xl  */
  --r-lg:  1rem;      /* 16px — rounded-2xl */
  --r-full:9999px;

  /* Elevation / Shadow */
  --sh-sm: 0 1px 2px 0 rgb(0 0 0 / .05);
  --sh-md: 0 4px 6px -1px rgb(0 0 0 / .08), 0 2px 4px -2px rgb(0 0 0 / .06);
  --sh-lg: 0 10px 15px -3px rgb(0 0 0 / .08), 0 4px 6px -4px rgb(0 0 0 / .05);

  /* Focus ring — applied via focus-visible only */
  --focus-ring: 0 0 0 3px rgb(99 102 241 / .35);
  --focus-ring-offset: 0 0 0 2px rgb(255 255 255);
}


/* ── 2. Global focus-visible (keyboard) ─────────────────────────────────── */
:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring-offset), var(--focus-ring);
}

/* Remove default outline only when focus-visible is active (doesn't remove
   mouse-click focus in browsers that lack :focus-visible support) */
:focus:not(:focus-visible) { outline: none; box-shadow: none; }


/* ── 3. Typography helpers ───────────────────────────────────────────────── */
.text-heading-lg  { font-size: 1.125rem; font-weight: 700; color: rgb(var(--c-text-1)); line-height: 1.4; }
.text-heading-sm  { font-size: 0.6875rem; font-weight: 600; color: rgb(var(--c-text-4)); letter-spacing: .06em; text-transform: uppercase; }
.text-body        { font-size: 0.875rem; color: rgb(var(--c-text-2)); }
.text-caption     { font-size: 0.75rem;  color: rgb(var(--c-text-3)); }
.text-label       { font-size: 0.875rem; font-weight: 500; color: rgb(var(--c-text-2)); }


/* ── 4. Button system ────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-radius: var(--r-md);
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.25;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, opacity 0.15s, box-shadow 0.15s;
  white-space: nowrap;
}
.btn:disabled, .btn[disabled] { opacity: 0.5; cursor: not-allowed; pointer-events: none; }

.btn-primary {
  background: rgb(var(--c-invoices));
  color: white;
  box-shadow: var(--sh-sm);
}
.btn-primary:hover:not(:disabled) { background: rgb(67 56 202); }   /* indigo-700 */
.btn-primary:active:not(:disabled){ background: rgb(55 48 163); }   /* indigo-800 */

.btn-success {
  background: rgb(var(--c-expenses));
  color: white;
  box-shadow: var(--sh-sm);
}
.btn-success:hover:not(:disabled) { background: rgb(4 120 87); }    /* emerald-700 */

.btn-danger {
  background: rgb(var(--c-danger));
  color: white;
  box-shadow: var(--sh-sm);
}
.btn-danger:hover:not(:disabled) { background: rgb(220 38 38); }    /* red-600 */

.btn-secondary {
  background: rgb(var(--c-surface));
  color: rgb(var(--c-text-2));
  border-color: rgb(var(--c-border));
  box-shadow: var(--sh-sm);
}
.btn-secondary:hover:not(:disabled) {
  border-color: rgb(165 180 252);    /* indigo-300 */
  color: rgb(var(--c-invoices));
}

.btn-ghost {
  background: transparent;
  color: rgb(var(--c-text-3));
}
.btn-ghost:hover:not(:disabled) {
  background: rgb(var(--c-raised));
  color: rgb(var(--c-text-2));
}

.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8125rem; }
.btn-lg { padding: 0.625rem 1.25rem; font-size: 0.9375rem; }


/* ── 5. Badge / Pill system ─────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.625rem;
  border-radius: var(--r-full);
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
}
.badge-success { background: rgb(var(--c-success-bg)); color: rgb(4 120 87); }
.badge-warning { background: rgb(var(--c-warning-bg)); color: rgb(146 64  14); }
.badge-danger  { background: rgb(var(--c-danger-bg));  color: rgb(185 28  28); }
.badge-info    { background: rgb(var(--c-info-bg));    color: rgb(29  78 216); }
.badge-neutral { background: rgb(var(--c-raised)); border: 1px solid rgb(var(--c-border)); color: rgb(var(--c-text-3)); }
.badge-invoices { background: rgb(var(--c-invoices-bg)); color: rgb(var(--c-invoices)); }
.badge-expenses { background: rgb(var(--c-expenses-bg)); color: rgb(var(--c-expenses)); }

/* Count badge on sidebar */
.badge-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  padding: 0 0.375rem;
  border-radius: var(--r-full);
  font-size: 0.6875rem;
  font-weight: 700;
  line-height: 1.5;
}


/* ── 6. Card system ──────────────────────────────────────────────────────── */
.card {
  background: rgb(var(--c-surface));
  border: 1px solid rgb(var(--c-border));
  border-radius: var(--r-lg);
  box-shadow: var(--sh-sm);
}
.card-body  { padding: 1.25rem; }
.card-title { font-size: 0.6875rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: rgb(var(--c-text-4)); margin-bottom: 1rem; }


/* ── 7. Form controls ────────────────────────────────────────────────────── */
.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  color: rgb(var(--c-text-1));
  background: rgb(var(--c-surface));
  border: 1px solid rgb(var(--c-border));
  border-radius: var(--r-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
  line-height: 1.5;
}
.form-input::placeholder,
.form-textarea::placeholder { color: rgb(var(--c-text-4)); }

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: rgb(var(--c-invoices));
  box-shadow: 0 0 0 3px rgb(var(--c-invoices) / .2);
}

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: rgb(var(--c-text-2));
  margin-bottom: 0.375rem;
}


/* ── 8. Alert / Banner system ────────────────────────────────────────────── */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  border-radius: var(--r-md);
  font-size: 0.875rem;
  border: 1px solid transparent;
}
.alert-icon { flex-shrink: 0; width: 1.125rem; height: 1.125rem; margin-top: 0.0625rem; }

.alert-warning {
  background: rgb(var(--c-warning-bg));
  border-color: rgb(253 230 138);   /* amber-200 */
  color: rgb(120 53 15);            /* amber-900 */
}
.alert-danger {
  background: rgb(var(--c-danger-bg));
  border-color: rgb(254 202 202);   /* red-200 */
  color: rgb(153 27 27);            /* red-800 */
}
.alert-info {
  background: rgb(var(--c-info-bg));
  border-color: rgb(191 219 254);   /* blue-200 */
  color: rgb(30 64 175);            /* blue-800 */
}
.alert-success {
  background: rgb(var(--c-success-bg));
  border-color: rgb(167 243 208);   /* emerald-200 */
  color: rgb(6 78 59);              /* emerald-900 */
}

/* Bottleneck alert — shown when a pipeline phase is accumulating items */
.alert-bottleneck {
  background: rgb(255 251 235);     /* amber-50 */
  border-color: rgb(252 211 77);    /* amber-300 */
  color: rgb(120 53 15);            /* amber-900 */
  border-radius: var(--r-md);
  padding: 0.625rem 0.875rem;
  font-size: 0.8125rem;
  display: flex;
  align-items: center;
  gap: 0.625rem;
}


/* ── 9. Table enhancements ───────────────────────────────────────────────── */
/* Always-visible checkboxes (not only on hover) */
.table-checkbox-cell input[type="checkbox"] {
  opacity: 1 !important;
  visibility: visible !important;
}

/* Row hover with smoother transition */
.table-row-hover { transition: background 0.1s; }
.table-row-hover:hover { background: rgb(248 250 252); }

/* Sticky table header */
.table-sticky-head thead th { position: sticky; top: 0; z-index: 2; }


/* ── 10. Semaphore indicators ─────────────────────────────────────────────── */
.semaphore-dot {
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: var(--r-full);
  flex-shrink: 0;
}
.sem-green  { background: rgb(52 211 153); }   /* emerald-400 */
.sem-red    { background: rgb(248 113 113); }  /* red-400     */
.sem-gray   { background: rgb(203 213 225); }  /* slate-300   */
.sem-amber  { background: rgb(251 191  36); }  /* amber-400   */


/* ── 11. Modal backdrop ───────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgb(0 0 0 / .45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-panel {
  background: rgb(var(--c-surface));
  border-radius: var(--r-lg);
  box-shadow: var(--sh-lg);
  width: 100%;
  max-width: 28rem;
  padding: 1.5rem;
}
.modal-panel-lg { max-width: 42rem; }
.modal-panel-xl { max-width: 56rem; }


/* ── 12. Sidebar enhancements ─────────────────────────────────────────────── */
/* Collapsed sidebar shows tooltip on hover */
.sidebar-collapsed-tip {
  position: absolute;
  left: calc(100% + 0.5rem);
  top: 50%;
  transform: translateY(-50%);
  background: rgb(30 41 59);
  color: white;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.25rem 0.625rem;
  border-radius: var(--r-sm);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 100;
}
.sidebar-item:hover .sidebar-collapsed-tip { opacity: 1; }

/* Group headers — unified style */
.sidebar-group-header {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0.75rem;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  border-radius: var(--r-sm);
  transition: background 0.15s;
  cursor: pointer;
}


/* ── 13. Scrollbar (unified) ──────────────────────────────────────────────── */
::-webkit-scrollbar       { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgb(var(--c-border)); border-radius: var(--r-full); }
::-webkit-scrollbar-thumb:hover { background: rgb(148 163 184); }


/* ── 14. Loading skeleton ─────────────────────────────────────────────────── */
@keyframes bs-shimmer {
  from { background-position: -600px 0; }
  to   { background-position:  600px 0; }
}
.skeleton {
  animation: bs-shimmer 1.4s linear infinite;
  background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 37%, #f1f5f9 63%);
  background-size: 800px 100%;
  border-radius: var(--r-sm);
}
/* Row skeletons for tables */
.skeleton-row  { height: 2.5rem; border-radius: var(--r-sm); }
.skeleton-text { height: 0.875rem; border-radius: var(--r-sm); }


/* ── 15. Animations ───────────────────────────────────────────────────────── */
@keyframes bs-fadeIn {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: translateY(0);   }
}
@keyframes bs-slideDown {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0);    }
}
.animate-fade-in   { animation: bs-fadeIn   0.2s ease forwards; }
.animate-slide-down{ animation: bs-slideDown 0.18s ease forwards; }


/* ── 16. Accessibility helpers ────────────────────────────────────────────── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border-width: 0;
}

/* Skip-to-content link */
.skip-link {
  position: absolute;
  top: -3rem;
  left: 0;
  z-index: 9999;
  padding: 0.5rem 1rem;
  background: rgb(var(--c-invoices));
  color: white;
  border-radius: 0 0 var(--r-sm) 0;
  font-size: 0.875rem;
  font-weight: 600;
  transition: top 0.15s;
}
.skip-link:focus { top: 0; }

/* High-contrast mode support */
@media (forced-colors: active) {
  .btn-primary, .btn-success, .btn-danger { border: 2px solid ButtonText; }
  .badge-success, .badge-danger, .badge-warning { border: 1px solid ButtonText; }
}


/* ── 17. Bottleneck KPI band (Dashboard) ──────────────────────────────────── */
.pipeline-phase-card {
  position: relative;
  transition: transform 0.15s, box-shadow 0.15s;
}
.pipeline-phase-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--sh-md);
}
.pipeline-phase-card.bottleneck-hi {
  border: 1.5px solid rgb(252 211 77) !important;  /* amber-300 */
  box-shadow: 0 0 0 3px rgb(252 211 77 / .25);
}
.pipeline-phase-card.bottleneck-hi::after {
  content: '!';
  position: absolute;
  top: -6px;
  right: -6px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgb(var(--c-warning));
  color: white;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 16px;
  text-align: center;
}


/* ── 18. Validation summary bar ───────────────────────────────────────────── */
.validation-summary {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.625rem 1rem;
  background: rgb(var(--c-surface));
  border: 1px solid rgb(var(--c-border));
  border-radius: var(--r-md);
  margin-bottom: 0.75rem;
  font-size: 0.8125rem;
}
.validation-summary-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.625rem;
  border-radius: var(--r-full);
  font-size: 0.75rem;
  font-weight: 600;
}
.vs-ok    { background: rgb(var(--c-success-bg)); color: rgb(4 120 87); }
.vs-error { background: rgb(var(--c-danger-bg));  color: rgb(185 28 28); }
.vs-total { background: rgb(var(--c-raised));      color: rgb(var(--c-text-2)); }
