/* ============================================================
   Gestion - hoja de estilos
   Paleta: navy #072D40 / teal #11BCB3 / crema #F0EDE8
           dorado #D7CA4A / bordo #790F35
   ============================================================ */

:root {
  --navy:    #072D40;
  --teal:    #11BCB3;
  --crema:   #F0EDE8;
  --dorado:  #D7CA4A;
  --bordo:   #790F35;

  --tinta:   #072D40;
  --tinta-2: #4A6675;
  --tinta-3: #8399A5;
  --linea:   #D9DEE1;
  --linea-2: #EAEDEF;
  --papel:   #FFFFFF;

  --ok:      #0D7F79;
  --alerta:  #8A6D00;

  --r:  6px;
  --r2: 10px;

  --sombra: 0 1px 2px rgba(7,45,64,.06), 0 4px 16px rgba(7,45,64,.06);

  --rail: 76px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: Poppins, system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--tinta);
  background: var(--crema);
  -webkit-font-smoothing: antialiased;
}

/* Cifras siempre alineadas: es un sistema de plata. */
.num, td.num, th.num, input[inputmode="decimal"] {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  text-align: right;
}

h1, h2, h3 { margin: 0; font-weight: 600; }

a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }

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

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ============================================================
   LOGIN
   ============================================================ */

.login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(17,188,179,.10), transparent 60%),
    var(--crema);
}

.login-caja {
  width: 100%;
  max-width: 360px;
  background: var(--papel);
  border: 1px solid var(--linea);
  border-radius: var(--r2);
  padding: 32px;
  box-shadow: var(--sombra);
}

.marca {
  font-family: "Baloo 2", Poppins, sans-serif;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -.01em;
  line-height: 1.1;
}

.login-sub {
  margin: 4px 0 24px;
  color: var(--tinta-2);
  font-size: 13px;
}

.login-caja label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--tinta-2);
  margin: 14px 0 5px;
}

.login-error {
  margin-top: 14px;
  padding: 9px 11px;
  border-radius: var(--r);
  background: #FBE9EF;
  color: var(--bordo);
  font-size: 13px;
}

/* ============================================================
   CONTROLES
   ============================================================ */

input[type=text], input[type=email], input[type=password],
input[type=date], input[type=number], select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--linea);
  border-radius: var(--r);
  font: inherit;
  color: var(--tinta);
  background: var(--papel);
}

input:disabled, select:disabled, textarea:disabled {
  background: var(--linea-2);
  color: var(--tinta-3);
}

textarea { min-height: 72px; resize: vertical; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: var(--r);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  background: var(--papel);
  color: var(--tinta);
  border-color: var(--linea);
  white-space: nowrap;
}

.btn:hover { border-color: var(--tinta-3); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-pri { background: var(--teal); color: #fff; border-color: var(--teal); }
.btn-pri:hover { background: #0FA9A1; border-color: #0FA9A1; }

.btn-peligro { background: var(--bordo); color: #fff; border-color: var(--bordo); }
.btn-peligro:hover { background: #5F0C2A; border-color: #5F0C2A; }

.btn-ancho { width: 100%; justify-content: center; margin-top: 22px; padding: 11px; }
.btn-chico { padding: 5px 9px; font-size: 13px; }

/* ============================================================
   ESTRUCTURA
   ============================================================ */

.app { display: flex; min-height: 100vh; }

.rail {
  width: var(--rail);
  flex: 0 0 var(--rail);
  background: var(--navy);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 0;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.rail-marca {
  font-family: "Baloo 2", sans-serif;
  font-size: 22px;
  font-weight: 700;
  color: var(--teal);
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: var(--r);
  background: rgba(255,255,255,.06);
  margin-bottom: 14px;
}

.rail-it {
  width: 60px;
  padding: 9px 4px;
  border: 0;
  background: none;
  border-radius: var(--r);
  color: rgba(240,237,232,.62);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font: inherit;
  font-size: 10px;
  cursor: pointer;
  text-decoration: none;
}

.rail-it:hover { background: rgba(255,255,255,.07); color: #fff; text-decoration: none; }
.rail-it.activo { background: rgba(17,188,179,.16); color: var(--teal); }

.rail-it svg {
  width: 20px; height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.rail-salir { margin-top: auto; }

.lienzo {
  flex: 1;
  min-width: 0;
  padding: 22px 26px 60px;
}

.cargando {
  padding: 40px;
  color: var(--tinta-3);
}

/* Encabezado de vista */
.vista-cab {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.vista-cab h2 {
  font-family: "Baloo 2", Poppins, sans-serif;
  font-size: 24px;
  font-weight: 600;
}

.vista-cab .sub { color: var(--tinta-2); font-size: 13px; margin-top: 2px; }

.acciones { display: flex; gap: 8px; align-items: center; }

/* ============================================================
   FILTROS
   ============================================================ */

.filtros {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-end;
  padding: 12px 14px;
  background: var(--papel);
  border: 1px solid var(--linea);
  border-radius: var(--r2);
  margin-bottom: 14px;
}

.campo { display: flex; flex-direction: column; gap: 4px; min-width: 130px; }
.campo.ancho { flex: 1 1 220px; }
.campo label { font-size: 11px; color: var(--tinta-2); font-weight: 500; }
.campo input, .campo select { padding: 6px 8px; font-size: 13px; }

/* ============================================================
   TABLAS
   ============================================================ */

.tabla-caja {
  background: var(--papel);
  border: 1px solid var(--linea);
  border-radius: var(--r2);
  overflow: auto;
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }

thead th {
  position: sticky;
  top: 0;
  background: #F7F8F9;
  border-bottom: 1px solid var(--linea);
  padding: 9px 12px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  color: var(--tinta-2);
  white-space: nowrap;
  z-index: 1;
}

thead th.orden { cursor: pointer; user-select: none; }
thead th.orden:hover { color: var(--tinta); }

tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--linea-2);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: 0; }
tbody tr.clic { cursor: pointer; }
tbody tr.clic:hover { background: #F5FBFB; }
tbody tr.anulada td { color: var(--tinta-3); text-decoration: line-through; }

tfoot td {
  padding: 10px 12px;
  border-top: 2px solid var(--linea);
  font-weight: 600;
  background: #F7F8F9;
}

.codigo {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.deuda { color: var(--bordo); font-weight: 600; }
.saldado { color: var(--ok); }
.negativo { color: var(--bordo); }

.vacio {
  padding: 44px 20px;
  text-align: center;
  color: var(--tinta-2);
}

.vacio p { margin: 0 0 14px; }

/* Chips de estado */
.chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  border: 1px solid transparent;
}

.chip-presupuesto { background: #EFF2F4; color: var(--tinta-2); }
.chip-confirmado  { background: #E4F7F6; color: var(--ok); }
.chip-operado     { background: #FBF6DC; color: var(--alerta); }
.chip-cerrado     { background: #E9EDF0; color: var(--tinta-2); }
.chip-cancelado   { background: #FBE9EF; color: var(--bordo); }
.chip-pendiente   { background: #FBF6DC; color: var(--alerta); }

/* Paginacion */
.paginacion {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 2px 0;
  color: var(--tinta-2);
  font-size: 13px;
}

/* ============================================================
   FICHA DE EXPEDIENTE
   ============================================================ */

.ficha-cab {
  background: var(--papel);
  border: 1px solid var(--linea);
  border-radius: var(--r2);
  padding: 18px 20px;
  margin-bottom: 16px;
}

.ficha-titulo {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.ficha-titulo h2 {
  font-family: "Baloo 2", Poppins, sans-serif;
  font-size: 22px;
}

.ficha-datos {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px 20px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--linea-2);
}

.dato label { display: block; font-size: 11px; color: var(--tinta-2); margin-bottom: 2px; }
.dato span { font-size: 14px; font-variant-numeric: tabular-nums; }

/* El saldo es el numero que mas se mira: es el unico elemento con peso. */
.saldo-destacado {
  margin-left: auto;
  text-align: right;
}

.saldo-destacado label {
  display: block;
  font-size: 11px;
  color: var(--tinta-2);
  margin-bottom: 2px;
}

.saldo-destacado .cifra {
  font-family: "Baloo 2", Poppins, sans-serif;
  font-size: 30px;
  font-weight: 600;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.saldo-destacado .cifra.deuda { color: var(--bordo); }
.saldo-destacado .cifra.saldado { color: var(--ok); }
.saldo-destacado .aclara { font-size: 12px; color: var(--tinta-2); }

.bloque {
  background: var(--papel);
  border: 1px solid var(--linea);
  border-radius: var(--r2);
  margin-bottom: 16px;
  overflow: hidden;
}

.bloque-cab {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--linea-2);
}

.bloque-cab h3 { font-size: 15px; }
.bloque-cab .cuenta { color: var(--tinta-3); font-weight: 400; font-size: 13px; }
.bloque .tabla-caja { border: 0; border-radius: 0; }

/* ============================================================
   INFORMES
   ============================================================ */

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1px;
  background: var(--linea);
  border: 1px solid var(--linea);
  border-radius: var(--r2);
  overflow: hidden;
  margin-bottom: 16px;
}

.kpi { background: var(--papel); padding: 14px 16px; }
.kpi label { display: block; font-size: 12px; color: var(--tinta-2); margin-bottom: 3px; }

.kpi .v {
  font-size: 20px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.kpi .n { font-size: 12px; color: var(--tinta-3); }

.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--linea);
  margin-bottom: 14px;
  overflow-x: auto;
}

.tab {
  padding: 8px 14px;
  border: 0;
  background: none;
  font: inherit;
  font-size: 13px;
  color: var(--tinta-2);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}

.tab:hover { color: var(--tinta); }
.tab.activo { color: var(--tinta); border-bottom-color: var(--teal); font-weight: 500; }

/* Barra proporcional dentro de tabla */
.barra {
  height: 5px;
  border-radius: 3px;
  background: var(--teal);
  min-width: 2px;
}

.barra.neg { background: var(--bordo); }

/* ============================================================
   MODAL
   ============================================================ */

.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 20px; }
.modal-fondo { position: absolute; inset: 0; background: rgba(7,45,64,.45); }

.modal-caja {
  position: relative;
  background: var(--papel);
  border-radius: var(--r2);
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 18px 50px rgba(7,45,64,.25);
}

.modal-caja.ancho { max-width: 800px; }

.modal-cab {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--linea-2);
}

.modal-cab h2 { font-size: 17px; }

.modal-x {
  border: 0; background: none; font-size: 24px; line-height: 1;
  color: var(--tinta-3); cursor: pointer; padding: 0 4px;
}

.modal-x:hover { color: var(--tinta); }
.modal-cuerpo { padding: 20px; overflow: auto; }

.modal-pie {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--linea-2);
}

/* Grilla de formulario */
.form-grilla {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.form-grilla .full { grid-column: 1 / -1; }
.form-grilla label { display: block; font-size: 12px; color: var(--tinta-2); margin-bottom: 4px; }
.form-ayuda { font-size: 12px; color: var(--tinta-3); margin-top: 4px; }

/* ============================================================
   TOASTS
   ============================================================ */

.toasts {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--navy);
  color: #fff;
  padding: 11px 15px;
  border-radius: var(--r);
  font-size: 13px;
  max-width: 340px;
  box-shadow: 0 8px 24px rgba(7,45,64,.28);
}

.toast.error { background: var(--bordo); }
.toast.ok { background: var(--ok); }

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 820px) {
  .rail {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    top: auto;
    width: 100%;
    height: auto;
    flex-direction: row;
    justify-content: space-around;
    padding: 6px 0;
    z-index: 40;
  }

  .rail-marca { display: none; }
  .rail-salir { margin-top: 0; }
  .lienzo { padding: 16px 14px 90px; }
  .form-grilla { grid-template-columns: 1fr; }
  .saldo-destacado { margin-left: 0; text-align: left; width: 100%; }
}