/* LEX · hoja de estilos */
:root {
  --bg: #f5f4f0;
  --panel: #ffffff;
  --ink: #1c1d21;
  --ink-2: #4a4d55;
  --muted: #8a8d95;
  --line: #e4e2dc;
  --line-2: #efede8;
  --side: #17181c;
  --side-ink: #b9bbc2;
  --accent: #8a6a2f;       /* bronce: sobrio, legal */
  --accent-ink: #ffffff;
  --accent-soft: #f4ecdc;
  --pos: #0b6aa2; --pos-soft: #e3f0f8;
  --neg: #b3263e; --neg-soft: #fbe7ea;
  --hold: #6b46b5; --hold-soft: #eee8f8;
  --def: #6b6e76; --def-soft: #eceae6;
  --ok: #1d7a4f; --ok-soft: #e2f3ea;
  --warn: #a8640a; --warn-soft: #fbf0dd;
  --err: #b3263e; --err-soft: #fbe7ea;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20,20,25,.05), 0 2px 8px rgba(20,20,25,.04);
  font-size: 15px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--ink); line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.25; }
h1 { font-family: "Source Serif 4", Georgia, serif; font-weight: 600; font-size: 1.75rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; font-weight: 600; }
h3 { font-size: .95rem; font-weight: 600; }
p { margin: 0 0 .75em; }
code { background: var(--line-2); padding: 1px 5px; border-radius: 4px; font-size: .9em; }
.ic { width: 18px; height: 18px; flex: none; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .88em; }

/* ---------- Estructura ---------- */
.shell { display: flex; min-height: 100vh; }
.side { width: 232px; background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; flex: none; }
.brand { display: flex; align-items: baseline; gap: 10px; padding: 22px 20px 18px; color: #fff; text-decoration: none !important; }
.brand-mark { font-family: "Source Serif 4", Georgia, serif; font-weight: 600; font-size: 1.45rem; letter-spacing: .12em; color: #fff; }
.brand-sub { font-size: .78rem; color: #8d9098; }
.side nav { flex: 1; overflow-y: auto; padding: 4px 10px; }
.side nav a { display: flex; align-items: center; gap: 11px; padding: 8px 11px; border-radius: 7px; color: var(--side-ink); font-size: .9rem; text-decoration: none; margin-bottom: 1px; }
.side nav a:hover { background: #23252b; color: #fff; }
.side nav a.on { background: #2b2d34; color: #fff; }
.side nav a.on .ic { color: #d6b678; }
.nav-sep { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: #6c6f77; padding: 16px 11px 6px; }
.side-user { border-top: 1px solid #26282e; padding: 12px 12px; display: flex; align-items: center; gap: 8px; }
.side-user .who { flex: 1; display: flex; gap: 10px; align-items: center; color: #e6e7ea; text-decoration: none; min-width: 0; }
.side-user .who span { display: flex; flex-direction: column; font-size: .85rem; min-width: 0; }
.side-user .who small { color: #8d9098; font-size: .74rem; }
.side-user .out { color: #8d9098; padding: 6px; border-radius: 6px; }
.side-user .out:hover { background: #23252b; color: #fff; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; }
.content { padding: 28px 32px 60px; max-width: 1320px; width: 100%; }

@media (max-width: 900px) {
  .side { position: fixed; left: -260px; z-index: 50; transition: left .2s; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .side.open { left: 0; }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--side); color: #fff; position: sticky; top: 0; z-index: 40; }
  .menu-btn { background: none; border: 0; color: #fff; padding: 6px; cursor: pointer; }
  .content { padding: 18px 16px 50px; }
}

/* ---------- Encabezados de página ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--ink-2); margin: 4px 0 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.crumbs { font-size: .82rem; color: var(--muted); margin-bottom: 6px; }
.crumbs a { color: var(--muted); }

/* ---------- Paneles ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 18px; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush .card-head { padding: 16px 20px 0; }
.grid { display: grid; gap: 18px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 1000px) { .g3, .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); } .g-main { grid-template-columns: 1fr; } }
@media (max-width: 640px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }

/* KPIs */
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); text-decoration: none !important; color: inherit; display: block; }
.kpi:hover { border-color: #d3cfc4; }
.kpi .n { font-size: 1.9rem; font-weight: 600; letter-spacing: -.02em; line-height: 1.1; }
.kpi .l { color: var(--ink-2); font-size: .85rem; margin-top: 4px; }
.kpi.alerta .n { color: var(--err); }
.kpi.aviso .n { color: var(--warn); }

/* Barra de progreso */
.prog { height: 8px; background: var(--line-2); border-radius: 99px; overflow: hidden; }
.prog > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.prog.pos > span { background: var(--pos); }
.prog.neg > span { background: var(--neg); }
.prog-row { display: flex; justify-content: space-between; font-size: .85rem; margin: 10px 0 5px; }

/* ---------- Tablas ---------- */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th { text-align: left; font-weight: 600; font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); background: #fbfaf8; white-space: nowrap; }
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr:hover td { background: #fcfbf9; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl .row-link { color: var(--ink); font-weight: 500; }
.tbl tfoot td { font-weight: 600; background: #fbfaf8; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* ---------- Etiquetas ---------- */
.tag, .st { display: inline-flex; align-items: center; gap: 5px; font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.tag::before { content: ""; width: 7px; height: 7px; border-radius: 99px; background: currentColor; }
.tag-positiva { color: var(--pos); background: var(--pos-soft); }
.tag-negativa { color: var(--neg); background: var(--neg-soft); }
.tag-holding { color: var(--hold); background: var(--hold-soft); }
.tag-por_definir { color: var(--def); background: var(--def-soft); }
.st { background: var(--def-soft); color: var(--ink-2); }
.st-pendiente { background: #eef0f3; color: #4a5160; }
.st-ingresado { background: #e3eefb; color: #1f5fa8; }
.st-observado { background: var(--warn-soft); color: var(--warn); }
.st-finalizado { background: var(--ok-soft); color: var(--ok); }
.st-inscrito { background: #d5efe1; color: #12603c; }
.st-stand_by { background: #f1e9fa; color: #6b46b5; }
.st-anulado { background: #f0eeea; color: #8a8d95; text-decoration: line-through; }
.st-t-pendiente { background: #eef0f3; color: #4a5160; }
.st-t-en_curso { background: #e3eefb; color: #1f5fa8; }
.st-t-hecha { background: var(--ok-soft); color: var(--ok); }
.st-t-descartada { background: #f0eeea; color: #8a8d95; }
.pill { display: inline-block; font-size: .75rem; padding: 1px 7px; border-radius: 5px; background: var(--line-2); color: var(--ink-2); font-weight: 500; }
.pill.enc { background: #1c1d21; color: #fff; letter-spacing: .03em; }
.dl { font-size: .8rem; font-weight: 600; white-space: nowrap; }
.dl-vencido { color: var(--err); }
.dl-pronto { color: var(--warn); }
.dl-ok { color: var(--ink-2); }

/* ---------- Alertas ---------- */
.alert { padding: 11px 14px; border-radius: 8px; margin-bottom: 14px; font-size: .9rem; border: 1px solid transparent; }
.alert.ok { background: var(--ok-soft); color: #145a3a; border-color: #c4e6d3; }
.alert.error { background: var(--err-soft); color: #8e1c30; border-color: #f2c7cf; }
.alert.warn { background: var(--warn-soft); color: #7d4a07; border-color: #f0dbb6; }
.alert.info { background: #eef3fa; color: #234a7a; border-color: #d3e1f3; }

/* ---------- Formularios ---------- */
.form label, label.f { display: block; font-size: .82rem; font-weight: 500; color: var(--ink-2); margin-bottom: 12px; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], input[type=url], input:not([type]), select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 8px 10px; font: inherit; font-size: .92rem; color: var(--ink);
  background: #fff; border: 1px solid #d9d6ce; border-radius: 7px; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(138,106,47,.15); }
textarea { min-height: 90px; resize: vertical; }
.form h3 { margin-top: 18px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 16px; }
@media (max-width: 640px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
label.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
label.check input { width: auto; margin: 0; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 6px; }
.checks label { display: flex; gap: 6px; align-items: center; font-weight: 400; color: var(--ink); margin: 0; }
.checks input { width: auto; margin: 0; }
.inline-form { display: inline; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 16px; }
.filters label { margin: 0; font-size: .78rem; }
.filters select, .filters input { min-width: 150px; }

/* Botones */
.btn { display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px; font: inherit; font-size: .88rem; font-weight: 500; border-radius: 7px; border: 1px solid #d9d6ce; background: #fff; color: var(--ink); cursor: pointer; text-decoration: none !important; white-space: nowrap; }
.btn:hover { background: #faf9f6; border-color: #c9c5bb; }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.primary:hover { background: #33353b; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.accent:hover { background: #765a26; }
.btn.danger { color: var(--err); border-color: #efc4cc; }
.btn.danger:hover { background: var(--err-soft); }
.btn.sm { padding: 4px 9px; font-size: .8rem; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ia { background: linear-gradient(180deg, #2a2b31, #17181c); color: #f3e3c0; border-color: #17181c; }
.btn.ia:hover { background: #33353b; }
.btn[disabled] { opacity: .55; cursor: wait; }
.btn .ic { width: 15px; height: 15px; }

/* ---------- Cap table ---------- */
.cap-row { display: grid; grid-template-columns: minmax(0, 1fr) 120px 120px 34px; gap: 8px; align-items: center; margin-bottom: 6px; }
.cap-row select, .cap-row input { margin: 0; }
.cap-sum { display: flex; justify-content: space-between; align-items: center; padding: 10px 0 2px; font-weight: 600; }
.sum-ok { color: var(--ok); }
.sum-bad { color: var(--err); }
.bar-stack { display: flex; height: 10px; border-radius: 99px; overflow: hidden; background: var(--line-2); margin: 6px 0 12px; }
.bar-stack span { display: block; height: 100%; }

/* Línea de tiempo */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline > li { position: relative; padding: 0 0 16px 22px; border-left: 2px solid var(--line); margin-left: 6px; }
.timeline > li:last-child { border-left-color: transparent; }
.timeline > li::before { content: ""; position: absolute; left: -7px; top: 3px; width: 12px; height: 12px; border-radius: 99px; background: #fff; border: 2px solid var(--accent); }
.timeline > li.ia::before { border-color: #1c1d21; background: #f3e3c0; }
.timeline .meta { font-size: .78rem; color: var(--muted); margin-bottom: 2px; }

/* Diff de escenarios */
.mov { display: flex; gap: 10px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--line-2); font-size: .9rem; flex-wrap: wrap; }
.mov:last-child { border-bottom: 0; }
.mov .arrow { color: var(--muted); }
.delta-up { color: var(--ok); font-weight: 600; }
.delta-down { color: var(--err); font-weight: 600; }

/* Organigrama */
.org-wrap { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; overflow: auto; min-height: 400px; }
.org-wrap svg { max-width: none !important; height: auto; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: .8rem; color: var(--ink-2); margin: 10px 0; }
.legend i { display: inline-block; width: 22px; height: 0; border-top: 2px solid; vertical-align: middle; margin-right: 6px; }
.seg { display: inline-flex; border: 1px solid #d9d6ce; border-radius: 8px; overflow: hidden; }
.seg a { padding: 7px 13px; font-size: .85rem; color: var(--ink-2); text-decoration: none; border-right: 1px solid #d9d6ce; background: #fff; }
.seg a:last-child { border-right: 0; }
.seg a.on { background: var(--ink); color: #fff; }

/* Tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs a { padding: 9px 14px; font-size: .9rem; color: var(--ink-2); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }

/* IA */
.ia-box { background: #1c1d21; color: #e9e6df; border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px; }
.ia-box h2, .ia-box h3 { color: #f3e3c0; }
.ia-box textarea, .ia-box input, .ia-box select { background: #26272c; color: #f2f0eb; border-color: #3a3c43; }
.ia-box .muted { color: #9a9ca3; }
.ia-out { background: #fff; border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 8px; padding: 14px 18px; font-size: .92rem; }
.ia-out h1, .ia-out h2, .ia-out h3 { font-family: Inter, sans-serif; font-size: 1rem; margin-top: 14px; }
.ia-out ul { padding-left: 20px; margin: 6px 0 10px; }
.ia-out p { margin-bottom: .6em; }
.chat { display: flex; flex-direction: column; gap: 12px; margin-bottom: 14px; }
.msg { max-width: 85%; padding: 10px 14px; border-radius: 12px; font-size: .92rem; }
.msg.user { align-self: flex-end; background: var(--ink); color: #fff; border-bottom-right-radius: 3px; }
.msg.bot { align-self: flex-start; background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 3px; }
.msg.bot ul { padding-left: 18px; margin: 4px 0; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 99px; animation: spin .7s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.propuesta { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; background: #fff; display: flex; gap: 10px; align-items: flex-start; }
.propuesta input[type=checkbox] { width: auto; margin-top: 4px; }
.propuesta .grow { flex: 1; min-width: 0; }

/* Detalle (definición) */
dl.kv { display: grid; grid-template-columns: 150px 1fr; gap: 7px 14px; margin: 0; font-size: .9rem; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }

/* Login */
.auth-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--side); padding: 20px; }
.auth-card { background: #fff; border-radius: 14px; padding: 34px 32px; width: 100%; max-width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.auth-card.wide { max-width: 620px; }
.auth-card .brand-mark { color: var(--ink); display: block; margin-bottom: 4px; }
.auth-card h1 { font-size: 1.3rem; margin-bottom: 18px; }

/* Documento (borradores, reportes) */
.doc { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 40px 48px; max-width: 820px; margin: 0 auto; font-family: "Source Serif 4", Georgia, serif; font-size: 1rem; line-height: 1.65; }
.doc h1, .doc h2, .doc h3 { font-family: "Source Serif 4", Georgia, serif; }
textarea.doc-edit { font-family: "Source Serif 4", Georgia, serif; font-size: 1rem; line-height: 1.6; min-height: 520px; }

@media print {
  .side, .topbar, .actions, .no-print, .btn, .filters, .tabs { display: none !important; }
  body { background: #fff; }
  .content { padding: 0; max-width: none; }
  .card { box-shadow: none; break-inside: avoid; }
  .doc { border: 0; padding: 0; }
  a { color: inherit; }
}
.filters input[type=checkbox] { min-width: 0; width: auto; display: inline-block; margin: 0; }
.esc-cia { border: 1px solid var(--line); border-radius: var(--radius); background: #fff; margin-bottom: 14px; box-shadow: var(--shadow); }
.esc-cia-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line-2); flex-wrap: wrap; }
.esc-cia-head h3 { margin: 0; font-size: 1rem; }
.esc-cia-body { display: grid; grid-template-columns: 1fr 1fr 1.1fr; gap: 0; }
.esc-cia-body > div { padding: 12px 16px; border-right: 1px solid var(--line-2); min-width: 0; }
.esc-cia-body > div:last-child { border-right: 0; }
.esc-cia-body h4 { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 6px; }
.esc-cia-body .ln { display: flex; justify-content: space-between; gap: 8px; font-size: .86rem; padding: 3px 0; }
.esc-cia.ok { border-left: 3px solid var(--ok); }
.esc-cia.pend { border-left: 3px solid var(--warn); }
@media (max-width: 900px) { .esc-cia-body { grid-template-columns: 1fr; } .esc-cia-body > div { border-right: 0; border-bottom: 1px solid var(--line-2); } }
.grid > * { min-width: 0; }
@media (max-width: 640px) { .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); } .kpi .n { font-size: 1.5rem; } .card-head { flex-wrap: wrap; } }
