:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e3e6eb;
  --text: #1c2430;
  --muted: #667085;
  --accent: #2f5bea;
  --accent-soft: #eef2fe;
  --ok: #16794c;
  --ok-soft: #e7f6ee;
  --warn: #9a5b00;
  --warn-soft: #fff4e0;
  --bad: #b42318;
  --bad-soft: #fdecea;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 8px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 230px; flex-shrink: 0; background: #111827; color: #d1d5db;
  padding: 20px 14px; display: flex; flex-direction: column; gap: 4px;
}
.sidebar .brand { color: #fff; font-weight: 700; font-size: 16px; padding: 0 10px 4px; }
.sidebar .tenant { color: #fff; font-weight: 600; background: #1f2937; border-radius: 8px; padding: 8px 10px; margin: 6px 0 12px; }
.sidebar .tenant span { display: block; color: #9ca3af; font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: .05em; }
.tenant-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; background: var(--accent-soft); border: 1px solid #d6defc; border-radius: 8px; padding: 8px 14px; margin-bottom: 16px; font-size: 14px; }
.sidebar a {
  color: #d1d5db; padding: 8px 10px; border-radius: 8px; display: flex; justify-content: space-between;
}
.sidebar a:hover { background: #1f2937; text-decoration: none; }
.sidebar a.active { background: #2f5bea; color: #fff; }
.sidebar .spacer { flex: 1; }
.sidebar form button { width: 100%; background: transparent; color: #9ca3af; border: 1px solid #374151; }
.main { flex: 1; padding: 28px 32px; max-width: 1200px; min-width: 0; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head select { width: auto; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px; }
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-form { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.kpis { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.kpi .value { font-size: 26px; font-weight: 700; }
.kpi .label { color: var(--muted); font-size: 13px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }

label { display: block; font-weight: 600; font-size: 13px; margin: 12px 0 4px; }
label.inline { display: flex; align-items: center; gap: 8px; font-weight: 500; }
input[type=text], input[type=email], input[type=password], input[type=url], input[type=number], input[type=date], input[type=time], textarea, select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font: inherit; background: #fff;
}
textarea { min-height: 90px; resize: vertical; }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
button, .button {
  display: inline-block; background: var(--accent); color: #fff; border: 0; border-radius: 8px;
  padding: 8px 14px; font: inherit; font-weight: 600; cursor: pointer;
}
button.secondary, .button.secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
button.danger { background: #fff; color: var(--bad); border: 1px solid #f3c2bd; }
button.small { padding: 4px 10px; font-size: 13px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 14px; }
form.inline { display: inline; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #eef0f3; color: #344054; white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--accent-soft); color: var(--accent); }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; background: var(--ok-soft); color: var(--ok); overflow-wrap: anywhere; }
.flash.error { background: var(--bad-soft); color: var(--bad); }

.bars .row { display: grid; grid-template-columns: 120px 1fr 48px; gap: 10px; align-items: center; margin: 6px 0; font-size: 13px; }
.bar { height: 10px; border-radius: 6px; background: #eef0f3; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--accent); }
.bar.s-muy_negativo span { background: #d92d20; }
.bar.s-negativo span { background: #f79009; }
.bar.s-neutral span { background: #98a2b3; }
.bar.s-positivo span { background: #32d583; }
.bar.s-muy_positivo span { background: #039855; }
.daily { display: flex; align-items: flex-end; gap: 6px; height: 120px; }
.daily .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; font-size: 11px; color: var(--muted); }
.daily .col span { width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; }

.checklist li { margin: 4px 0; }
details > summary { cursor: pointer; color: var(--accent); margin: 4px 0; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; background: #98a2b3; vertical-align: middle; }
.dot.ok { background: #12b76a; }
.dot.warn { background: #f79009; }
.dot.error { background: #d92d20; }
.dot.off { background: #d0d5dd; }
table.checks td { padding: 8px 6px; }
.bad-text { color: var(--bad); }
.nav-badge { background: #475467; color: #fff; border-radius: 999px; padding: 0 7px; font-size: 12px; font-weight: 700; }
.nav-badge.urgent { background: #d92d20; }
.funnel { display: flex; gap: 10px; flex-wrap: wrap; }
.funnel .stage { flex: 1; min-width: 110px; display: flex; flex-direction: column; gap: 4px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; color: var(--text); background: #fff; }
.funnel .stage:hover { text-decoration: none; border-color: var(--accent); }
.funnel .stage.active { border-color: var(--accent); background: var(--accent-soft); }
.funnel .stage .count { font-size: 22px; font-weight: 700; }
.funnel .stage .bar { height: 6px; border-radius: 4px; background: #eef0f3; overflow: hidden; }
.funnel .stage .bar span { display: block; height: 100%; background: var(--accent); }
.chat { display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 78%; padding: 10px 12px; border-radius: 12px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { background: #fff; border: 1px solid var(--border); align-self: flex-start; }
.msg.assistant { background: var(--accent-soft); align-self: flex-end; }
.msg.agent { background: #e8f5e9; align-self: flex-end; }
.msg .meta { font-size: 12px; color: var(--muted); margin-top: 6px; white-space: normal; }
.msg .note { font-size: 13px; color: var(--muted); margin-top: 4px; font-style: italic; }
pre.chunk { white-space: pre-wrap; background: #f8f9fb; border: 1px solid var(--border); border-radius: 8px; padding: 10px; font-size: 13px; }
pre.chunk mark { background: #fff1b8; color: inherit; border-radius: 3px; }
code.block { display: block; white-space: pre-wrap; word-break: break-all; background: #0f172a; color: #e2e8f0; padding: 12px; border-radius: 8px; font-size: 13px; }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login { width: 100%; max-width: 380px; }

@media (max-width: 800px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; flex-wrap: wrap; padding: 12px; }
  .sidebar .spacer, .sidebar .tenant { display: none; }
  .main { padding: 18px 16px; }
  .msg { max-width: 92%; }
}
