/* ═══════════════════════════════════════════════════════════
   Sistema Finca — estructura tipo Plastic City (sidebar izquierda)
   con la paleta de la cotización: verde campo, naranja dorado y crema.
═══════════════════════════════════════════════════════════ */
:root {
  /* Fondos */
  --bg-primary: #f4f1e8;
  --bg-sidebar: #14301d;
  --bg-card: #fffdf8;
  --bg-input: #faf8f1;

  /* Verde de marca */
  --primary: #2f6b3c;
  --primary-light: #3f8a4f;
  --primary-dark: #275a32;
  --primary-subtle: rgba(47, 107, 60, 0.12);

  /* Acento naranja dorado */
  --accent: #e0a83d;
  --accent-dim: #cf9832;
  --accent-subtle: rgba(224, 168, 61, 0.16);

  /* Texto */
  --text-primary: #23301f;
  --text-secondary: #3d4a38;
  --text-muted: #5a6b52;

  /* Bordes */
  --border: rgba(107, 114, 103, 0.22);
  --border-med: rgba(107, 114, 103, 0.4);

  /* Semánticos */
  --success: #2f6b3c;
  --success-bg: #e7f0e3;
  --error-c: #c0392b;
  --error-bg: rgba(192, 57, 43, 0.1);
  --warning: #8a5a2b;
  --warning-bg: #fbeecf;

  /* Medidas */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --sidebar-width: 224px;
  --topbar-height: 58px;

  /* Sombras */
  --shadow-sm: 0 1px 3px rgba(35, 48, 31, 0.08), 0 1px 2px rgba(35, 48, 31, 0.05);
  --shadow-lg: 0 12px 40px rgba(20, 48, 29, 0.22), 0 4px 12px rgba(20, 48, 29, 0.12);

  --transition: 0.16s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  box-sizing: border-box;
}

html {
  font-size: 14px;
}

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text-primary);
  background: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: var(--accent-subtle);
  color: var(--primary-dark);
}

::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 99px;
}

.oculto {
  display: none !important;
}

/* ===== Login ===== */
.login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #14301d 0%, #1e4a29 55%, #2f6b3c 160%);
}

.login__caja {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 36px 40px;
  width: min(380px, 92vw);
  box-shadow: var(--shadow-lg);
}

.login__logo {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
  border-bottom: 3px solid var(--accent);
}

.login__caja h1 {
  margin: 0 0 4px;
  color: var(--text-primary);
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.login__sub {
  color: var(--text-muted);
  margin: 0 0 20px;
}

/* ===== Sidebar (secciones a la izquierda) ===== */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  padding: 14px 10px 20px;
  overflow-y: auto;
  z-index: 20;
}

.sidebar__marca {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #fff;
  font-weight: 800;
  font-size: 1.02rem;
  letter-spacing: -0.01em;
  padding: 8px 12px 16px;
  border-bottom: 1px solid rgba(231, 240, 227, 0.14);
  margin-bottom: 8px;
}

.sidebar__marca svg {
  color: var(--accent);
  flex-shrink: 0;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav__grupo {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(207, 224, 200, 0.55);
  padding: 12px 12px 5px;
}

.nav__btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: transparent;
  border: none;
  color: rgba(231, 240, 227, 0.8);
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.98rem;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  position: relative;
  transition: background var(--transition), color var(--transition);
}

.nav__btn svg {
  opacity: 0.55;
  flex-shrink: 0;
  transition: opacity var(--transition);
}

.nav__btn:hover {
  background: rgba(231, 240, 227, 0.1);
  color: #fff;
}

.nav__btn:hover svg {
  opacity: 0.9;
}

.nav__btn--activo {
  background: rgba(224, 168, 61, 0.16);
  color: #fff;
  font-weight: 600;
}

.nav__btn--activo svg {
  opacity: 1;
  color: var(--accent);
}

.nav__btn--activo::before {
  content: '';
  position: absolute;
  left: 0;
  top: 20%;
  bottom: 20%;
  width: 3px;
  border-radius: 99px;
  background: var(--accent);
}

/* ===== Barra superior ===== */
.topbar {
  position: fixed;
  top: 0;
  left: var(--sidebar-width);
  right: 0;
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  padding: 0 22px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-med);
  box-shadow: 0 2px 10px rgba(35, 48, 31, 0.06);
  z-index: 10;
}

.topbar__derecha {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.usuario {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.tasa {
  background: var(--warning-bg);
  border: 1px solid var(--accent);
  color: var(--warning);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.tasa--manual {
  border-color: var(--error-c);
  background: var(--error-bg);
  color: var(--error-c);
}

/* ===== Contenido ===== */
.contenido {
  margin-left: var(--sidebar-width);
  padding: calc(var(--topbar-height) + 24px) 26px 40px;
  max-width: calc(var(--sidebar-width) + 1160px);
}

.vista__cabecera {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.vista__cabecera h2 {
  margin: 0;
  color: var(--text-primary);
  font-weight: 800;
  letter-spacing: -0.02em;
}

.btn-ayuda {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--accent);
  background: var(--bg-card);
  color: var(--primary);
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  transition: background var(--transition);
}

.btn-ayuda:hover {
  background: var(--warning-bg);
}

/* ===== Tarjetas y formularios ===== */
.tarjeta {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
}

.tarjeta h3 {
  margin: 0 0 12px;
  color: var(--primary);
  font-size: 1.05rem;
  font-weight: 700;
}

label {
  display: block;
  margin-bottom: 12px;
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--text-secondary);
}

input,
select,
textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  font-size: 1rem;
  font-family: inherit;
  border: 1px solid var(--border-med);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  transition: border-color var(--transition), box-shadow var(--transition);
}

input[type='checkbox'],
input[type='radio'] {
  display: inline-block;
  width: auto;
  margin-top: 0;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.fila {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

.fila > label {
  flex: 1;
  min-width: 140px;
}

.btn {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 20px;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--transition);
}

.btn:hover {
  background: var(--primary-dark);
}

.btn--grande {
  width: 100%;
  padding: 12px;
  font-size: 1.05rem;
}

.btn--borde {
  background: transparent;
  border: 1px solid var(--border-med);
  color: var(--text-secondary);
  font-weight: 500;
}

.btn--borde:hover {
  background: var(--primary-subtle);
  border-color: var(--primary);
  color: var(--primary-dark);
}

.btn--chico {
  padding: 6px 12px;
  font-size: 0.85rem;
}

.btn--dorado {
  background: var(--accent);
  color: var(--text-primary);
}

.btn--dorado:hover {
  background: var(--accent-dim);
}

/* ===== Tablas ===== */
.tabla-envoltura {
  overflow-x: auto;
}

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

th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 2px solid var(--border-med);
  padding: 8px 10px;
  white-space: nowrap;
}

td {
  border-bottom: 1px solid var(--border);
  padding: 8px 10px;
  font-variant-numeric: tabular-nums;
}

tr:hover td {
  background: var(--success-bg);
}

.num {
  text-align: right;
}

.pill {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.8rem;
  font-weight: 600;
}

.pill--abierta {
  background: var(--warning-bg);
  color: var(--warning);
}

.pill--pagada {
  background: var(--success-bg);
  color: var(--success);
}

.error {
  color: var(--error-c);
  font-size: 0.9rem;
}

.exito {
  color: var(--success);
  font-size: 0.9rem;
}

.vacio {
  color: var(--text-muted);
  font-style: italic;
  padding: 12px 0;
}

/* ===== Detalle de venta (conciliación) ===== */
.detalle-venta {
  background: var(--success-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-top: 8px;
}

.totales {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  margin: 10px 0;
}

.totales__item {
  min-width: 150px;
}

.totales__monto {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

.totales__etiqueta {
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* ===== Sub-pestañas (Campo / Quesera) ===== */
.subtabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.subtab {
  border: 1px solid var(--border-med);
  background: var(--bg-card);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 7px 18px;
  font-size: 0.95rem;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.subtab--activa {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  font-weight: 600;
}

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 48, 29, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal__caja {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 26px 30px;
  width: min(480px, 92vw);
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal__caja h2 {
  margin-top: 0;
  color: var(--primary);
  font-weight: 800;
}

.modal__caja p,
.modal__caja li {
  line-height: 1.55;
  color: var(--text-secondary);
}

/* ===== Teléfono / pantallas angostas =====
   El MISMO sistema, con el menú lateral escondido tras la hamburguesa
   y cada tabla con su propio scroll horizontal (nada se corta). */

.btn-menu {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border-med);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  flex-shrink: 0;
}

.topbar__marca {
  display: none;
  font-weight: 800;
  letter-spacing: -0.01em;
  margin-left: 10px;
  white-space: nowrap;
}

.velo {
  display: none;
}

@media (max-width: 860px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    width: 250px;
    box-shadow: none;
    z-index: 40;
  }

  .sidebar--abierta {
    transform: none;
    box-shadow: var(--shadow-lg);
  }

  .velo {
    position: fixed;
    inset: 0;
    background: rgba(20, 48, 29, 0.45);
    z-index: 30;
  }

  .velo--activo {
    display: block;
  }

  .btn-menu {
    display: flex;
  }

  .topbar {
    left: 0;
    padding: 0 12px;
  }

  .topbar__marca {
    display: block;
  }

  .topbar__derecha {
    gap: 8px;
  }

  .contenido {
    margin-left: 0;
    padding: calc(var(--topbar-height) + 14px) 12px 30px;
  }

  /* Los cuadros anchos ruedan dentro de su tarjeta, no fuera de la pantalla */
  .tarjeta {
    overflow-x: auto;
    padding: 14px 14px;
  }

  .fila {
    gap: 10px;
  }

  .modal__caja {
    padding: 20px 18px;
  }
}

@media (max-width: 560px) {
  /* En pantallas chiquitas: fuera el título (el menú ya trae la marca),
     el nombre del usuario se recorta con puntos y la tasa va en una línea */
  .topbar__marca {
    display: none;
  }

  .usuario {
    max-width: 90px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .tasa {
    padding: 6px 10px;
    font-size: 0.82rem;
    white-space: nowrap;
  }

  .btn--borde {
    padding: 8px 10px;
    font-size: 0.9rem;
  }
}

.pill--anulada,
.pill--anulado {
  background: var(--error-bg);
  color: var(--error-c);
}

/* Crédito vencido: la fecha límite ya pasó */
.txt-vencido {
  color: var(--error-c);
  font-weight: 600;
}
.txt-muted {
  color: var(--text-muted);
}
/* La casilla de fecha límite vencida se resalta con borde rojo */
input.edit-vence-cxc.txt-vencido,
input.edit-vence-cxp.txt-vencido {
  border-color: var(--error-c);
}
