/* ============================================================
   FSQ Facturas — Estilos principales
   Colores de marca: Rojo oscuro (#8B1A1A), Dorado (#D4A017)
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:opsz,wght@9..40,300;9..40,400;9..40,500;9..40,600;9..40,700&family=DM+Mono:wght@400;500&display=swap');

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

:root {
  /* Backgrounds */
  --bg: #FAF8F5;
  --surface: #FFFFFF;
  --surface2: #F3F0EB;
  --border: #E5E0D8;

  /* Text */
  --text: #1A1612;
  --muted: #7A7570;

  /* FSQ Brand */
  --primary: #8B1A1A;
  --primary-dark: #6B1414;
  --primary-light: #FDF0F0;
  --gold: #D4A017;
  --gold-light: #FDF8E8;

  /* Semantic */
  --success: #2D6B3F;
  --success-light: #EAF5EE;
  --danger: #B84040;
  --danger-light: #FDF0F0;
  --warn: #C07828;
  --warn-light: #FDF4EA;
  --info: #235280;
  --info-light: #EEF4FB;
  --purple: #5B3FA0;
  --purple-light: #F5F0FF;

  /* Layout */
  --r: 10px;
  --font: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: 'DM Mono', monospace;
  --nav-height: 56px;
}

html { font-size: 14px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ============================================================
   NAVBAR
   ============================================================ */
.nav {
  background: var(--primary);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--nav-height);
  position: sticky;
  top: 0;
  z-index: 200;
  box-shadow: 0 2px 8px rgba(139, 26, 26, 0.15);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-logo {
  height: 32px;
  width: auto;
}
.brand-text {
  font-weight: 600;
  font-size: 15px;
  color: #fff;
  letter-spacing: -.3px;
}

.tabs {
  display: flex;
  gap: 2px;
  background: rgba(255,255,255,0.1);
  border-radius: 8px;
  padding: 3px;
}
.tab {
  padding: 6px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: rgba(255,255,255,0.7);
  font-weight: 500;
  border: none;
  background: none;
  transition: all .2s;
  font-family: var(--font);
  white-space: nowrap;
}
.tab:hover {
  color: #fff;
  background: rgba(255,255,255,0.1);
}
.tab.active {
  background: rgba(255,255,255,0.2);
  color: #fff;
  font-weight: 600;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 20px;
  padding: 4px 12px 4px 4px;
  font-size: 12px;
  font-weight: 500;
  color: #fff;
}
.avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--gold);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  flex-shrink: 0;
}

/* ============================================================
   LAYOUT
   ============================================================ */
.main {
  padding: 24px;
  max-width: 960px;
  margin: 0 auto;
}
.page { display: none; }
.page.active { display: block; }

/* Page header */
.ph { margin-bottom: 22px; }
.pt {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.5px;
  color: var(--text);
}
.ps {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 20px;
  margin-bottom: 14px;
}
.ct {
  font-size: 11px;
  font-weight: 600;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: .6px;
  margin-bottom: 14px;
}

/* ============================================================
   FORMS
   ============================================================ */
.fg { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.ff { grid-column: 1 / -1; }
.fgroup { display: flex; flex-direction: column; gap: 5px; }
.fl { font-size: 12px; font-weight: 500; color: var(--muted); }
.fi {
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 11px;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
  width: 100%;
  font-family: var(--font);
}
.fi:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(139, 26, 26, 0.08);
}
.fi:disabled, .fi[readonly] { background: var(--surface2); color: var(--muted); }
select.fi { cursor: pointer; }
textarea.fi { resize: vertical; min-height: 70px; }

/* OC toggle */
.oc-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
}
.tr {
  width: 34px; height: 19px;
  background: var(--border);
  border-radius: 10px;
  position: relative;
  transition: background .2s;
  flex-shrink: 0;
}
.tr.on { background: var(--primary); }
.tth {
  width: 15px; height: 15px;
  background: #fff;
  border-radius: 50%;
  position: absolute;
  top: 2px; left: 2px;
  transition: transform .2s;
}
.tr.on .tth { transform: translateX(15px); }

.oc-field {
  overflow: hidden;
  max-height: 0;
  transition: max-height .3s, opacity .3s;
  opacity: 0;
}
.oc-field.open { max-height: 80px; opacity: 1; }

.route {
  border-radius: 8px;
  padding: 11px 14px;
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  border: 1px solid;
}
.r-direct { background: var(--info-light); border-color: #C0D4EE; color: var(--info); }
.r-lider { background: var(--warn-light); border-color: #F0D0A0; color: var(--warn); }

/* AI bar */
.ai-bar {
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid;
  margin-top: 10px;
}
.ai-load { background: var(--info-light); border-color: #C0D4EE; color: var(--info); }
.ai-ok { background: var(--success-light); border-color: #B0D4BA; color: var(--success); }
.ai-err { background: var(--danger-light); border-color: #ECC0C0; color: var(--danger); }

@keyframes spin { to { transform: rotate(360deg); } }
.spin {
  width: 14px; height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .8s linear infinite;
  flex-shrink: 0;
  opacity: .6;
}

/* ============================================================
   STATS CARDS (Panel)
   ============================================================ */
.stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 14px 16px;
  cursor: pointer;
  transition: all .2s;
  position: relative;
  overflow: hidden;
}
.stat:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(139, 26, 26, 0.08);
}
.stat.active {
  border-color: var(--primary);
  background: var(--primary-light);
}
.stat.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--primary);
}
.sn { font-size: 24px; font-weight: 700; letter-spacing: -.5px; }
.sl { font-size: 11px; color: var(--muted); margin-top: 2px; font-weight: 500; }

/* ============================================================
   FILTERS
   ============================================================ */
.filters-row {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
  align-items: center;
}
.filters {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  flex: 1;
}
.fbtn {
  padding: 5px 13px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: all .15s;
  color: var(--muted);
  font-family: var(--font);
}
.fbtn:hover {
  background: var(--surface2);
  color: var(--text);
}
.fbtn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.filter-select {
  padding: 5px 10px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  cursor: pointer;
  outline: none;
}
.filter-select:focus {
  border-color: var(--primary);
}

/* ============================================================
   TABLE
   ============================================================ */
.tw { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .4px;
  padding: 8px 12px;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--surface2);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tbody tr { cursor: pointer; transition: background .1s; }
tbody tr:hover td { background: var(--surface2); }

/* ============================================================
   BADGES
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid;
}
.badge::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  flex-shrink: 0;
}
.bw  { background: var(--warn-light);   color: var(--warn);   border-color: #F0D0A0; }
.bw::before  { background: var(--warn); }
.bv  { background: var(--purple-light); color: var(--purple); border-color: #D0C0F0; }
.bv::before  { background: var(--purple); }
.bc  { background: var(--info-light);   color: var(--info);   border-color: #C0D4EE; }
.bc::before  { background: var(--info); }
.bf  { background: var(--gold-light);   color: var(--gold);   border-color: #E8D48A; }
.bf::before  { background: var(--gold); }
.bd  { background: var(--success-light);color: var(--success); border-color: #B0D4BA; }
.bd::before  { background: var(--success); }
.br  { background: var(--danger-light); color: var(--danger);  border-color: #ECC0C0; }
.br::before  { background: var(--danger); }

/* ============================================================
   BUTTONS
   ============================================================ */
.brow { display: flex; gap: 9px; margin-top: 18px; justify-content: flex-end; }
.btn {
  padding: 9px 18px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all .15s;
  font-family: var(--font);
}
.btn-p { background: var(--primary); color: #fff; }
.btn-p:hover { background: var(--primary-dark); }
.btn-s { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-s:hover { background: var(--surface2); }
.btn-d { background: var(--danger); color: #fff; }
.btn-d:hover { background: #952f2f; }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ============================================================
   MODAL
   ============================================================ */
.mbg {
  position: fixed;
  inset: 0;
  background: rgba(26, 22, 18, 0.4);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
  backdrop-filter: blur(2px);
}
.mbg.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--surface);
  border-radius: 14px;
  padding: 24px;
  width: 480px;
  max-width: 95vw;
  transform: translateY(12px);
  transition: transform .2s;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}
.mbg.open .modal { transform: translateY(0); }
.mtitle {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -.3px;
  margin-bottom: 6px;
}
.msub { font-size: 13px; color: var(--muted); margin-bottom: 18px; }

/* Detail rows */
.dr {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--surface2);
  font-size: 13px;
}
.dr:last-child { border-bottom: none; }
.dr span:first-child { color: var(--muted); }
.dr span:last-child { font-weight: 500; text-align: right; max-width: 60%; }

/* Timeline */
.tli { display: flex; gap: 12px; margin-bottom: 14px; }
.tld {
  width: 28px; height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  margin-top: 2px;
}
.tl-done { background: var(--success-light); color: var(--success); border: 1px solid #B0D4BA; }
.tl-act  { background: var(--warn-light);    color: var(--warn);    border: 1px solid #F0D0A0; }
.tl-rej  { background: var(--danger-light);  color: var(--danger);  border: 1px solid #ECC0C0; }
.tl-pen  { background: var(--surface2);      color: var(--muted);   border: 1px solid var(--border); }
.tltitle { font-weight: 500; font-size: 13px; }
.tlmeta  { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ============================================================
   MISC
   ============================================================ */
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.ibox {
  background: var(--info-light);
  border: 1px solid #C0D4EE;
  border-radius: 8px;
  padding: 11px 14px;
  font-size: 12px;
  color: var(--info);
}
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--text);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  transform: translateY(80px);
  opacity: 0;
  transition: all .3s;
  z-index: 999;
  max-width: 360px;
}
.toast.show { transform: translateY(0); opacity: 1; }

.mono { font-family: var(--mono); }
.mt8 { margin-top: 8px; }
.mt12 { margin-top: 12px; }

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(250, 248, 245, 0.7);
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
}
.loading-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 28px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 8px 32px rgba(0,0,0,0.08);
}

/* Responsive */
@media (max-width: 768px) {
  .stats { grid-template-columns: repeat(3, 1fr); }
  .nav { padding: 0 12px; }
  .tabs { overflow-x: auto; }
  .main { padding: 16px; }
  .fg { grid-template-columns: 1fr; }
  .user-chip span:not(.avatar) { display: none; }
}
@media (max-width: 480px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}
.empty-state-icon {
  font-size: 40px;
  margin-bottom: 12px;
  opacity: 0.4;
}
.empty-state-text {
  font-size: 14px;
  font-weight: 500;
}

/* ── Chips responsables sugeridos ── */
.sugerido-chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--surface2); border: 1.5px solid var(--border);
  border-radius: 20px; padding: 5px 12px; font-size: 12px;
  cursor: pointer; font-family: var(--font);
  transition: all .15s; color: var(--text);
}
.sugerido-chip:hover {
  border-color: var(--primary); background: var(--primary-light);
  color: var(--primary);
}
.sugerido-chip.chip-activo {
  background: var(--primary); border-color: var(--primary);
  color: #fff; font-weight: 600;
}
