/* ==========================================================
   Gestión de agencia de viajes — interfaz
   ========================================================== */
:root {
  --bg: #f3f5f9;
  --card: #ffffff;
  --border: #e4e7ee;
  --border-strong: #d3d8e2;
  --text: #16202e;
  --muted: #6b7686;
  --primary: #1d4fd8;
  --primary-dark: #173fae;
  --primary-soft: #eef3ff;
  --ok: #0f8a4c;
  --warn: #b26a0b;
  --bad: #c0332b;
  --sidebar-bg: #0e1626;
  --sidebar-bg2: #131e33;
  --sidebar-text: #9daabd;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(22, 32, 46, .05), 0 1px 6px rgba(22, 32, 46, .04);
  --shadow-lg: 0 4px 14px rgba(22, 32, 46, .08), 0 1px 4px rgba(22, 32, 46, .06);
}

* { box-sizing: border-box; }
html { font-size: 15px; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 8px; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 20px; }
h3 { font-size: 15px; }
code {
  background: #edf0f6; padding: 1px 6px; border-radius: 5px;
  font-size: 12.5px; font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.ta-r { text-align: right; }
.ta-c { text-align: center; }
.txt-ok { color: var(--ok); }
.txt-bad { color: var(--bad); }
.txt-warn { color: var(--warn); }
.inline { display: inline; }
.sep { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.push-right { margin-left: auto; }

/* ---------------- Layout ---------------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex-shrink: 0;
  background: linear-gradient(180deg, var(--sidebar-bg2) 0%, var(--sidebar-bg) 240px);
  color: var(--sidebar-text);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand {
  display: flex; align-items: center; gap: 11px;
  padding: 20px 18px 16px; color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, .06);
  margin-bottom: 8px;
}
.brand-icon {
  font-size: 17px; background: linear-gradient(135deg, #2c62f0, #1d4fd8);
  width: 34px; height: 34px; border-radius: 9px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 3px 8px rgba(29, 79, 216, .45);
}
.brand-name { font-weight: 700; font-size: 14px; line-height: 1.25; letter-spacing: .01em; }
.brand-logo {
  max-height: 38px; max-width: 150px; border-radius: 9px;
  object-fit: contain;
}
.auth-logo-img { display: block; max-height: 64px; max-width: 220px; margin: 0 auto 12px; object-fit: contain; }
.sidebar nav { display: flex; flex-direction: column; padding: 0 10px 24px; }
.sidebar nav a {
  color: var(--sidebar-text); padding: 7.5px 11px; border-radius: 8px;
  font-size: 13.5px; font-weight: 500; margin: 1px 0;
  display: flex; align-items: center; gap: 10px;
  transition: background .12s ease, color .12s ease;
}
.sidebar nav a:hover { background: rgba(255, 255, 255, .06); color: #eef2f8; text-decoration: none; }
.sidebar nav a.active {
  background: linear-gradient(90deg, rgba(44, 98, 240, .28), rgba(44, 98, 240, .12));
  color: #fff; box-shadow: inset 2.5px 0 0 #4a7dff;
}
.ni { width: 19px; text-align: center; font-size: 13px; opacity: .85; }
.nav-sec {
  font-size: 10px; text-transform: uppercase; letter-spacing: .12em;
  color: #55617a; padding: 16px 11px 5px; font-weight: 600;
}
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: rgba(255, 255, 255, .92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding: 11px 26px; display: flex; justify-content: space-between; align-items: center;
  position: sticky; top: 0; z-index: 10;
}
.topbar-title { font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.topbar-user { display: flex; align-items: center; gap: 10px; }
.user-name { font-size: 13.5px; font-weight: 550; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: linear-gradient(135deg, #2c62f0, #6b3df0);
  color: #fff; font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.content { padding: 24px 26px 70px; max-width: 1320px; width: 100%; }

/* ---------------- Tarjetas ---------------- */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.card-head {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  margin-bottom: 12px; flex-wrap: wrap;
}
.card-head h3 { margin: 0; }
.card-link { display: block; color: inherit; transition: box-shadow .15s ease, transform .15s ease, border-color .15s ease; }
.card-link:hover { text-decoration: none; border-color: #b9c8f2; box-shadow: var(--shadow-lg); transform: translateY(-1px); }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.page-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------------- KPIs ---------------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.kpis-3 { grid-template-columns: repeat(3, 1fr); }
.kpi {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 15px 18px; box-shadow: var(--shadow);
  border-top: 3px solid var(--primary);
}
.kpi:nth-child(2) { border-top-color: var(--ok); }
.kpi:nth-child(3) { border-top-color: #6b3df0; }
.kpi:nth-child(4) { border-top-color: var(--warn); }
.kpi-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; font-weight: 600; }
.kpi-value { font-size: 23px; font-weight: 750; margin-top: 5px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.kpi-value.ok { color: var(--ok); }
.kpi-value.warn { color: var(--warn); }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }

.grid-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }

/* ---------------- Tablas ---------------- */
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); font-weight: 650;
  padding: 8px 9px; border-bottom: 1.5px solid var(--border-strong); white-space: nowrap;
}
.tbl th.ta-r { text-align: right; }
.tbl td { padding: 9px; border-bottom: 1px solid #edf0f5; vertical-align: middle; font-variant-numeric: tabular-nums; }
.tbl tbody tr { transition: background .1s ease; }
.tbl tbody tr:hover { background: #f7f9fc; }
.tbl tfoot td { border-top: 2px solid var(--border-strong); border-bottom: none; }
.tfoot-tot td { background: #f6f8fb; font-size: 13.5px; }
.row-late td { background: #fef4f1; }
.row-inactivo td { opacity: .55; }
.row-rect td { background: #faf8ff; }

/* ---------------- Badges ---------------- */
.badge {
  display: inline-block; font-size: 11px; font-weight: 650; padding: 2.5px 9px;
  border-radius: 20px; text-transform: capitalize; white-space: nowrap; letter-spacing: .01em;
}
.badge-rol { background: #edf0f6; color: #454f5e; }
.badge-presupuesto { background: #fcf0da; color: #8a5800; }
.badge-confirmado { background: #e2eaff; color: #1a3fa8; }
.badge-completado { background: #dcf3e6; color: #10663a; }
.badge-cancelado { background: #fadddb; color: #8f1f18; }
.badge-facturado { background: #ece4fb; color: #5836ac; margin-left: 4px; }
.badge-rect { background: #ece4fb; color: #5836ac; }
.badge-srv { background: #edf0f6; color: #454f5e; }
.badge-tipo-particular { background: #e3f2fb; color: #145a80; }
.badge-tipo-empresa { background: #ece4fb; color: #5836ac; }
.badge-reg-reav { background: #e2eaff; color: #1a3fa8; }
.badge-reg-general { background: #fdecdc; color: #96450d; }
.badge-op-nueva { background: #e3f2fb; color: #145a80; }
.badge-op-contactado { background: #fcf0da; color: #8a5800; }
.badge-op-presupuestada { background: #ece4fb; color: #5836ac; }
.badge-op-ganada { background: #dcf3e6; color: #10663a; }
.badge-op-perdida { background: #fadddb; color: #8f1f18; }

/* ---------------- Formularios ---------------- */
label { display: block; font-size: 13px; font-weight: 570; margin-bottom: 11px; color: #2a3442; }
.inp {
  display: block; width: 100%; margin-top: 5px;
  border: 1px solid var(--border-strong); border-radius: 8px; padding: 8px 11px;
  font-size: 14px; font-family: inherit; background: #fff; color: var(--text);
  transition: border-color .12s ease, box-shadow .12s ease;
}
.inp:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(29, 79, 216, .14); }
.inp-sm { padding: 5px 8px; font-size: 13px; margin-top: 0; border-radius: 7px; }
select.inp { appearance: auto; }
textarea.inp { resize: vertical; }
.chk { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.chk input { margin: 0; accent-color: var(--primary); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 16px; }
.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.search-form { display: flex; gap: 8px; align-items: center; flex: 1; flex-wrap: wrap; }
.search-form .inp { width: auto; margin-top: 0; min-width: 130px; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.inline-form .inp { width: auto; }

/* ---------------- Botones ---------------- */
.btn {
  display: inline-block; border: 1px solid var(--border-strong); background: #fff; color: var(--text);
  border-radius: 8px; padding: 7px 15px; font-size: 13.5px; font-weight: 600;
  cursor: pointer; font-family: inherit; line-height: 1.3; white-space: nowrap;
  transition: background .12s ease, border-color .12s ease, box-shadow .12s ease, transform .05s ease;
}
.btn:hover { background: #f4f6fa; border-color: #bec7d6; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: linear-gradient(180deg, #2458e8, var(--primary)); border-color: var(--primary-dark); color: #fff;
  box-shadow: 0 1px 3px rgba(29, 79, 216, .35);
}
.btn-primary:hover { background: linear-gradient(180deg, #1f4ed2, var(--primary-dark)); border-color: var(--primary-dark); }
.btn-danger { background: #fff; border-color: #e6b6b3; color: var(--bad); }
.btn-danger:hover { background: #fdf1f0; border-color: #d99b97; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); box-shadow: none; }
.btn-ghost:hover { background: #edf0f6; border-color: transparent; }
.btn-sm { padding: 3.5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn-block { width: 100%; text-align: center; }

/* ---------------- Avisos ---------------- */
.flash { border-radius: 10px; padding: 11px 15px; margin-bottom: 16px; font-size: 13.5px; font-weight: 500; }
.flash-ok { background: #ddf4e7; color: #0f5c33; border: 1px solid #b5e3c9; }
.flash-error { background: #fbdedb; color: #85211b; border: 1px solid #f0b7b3; }
.flash-info { background: #e2eaff; color: #1a3fa8; border: 1px solid #bdd0f8; }

/* ---------------- Login / configuración inicial ---------------- */
.auth-body {
  display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px;
  background: radial-gradient(1100px 500px at 85% -10%, #23407e 0%, transparent 55%),
              radial-gradient(900px 500px at -10% 110%, #1b2c52 0%, transparent 50%),
              var(--sidebar-bg);
}
.auth-card {
  background: #fff; border-radius: 16px; padding: 34px 36px; width: 100%; max-width: 390px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .45);
}
.auth-logo {
  font-size: 26px; margin: 0 auto 12px;
  background: linear-gradient(135deg, #2c62f0, #1d4fd8);
  width: 56px; height: 56px; border-radius: 15px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 20px rgba(29, 79, 216, .4);
}
.auth-card h1 { font-size: 20px; text-align: center; }
.auth-card p { text-align: center; margin-top: 0; }
.auth-card form { margin-top: 20px; }

/* ---------------- Pipeline CRM ---------------- */
.pipeline { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; align-items: start; }
.pipe-col { background: #eaedf3; border-radius: var(--radius); padding: 9px; min-height: 130px; }
.pipe-head {
  font-size: 12.5px; font-weight: 700; padding: 6px 11px; border-radius: 8px;
  margin-bottom: 9px; display: flex; justify-content: space-between; align-items: center;
}
.pipe-count { background: rgba(0, 0, 0, .1); border-radius: 12px; padding: 0 7px; font-size: 11.5px; }
.pipe-card {
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
  padding: 11px 12px; margin-bottom: 9px; box-shadow: var(--shadow);
}
.pipe-title { font-weight: 650; font-size: 13.5px; display: block; color: var(--text); }
.pipe-meta { display: flex; justify-content: space-between; margin: 6px 0; font-size: 13px; font-weight: 650; font-variant-numeric: tabular-nums; }
.pipe-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.pipe-actions .inp-sm { width: auto; font-size: 11.5px; }

/* ---------------- Historial CRM ---------------- */
.timeline { display: flex; flex-direction: column; gap: 11px; max-height: 520px; overflow-y: auto; }
.tl-item { border-left: 3px solid var(--border-strong); padding: 2px 0 2px 13px; }
.tl-head { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; flex-wrap: wrap; }
.tl-body { font-size: 13px; margin-top: 3px; white-space: pre-wrap; }
.tl-next { font-size: 12.5px; margin-top: 5px; color: var(--warn); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tl-next.done { color: var(--muted); }

/* ---------------- Editor de líneas ---------------- */
.lineas-tbl .inp-sm { width: 100%; }
.lineas-tbl td { padding: 4px 4px; }
.totales-box {
  margin-top: 14px; margin-left: auto; max-width: 500px;
  background: #f6f8fb; border: 1px solid var(--border); border-radius: 10px; padding: 14px 18px;
}
.tot-row { display: flex; justify-content: space-between; padding: 3px 0; font-size: 13.5px; gap: 20px; font-variant-numeric: tabular-nums; }
.aviso-fiscal {
  margin-top: 10px; font-size: 12px; color: var(--muted);
  border-top: 1px dashed var(--border-strong); padding-top: 9px;
}
.resumen-fiscal {
  background: #f6f8fb; border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 18px; margin-top: 14px; max-width: 580px;
}
.resumen-fiscal h4 { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }

/* Selector de régimen */
.regimen-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.regimen-opt {
  display: flex; gap: 11px; align-items: flex-start; border: 1.5px solid var(--border-strong);
  border-radius: 11px; padding: 13px 15px; cursor: pointer; font-weight: 500;
  transition: border-color .12s ease, background .12s ease;
}
.regimen-opt:hover { border-color: #a9bdf0; }
.regimen-opt:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 3px rgba(29, 79, 216, .1); }
.regimen-opt input { margin-top: 3px; accent-color: var(--primary); }

.modo-reav .solo-general { display: none; }
.modo-general .solo-reav { display: none; }

/* ---------------- Informes: barras ---------------- */
.barras { display: flex; gap: 10px; align-items: flex-end; height: 190px; padding: 10px 4px 0; }
.barra-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; }
.barra-wrap { flex: 1; width: 100%; display: flex; gap: 3px; align-items: flex-end; justify-content: center; }
.barra { width: 16px; background: linear-gradient(180deg, #3a6cf0, var(--primary)); border-radius: 4px 4px 0 0; min-height: 2px; }
.barra-margen { background: linear-gradient(180deg, #23b46b, var(--ok)); }
.barra-label { font-size: 11px; color: var(--muted); margin-top: 5px; }
.leyenda { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--primary); margin-right: 3px; }
.leyenda-margen { background: var(--ok); }

/* ---------------- Liquidación por expedientes ---------------- */
.liq-kpis { display: flex; gap: 10px; flex-wrap: wrap; }
.liq-kpis span {
  background: #f6f8fb; border: 1px solid var(--border); border-radius: 9px;
  padding: 6px 13px; font-size: 11.5px; color: var(--muted);
}
.liq-kpis strong { display: block; font-size: 14px; color: var(--text); font-variant-numeric: tabular-nums; }
.liq-kpis strong.txt-ok { color: var(--ok); }
.liq-kpis strong.txt-bad { color: var(--bad); }
.liq-kpis strong.txt-warn { color: var(--warn); }
.liq-sub { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 0 0 6px; font-weight: 650; }

/* ---------------- Libros banco / tarjeta / caja ---------------- */
.tabs { display: flex; gap: 6px; }
.tab {
  padding: 8px 18px; border-radius: 9px; font-weight: 650; font-size: 13.5px;
  color: var(--muted); border: 1px solid transparent;
  transition: background .12s ease, color .12s ease;
}
.tab.active { background: var(--card); color: var(--primary); border-color: var(--border); box-shadow: var(--shadow); }
.tab:hover { text-decoration: none; color: var(--text); }
.mov-acciones { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.mov-acciones .inp-sm { width: auto; max-width: 170px; }
.asig-form { display: flex; gap: 4px; align-items: center; }
.asig-chip {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  background: var(--primary-soft); border: 1px solid #ccdafc; border-radius: 8px;
  padding: 3px 4px 3px 10px; font-size: 12.5px; margin-bottom: 4px;
  font-variant-numeric: tabular-nums;
}
.asig-chip em { font-style: normal; color: var(--muted); }

.lista { line-height: 1.75; padding-left: 20px; }
.lista li { margin-bottom: 6px; }
pre.code {
  background: #0e1626; color: #d6deea; border-radius: 10px; padding: 15px 18px;
  font-size: 12.5px; overflow-x: auto; line-height: 1.55;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}

/* ---------------- Impresión ---------------- */
@media print {
  .sidebar, .topbar, .page-actions, .search-form, .btn, form { display: none !important; }
  .content { padding: 0; }
  .card { box-shadow: none; break-inside: avoid; }
  body { background: #fff; }
}

/* ---------------- Responsive ---------------- */
@media (max-width: 1100px) {
  .pipeline { grid-template-columns: repeat(3, 1fr); }
  .kpis { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 860px) {
  .grid-2col { grid-template-columns: 1fr; }
  .sidebar { width: 62px; }
  .brand { padding: 14px 10px; justify-content: center; }
  .brand-icon { width: 32px; height: 32px; }
  .brand-name, .nav-sec { display: none; }
  .sidebar nav { padding: 0 7px 24px; }
  .sidebar nav a { justify-content: center; padding: 12px 6px; font-size: 0; }
  .sidebar nav a .ni { font-size: 17px; width: auto; opacity: 1; }
  .content { padding: 16px 13px 60px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .pipeline { grid-template-columns: 1fr; }
  .kpis, .kpis-3 { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { padding: 12px 14px; }
  .kpi-value { font-size: 19px; }
  .topbar { padding: 10px 13px; }
  .topbar-title { font-size: 15px; }

  /* Tablas: desplazamiento horizontal en pantallas pequeñas */
  .tbl { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tbl th, .tbl td { white-space: nowrap; }
  .tbl td:first-child, .tbl th:first-child { position: sticky; left: 0; background: var(--card); }
  .tfoot-tot td:first-child { background: #f6f8fb; }

  /* Botones y campos más cómodos al tacto */
  .btn { padding: 9px 15px; }
  .btn-sm { padding: 6px 11px; }
  .inp { padding: 10px 11px; font-size: 16px; } /* 16px evita el zoom automático de iOS */
  .inp-sm { padding: 7px 9px; font-size: 14px; }
}
@media (max-width: 560px) {
  .user-name, .topbar-user .badge-rol { display: none; }
  .kpis, .kpis-3 { grid-template-columns: 1fr 1fr; }
  .page-head { flex-direction: column; align-items: stretch; }
  .card { padding: 14px 14px; border-radius: 10px; }
  .auth-card { padding: 26px 22px; }
  .regimen-picker { grid-template-columns: 1fr; }
  .search-form .inp { min-width: 0; flex: 1; }
  .liq-kpis span { flex: 1 1 40%; }
  .tabs { width: 100%; }
  .tab { flex: 1; text-align: center; padding: 8px 8px; }
}
