/* ============================================================
   Transbull Facturas — Design System (Light, Premium)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Syne:wght@600;700&display=swap');

/* --- Tokens --- */
:root {
  --brand-50:  #EFF6FF;
  --brand-100: #DBEAFE;
  --brand-200: #BFDBFE;
  --brand-400: #60A5FA;
  --brand-500: #3B82F6;
  --brand-600: #2563EB;
  --brand-700: #1D4ED8;

  --accent-400: #A78BFA;
  --accent-500: #8B5CF6;
  --accent-600: #7C3AED;

  --neutral-0:   #FFFFFF;
  --neutral-50:  #F8FAFC;
  --neutral-100: #F1F5F9;
  --neutral-150: #EBF0F7;
  --neutral-200: #E2E8F0;
  --neutral-300: #CBD5E1;
  --neutral-400: #94A3B8;
  --neutral-500: #64748B;
  --neutral-600: #475569;
  --neutral-700: #334155;
  --neutral-800: #1E293B;
  --neutral-900: #0F172A;

  --success-50:  #F0FDF4;
  --success-500: #22C55E;
  --success-600: #16A34A;
  --error-50:    #FEF2F2;
  --error-500:   #EF4444;
  --warning-50:  #FFFBEB;
  --warning-500: #F59E0B;

  --radius-sm:  6px;
  --radius-md:  12px;
  --radius-lg:  18px;
  --radius-xl:  24px;
  --radius-2xl: 32px;

  --shadow-sm:   0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:   0 4px 12px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.04);
  --shadow-lg:   0 12px 32px rgba(0,0,0,.10), 0 4px 8px rgba(0,0,0,.05);
  --shadow-xl:   0 24px 48px rgba(0,0,0,.12), 0 8px 16px rgba(0,0,0,.06);
  --shadow-brand: 0 8px 24px rgba(59,130,246,.25);
  --shadow-accent: 0 8px 24px rgba(139,92,246,.20);

  --transition: .2s cubic-bezier(.4,0,.2,1);
  --transition-slow: .4s cubic-bezier(.4,0,.2,1);
}

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

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', sans-serif;
  background: var(--neutral-50);
  color: var(--neutral-800);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* --- Layout --- */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ============================================================
   HEADER
   ============================================================ */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255,255,255,.9);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--neutral-200);
  padding: 0 2rem;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: .75rem;
}

.header-logo {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--brand-500), var(--accent-500));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-logo svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: #fff;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.header-title {
  font-family: 'Syne', sans-serif;
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--neutral-900);
  letter-spacing: -.01em;
}

.header-subtitle {
  font-size: .75rem;
  color: var(--neutral-500);
  font-weight: 400;
}

.header-badge {
  font-size: .7rem;
  font-weight: 600;
  padding: .25rem .625rem;
  border-radius: 999px;
  background: var(--brand-50);
  color: var(--brand-600);
  border: 1px solid var(--brand-200);
  letter-spacing: .03em;
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main-content {
  flex: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 2.5rem 2rem 4rem;
  width: 100%;
}

/* ============================================================
   STEP INDICATOR
   ============================================================ */
.steps-bar {
  display: flex;
  align-items: center;
  gap: 0;
  margin-bottom: 3rem;
}

.step {
  display: flex;
  align-items: center;
  gap: .625rem;
  flex: 1;
  position: relative;
}

.step::after {
  content: '';
  flex: 1;
  height: 2px;
  background: var(--neutral-200);
  margin: 0 .5rem;
  transition: background var(--transition);
}

.step:last-child::after { display: none; }

.step.completed::after { background: var(--brand-400); }

.step-num {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .8rem;
  font-weight: 700;
  flex-shrink: 0;
  border: 2px solid var(--neutral-300);
  background: var(--neutral-0);
  color: var(--neutral-400);
  transition: all var(--transition);
}

.step.active .step-num {
  border-color: var(--brand-500);
  background: var(--brand-500);
  color: #fff;
  box-shadow: var(--shadow-brand);
}

.step.completed .step-num {
  border-color: var(--brand-500);
  background: var(--brand-500);
  color: #fff;
}

.step-label {
  font-size: .75rem;
  font-weight: 500;
  color: var(--neutral-400);
  white-space: nowrap;
  transition: color var(--transition);
}

.step.active .step-label,
.step.completed .step-label { color: var(--brand-600); }

/* ============================================================
   SECTION TITLE
   ============================================================ */
.section-header {
  margin-bottom: 1.5rem;
}

.section-title {
  font-family: 'Syne', sans-serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--neutral-900);
  letter-spacing: -.02em;
  line-height: 1.2;
}

.section-desc {
  margin-top: .375rem;
  font-size: .875rem;
  color: var(--neutral-500);
  line-height: 1.6;
}

/* ============================================================
   COMPANY CARDS
   ============================================================ */
.company-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}

.company-card {
  background: var(--neutral-0);
  border: 2px solid var(--neutral-200);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  flex-direction: column;
  gap: .75rem;
  position: relative;
  overflow: hidden;
}

.company-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--brand-50), transparent 60%);
  opacity: 0;
  transition: opacity var(--transition);
}

.company-card:hover {
  border-color: var(--brand-300);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.company-card:hover::before { opacity: 1; }

.company-card.selected {
  border-color: var(--brand-500);
  box-shadow: var(--shadow-brand);
  background: var(--brand-50);
}

.company-card.selected::before { opacity: 1; }

.company-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  background: var(--neutral-100);
  position: relative;
  z-index: 1;
  transition: background var(--transition);
}

.company-card.selected .company-icon,
.company-card:hover .company-icon {
  background: linear-gradient(135deg, var(--brand-500), var(--accent-500));
}

.company-name {
  font-family: 'Syne', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: var(--neutral-900);
  position: relative;
  z-index: 1;
}

.company-desc {
  font-size: .78rem;
  color: var(--neutral-500);
  line-height: 1.5;
  position: relative;
  z-index: 1;
}

.company-check {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--brand-500);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: scale(0);
  transition: all var(--transition);
  z-index: 1;
}

.company-check svg {
  width: 12px;
  height: 12px;
  stroke: #fff;
  stroke-width: 2.5;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.company-card.selected .company-check {
  opacity: 1;
  transform: scale(1);
}

/* ============================================================
   FILE DROP ZONE
   ============================================================ */
.upload-section {
  display: none;
}

.upload-section.visible {
  display: block;
  animation: fadeSlideUp .3s ease;
}

.file-slots {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.file-slot {
  background: var(--neutral-0);
  border: 2px dashed var(--neutral-300);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: 1rem;
  position: relative;
}

.file-slot:hover {
  border-color: var(--brand-400);
  background: var(--brand-50);
}

.file-slot.dragover {
  border-color: var(--brand-500);
  background: var(--brand-50);
  box-shadow: 0 0 0 4px var(--brand-100);
}

.file-slot.filled {
  border-style: solid;
  border-color: var(--success-500);
  background: var(--success-50);
}

.file-slot-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: var(--neutral-100);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition);
}

.file-slot:hover .file-slot-icon,
.file-slot.dragover .file-slot-icon {
  background: var(--brand-100);
}

.file-slot.filled .file-slot-icon {
  background: var(--success-500);
}

.file-slot-icon svg {
  width: 22px;
  height: 22px;
  stroke: var(--neutral-500);
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke var(--transition);
}

.file-slot:hover .file-slot-icon svg,
.file-slot.dragover .file-slot-icon svg {
  stroke: var(--brand-500);
}

.file-slot.filled .file-slot-icon svg { stroke: #fff; }

.file-slot-info {
  flex: 1;
  min-width: 0;
}

.file-slot-label {
  font-weight: 600;
  font-size: .875rem;
  color: var(--neutral-800);
}

.file-slot-label .required-badge {
  display: inline-block;
  margin-left: .4rem;
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: .05em;
  color: var(--brand-600);
  background: var(--brand-100);
  padding: .1rem .375rem;
  border-radius: 999px;
  vertical-align: middle;
}

.file-slot-hint {
  font-size: .775rem;
  color: var(--neutral-400);
  margin-top: .15rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-slot.filled .file-slot-label { color: var(--success-600); }
.file-slot.filled .file-slot-hint {
  color: var(--success-500);
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
}

.file-remove-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: var(--error-50);
  border-radius: 50%;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition);
  position: relative;
  z-index: 10;
}

.file-remove-btn:hover { background: var(--error-500); }

.file-remove-btn svg {
  width: 12px;
  height: 12px;
  stroke: var(--error-500);
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
}

.file-remove-btn:hover svg { stroke: #fff; }

.file-slot.filled .file-remove-btn { display: flex; }

/* Hidden native input */
.file-input-native {
  display: none;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  padding: .625rem 1.25rem;
  border-radius: var(--radius-md);
  font-family: 'Inter', sans-serif;
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  white-space: nowrap;
  text-decoration: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--brand-500), var(--brand-600));
  color: #fff;
  box-shadow: var(--shadow-brand);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--brand-600), var(--brand-700));
  transform: translateY(-1px);
  box-shadow: 0 12px 28px rgba(59,130,246,.35);
}

.btn-primary:disabled {
  opacity: .45;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.btn-secondary {
  background: var(--neutral-0);
  color: var(--neutral-700);
  border: 1.5px solid var(--neutral-300);
}

.btn-secondary:hover {
  background: var(--neutral-50);
  border-color: var(--neutral-400);
}

.btn-success {
  background: linear-gradient(135deg, var(--success-500), var(--success-600));
  color: #fff;
}

.btn-success:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 24px rgba(34,197,94,.30);
}

.btn svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn-lg {
  padding: .875rem 2rem;
  font-size: 1rem;
  border-radius: var(--radius-lg);
}

.action-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: .75rem;
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--neutral-200);
}

/* ============================================================
   LOADING STATE
   ============================================================ */
.processing-overlay {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  padding: 4rem 2rem;
  background: var(--neutral-0);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.processing-overlay.visible { display: flex; }

.spinner-ring {
  width: 64px;
  height: 64px;
  border: 4px solid var(--neutral-200);
  border-top-color: var(--brand-500);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.processing-title {
  font-family: 'Syne', sans-serif;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--neutral-900);
}

.processing-subtitle {
  font-size: .875rem;
  color: var(--neutral-500);
  max-width: 380px;
}

.processing-steps {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  width: 100%;
  max-width: 360px;
}

.p-step {
  display: flex;
  align-items: center;
  gap: .625rem;
  font-size: .82rem;
  color: var(--neutral-400);
  padding: .5rem .75rem;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.p-step.active {
  background: var(--brand-50);
  color: var(--brand-600);
  font-weight: 500;
}

.p-step.done {
  color: var(--success-600);
}

.p-step-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--neutral-300);
  flex-shrink: 0;
  transition: background var(--transition);
}

.p-step.active .p-step-dot { background: var(--brand-500); animation: pulse 1s ease infinite; }
.p-step.done .p-step-dot { background: var(--success-500); }

/* ============================================================
   RESULTS TABLE
   ============================================================ */
.results-section {
  display: none;
  animation: fadeSlideUp .4s ease;
}

.results-section.visible { display: block; }

.results-card {
  background: var(--neutral-0);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.results-card-header {
  padding: 1.25rem 1.75rem;
  border-bottom: 1px solid var(--neutral-150);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

.results-title {
  font-family: 'Syne', sans-serif;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--neutral-900);
}

.results-meta {
  font-size: .8rem;
  color: var(--neutral-500);
  margin-top: .125rem;
}

.results-actions {
  display: flex;
  gap: .75rem;
  align-items: center;
}

.table-wrapper {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .82rem;
}

thead th {
  background: var(--neutral-50);
  color: var(--neutral-600);
  font-weight: 600;
  font-size: .72rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  padding: .75rem 1rem;
  text-align: left;
  border-bottom: 2px solid var(--neutral-200);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--neutral-100);
  transition: background var(--transition);
}

tbody tr:hover { background: var(--neutral-50); }
tbody tr:last-child { border-bottom: none; }

tbody td {
  padding: .75rem 1rem;
  color: var(--neutral-700);
  max-width: 280px;
}

.cell-number {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.cell-taric {
  font-family: 'Courier New', monospace;
  font-size: .8rem;
  background: var(--neutral-100);
  padding: .125rem .375rem;
  border-radius: 4px;
  display: inline-block;
}

.cell-desc {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-state {
  padding: 3rem;
  text-align: center;
  color: var(--neutral-400);
  font-size: .875rem;
}

/* ============================================================
   ERROR / TOAST
   ============================================================ */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  max-width: 400px;
  padding: 1rem 1.25rem;
  border-radius: var(--radius-md);
  background: var(--neutral-0);
  box-shadow: var(--shadow-xl);
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  transform: translateY(120%);
  transition: transform var(--transition);
  z-index: 999;
  border-left: 4px solid var(--error-500);
}

.toast.show { transform: translateY(0); }
.toast.toast-success { border-left-color: var(--success-500); }

.toast-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  margin-top: .1rem;
}

.toast-content {}
.toast-title { font-weight: 600; font-size: .875rem; color: var(--neutral-900); }
.toast-msg { font-size: .8rem; color: var(--neutral-500); margin-top: .125rem; }

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

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

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: .5; transform: scale(.7); }
}

/* ============================================================
   UTILITIES
   ============================================================ */
.hidden { display: none !important; }
.mt-1 { margin-top: .25rem; }
.mt-2 { margin-top: .5rem; }
.mt-4 { margin-top: 1rem; }

/* ============================================================
   PROGRESS DETAILS
   ============================================================ */
.progress-details-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
  max-width: 480px;
  margin: 1rem auto;
  padding: 1.25rem;
  background: var(--neutral-50);
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-lg);
  text-align: left;
}

.progress-file-row {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.progress-file-row:not(:last-child) {
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--neutral-200);
}

.progress-file-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.progress-file-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--neutral-800);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 320px;
}

.progress-file-page {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--brand-600);
  white-space: nowrap;
}

.progress-file-bar-bg {
  width: 100%;
  height: 6px;
  background: var(--neutral-200);
  border-radius: 99px;
  overflow: hidden;
}

.progress-file-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--brand-500), var(--brand-600));
  border-radius: 99px;
  width: 0%;
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.progress-file-status {
  font-size: 0.75rem;
  color: var(--neutral-500);
  margin-top: 0.125rem;
}

/* ============================================================
   WARNING BANNER (FALLBACKS)
   ============================================================ */
.warning-banner {
  background-color: var(--warning-50);
  border: 1px solid var(--warning-500);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  margin: 0 1.5rem 1.5rem;
  display: flex;
  align-items: flex-start;
  gap: 0.875rem;
  text-align: left;
}

.warning-banner-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: var(--warning-500);
}

.warning-banner-icon svg {
  width: 100%;
  height: 100%;
}

.warning-banner-content {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.warning-banner-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: #B45309; /* Darker amber for readability */
}

.warning-banner-text {
  font-size: 0.825rem;
  color: var(--neutral-700);
  line-height: 1.4;
}

.warning-banner-text ul {
  margin-top: 0.25rem;
  padding-left: 1.25rem;
}

.warning-banner-text li {
  margin-top: 0.125rem;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 640px) {
  .main-content { padding: 1.5rem 1rem 3rem; }
  .steps-bar { gap: .25rem; }
  .step-label { display: none; }
  .company-grid { grid-template-columns: 1fr 1fr; }
  .results-card-header { flex-direction: column; align-items: flex-start; }
}
