/* T.T AI Firm · Demo fulfillment · sistema de diseño (claro, sobrio, datos al frente)
   Colores de datos: paleta categórica validada (canales) y paleta de estado (bien / aviso / serio / crítico). */
:root {
  --bg: #F4F4F1; --surface: #FCFCFB; --surface2: #F7F7F4; --line: #E6E5E0; --line2: #D9D8D2;
  --ink: #0B0B0B; --ink2: #52514E; --muted: #85847E; --faint: #AFAEA8;
  --side: #121212; --side2: #1D1D1C; --side-ink: #F2F1EC; --side-muted: #9D9C95;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #c98500;
  --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --good-ink: #127a12; --warning-ink: #8a5b00; --serious-ink: #a4461f; --critical-ink: #a82b2b;
  --good-bg: #E8F5E6; --warning-bg: #FDF3DC; --serious-bg: #FCEAE2; --critical-bg: #FBE6E4; --neutral-bg: #EEEDE8;
  --r: 14px; --r-sm: 10px; --shadow: 0 1px 2px rgba(20, 20, 18, .05), 0 6px 20px rgba(20, 20, 18, .05);
  --font: "Manrope", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --ease: cubic-bezier(.23, 1, .32, 1);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); font-size: 14.5px; line-height: 1.45; color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
a { color: inherit; }
h1, h2, h3, h4 { margin: 0; letter-spacing: -.015em; }
p { margin: 0; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); } .ink2 { color: var(--ink2); } .small { font-size: 12.5px; } .tiny { font-size: 11.5px; }
.neg { color: var(--critical-ink); } .pos { color: var(--good-ink); }
:focus-visible { outline: 2px solid var(--s1); outline-offset: 2px; }

/* ───── estructura ───── */
.app { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; background: var(--side); color: var(--side-ink); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand i { width: 34px; height: 34px; border-radius: 10px; background: linear-gradient(145deg, #2F6B4F, #173A2B); display: grid; place-items: center; font-style: normal; font-weight: 800; color: #CFE9D9; flex: none; }
.brand b { display: block; font-size: 15px; letter-spacing: -.01em; }
.brand span { display: block; font-size: 11.5px; color: var(--side-muted); }
.nav-i { display: flex; align-items: center; gap: 10px; width: 100%; height: 40px; padding: 0 10px; border-radius: 10px; color: var(--side-muted); font-weight: 600; font-size: 13.5px; text-align: left; transition: background-color 160ms ease, color 160ms ease; }
.nav-i svg { width: 18px; height: 18px; flex: none; }
.nav-i:hover { background: var(--side2); color: var(--side-ink); }
.nav-i.on { background: #F2F1EC; color: #111; }
.nav-i .n { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 99px; background: var(--critical); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }
.side .foot { margin-top: auto; padding: 12px 10px 4px; border-top: 1px solid #2A2A28; font-size: 11.5px; color: var(--side-muted); }
.side .foot b { color: var(--side-ink); font-weight: 700; }
.main { min-width: 0; padding: 22px 28px 90px; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.top h1 { font-size: 24px; }
.top p { color: var(--muted); margin-top: 3px; }
.demo-chip { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 12px; border-radius: 99px; background: var(--warning-bg); color: var(--warning-ink); font-size: 12px; font-weight: 700; white-space: nowrap; }
.mob-top, .mob-nav { display: none; }

/* ───── superficies ───── */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px 18px; box-shadow: var(--shadow); min-width: 0; }
.card h3 { font-size: 14.5px; display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card h3 small { font-size: 12px; color: var(--muted); font-weight: 600; }
.grid { display: grid; gap: 14px; }
.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-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.mt { margin-top: 14px; } .mt2 { margin-top: 22px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.row.start { justify-content: flex-start; }
.wrap { flex-wrap: wrap; }

/* ───── KPIs ───── */
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; text-align: left; }
button.kpi { transition: border-color 160ms ease, transform 140ms var(--ease); }
button.kpi:hover { border-color: var(--line2); }
button.kpi:active { transform: scale(.98); }
.kpi .l { font-size: 12.5px; font-weight: 600; color: var(--ink2); display: flex; align-items: center; gap: 6px; }
.kpi .v { font-size: 26px; font-weight: 800; letter-spacing: -.02em; margin-top: 6px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .s { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.kpi.alert { border-color: #F0C7C3; background: linear-gradient(180deg, #FFF8F7, var(--surface)); }
.kpi.alert .v { color: var(--critical-ink); }

/* ───── estado (siempre con ícono y texto, nunca solo color) ───── */
.st { display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 9px; border-radius: 99px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.st i { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.st.good { background: var(--good-bg); color: var(--good-ink); } .st.good i { background: var(--good); }
.st.warning { background: var(--warning-bg); color: var(--warning-ink); } .st.warning i { background: var(--warning); }
.st.serious { background: var(--serious-bg); color: var(--serious-ink); } .st.serious i { background: var(--serious); }
.st.critical { background: var(--critical-bg); color: var(--critical-ink); } .st.critical i { background: var(--critical); }
.st.neutral { background: var(--neutral-bg); color: var(--ink2); } .st.neutral i { background: var(--faint); }
.ch { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; white-space: nowrap; }
.ch i { width: 10px; height: 10px; border-radius: 3px; flex: none; }

/* ───── controles ───── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 38px; padding: 0 14px; border-radius: 10px; background: var(--ink); color: #fff; font-weight: 700; font-size: 13.5px; white-space: nowrap; transition: transform 140ms var(--ease), opacity 160ms ease; }
.btn:active { transform: scale(.97); }
.btn svg { width: 16px; height: 16px; }
.btn.sec { background: var(--surface); color: var(--ink); border: 1px solid var(--line2); }
.btn.sm { height: 32px; padding: 0 11px; font-size: 12.5px; border-radius: 9px; }
.btn[disabled] { opacity: .4; pointer-events: none; }
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 11px; background: #E9E8E3; }
.seg button { height: 32px; padding: 0 12px; border-radius: 8px; font-size: 13px; font-weight: 700; color: var(--ink2); white-space: nowrap; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .08); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 99px; border: 1px solid var(--line2); background: var(--surface); font-size: 13px; font-weight: 600; color: var(--ink2); white-space: nowrap; }
.chip.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip i { width: 9px; height: 9px; border-radius: 3px; }
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 14px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 18px 0 14px; overflow-x: auto; }
.tabs button { height: 40px; padding: 0 12px; font-weight: 700; font-size: 13.5px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--ink); }
.inp { height: 40px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line2); background: var(--surface); font-size: 16px; min-width: 0; }
input[type=range] { width: 100%; accent-color: var(--ink); }

/* ───── tablas (en el teléfono se vuelven tarjetas) ───── */
.tw { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); box-shadow: var(--shadow); }
table.t { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.t th { text-align: left; font-size: 11.5px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); font-weight: 700; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--surface2); white-space: nowrap; }
.t td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.t tr:last-child td { border-bottom: 0; }
.t td.r, .t th.r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.t tbody tr.click { cursor: pointer; transition: background-color 140ms ease; }
.t tbody tr.click:hover { background: #F6F5F1; }
.t .prod b { display: block; font-weight: 700; } .t .prod span { display: block; font-size: 12px; color: var(--muted); }
.more-rows { text-align: center; padding: 10px; }

/* ───── gráficas ───── */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 8px; font-size: 12.5px; color: var(--ink2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.legend i { width: 10px; height: 10px; border-radius: 3px; }
.tip { position: absolute; z-index: 20; pointer-events: none; background: #111; color: #fff; border-radius: 10px; padding: 9px 11px; font-size: 12px; line-height: 1.5; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); min-width: 150px; opacity: 0; transition: opacity 120ms ease; }
.tip.on { opacity: 1; }
.tip b { font-size: 12.5px; }
.tip .tr { display: flex; justify-content: space-between; gap: 14px; }
.tip .tr i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }
.bars .b { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 2fr) auto; align-items: center; gap: 10px; padding: 6px 0; font-size: 13px; }
.bars .b + .b { border-top: 1px dashed var(--line); }
.bars .trk { height: 10px; border-radius: 4px; background: #EEEDE8; position: relative; overflow: hidden; }
.bars .fill { position: absolute; top: 0; bottom: 0; left: 0; border-radius: 4px; }
.bars .v { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.spark { width: 88px; height: 26px; display: block; }

/* ───── cascada (del precio a la utilidad) ───── */
.wf .step { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 2fr) 90px; align-items: center; gap: 10px; padding: 5px 0; font-size: 13px; }
.wf .trk { position: relative; height: 16px; }
.wf .bar { position: absolute; top: 2px; height: 12px; border-radius: 3px; }
.wf .step.total { border-top: 1px solid var(--line2); margin-top: 4px; padding-top: 9px; font-weight: 800; }

/* ───── hallazgos, recomendaciones ───── */
.find { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; }
.find + .find { border-top: 1px solid var(--line); }
.find .ic { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; flex: none; }
.find .ic svg { width: 17px; height: 17px; }
.find .tx { flex: 1; min-width: 0; }
.find .tx b { display: block; font-size: 14px; }
.find .tx span { display: block; font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.find .amt { font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rec { border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); padding: 14px 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.rec .h { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.rec b { font-size: 14.5px; }
.rec .why { font-size: 12.5px; color: var(--muted); }
.rec .do { font-size: 13.5px; color: var(--ink2); background: var(--surface2); border-radius: 10px; padding: 9px 11px; }

/* ───── panel lateral / hoja ───── */
#over { position: fixed; inset: 0; z-index: 100; display: none; }
#over.on { display: block; }
#over .bg { position: absolute; inset: 0; background: rgba(17, 17, 16, .35); animation: fade 160ms ease; }
#over .pn { position: absolute; top: 0; right: 0; bottom: 0; width: min(560px, 100%); background: var(--surface); box-shadow: -10px 0 40px rgba(0, 0, 0, .15); overflow-y: auto; padding: 20px 22px 40px; animation: slideIn 260ms var(--ease); }
.pn-h { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.pn-h h2 { font-size: 19px; }
.pn-h p { color: var(--muted); font-size: 13px; margin-top: 3px; }
.x { width: 34px; height: 34px; border-radius: 10px; background: #EEEDE8; display: grid; place-items: center; flex: none; }
.x svg { width: 16px; height: 16px; }
.tl { position: relative; padding-left: 18px; margin: 6px 0 4px; }
.tl::before { content: ""; position: absolute; left: 5px; top: 8px; bottom: 8px; width: 2px; background: var(--line2); }
.tl .e { position: relative; padding: 5px 0; font-size: 13px; }
.tl .e::before { content: ""; position: absolute; left: -17px; top: 10px; width: 10px; height: 10px; border-radius: 50%; background: var(--good); border: 2px solid var(--surface); }
.tl .e.miss::before { background: var(--critical); }
.tl .e.wait::before { background: var(--faint); }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; font-size: 13.5px; border-bottom: 1px dashed var(--line); }
.kv span:first-child { color: var(--muted); }
.kv b, .kv span:last-child { text-align: right; font-variant-numeric: tabular-nums; }
@keyframes slideIn { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 200; }
#toast div { background: #111; color: #fff; padding: 11px 18px; border-radius: 99px; font-weight: 700; font-size: 13.5px; box-shadow: 0 10px 30px rgba(0, 0, 0, .25); animation: fade 160ms ease; white-space: nowrap; }

/* ───── asistente ───── */
.ai-fab { position: fixed; right: 22px; bottom: 22px; z-index: 90; display: inline-flex; align-items: center; gap: 8px; height: 48px; padding: 0 18px 0 8px; border-radius: 99px; background: #111; color: #fff; font-weight: 700; box-shadow: 0 10px 30px rgba(0, 0, 0, .25); transition: transform 140ms var(--ease); }
.ai-fab:active { transform: scale(.97); }
.ai-fab i { width: 34px; height: 34px; border-radius: 50%; background: conic-gradient(from 210deg, #2a78d6, #1baf7a, #c98500, #eb6834, #2a78d6); display: grid; place-items: center; font-style: normal; font-size: 13px; }
.ai-msgs { display: flex; flex-direction: column; gap: 10px; margin: 12px 0; }
.ai-q { align-self: flex-end; background: #111; color: #fff; border-radius: 14px 14px 4px 14px; padding: 9px 12px; max-width: 85%; font-size: 13.5px; }
.ai-a { align-self: flex-start; background: var(--surface2); border: 1px solid var(--line); border-radius: 14px 14px 14px 4px; padding: 11px 13px; max-width: 94%; font-size: 13.5px; }
.ai-a ul { margin: 6px 0 0; padding-left: 18px; } .ai-a li { margin: 3px 0; }
.ai-a .src { margin-top: 8px; font-size: 11.5px; color: var(--muted); }
.ai-in { display: flex; gap: 8px; position: sticky; bottom: -40px; background: var(--surface); padding: 10px 0 0; }
.ai-in .inp { flex: 1; }

.note { font-size: 12px; color: var(--muted); margin-top: 18px; line-height: 1.5; }

/* ───── teléfono ───── */
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { display: none; }
  .main { padding: 14px 14px 110px; }
  .mob-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; position: sticky; top: 0; z-index: 50; background: rgba(244, 244, 241, .92); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); padding: 10px 14px; border-bottom: 1px solid var(--line); }
  .mob-top .brand { padding: 0; } .mob-top .brand b { color: var(--ink); } .mob-top .brand span { color: var(--muted); }
  .mob-nav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 80; background: var(--surface); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .mob-nav button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; height: 52px; justify-content: center; font-size: 10.5px; font-weight: 700; color: var(--muted); border-radius: 10px; min-width: 0; }
  .mob-nav button svg { width: 21px; height: 21px; }
  .mob-nav button.on { color: var(--ink); }
  .top { flex-wrap: wrap; } .top h1 { font-size: 21px; }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3, .g2, .g-2-1 { grid-template-columns: minmax(0, 1fr); }
  .kpi .v { font-size: 21px; }
  .ai-fab { display: none; } /* en el teléfono el asistente se abre desde la barra de arriba */
  #over .pn { top: auto; max-height: 90vh; width: 100%; border-radius: 18px 18px 0 0; padding: 16px 16px 30px; animation: up 260ms var(--ease); }
  @keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
  /* tablas → tarjetas */
  .tw.cards { border: 0; background: transparent; box-shadow: none; overflow: visible; }
  .tw.cards table, .tw.cards tbody, .tw.cards tr, .tw.cards td { display: block; width: 100%; }
  .tw.cards thead { display: none; }
  .tw.cards tr { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 8px 12px; margin-bottom: 10px; box-shadow: var(--shadow); }
  .tw.cards td { border: 0; padding: 4px 0; display: flex; justify-content: space-between; align-items: center; gap: 12px; text-align: right; }
  .tw.cards td::before { content: attr(data-l); font-size: 12px; color: var(--muted); font-weight: 600; text-align: left; flex: none; }
  .tw.cards td.first { display: block; text-align: left; padding-bottom: 6px; border-bottom: 1px dashed var(--line); margin-bottom: 4px; }
  .tw.cards td.first::before { display: none; }
  .bars .b { grid-template-columns: minmax(0, 1fr) 90px auto; }
  .wf .step { grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) 76px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; } }
