/* AutoScaleAI — sistema visual minimalista premium (monocromo + 1 acento).
   Claro, denso útil, sin gradientes ni decoración. Tipografía: Space Grotesk
   (display/cifras) + Inter (cuerpo). Un único color de marca para estados/acciones. */
@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=Space+Grotesk:wght@500;600;700&display=swap");

/* El atributo hidden debe ganar siempre: .login y .wrap fijan su propio display
   y, sin esto, anulan [hidden] — el overlay de login no se ocultaba tras entrar. */
[hidden] { display: none !important; }

:root {
  --accent: #3b5bdb;            /* único color de marca */
  --accent-ink: #2c46ad;
  --accent-wash: #eef1fd;
  --bg: #f7f7f8;
  --surface: #ffffff;
  --ink: #16181d;              /* texto principal casi negro */
  --ink-2: #3d4250;
  --muted: #8a8f9c;            /* texto terciario */
  --line: #e9e9ec;
  --line-2: #f1f1f3;
  --ok: #1f9d6b;
  --warn: #c2410c;
  --down: #c0364a;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(20, 24, 29, .04), 0 1px 3px rgba(20, 24, 29, .06);
  --shadow-pop: 0 8px 28px rgba(20, 24, 29, .12);
  --mono: "Space Grotesk", ui-sans-serif, system-ui;
  --sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
.num, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
h1, h2, h3, .display { font-family: var(--mono); letter-spacing: -.01em; }
button { font-family: var(--sans); cursor: pointer; }
input, select, textarea { font-family: var(--sans); font-size: 13px; color: var(--ink); }
a { color: var(--accent); text-decoration: none; }

/* ---------- Login ---------- */
.login { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--bg); z-index: 50; }
.loginbox { width: 320px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px; box-shadow: var(--shadow); }
.loginbox .brand { font-family: var(--mono); font-weight: 700; font-size: 20px; letter-spacing: -.02em; }
.loginbox p { color: var(--muted); font-size: 13px; margin: 8px 0 18px; }
.loginbox input { width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); margin-bottom: 10px; }
.loginbox input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
.loginbox button { width: 100%; padding: 11px; background: var(--ink); color: #fff; border: 0; border-radius: var(--radius-sm); font-weight: 600; }
.loginbox button:hover { background: #000; }
.loginerr { color: var(--down); font-size: 12px; margin-top: 10px; min-height: 14px; }

/* ---------- Layout ---------- */
.wrap { max-width: 1280px; margin: 0 auto; padding: 0 22px 64px; }
.head { display: flex; align-items: center; justify-content: space-between; padding: 18px 0 14px; }
.head .brand { font-family: var(--mono); font-weight: 700; font-size: 18px; letter-spacing: -.02em; display: flex; align-items: baseline; gap: 10px; }
.head .brand .sub { font-family: var(--sans); font-weight: 500; font-size: 12px; color: var(--muted); letter-spacing: 0; }
.head .meta { display: flex; align-items: center; gap: 14px; }
.fresh { font-size: 12px; color: var(--muted); }
.health { display: inline-flex; gap: 8px; }
.health .dot { font-size: 11px; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; }
.health .dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.health .dot.ok::before { background: var(--ok); }
.health .dot.down::before { background: var(--down); }
.refresh { padding: 7px 13px; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius-sm); font-weight: 600; font-size: 13px; color: var(--ink); }
.refresh:hover { border-color: var(--ink-2); }
.refresh:disabled { opacity: .5; cursor: default; }

/* periodo */
.periodbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 4px 0 16px; }
.plabel { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.chips { display: inline-flex; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.chip { padding: 6px 14px; border: 0; background: transparent; border-radius: 999px; font-size: 13px; font-weight: 500; color: var(--ink-2); }
.chip:hover { color: var(--ink); }
.chip.on { background: var(--ink); color: #fff; }
.rangewrap { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; }
.rangewrap input { padding: 6px 8px; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.rangewrap .dash { color: var(--muted); }

/* nav */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 22px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { white-space: nowrap; padding: 11px 14px; border: 0; background: transparent; color: var(--muted); font-weight: 500; font-size: 13.5px; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }

.view { display: none; }
.view.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

/* ---------- Tarjetas / KPIs ---------- */
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 26px 0 12px; font-weight: 600; }
.section-title:first-child { margin-top: 4px; }
.grid { display: grid; gap: 12px; }
.cards { grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.kpi .val { font-family: var(--mono); font-weight: 600; font-size: 24px; letter-spacing: -.02em; margin-top: 6px; }
.kpi .val.small { font-size: 19px; }
.kpi .extra { font-size: 12px; color: var(--muted); margin-top: 3px; }
.kpi .delta.up { color: var(--ok); } .kpi .delta.down { color: var(--down); }
.kpi.accent .val { color: var(--accent); }

/* embudo / cascada */
.funnel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.fstage { display: grid; grid-template-columns: 150px 1fr auto; align-items: center; gap: 14px; padding: 13px 16px; border-bottom: 1px solid var(--line-2); }
.fstage:last-child { border-bottom: 0; }
.fstage .fname { font-weight: 600; font-size: 13.5px; }
.fstage .fbar { height: 8px; background: var(--line-2); border-radius: 999px; overflow: hidden; }
.fstage .fbar > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.fstage .fnums { font-family: var(--mono); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.fstage .fnums b { font-weight: 600; }
.fstage .fnums .conv { color: var(--muted); font-size: 12px; margin-left: 8px; }
.fstage.bottleneck { background: var(--accent-wash); }
.fstage.bottleneck .fname::after { content: " · cuello"; color: var(--accent); font-weight: 600; font-size: 11px; }

/* ---------- Tablas ---------- */
.tablewrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th { position: sticky; top: 0; background: var(--surface); text-align: left; font-weight: 600; color: var(--ink-2); font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { color: var(--ink); }
thead th .arr { color: var(--accent); margin-left: 3px; }
tbody td { padding: 9px 12px; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
tbody tr:hover { background: var(--line-2); }
td.num, th.num { font-family: var(--mono); font-variant-numeric: tabular-nums; text-align: right; }
tr.total td { font-weight: 700; background: var(--bg); border-top: 2px solid var(--line); }
tr.empty-month td { color: var(--muted); }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar input[type="text"], .toolbar input:not([type]), .input { padding: 8px 11px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); min-width: 200px; }
.toolbar select, select.input { padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }
.input:focus, .toolbar input:focus, .toolbar select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.colmenu { position: relative; }
.colmenu .pop { position: absolute; right: 0; top: 110%; z-index: 20; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-pop); padding: 8px; min-width: 200px; max-height: 320px; overflow: auto; }
.colmenu label { display: flex; gap: 8px; align-items: center; padding: 5px 6px; border-radius: 6px; font-size: 13px; }
.colmenu label:hover { background: var(--line-2); }
.pager { display: flex; align-items: center; gap: 10px; justify-content: flex-end; margin-top: 12px; color: var(--muted); font-size: 13px; }
.pager button { padding: 6px 12px; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius-sm); }
.pager button:disabled { opacity: .4; cursor: default; }

.tag-pill { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--line-2); color: var(--ink-2); }
.pill-source { background: var(--accent-wash); color: var(--accent-ink); }
.pill-won { background: #e7f6ef; color: var(--ok); }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--ink-2); }
.badge.shadow { background: #f3f4f6; } .badge.assisted { background: var(--accent-wash); color: var(--accent-ink); }
.badge.escalado { background: #fdeee6; color: var(--warn); }
.dot-y { width: 7px; height: 7px; border-radius: 50%; display: inline-block; background: var(--ok); }
.dot-n { width: 7px; height: 7px; border-radius: 50%; display: inline-block; background: var(--line); }

/* ---------- CRM ---------- */
.crmsplit { display: grid; grid-template-columns: 380px 1fr; gap: 16px; align-items: start; }
.crmlist { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); max-height: 72vh; overflow: auto; }
.crmcount { padding: 9px 14px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line-2); position: sticky; top: 0; background: var(--surface); }
.crmrow { display: flex; gap: 11px; padding: 11px 14px; border-bottom: 1px solid var(--line-2); cursor: pointer; }
.crmrow:hover { background: var(--line-2); }
.crmrow.sel { background: var(--accent-wash); }
.crmrow.pend { box-shadow: inset 3px 0 0 var(--accent); }
.crmrow.arch { opacity: .55; }
.ava { width: 34px; height: 34px; border-radius: 50%; background: var(--ink); color: #fff; display: flex; align-items: center; justify-content: center; font-family: var(--mono); font-weight: 600; font-size: 12px; flex: none; }
.ava.big { width: 44px; height: 44px; font-size: 15px; }
.crmmain { min-width: 0; flex: 1; }
.who { font-weight: 600; font-size: 13.5px; display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.when { color: var(--muted); font-weight: 400; font-size: 12px; }
.when.idle { color: #b6b9c2; }
.pendb { color: var(--accent); font-size: 11px; font-weight: 600; }
.crmbadges { display: flex; gap: 6px; margin: 4px 0; flex-wrap: wrap; }
.stage { font-size: 11px; color: var(--ink-2); background: var(--line-2); padding: 2px 8px; border-radius: 999px; }
.preview { font-size: 12.5px; color: var(--ink-2); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview b { color: var(--muted); font-weight: 600; }
.tags { display: flex; gap: 4px; margin-top: 5px; flex-wrap: wrap; }
.tags .t { font-size: 10.5px; color: var(--muted); background: var(--line-2); padding: 1px 7px; border-radius: 999px; }

.crmdetail { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; min-height: 200px; }
.cdhead { display: flex; gap: 12px; align-items: center; margin-bottom: 6px; }
.cdname { font-family: var(--mono); font-weight: 600; font-size: 18px; }
.cdsub { color: var(--muted); font-size: 12.5px; }
.cdactions { display: flex; gap: 8px; margin-left: auto; }
.cdsec { margin-top: 18px; }
.cdlabel { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 8px; font-weight: 600; }
.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; background: var(--line-2); padding: 3px 9px; border-radius: 999px; }
.pill.src { background: var(--accent-wash); color: var(--accent-ink); }
.pill button { border: 0; background: transparent; color: var(--muted); font-size: 13px; line-height: 1; padding: 0; }
.pill button:hover { color: var(--down); }
.addrow { display: flex; gap: 8px; margin-top: 10px; position: relative; }
.addrow input { flex: 1; padding: 8px 11px; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.btn { padding: 8px 13px; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius-sm); font-weight: 600; font-size: 13px; color: var(--ink); }
.btn:hover { border-color: var(--ink-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--down); border-color: #f0d5da; }
.btn:disabled { opacity: .5; cursor: default; }
.autobox { position: absolute; top: 100%; left: 0; right: 0; z-index: 30; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-pop); max-height: 220px; overflow: auto; margin-top: 4px; }
.autobox div { padding: 8px 11px; cursor: pointer; font-size: 13px; }
.autobox div:hover, .autobox div.hl { background: var(--accent-wash); }

.thread { display: flex; flex-direction: column; gap: 7px; max-height: 340px; overflow: auto; padding: 4px 2px; }
.msg { max-width: 78%; padding: 8px 11px; border-radius: 12px; font-size: 13px; }
.msg .when { display: block; font-size: 10.5px; margin-top: 3px; opacity: .7; }
.msg.in { background: var(--line-2); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.out { background: var(--accent); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.note { background: var(--bg); border: 1px solid var(--line-2); border-radius: var(--radius-sm); padding: 9px 11px; margin-bottom: 7px; font-size: 13px; }
.note .when { color: var(--muted); font-size: 11px; margin-top: 3px; }
.sendbox { display: flex; gap: 8px; margin-top: 10px; }
.sendbox textarea { flex: 1; padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--radius-sm); resize: vertical; min-height: 42px; font-size: 13px; }
.cdmsg { margin-top: 10px; font-size: 12.5px; color: var(--muted); min-height: 16px; }
.cdmsg.ok { color: var(--ok); } .cdmsg.err { color: var(--down); }

/* ---------- Equipo ---------- */
.team-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.member { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.member .mname { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.member .mstats { display: flex; gap: 18px; margin-top: 12px; }
.member .mstats .s .v { font-family: var(--mono); font-weight: 600; font-size: 20px; }
.member .mstats .s .l { font-size: 11px; color: var(--muted); }

/* ---------- Evolución ---------- */
.evo-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.yearnav { display: inline-flex; gap: 4px; align-items: center; }
.yearnav .y { padding: 6px 12px; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius-sm); font-family: var(--mono); font-weight: 600; }
.yearnav .y.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.mini-months { display: grid; grid-template-columns: repeat(auto-fill, minmax(116px, 1fr)); gap: 8px; margin-bottom: 18px; }
.mm { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 11px 12px; box-shadow: var(--shadow); }
.mm.empty { opacity: .45; }
.mm.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-wash); }
.mm .m { font-size: 12px; color: var(--muted); font-weight: 600; }
.mm .big { font-family: var(--mono); font-weight: 700; font-size: 22px; letter-spacing: -.02em; }
.mm .row { display: flex; justify-content: space-between; font-size: 11px; color: var(--ink-2); margin-top: 4px; }
.mm.clickable { cursor: pointer; }

/* ---------- Setter ---------- */
.setterhead { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.killbox { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.klabel { font-family: var(--mono); font-weight: 600; }
.drytag { font-size: 10px; background: var(--accent-wash); color: var(--accent-ink); padding: 2px 7px; border-radius: 999px; vertical-align: middle; }
.kbtn { padding: 7px 14px; border-radius: var(--radius-sm); border: 1px solid var(--line); font-weight: 600; font-size: 13px; }
.kbtn.on { background: var(--ok); color: #fff; border-color: var(--ok); }
.kbtn.off { background: var(--surface); color: var(--ink); }
.khint { color: var(--muted); font-size: 12px; }
.smetrics { display: flex; gap: 20px; flex-wrap: wrap; margin-top: 14px; }
.sm .smv { font-family: var(--mono); font-weight: 600; font-size: 18px; }
.sm .sml { font-size: 11px; color: var(--muted); }
.dcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 15px; margin-bottom: 12px; }
.dtop { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.dmeta { color: var(--muted); font-size: 12px; margin-left: auto; }
.dbadge { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--line-2); }
.dbadge.esc { background: #fdeee6; color: var(--warn); }
.dthread { display: flex; flex-direction: column; gap: 5px; margin: 10px 0; }
.dmsg { max-width: 80%; padding: 6px 10px; border-radius: 10px; font-size: 12.5px; }
.dmsg.in { background: var(--line-2); align-self: flex-start; } .dmsg.out { background: var(--accent); color: #fff; align-self: flex-end; }
.ddraft { background: var(--bg); border: 1px dashed var(--line); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13.5px; }
.ddraft.none { color: var(--muted); font-style: italic; }
.dwhy { color: var(--muted); font-size: 12px; margin: 8px 0; }
.dedit { width: 100%; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 9px 11px; font-size: 13.5px; min-height: 56px; resize: vertical; }
.dactions { display: flex; gap: 8px; align-items: center; margin-top: 9px; flex-wrap: wrap; }
.send { padding: 8px 14px; background: var(--accent); color: #fff; border: 0; border-radius: var(--radius-sm); font-weight: 600; }
.rate { border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius-sm); padding: 5px 9px; }
.rate.sel { border-color: var(--accent); background: var(--accent-wash); }
.sendstate { font-size: 12px; color: var(--muted); }
.sendstate.sent { color: var(--ok); } .sendstate.sent_unknown { color: var(--warn); } .sendstate.failed { color: var(--down); }

/* ---------- estados ---------- */
.empty, .loading { color: var(--muted); text-align: center; padding: 34px 16px; font-size: 13.5px; }
.skeleton { background: linear-gradient(90deg, var(--line-2) 25%, #f6f6f8 50%, var(--line-2) 75%); background-size: 200% 100%; animation: sh 1.2s infinite; border-radius: 6px; height: 48px; margin-bottom: 8px; }
@keyframes sh { to { background-position: -200% 0; } }
.errbox { background: #fdf3f4; border: 1px solid #f3d6dc; color: var(--down); border-radius: var(--radius); padding: 14px 16px; display: flex; gap: 12px; align-items: center; justify-content: space-between; }
.hint { color: var(--muted); font-size: 12.5px; }
.shell { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; max-width: 760px; }
.shell h3 { margin: 0 0 8px; }
.exporttext { width: 100%; min-height: 220px; margin-top: 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 11px; font-family: ui-monospace, monospace; font-size: 12px; }
.defs { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); margin-top: 6px; }
.def { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 11px 13px; }
.def .k { font-weight: 600; font-size: 13px; } .def .r { color: var(--muted); font-size: 12px; margin-top: 4px; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .crmsplit { grid-template-columns: 1fr; }
  .rangewrap { margin-left: 0; }
  .head { flex-wrap: wrap; gap: 10px; }
}
