/* Invest. Sistema de diseno en DESIGN.md (tokens, componentes, estados). Radios: 6 chips, 8 controles, 12 paneles. */
@font-face { font-family: "Geist"; src: url("/static/fonts/geist.woff2") format("woff2"); font-weight: 100 900; font-display: swap; }

:root {
  color-scheme: light dark;
  --bg: #F5F6F8; --surface: #FCFCFD; --surface-2: #ECEEF2;
  --ink: #13161B; --muted: #596070; --hair: #DDE0E6; --hair-strong: #C5CAD3; --field: #7D8595;
  --accent: #2457D6; --on-accent: #FFFFFF;
  --ok: #0B6B38; --ok-bg: #DDF3E5; --warn: #7A4F00; --warn-bg: #FBEBC8; --bad: #B3261E; --bad-bg: #FADDDA;
  --r-chip: 6px; --r: 8px; --r-panel: 12px;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
  --font: "Geist", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
  --side-w: 232px; --tabs-h: 60px; --top-h: 52px; --gutter: 16px;
  --ease: cubic-bezier(.16, 1, .3, 1);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0B0D11; --surface: #13161B; --surface-2: #1B1F26;
    --ink: #E8EBF0; --muted: #98A0AE; --hair: #232831; --hair-strong: #343A46; --field: #6B7385;
    --accent: #7FA3FF; --on-accent: #0B0D11;
    --ok: #5FD08A; --ok-bg: #12301F; --warn: #F2B84B; --warn-bg: #34270B; --bad: #FF8F86; --bad-bg: #3A1815;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0B0D11; --surface: #13161B; --surface-2: #1B1F26;
  --ink: #E8EBF0; --muted: #98A0AE; --hair: #232831; --hair-strong: #343A46; --field: #6B7385;
  --accent: #7FA3FF; --on-accent: #0B0D11;
  --ok: #5FD08A; --ok-bg: #12301F; --warn: #F2B84B; --warn-bg: #34270B; --bad: #FF8F86; --bad-bg: #3A1815;
}
:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; scroll-padding-top: calc(var(--top-h) + 16px); }
@media (pointer: fine) { html { overscroll-behavior: none; } }
a, button, input, select, summary { touch-action: manipulation; }
body {
  margin: 0; background: var(--bg); color: var(--ink); min-height: 100dvh;
  font: 400 .9375rem/1.5 var(--font); -webkit-font-smoothing: antialiased; font-variant-numeric: tabular-nums;
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom));
}
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.015em; text-wrap: balance; }
h1 { font-size: 1.5rem; line-height: 1.2; }
h2 { font-size: 1.0625rem; line-height: 1.3; }
p { margin: 0; text-wrap: pretty; }
a { color: inherit; }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ico { width: 1.25rem; height: 1.25rem; fill: currentColor; flex: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-chip); }
.skip { position: absolute; left: var(--gutter); top: -60px; z-index: 100; background: var(--ink); color: var(--bg);
  padding: 0 var(--s4); min-height: 44px; display: inline-flex; align-items: center; border-radius: var(--r); }
.skip:focus { top: 8px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* Estructura: barra superior + barra inferior en movil; barra lateral en escritorio */
.top { position: sticky; top: 0; z-index: 20; height: calc(var(--top-h) + env(safe-area-inset-top)); padding: env(safe-area-inset-top) var(--gutter) 0;
  display: flex; align-items: center; justify-content: space-between; background: var(--bg); border-bottom: 1px solid var(--hair); }
.brand { display: inline-flex; align-items: center; min-height: 44px; font-weight: 650; font-size: 1.0625rem; letter-spacing: -.02em; text-decoration: none; }
.side { display: none; }
.tabs { position: fixed; inset: auto 0 0 0; z-index: 20; height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--hair); }
.tabs a, .tabs button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 44px;
  background: none; border: 0; padding: 0; font: 500 .6875rem/1.2 var(--font); color: var(--muted); text-decoration: none; cursor: pointer; }
.tabs [aria-current="page"] { color: var(--ink); }
.tabs [aria-current="page"] .ico { color: var(--accent); }
main { padding: var(--s5) var(--gutter) var(--s6); max-width: 1240px; margin: 0 auto; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s5); }
.page-head p { color: var(--muted); margin-top: var(--s1); max-width: 62ch; }
.fab { position: fixed; z-index: 15; right: var(--gutter); bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + var(--s4)); }

@media (min-width: 900px) {
  :root { --gutter: 40px; }
  body { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); padding-bottom: 0; }
  .top, .tabs { display: none; }
  .side { display: flex; flex-direction: column; position: sticky; top: 0; height: 100dvh; padding: var(--s5) var(--s3) var(--s4);
    border-right: 1px solid var(--hair); background: var(--surface); }
  .side .brand { padding: 0 var(--s3); margin-bottom: var(--s5); color: var(--ink); font-weight: 650; }
  .side nav { flex: 1; }
  .side ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
  .side a { display: flex; align-items: center; gap: var(--s3); min-height: 40px; padding: 0 var(--s3); border-radius: var(--r);
    color: var(--muted); text-decoration: none; font-weight: 500; transition: background .15s, color .15s; }
  .side a:hover { background: var(--surface-2); color: var(--ink); }
  .side a[aria-current="page"] { background: var(--surface-2); color: var(--ink); }
  .side a[aria-current="page"] .ico { color: var(--accent); }
  .side-foot { display: grid; gap: 2px; border-top: 1px solid var(--hair); padding-top: var(--s3); }
  main { padding: var(--s6) var(--gutter) var(--s7); width: 100%; }
  .fab { bottom: var(--s5); right: var(--s5); }
}

/* Botones */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--s2); min-height: 44px; padding: 0 var(--s4);
  border-radius: var(--r); border: 1px solid var(--accent); background: var(--accent); color: var(--on-accent);
  font: 600 .9375rem/1 var(--font); text-decoration: none; white-space: nowrap; cursor: pointer;
  transition: background-color .15s, border-color .15s, transform .15s var(--ease); }
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: var(--surface); color: var(--ink); border-color: var(--hair-strong); }
.btn.secondary:hover { background: var(--surface-2); filter: none; }
.btn.ghost { background: transparent; color: var(--muted); border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); filter: none; }
.btn.danger { background: transparent; color: var(--bad); border-color: var(--bad); }
.btn.danger:hover { background: var(--bad-bg); filter: none; }
@media (pointer: fine) { .btn.sm { min-height: 34px; padding: 0 var(--s3); font-size: .8125rem; } }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; transform: none; filter: none; }
.btn.start { justify-content: flex-start; width: 100%; }
.skeleton.w60 { width: 60%; }
.btn.round { border-radius: 999px; min-height: 48px; padding: 0 var(--s4) 0 var(--s3); box-shadow: 0 6px 20px rgb(19 22 27 / .22); }

/* Tarjeta KPI y paneles */
.panel { background: var(--surface); border: 1px solid var(--hair); border-radius: var(--r-panel); padding: var(--s4); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--s3); }
.kpi { background: var(--surface); border: 1px solid var(--hair); border-radius: var(--r-panel); padding: var(--s4); min-width: 0; }
.kpi .label { color: var(--muted); font-size: .8125rem; font-weight: 500; }
.kpi .value { font-size: clamp(1.25rem, 5.4vw, 1.625rem); font-weight: 600; letter-spacing: -.02em; line-height: 1.2; margin-top: var(--s1); white-space: nowrap; }
.kpi .sub { margin-top: var(--s1); font-size: .8125rem; color: var(--muted); }
.delta { display: inline-flex; align-items: center; gap: 2px; font-weight: 600; }
.delta .ico { width: 1em; height: 1em; }
.delta.up { color: var(--ok); } .delta.down { color: var(--bad); } .delta.flat { color: var(--muted); }

/* Tabla densa ordenable */
.table-wrap { overflow-x: auto; border: 1px solid var(--hair); border-radius: var(--r-panel); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
caption { text-align: left; padding: var(--s3) var(--s4); font-weight: 600; }
th, td { padding: var(--s2) var(--s4); text-align: left; white-space: nowrap; border-top: 1px solid var(--hair); }
td { height: 44px; } @media (pointer: fine) { td { height: 38px; } }
thead th { border-top: 0; font-size: .75rem; font-weight: 600; color: var(--muted); background: var(--surface-2); padding-block: var(--s2); }
th.num, td.num { text-align: right; }
th[aria-sort] a { display: inline-flex; align-items: center; gap: 2px; text-decoration: none; min-height: 32px; }
th[aria-sort] a:hover, th[aria-sort="ascending"] a, th[aria-sort="descending"] a { color: var(--ink); }
tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
tfoot td { font-weight: 600; background: var(--surface-2); }

/* Chips de estado: texto + icono, nunca solo color */
.chip { display: inline-flex; align-items: center; gap: 4px; min-height: 24px; padding: 0 var(--s2); border-radius: var(--r-chip);
  font-size: .75rem; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.chip .ico { width: 14px; height: 14px; }
.chip.ok { background: var(--ok-bg); color: var(--ok); } .chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.bad { background: var(--bad-bg); color: var(--bad); } .chip.accent { background: var(--accent); color: var(--on-accent); }

/* Formulario */
.field { display: grid; gap: var(--s1); margin-bottom: var(--s4); }
.field label { font-weight: 500; font-size: .875rem; }
.field input, .field select, .field textarea { width: 100%; min-height: 44px; padding: 0 var(--s3); border-radius: var(--r); border: 1px solid var(--field);
  background: var(--surface); color: var(--ink); font: 400 1rem/1.4 var(--font); }
.field textarea { padding: var(--s2) var(--s3); min-height: 96px; }
@media (pointer: fine) { .field input, .field select, .field textarea { font-size: .9375rem; } }
.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.field .hint { color: var(--muted); font-size: .8125rem; }
.field .error { color: var(--bad); font-size: .8125rem; display: flex; align-items: center; gap: var(--s1); }
.field [aria-invalid="true"] { border-color: var(--bad); }

/* Estados: vacio, carga, error */
.empty { display: grid; gap: var(--s3); justify-items: start; padding: var(--s6) var(--s5); background: var(--surface); border: 1px solid var(--hair); border-radius: var(--r-panel); }
.empty .badge { display: grid; place-items: center; width: 44px; height: 44px; border-radius: var(--r); background: var(--surface-2); color: var(--accent); }
.empty .badge .ico { width: 1.5rem; height: 1.5rem; }
.empty p { color: var(--muted); max-width: 60ch; }
.empty ul { margin: 0; padding: 0 0 0 1.1rem; color: var(--muted); display: grid; gap: var(--s1); }
.empty ul li::marker { color: var(--hair-strong); }
.skeleton { display: block; height: 1em; border-radius: var(--r-chip); background: var(--surface-2); }
@media (prefers-reduced-motion: no-preference) {
  .skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--hair) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
  @keyframes shimmer { to { background-position: -200% 0; } }
}
.alert { display: flex; gap: var(--s3); align-items: flex-start; padding: var(--s3) var(--s4); border-radius: var(--r); background: var(--bad-bg); color: var(--bad); font-weight: 500; }
.alert .ico { margin-top: 2px; }
.htmx-indicator { opacity: 0; transition: opacity .2s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }

/* Dialogos: chat y «Mas» */
dialog { border: 1px solid var(--hair); border-radius: var(--r-panel); background: var(--surface); color: var(--ink); padding: 0; width: min(440px, calc(100vw - 24px)); max-height: calc(100dvh - 48px); overscroll-behavior: contain; }
dialog::backdrop { background: rgb(8 10 14 / .55); }
dialog .sheet { padding: var(--s4); display: grid; gap: var(--s3); }
dialog .sheet-head { display: flex; align-items: center; justify-content: space-between; }
@media (max-width: 899px) { dialog { margin: auto auto 0; width: 100%; max-width: 100%; border-radius: var(--r-panel) var(--r-panel) 0 0; padding-bottom: env(safe-area-inset-bottom); } }
@media (min-width: 900px) { dialog.chat { margin: auto var(--s5) var(--s5) auto; } }
.more-list { list-style: none; margin: 0; padding: 0; display: grid; }
.more-list a, .more-list button { display: flex; align-items: center; gap: var(--s3); min-height: 48px; width: 100%; padding: 0 var(--s2);
  background: none; border: 0; border-radius: var(--r); color: var(--ink); text-decoration: none; font: 500 1rem var(--font); cursor: pointer; }
.more-list a:hover, .more-list button:hover { background: var(--surface-2); }

/* Login */
.login-page { display: grid; place-items: center; padding: var(--gutter); }
.login { width: min(360px, 100%); display: grid; gap: var(--s5); }
.login .brand { font-size: 1.25rem; }
.login-form { display: grid; padding: var(--s5); background: var(--surface); border: 1px solid var(--hair); border-radius: var(--r-panel); }
.login-form h1 { margin-bottom: var(--s4); }

/* Cartera e Historial */
h2.section { margin: var(--s5) 0 var(--s3); }
.kpis { margin-bottom: var(--s2); }
.seg { display: flex; gap: var(--s1); }
.seg [aria-current="true"] { background: var(--surface-2); border-color: var(--accent); }
.tk a { font-weight: 600; text-decoration: none; }
.tk a:hover { text-decoration: underline; }
.sub { display: block; color: var(--muted); font-size: .75rem; font-weight: 400; }
tbody th[scope="row"] { text-align: left; font-weight: 400; white-space: nowrap; border-top: 1px solid var(--hair); padding: var(--s2) var(--s4); }
.only-sm { display: none; }
.alert { margin-bottom: var(--s4); }
.only-md { display: none; }
@media (max-width: 899px) {
  .hide-md { display: none; } .only-md { display: block; }
  main { padding-bottom: calc(var(--s7) + 48px); }  /* el botón flotante de Chat no tapa el final */
  .only-md .chip { vertical-align: middle; margin-right: var(--s1); }
}
@media (pointer: coarse) { th[aria-sort] a { min-height: 44px; } .tk a { display: inline-flex; align-items: center; min-height: 44px; } }
.table-wrap { position: relative; }  /* contiene los .sr absolutos de las celdas: sin ello desbordan la pagina */
.field { align-content: start; }
.tk .sub { white-space: normal; }
@media (max-width: 719px) { .hide-sm { display: none; } .only-sm { display: block; } th, td, tbody th[scope="row"] { padding-inline: var(--s3); } }
.notice { display: flex; gap: var(--s3); align-items: flex-start; padding: var(--s3) var(--s4); margin-bottom: var(--s4); border-radius: var(--r); background: var(--ok-bg); color: var(--ok); font-weight: 500; }
.panel > h2 { margin-bottom: var(--s3); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0 var(--s3); align-items: end; }
.toolbar { display: flex; flex-wrap: wrap; gap: 0 var(--s3); align-items: end; margin: var(--s5) 0 var(--s3); }
.toolbar .field { margin-bottom: var(--s2); }
.toolbar select { min-width: 130px; }
.form { max-width: 640px; }
.form .two { display: grid; gap: 0 var(--s3); grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.form details { margin-bottom: var(--s4); }
.form summary { padding: var(--s3) 0; font-weight: 500; cursor: pointer; }
.actions { display: flex; flex-wrap: wrap; gap: var(--s3); }
.confirm { max-width: 520px; display: grid; gap: var(--s3); }
.acts { white-space: nowrap; text-align: right; }
.acts .btn + .btn { margin-left: var(--s2); }
.note { max-width: 28ch; overflow: hidden; text-overflow: ellipsis; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); margin-top: var(--s4); }

@media (min-width: 900px) { body.login-page { grid-template-columns: 1fr; } }
@media (prefers-reduced-motion: reduce) { * { transition-duration: .01ms !important; animation-duration: .01ms !important; } }

/* Fondos */
ul.plain { list-style: none; margin: var(--s3) 0 0; padding: 0; display: grid; gap: var(--s2); }
.note-line { margin-top: var(--s3); font-size: .8125rem; max-width: 80ch; }
.panel.form { max-width: none; margin-bottom: var(--s4); }
.panel.form h3, .chart-panel h3 { font-size: .9375rem; margin-bottom: var(--s3); }
.spaced { margin-top: var(--s4); }
.chart-panel { margin-bottom: var(--s3); }
.chart-box { position: relative; height: 240px; }
@media (min-width: 900px) { .chart-box { height: 300px; } }
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s4); margin-top: var(--s3); font-size: .8125rem; color: var(--muted); }
.legend .key { display: inline-block; width: 16px; height: 3px; border-radius: 2px; margin-right: calc(var(--s1) * -1); }
.key-value { background: var(--accent); } .key-inv { background: var(--muted); }
form.inline { display: flex; gap: var(--s2); align-items: center; }
form.inline input { width: 110px; min-height: 44px; padding: 0 var(--s3); border-radius: var(--r); border: 1px solid var(--field); background: var(--surface); color: var(--ink); font: 400 1rem var(--font); text-align: right; }
form.inline input[aria-invalid="true"] { border-color: var(--bad); }
@media (pointer: fine) { form.inline input { min-height: 34px; font-size: .9375rem; } }
.error { color: var(--bad); font-size: .8125rem; display: flex; align-items: center; gap: var(--s1); }
.cal-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 0 var(--s3); align-items: end; padding-top: var(--s3); border-top: 1px solid var(--hair); margin-top: var(--s3); }
.field.check label { display: flex; align-items: center; gap: var(--s2); min-height: 44px; }
.field.check input { width: 20px; min-height: 20px; }
.wrap-first td:first-child, .wrap-first tbody th[scope="row"], .wrap-first td:nth-child(2) { white-space: normal; min-width: 5rem; }
@media (max-width: 719px) { form.inline { flex-wrap: wrap; } form.inline input { width: 84px; } .wrap-first .chip { white-space: normal; } }

/* Dashboard */
.status-line { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s3); margin-bottom: var(--s4); font-size: .875rem; }
.kpis-main { margin-bottom: var(--s3); }
.kpi .value a { text-decoration: none; }
.kpi .value a:hover { text-decoration: underline; }
.kpi .sub + .sub { margin-top: 0; }
@media (min-width: 900px) { .kpis-main { grid-template-columns: 1.5fr repeat(3, 1fr); } .kpi-lead .value { font-size: 2rem; } }
.panel-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s2) var(--s3); margin-bottom: var(--s3); }
.panel-head h3 { margin-bottom: 0; }
.chart-box.tall { height: 260px; }
@media (min-width: 900px) { .chart-box.tall { height: 360px; } }
.charts { display: grid; gap: var(--s3); grid-template-columns: minmax(0, 1fr); }
.charts .chart-panel { margin-bottom: 0; min-width: 0; }
@media (min-width: 900px) { .charts { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1200px) { .charts-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.key-up { background: var(--ok); } .key-down { background: var(--bad); } .key-index { background: var(--ink); }
.data-details summary { cursor: pointer; font-weight: 500; min-height: 44px; display: flex; align-items: center; }
.data-details .table-wrap { margin-top: 0; }
@media (pointer: coarse) { .kpi .value a { display: inline-flex; align-items: center; min-height: 44px; } }

/* Watchlist, ficha de empresa y editor de valoracion */
.seg.wrap { flex-wrap: wrap; margin-bottom: var(--s3); }
.chips { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); }
.verdict-line { font-size: 1.0625rem; font-weight: 500; margin-bottom: var(--s3); max-width: 70ch; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--s3); }
.fact { display: grid; gap: var(--s1); min-width: 0; }
.fact .label { color: var(--muted); font-size: .8125rem; }
.fact .value { font-size: 1.25rem; font-weight: 600; letter-spacing: -.015em; white-space: nowrap; }
tr.zone-now th, tr.zone-now td { background: var(--surface-2); font-weight: 600; }
.skeleton.w40 { width: 40%; } .skeleton.w80 { width: 80%; }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.checks { display: flex; flex-wrap: wrap; gap: 0 var(--s5); }
.news li { padding-top: var(--s2); border-top: 1px solid var(--hair); }
.news li:first-child { border-top: 0; padding-top: 0; }
.news a { text-decoration: none; font-weight: 500; }
.news a:hover { text-decoration: underline; }
.verdict .note-line, .panel .note-line { margin-top: var(--s3); }
#datos { margin-top: var(--s2); }
.panel.form .form-grid { align-items: start; }
.metrics tbody th[scope="row"] { white-space: normal; min-width: 6.5rem; }
.metrics td { padding-inline: var(--s2); }
p.hint { color: var(--muted); font-size: .8125rem; margin-top: var(--s2); }
.actions + p.hint { margin-top: var(--s3); }
@media (pointer: coarse) {
  .kpi .sub a, .note-line a, .news a, .data-details.caret > summary { display: inline-flex; align-items: center; min-height: 44px; }
  .news li { padding-block: 0; }
}
@media (max-width: 899px) {   /* el boton de Chat solo con icono en movil: tapa menos contenido */
  .btn.fab { width: 48px; padding: 0; }
  .btn.fab > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}
.wl th, .wl td { padding-inline: var(--s3); }
.wl tbody th[scope="row"] { padding-inline: var(--s3); }
.wl .tk .sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 26ch; }
.data-details.caret > summary { list-style: none; }
.data-details.caret > summary::before { content: "▸"; display: inline-block; width: 1.25em; color: var(--muted); }
.data-details.caret[open] > summary::before { content: "▾"; }
.data-details.caret > summary::-webkit-details-marker { display: none; }

/* Editor de tesis, versiones y Ajustes */
fieldset.field { border: 0; padding: 0; margin: 0 0 var(--s4); min-width: 0; }
fieldset.field > legend { font-weight: 500; font-size: .875rem; padding: 0; margin-bottom: var(--s2); }
.row-edit { display: grid; gap: 0 var(--s3); grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); align-items: end; padding: var(--s3) 0; border-top: 1px solid var(--hair); }
.row-edit.single { grid-template-columns: minmax(0, 1fr) auto; padding: var(--s2) 0; border-top: 0; align-items: start; }
.row-edit .btn { margin-bottom: var(--s4); }
.row-edit.single .btn { margin-bottom: 0; }
.panel.form.wide { max-width: 860px; }
.prewrap { white-space: pre-wrap; max-width: 70ch; }
tr.proposal th, tr.proposal td, .panel.proposal { box-shadow: inset 3px 0 0 var(--accent); }
.settings .panel { margin-bottom: var(--s4); }
.panel + .panel { margin-top: var(--s4); }
.settings .form-grid { align-items: start; }
.settings > .actions { margin-bottom: var(--s4); }
td.ver a { display: inline-flex; align-items: center; }
@media (pointer: coarse) { td.ver a { min-height: 44px; min-width: 44px; justify-content: center; } }
.summary { display: block; font-weight: 400; }
/* Voz en el chat (F9a): microfono con estados; los avisos van en una fila debajo (vacia = sin altura) */
.voz-btn { padding: 0; min-width: 48px; }
.voz-btn:not([data-state="rec"]) .ico:nth-of-type(2), .voz-btn[data-state="rec"] .ico:nth-of-type(1) { display: none; }
.voz-btn[data-state="rec"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); padding: 0 1rem 0 .8rem; }
.voz-time { font-variant-numeric: tabular-nums; font-weight: 600; font-size: .95rem; }
.voz-box { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s3); }
.voz-status, .voz-error { flex: 1 1 14rem; margin: 0; font-size: .875rem; }
.voz-box [hidden] { display: none; }

/* Bandeja (F8a): tarjetas de propuestas, alertas y analisis; contador en la navegacion */
.tray-sec { margin-bottom: var(--s6); }
.tray-sec > h2 { display: flex; align-items: center; gap: var(--s2); margin-bottom: var(--s3); }
.tray-card { display: grid; gap: var(--s3); }
.tray-card.read { background: transparent; }
.tray-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s3); }
.tray-head h3 { font-size: 1rem; margin-right: auto; }
.tray-card p { max-width: 70ch; }
.tray-card .bullets { margin: 0; padding-left: 1.1rem; display: grid; gap: var(--s1); max-width: 70ch; }
.tray-alerts { list-style: none; margin: 0; padding: 0; }
.tray-alerts li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s2) var(--s3); align-items: center; padding: var(--s2) 0; border-top: 1px solid var(--hair); }
.tray-alerts li:first-child { border-top: 0; }
.tray-alerts p { margin-top: var(--s1); }
.tabs a, .side a { position: relative; }
.nav-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: var(--r-chip);
  background: var(--accent); color: var(--on-accent); font-size: .6875rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tabs .nav-badge { position: absolute; top: 4px; left: calc(50% + 4px); }
.side .nav-badge { margin-left: auto; }

/* Analisis (F7b2): formulario, cola y detalle */
.panel .bullets { margin: var(--s3) 0 0; padding-left: 1.1rem; display: grid; gap: var(--s1); max-width: 70ch; }
.panel h3 { font-size: 1rem; margin: var(--s4) 0 var(--s2); }
.panel .chips + .bullets { margin-top: var(--s3); }
td.an-wrap, th.an-wrap { white-space: normal; min-width: 14rem; max-width: 36rem; }
.an-md { white-space: pre-wrap; overflow-wrap: anywhere; max-width: 80ch; font: 400 .875rem/1.55 var(--font); margin: var(--s3) 0 0; }
@media (pointer: coarse) { .tk > a { display: inline-flex; align-items: center; min-height: 44px; } }
.panel.proposal .actions { margin-top: var(--s3); }
#cola > p.muted { margin-bottom: var(--s3); }
#lanzar .data-details { margin-bottom: var(--s4); }
@media (pointer: coarse) { .tray-head h3 a { display: inline-flex; align-items: center; min-height: 44px; } .tray-sec > p a { display: inline-flex; align-items: center; min-height: 44px; } }

/* Chat con el analista (F9b): mensajes, chips de acciones, formulario */
dialog.chat { width: min(520px, calc(100vw - 24px)); }
.chat-panel { display: grid; gap: var(--s3); min-width: 0; }
.chat-bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); }
.chat-bar .chip span { white-space: normal; }
.chat-hist > summary { list-style: none; cursor: pointer; }
.chat-hist > summary::-webkit-details-marker { display: none; }
.chat-hist[open] { flex-basis: 100%; }
.chat-hist ul { list-style: none; margin: var(--s2) 0 0; padding: 0; display: grid; border: 1px solid var(--hair); border-radius: var(--r); max-height: 11rem; overflow-y: auto; }
.chat-sess { display: flex; justify-content: space-between; gap: var(--s3); width: 100%; min-height: 44px; padding: 0 var(--s3); align-items: center; text-align: left;
  background: none; border: 0; border-top: 1px solid var(--hair); color: var(--ink); font: 400 .875rem var(--font); cursor: pointer; }
.chat-hist li:first-child .chat-sess { border-top: 0; }
.chat-sess:hover, .chat-sess[aria-current="true"] { background: var(--surface-2); }
.chat-sess > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-msgs { display: grid; gap: var(--s3); align-content: start; max-height: min(46dvh, 26rem); overflow-y: auto; overscroll-behavior: contain; padding: var(--s1); }
.chat-page .chat-msgs { max-height: 60dvh; }
.chat-empty { padding: var(--s3); }
.msg { display: grid; gap: var(--s1); max-width: 92%; padding: var(--s3); border: 1px solid var(--hair); border-radius: var(--r-panel); background: var(--surface); min-width: 0; }
.msg.user { justify-self: end; background: var(--surface-2); }
.msg.assistant { justify-self: start; }
.msg-who { display: flex; gap: var(--s2); align-items: baseline; font-size: .75rem; color: var(--muted); }
.msg-who strong { color: var(--ink); font-weight: 600; }
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-acts { list-style: none; margin: var(--s1) 0 0; padding: 0; display: grid; gap: var(--s2); }
.msg-acts li { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; }
.msg-acts .chip { white-space: normal; height: auto; padding-block: 2px; }
.msg-acts .chip.undone { text-decoration: line-through; opacity: .7; }
.msg-acts a { font-size: .8125rem; font-weight: 600; }
@media (pointer: coarse) { .msg-acts a { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; min-width: 44px; } .chat-bar .btn, .msg .btn { min-height: 44px; } }
.msg-wait { padding: var(--s2) var(--s3); }
.chat-form .field { margin-bottom: var(--s2); }
.chat-form textarea { min-height: 76px; resize: vertical; }
.chat-actions { display: flex; flex-wrap: wrap; align-items: flex-start; gap: var(--s3); justify-content: space-between; }
.chat-actions .voz-box { flex: 1 1 12rem; }
.chat-form .hint { margin-top: var(--s2); }
