:root {
  color-scheme: light dark;

  --bg: #F3F5FA;
  --surface: #FFFFFF;
  --surface-2: #EEF0F8;
  --border: #DEE2EF;
  --text: #1B2036;
  --text-muted: #5C6280;
  --text-faint: #8D93AC;

  --indigo: #2F4597;
  --indigo-ink: #232A6B;
  --indigo-soft: #E7E9F7;
  --azure: #0080C8;
  --azure-soft: #E2F2FA;

  --ok: #2E8B57;
  --ok-soft: #E1F1E7;
  --warn: #C99A2E;
  --warn-soft: #F6EDD7;
  --crit: #B23A3A;
  --crit-soft: #F8DEDE;
  --neutral: #8891A0;
  --neutral-soft: #EDEFF3;

  --shadow: 0 1px 2px rgba(35, 42, 107, 0.06), 0 10px 26px -14px rgba(35, 42, 107, 0.22);
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  --sans: -apple-system, "Segoe UI", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0E1220;
    --surface: #161B2E;
    --surface-2: #1D2338;
    --border: #2B3350;
    --text: #E8EAF5;
    --text-muted: #9BA1C2;
    --text-faint: #5F6690;
    --indigo: #8791E0;
    --indigo-ink: #C7CCF2;
    --indigo-soft: #232A50;
    --azure: #5FC1EA;
    --azure-soft: #123244;
    --ok: #57B37F;
    --ok-soft: #153524;
    --warn: #DDBB5E;
    --warn-soft: #3A3016;
    --crit: #E07070;
    --crit-soft: #3E1D1D;
    --neutral: #8891A0;
    --neutral-soft: #232838;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 26px -14px rgba(0, 0, 0, 0.65);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  font-family: var(--sans);
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

/* ---------- Shell: sidebar + contenido ---------- */
.app { display: grid; grid-template-columns: 224px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.logo { display: flex; align-items: center; justify-content: center; padding: 10px 4px 6px; }
.logo-img { height: 30px; width: auto; display: block; }
.logo-img-lg { height: 38px; }

nav.navlist { display: flex; flex-direction: column; gap: 2px; }
nav.navlist .item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 8px; border-radius: 7px;
  font-size: 13px; font-weight: 600; color: var(--text-muted); text-decoration: none;
  border-left: 3px solid transparent;
}
nav.navlist .item:hover { background: var(--surface-2); }
nav.navlist .item.active { background: var(--indigo-soft); color: var(--indigo-ink); border-left-color: var(--azure); }
nav.navlist .item .ic { width: 17px; height: 17px; flex: none; opacity: 0.6; }
nav.navlist .item .ic svg { width: 100%; height: 100%; }
nav.navlist .item.active .ic { opacity: 1; color: var(--azure); }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.user-chip { display: flex; align-items: center; gap: 9px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--azure); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 11.5px; font-weight: 800; flex: none;
}
.user-chip .who { line-height: 1.25; overflow: hidden; }
.user-chip .who b { font-size: 12.5px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip .who span { font-size: 11px; color: var(--text-faint); }
.logout-form button {
  width: 100%; background: transparent; border: 1px solid var(--border); color: var(--text-muted);
  border-radius: 7px; padding: 7px 10px; font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.logout-form button:hover { background: var(--surface-2); color: var(--crit); border-color: var(--crit); }

.contenido { padding: 22px 26px 60px; max-width: 1180px; }

.contenido-login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }

h1 { font-size: 17px; font-weight: 800; color: var(--indigo-ink); margin: 0 0 16px; letter-spacing: 0.1px; text-wrap: balance; }
h2 { font-size: 13px; font-weight: 800; margin: 0; color: var(--indigo-ink); }
h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-faint); margin: 0 0 10px; font-weight: 800; }

/* ---------- Tiles de resumen ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow); }
.tile .label { display: flex; align-items: center; gap: 6px; font-size: 10.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.4px; font-weight: 700; }
.tile .label svg { width: 13px; height: 13px; flex: none; opacity: 0.75; }
.tile .value { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 19px; font-weight: 700; margin-top: 5px; }
.tile .sub { font-size: 11.5px; color: var(--text-muted); margin-top: 3px; }

.ficha-meta { color: var(--text-muted); font-size: 12.5px; margin: 2px 0 16px; }
.back-link { display: inline-block; font-size: 12.5px; color: var(--azure); font-weight: 600; margin-bottom: 10px; text-decoration: none; }
.back-link:hover { text-decoration: underline; }

/* ---------- Tarjetas ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); margin-bottom: 18px; overflow: hidden;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; padding: 14px 18px;
  border-bottom: 1px solid var(--border); gap: 10px; flex-wrap: wrap;
}
.card-head h2 { margin: 0; }
summary.card-head { cursor: pointer; list-style: none; }
summary.card-head::-webkit-details-marker { display: none; }
summary.card-head h2::before { content: "▾ "; color: var(--text-faint); font-size: 12px; }
details.card:not([open]) > summary.card-head h2::before { content: "▸ "; }
details.card:not([open]) > summary.card-head { border-bottom: none; }
.tag {
  font-size: 11px; font-weight: 700; color: var(--text-faint); background: var(--surface-2);
  border-radius: 100px; padding: 3px 10px;
}
.card-body { padding: 16px 18px; }

/* Tarjeta colapsable anidada dentro de otra ya abierta (ej. cada empresa
   dentro de "Estado de cuenta") -- mismo patrón visual que .card-head pero
   sin depender de un <h2> ni de ser hijo directo de details.card. */
.subcard { border-top: 1px solid var(--border); }
.subcard-head {
  display: flex; align-items: center; justify-content: space-between; padding: 14px 18px;
  gap: 10px; flex-wrap: wrap; cursor: pointer; list-style: none; font-weight: 700;
}
.subcard-head::-webkit-details-marker { display: none; }
.subcard-head::before { content: "▾ "; color: var(--text-faint); font-size: 12px; font-weight: 400; }
details:not([open]) > .subcard-head::before { content: "▸ "; }
.subcard-body { padding: 0 18px 18px; }

/* ---------- Tablas ---------- */
.tabla { width: 100%; border-collapse: collapse; }
.tabla th.num, .tabla td.num { text-align: right; }
.tabla td.num, .money { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.tabla th {
  text-align: left; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.4px;
  color: var(--text-faint); font-weight: 700; padding: 8px 10px; border-bottom: 1px solid var(--border);
}
.tabla td { padding: 10px; border-bottom: 1px solid var(--border); font-size: 13px; }
.tabla tr:last-child td { border-bottom: none; }
.tabla .fila-total td { font-weight: 700; background: var(--surface-2); }

/* ---------- Login ---------- */
.login-box {
  width: 100%; max-width: 340px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow); padding: 32px 28px;
}
.login-box h1 { margin: 0 0 4px; }
.login-box p.subtitulo { font-size: 12px; color: var(--text-faint); margin: 0 0 20px; }
.login-box form { display: flex; flex-direction: column; gap: 14px; }
.error {
  color: var(--crit); background: var(--crit-soft); border-radius: 8px; padding: 8px 12px;
  font-size: 12.5px; margin: 0 0 16px;
}

/* ---------- Formularios ---------- */
form label { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; font-size: 12.5px; color: var(--text-muted); font-weight: 600; }
form input, form select, form textarea {
  padding: 9px 11px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface);
  color: var(--text); font-size: 13.5px; font-family: inherit;
}
form input:focus, form select:focus, form textarea:focus { outline: 2px solid var(--azure); outline-offset: 1px; }
button {
  padding: 9px 16px; border: none; border-radius: 7px; background: var(--indigo); color: #fff;
  cursor: pointer; font-size: 13.5px; font-weight: 700; font-family: inherit;
}
button:hover { filter: brightness(1.12); }
.btn-peligro { background: #dc2626; }

/* ---------- Campo de contraseña con botón de mostrar/ocultar ---------- */
.input-con-boton { display: flex; gap: 6px; }
.input-con-boton input { flex: 1; }
.input-con-boton button { flex-shrink: 0; padding: 9px 12px; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); font-weight: 600; }

/* ---------- Listas (bitácora / promesas) ---------- */
.bitacora-lista, .promesas-lista { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.bitacora-lista li, .promesas-lista li {
  border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; background: var(--surface);
}
.bitacora-lista li p, .promesas-lista li p { margin: 6px 0 0; font-size: 13px; }

.alerta { color: var(--warn); font-weight: 700; margin-left: 8px; }

/* ---------- Insignias de estado ---------- */
.status-badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 100px;
  font-weight: 700; font-size: 11px;
}
.status-ok { background: var(--ok-soft); color: var(--ok); }
.status-neutral { background: var(--neutral-soft); color: var(--neutral); }
.status-bloqueado { background: var(--crit-soft); color: var(--crit); }
.documentos-relacionados { color: var(--text-faint); font-size: 12px; }

/* ---------- Checklist ---------- */
.checklist {
  display: flex; flex-direction: column; gap: 4px; max-height: 170px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: 8px; padding: 8px; background: var(--surface-2);
}
.checklist-item { flex-direction: row !important; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 500; margin-bottom: 0 !important; }
.checklist-item input { width: auto; }

/* ---------- Pestañas (cartera general / mi cartera) ---------- */
.tabs2 { display: inline-flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 9px; border: 1px solid var(--border); margin-bottom: 14px; }
.tabs2 button { border: none; background: transparent; color: var(--text-muted); padding: 7px 14px; border-radius: 6px; font-size: 12.5px; font-weight: 700; cursor: pointer; font-family: inherit; }
.tabs2 button.active { background: var(--indigo); color: #fff; }
.tabpanel { display: none; }
.tabpanel.active { display: block; }

/* ---------- Filtro de cartera (buscar cliente / asignado a) ---------- */
.filtro-cartera { display: flex; flex-wrap: wrap; gap: 8px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.filtro-cartera .filtro-input { flex: 1 1 240px; min-width: 180px; }
.filtro-cartera .filtro-select { flex: 0 1 220px; }

/* ---------- Detalle de garantía ---------- */
.detalle-garantia { margin-top: 12px; }
.detalle-garantia > summary { cursor: pointer; font-size: 12.5px; font-weight: 700; color: var(--azure); list-style: none; }
.detalle-garantia > summary::-webkit-details-marker { display: none; }
.detalle-garantia > summary::before { content: "▸ "; }
.detalle-garantia[open] > summary::before { content: "▾ "; }
.detalle-garantia .tabla { margin-top: 10px; }

/* ---------- Formulario compacto embebido en fila de tabla (editar etapa/usuario) ---------- */
.form-etapa-editar, .form-usuario-editar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.form-etapa-editar label, .form-usuario-editar label { margin-bottom: 0; min-width: 110px; }
.form-etapa-editar input[type="text"], .form-etapa-editar input[type="number"], .form-etapa-editar select,
.form-usuario-editar select { min-width: 100px; }

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