:root {
  --navy: #003b71;
  --navy-light: #0a4d8f;
  --navy-soft: rgba(0, 59, 113, 0.06);
  --green: #76bc21;
  --green-dark: #5f9a1a;
  --green-soft: rgba(118, 188, 33, 0.14);
  --blue-gray: #a2b5d1;
  --blue-gray-soft: rgba(162, 181, 209, 0.28);
  --bg: #f2f5fa;
  --card: #ffffff;
  --text: #10233c;
  --muted: #5c6d85;
  --border: #e4e9f2;
  --error: #c0392b;
  --error-bg: #fdeceb;
  --success: #2f8f3f;
  --success-bg: #eaf7ec;
  --shadow-sm: 0 1px 2px rgba(0, 30, 60, 0.06), 0 1px 3px rgba(0, 30, 60, 0.04);
  --shadow-md: 0 8px 24px rgba(0, 30, 60, 0.08), 0 2px 6px rgba(0, 30, 60, 0.05);
  --shadow-lg: 0 20px 48px rgba(0, 30, 60, 0.14);
  --radius: 16px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }

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

::selection { background: var(--green-soft); color: var(--navy); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--blue-gray); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--navy-light); }

.hidden { display: none !important; }

.view { min-height: 100vh; }

button {
  cursor: pointer;
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 18px;
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.15s ease, box-shadow 0.15s ease, transform 0.08s ease, border-color 0.15s ease, color 0.15s ease;
}
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

/* ----------------------------- Login ----------------------------------- */

#login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  background: linear-gradient(160deg, #f2f5fa 0%, #eef3fb 55%, #e9f2e4 100%);
}

.login-bg-shape {
  position: absolute;
  border-radius: 50%;
  filter: blur(10px);
  opacity: 0.35;
  z-index: 0;
}
.shape-1 {
  width: 480px;
  height: 480px;
  background: radial-gradient(circle at 30% 30%, var(--navy-light), transparent 70%);
  top: -180px;
  left: -140px;
}
.shape-2 {
  width: 420px;
  height: 420px;
  background: radial-gradient(circle at 60% 60%, var(--green), transparent 70%);
  bottom: -160px;
  right: -120px;
  opacity: 0.25;
}

.login-card {
  position: relative;
  z-index: 1;
  background: var(--card);
  padding: 44px 40px 36px;
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  width: 360px;
  border: 1px solid rgba(255, 255, 255, 0.6);
}

.brand-mark {
  width: 56px;
  height: 56px;
  margin: 0 auto 20px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--navy), var(--navy-light));
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 24px rgba(0, 59, 113, 0.35);
}

.login-card h1 { margin: 0 0 4px; font-size: 21px; font-weight: 800; letter-spacing: -0.01em; }
.subtitle { color: var(--muted); margin: 0 0 28px; font-size: 13.5px; font-weight: 500; }

#login-btn {
  background: var(--card);
  color: var(--text);
  border: 1.5px solid var(--border);
  width: 100%;
  padding: 12px 16px;
  box-shadow: var(--shadow-sm);
}
#login-btn:hover { border-color: var(--blue-gray); box-shadow: var(--shadow-md); }

.error { color: var(--error); font-size: 13px; margin-top: 16px; font-weight: 600; }

/* ----------------------------- Header / drawer -------------------------- */

header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 20px;
  background: linear-gradient(120deg, var(--navy) 0%, var(--navy-light) 100%);
  color: white;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 4px 16px rgba(0, 30, 60, 0.18);
}
#menu-toggle {
  background: rgba(255, 255, 255, 0.12);
  color: white;
  padding: 9px;
  border-radius: 10px;
}
#menu-toggle:hover { background: rgba(255, 255, 255, 0.22); }

.header-title { flex: 1; display: flex; flex-direction: column; line-height: 1.15; }
.header-title-main { font-size: 16px; font-weight: 800; letter-spacing: -0.01em; }
.header-title-sub { font-size: 11px; color: var(--blue-gray); font-weight: 600; letter-spacing: 0.03em; text-transform: uppercase; }

.user-box { display: flex; align-items: center; gap: 12px; font-size: 13px; font-weight: 600; }
#user-name { color: rgba(255, 255, 255, 0.85); display: none; }
@media (min-width: 480px) {
  #user-name { display: inline; }
}
#logout-btn {
  background: rgba(255, 255, 255, 0.14);
  color: white;
  padding: 9px 14px;
  font-size: 13px;
}
#logout-btn:hover { background: rgba(255, 255, 255, 0.24); }

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(9, 20, 38, 0.4);
  z-index: 25;
  backdrop-filter: blur(1px);
}

.drawer {
  position: fixed;
  top: 0;
  left: 0;
  width: 260px;
  background: var(--card);
  height: 100%;
  padding: 20px 14px;
  z-index: 30;
  box-shadow: var(--shadow-lg);
  border-radius: 0 20px 20px 0;
}
.drawer nav { margin-top: 56px; }
.drawer-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-radius: 12px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 700;
  transition: background 0.15s ease, color 0.15s ease;
}
.drawer-item.active {
  background: var(--green-soft);
  color: var(--navy);
}
.drawer-item svg { flex-shrink: 0; }

/* ----------------------------- Layout ----------------------------------- */

main {
  max-width: 860px;
  margin: 32px auto 60px;
  padding: 0 16px;
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field + .field { margin-top: 14px; }
.field label { font-size: 12.5px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.02em; }

#query-form {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}
#query-form::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--navy), var(--green));
}

#query-form select, #query-form input {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  font-size: 14.5px;
  font-family: inherit;
  color: var(--text);
  background: white;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
#query-form select:focus, #query-form input:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 4px var(--green-soft);
}

#submit-btn {
  margin-top: 18px;
  width: 100%;
  background: linear-gradient(120deg, var(--green), var(--green-dark));
  color: white;
  padding: 13px 16px;
  font-size: 15px;
  box-shadow: 0 8px 20px rgba(118, 188, 33, 0.32);
}
#submit-btn:hover { box-shadow: 0 10px 26px rgba(118, 188, 33, 0.42); }

.status {
  margin-top: 16px;
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  border-left: 4px solid transparent;
}
.status.loading { background: #fff7e6; color: #8a5a00; border-left-color: #e0a300; }
.status.error { background: var(--error-bg); color: var(--error); border-left-color: var(--error); }
.status.success { background: var(--success-bg); color: var(--success); border-left-color: var(--success); }
.status.empty { background: var(--navy-soft); color: var(--navy); border-left-color: var(--blue-gray); }

.result {
  margin-top: 22px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}
.result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding-bottom: 16px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.result-header h2 { margin: 0; font-size: 18px; font-weight: 800; color: var(--navy); letter-spacing: -0.01em; }
.result-actions { display: flex; gap: 8px; }
.result-actions button { font-size: 13px; padding: 9px 14px; }

.btn-ghost {
  background: var(--bg);
  color: var(--navy);
  border: 1.5px solid var(--border);
}
.btn-ghost:hover { border-color: var(--blue-gray); background: var(--blue-gray-soft); }

.btn-solid {
  background: var(--navy);
  color: white;
}
.btn-solid:hover { background: var(--navy-light); }

.client-summary { margin-bottom: 8px; }
.client-summary h3 {
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tabs { margin-top: 24px; }
.tab-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}
.tab-btn {
  background: var(--blue-gray-soft);
  color: var(--navy);
  border: none;
  font-size: 13px;
  padding: 9px 16px;
  border-radius: 999px;
}
.tab-btn:hover { background: var(--blue-gray); }
.tab-btn.active {
  background: var(--green);
  color: white;
  box-shadow: 0 4px 12px rgba(118, 188, 33, 0.35);
}

/* --------------------- datos formateados (resumen y pestanas) ---------- */

.empty-state { color: var(--muted); font-size: 13.5px; margin: 8px 0; font-style: italic; }

.plain-fallback {
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 14px;
  font-family: inherit;
  font-size: 13.5px;
  margin: 0;
}

.summary-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.summary-header span:first-child {
  font-size: 19px;
  font-weight: 800;
  color: var(--navy);
  letter-spacing: -0.01em;
}
.summary-header span:not(:first-child) {
  font-size: 12px;
  font-weight: 700;
  color: var(--navy);
  background: var(--green-soft);
  border-radius: 999px;
  padding: 4px 12px;
}

.policy-line {
  font-size: 14.5px;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 14px;
}
.policy-line strong {
  color: var(--navy);
  font-weight: 800;
  margin-left: 4px;
}

.kv-grid {
  display: grid;
  grid-template-columns: minmax(150px, 230px) 1fr;
  row-gap: 4px;
  column-gap: 20px;
  margin: 0;
}
.kv-grid dt {
  font-size: 12.5px;
  color: var(--muted);
  font-weight: 700;
  align-self: start;
  padding: 10px 0;
}
.kv-grid dd {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  word-break: break-word;
  padding: 10px 0;
}
.kv-grid dt, .kv-grid dd { border-bottom: 1px solid var(--border); }
.kv-grid > dt:nth-of-type(2n), .kv-grid > dd:nth-of-type(2n) { background: var(--navy-soft); }

.subsection-title {
  font-size: 12.5px;
  color: var(--navy);
  margin: 22px 0 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  display: flex;
  align-items: center;
  gap: 8px;
}
.subsection-title::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  flex-shrink: 0;
}
.tab-content > .subsection-title:first-child { margin-top: 0; }

.stat-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 4px;
}
#top-stats:not(:empty) { margin-top: 14px; }
.stat-box {
  background: var(--navy-soft);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  min-width: 170px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  border: 1px solid var(--border);
}
.stat-label { font-size: 11.5px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.02em; }
.stat-value { font-size: 19px; font-weight: 800; color: var(--navy); }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  margin-bottom: 4px;
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.data-table th {
  text-align: left;
  font-size: 11.5px;
  color: var(--navy);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  padding: 10px 12px;
  background: var(--navy-soft);
  white-space: nowrap;
}
.data-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  font-weight: 500;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--green-soft); }

.coverage-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
  margin-bottom: 4px;
}
.coverage-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--green);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.coverage-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.coverage-name { font-size: 13.5px; font-weight: 800; color: var(--navy); margin-bottom: 3px; }
.coverage-date { font-size: 12px; color: var(--muted); margin-bottom: 10px; font-weight: 600; }
.coverage-amounts {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

@media (max-width: 600px) {
  .kv-grid { grid-template-columns: 1fr; row-gap: 0; }
  .kv-grid dt { padding-bottom: 0; border-bottom: none; background: none !important; }
  .kv-grid dd { padding-top: 2px; background: none !important; }
  .data-table { display: block; overflow-x: auto; white-space: nowrap; }
  .login-card { width: calc(100vw - 40px); padding: 36px 26px 30px; }
}

/* --------------------------- selector de polizas ------------------------ */

.candidatos-hint { color: var(--muted); font-size: 13.5px; margin: 0 0 16px; }

.candidatos-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.candidato-card {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.08s ease;
}
.candidato-card:hover {
  border-color: var(--green);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.candidato-nombre { font-size: 14px; font-weight: 800; color: var(--navy); }
.candidato-poliza {
  font-size: 12px;
  font-weight: 700;
  color: var(--navy);
  background: var(--green-soft);
  border-radius: 999px;
  padding: 3px 10px;
  align-self: flex-start;
}

/* ------------------------------ administracion --------------------------- */

#admin-page, #leads-page {
  /* Se "sale" del ancho angosto de <main> porque las tablas necesitan mas
     espacio horizontal que el formulario de consulta. */
  max-width: 1180px;
  width: 100vw;
  position: relative;
  left: 50%;
  transform: translateX(-50%);
  padding: 0 16px;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.admin-header h2 { margin: 0; font-size: 19px; font-weight: 800; color: var(--navy); }

.admin-date-filter {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}
.admin-date-filter .field { gap: 4px; }
.admin-date-filter .field label {
  font-size: 11.5px;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.admin-date-filter input[type="date"] {
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  font-size: 13.5px;
  font-family: inherit;
  color: var(--text);
}
.admin-date-filter input[type="date"]:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px var(--green-soft);
}
.admin-date-filter button { font-size: 13px; padding: 9px 16px; }
.admin-date-filter .btn-solid { margin-left: auto; }

@media (max-width: 600px) {
  .admin-date-filter .btn-solid { margin-left: 0; width: 100%; }
}

.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}
.stat-card-label {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  display: block;
  margin-bottom: 6px;
}
.stat-card-value { font-size: 26px; font-weight: 800; color: var(--navy); }

.admin-table-card { margin-top: 18px; }
.admin-table-card .result-header {
  flex-wrap: wrap;
  gap: 10px;
}
.admin-filter-input {
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  font-size: 13.5px;
  font-family: inherit;
  min-width: 220px;
}
.admin-filter-input:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px var(--green-soft);
}

.table-scroll { overflow-x: auto; }
.table-scroll .data-table { min-width: 560px; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
}
.status-pill.ok { background: var(--success-bg); color: var(--success); }
.status-pill.fail { background: var(--error-bg); color: var(--error); }

@media (max-width: 700px) {
  #admin-page, #leads-page { padding: 0 16px; }
}

.leads-hint { color: var(--muted); font-size: 13.5px; margin: 0 0 16px; }
