:root {
  --brand: #5817d5;
  --brand-ink: #3d0f96;
  --brand-soft: #efe9fc;
  --bg: #f6f6f8;
  --surface: #ffffff;
  --line: #e6e5ea;
  --ink: #1b1b21;
  --muted: #6b6a75;
  --faint: #9a99a3;
  --ok: #168a55;
  --ok-soft: #e6f5ed;
  --warn: #9a6200;
  --warn-soft: #fdf2dc;
  --bad: #c62b2b;
  --bad-soft: #fcebeb;
  --radius: 10px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.5 "Roboto", system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
[hidden] { display: none !important; }

/* ---------- sign in */
.gate {
  min-height: 100%;
  display: grid;
  place-items: center;
  background: var(--brand);
  padding: 24px;
}
.gate-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: 16px;
  padding: 36px 32px 28px;
  text-align: center;
}
.gate-card .logo { width: 128px; color: var(--brand); margin: 0 auto 18px; display: block; }
.gate-card h1 { font-size: 18px; font-weight: 500; margin: 0 0 6px; }
.gate-card p { color: var(--muted); margin: 0 0 24px; }
.gate-card code { font-size: 12px; background: var(--bg); padding: 2px 6px; border-radius: 6px; word-break: break-all; }

/* ---------- shell */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100%; }
.side {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.side .logo { width: 84px; color: var(--brand); margin: 2px 10px 22px; }
.nav {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: 0;
  background: none;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  color: var(--muted);
  font-weight: 500;
}
.nav:hover { background: var(--bg); color: var(--ink); }
.nav.on { background: var(--brand-soft); color: var(--brand-ink); }
.nav .count {
  margin-left: auto;
  font-size: 12px;
  min-width: 22px;
  text-align: center;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--bad);
  color: #fff;
}
.nav .count:empty { display: none; }
.side .me { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.side .me strong { display: block; color: var(--ink); font-weight: 500; overflow: hidden; text-overflow: ellipsis; }

main { padding: 28px 32px 48px; min-width: 0; }
.head { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.head h2 { font-size: 20px; font-weight: 500; margin: 0; }
.head .sub { color: var(--muted); }
.head .grow { flex: 1; }

/* ---------- controls */
.btn {
  height: 34px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
}
.btn:hover { border-color: #cfcdd6; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-ink); }
.btn.danger { color: var(--bad); }
.btn.danger.solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.small { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.big { height: 44px; width: 100%; font-size: 15px; }
.btn:disabled { opacity: .5; cursor: default; }
.search {
  height: 34px;
  width: 260px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.tabs { display: flex; gap: 4px; background: #ecebf0; padding: 3px; border-radius: 9px; }
.tabs button {
  border: 0;
  background: none;
  padding: 5px 12px;
  border-radius: 7px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 500;
}
.tabs button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .06); }

/* ---------- metrics */
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 28px; }
.metric { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; cursor: pointer; }
.metric:hover { border-color: #cfcdd6; }
.metric .label { color: var(--muted); font-size: 13px; }
.metric .value { font-size: 28px; font-weight: 500; margin-top: 2px; }
h3 { font-size: 15px; font-weight: 500; margin: 0 0 10px; }

/* ---------- tables */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  font-weight: 500;
  font-size: 12px;
  color: var(--muted);
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: #fbfbfc;
  white-space: nowrap;
}
td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr.link { cursor: pointer; }
tbody tr.link:hover td { background: #fafafb; }
td .line2 { color: var(--muted); font-size: 13px; }
td.actions { text-align: right; white-space: nowrap; }
td.actions .btn + .btn { margin-left: 6px; }
.clip { max-width: 360px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.empty { padding: 48px 16px; text-align: center; color: var(--muted); }
.who { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand-ink);
  font-size: 12px; font-weight: 500; flex: none;
  background-size: cover; background-position: center;
}

.tag { display: inline-block; font-size: 12px; font-weight: 500; padding: 1px 8px; border-radius: 999px; background: #efeef2; color: var(--muted); white-space: nowrap; }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.brand { background: var(--brand-soft); color: var(--brand-ink); }
.stars { color: #d99a00; letter-spacing: 1px; white-space: nowrap; }

/* ---------- drawer */
.scrim { position: fixed; inset: 0; background: rgba(20, 18, 30, .32); z-index: 10; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(520px, 100%);
  background: var(--surface);
  z-index: 11;
  display: flex; flex-direction: column;
  box-shadow: -8px 0 24px rgba(0, 0, 0, .08);
}
.drawer header { display: flex; align-items: center; gap: 10px; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.drawer header h3 { margin: 0; flex: 1; }
.drawer .body { padding: 20px 22px; overflow: auto; flex: 1; }
.drawer footer { padding: 14px 22px; border-top: 1px solid var(--line); display: flex; gap: 8px; flex-wrap: wrap; }
.x { border: 0; background: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); }
.section { margin-bottom: 20px; }
.section .label { font-size: 12px; color: var(--muted); font-weight: 500; margin-bottom: 6px; }
.box { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 13px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.quote { white-space: pre-wrap; background: var(--bg); border-radius: 8px; padding: 10px 12px; }

.chat { display: flex; flex-direction: column; gap: 6px; max-height: 360px; overflow: auto; background: var(--bg); padding: 12px; border-radius: 8px; }
.msg { max-width: 82%; padding: 7px 10px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); font-size: 13px; }
.msg.right { align-self: flex-end; background: var(--brand-soft); border-color: transparent; }
.msg.system { align-self: center; background: none; border: 0; color: var(--faint); font-size: 12px; }
.msg .meta { font-size: 11px; color: var(--faint); margin-top: 2px; }

/* ---------- dialog + toast */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(420px, calc(100% - 32px)); }
dialog::backdrop { background: rgba(20, 18, 30, .32); }
dialog form { padding: 22px; }
dialog h3 { margin-bottom: 6px; }
dialog p { color: var(--muted); margin: 0 0 14px; }
dialog textarea, dialog select { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 14px; }
dialog textarea { min-height: 84px; resize: vertical; }
dialog .row { display: flex; justify-content: flex-end; gap: 8px; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 20;
  font-size: 14px; box-shadow: 0 6px 18px rgba(0, 0, 0, .18);
}
.toast.bad { background: var(--bad); }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; border-right: 0; border-bottom: 1px solid var(--line); }
  .side .logo { margin: 6px 12px 6px 6px; }
  .side .me { display: none; }
  main { padding: 20px 16px 40px; }
  .search { width: 100%; }
}

tbody td:first-child { white-space: nowrap; }

/* ---------- departments, charts, map */
.group { font-size: 11px; font-weight: 500; letter-spacing: .04em; text-transform: uppercase; color: var(--faint); margin: 16px 10px 4px; }
.side { overflow-y: auto; }
.pad { padding: 16px 18px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 12px; }
.big { font-size: 22px; font-weight: 500; }
.big.small { font-size: 16px; }
.barrow { display: grid; grid-template-columns: 150px 1fr 90px; gap: 10px; align-items: center; padding: 5px 0; font-size: 13px; }
.barlabel { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bartrack { height: 8px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.barfill { height: 100%; background: var(--brand); border-radius: 99px; }
.barvalue { text-align: right; }
.charthead { display: flex; align-items: baseline; justify-content: space-between; }
.chart { display: flex; align-items: flex-end; gap: 3px; height: 96px; margin-top: 6px; }
.chart .col { flex: 1; height: 100%; display: flex; align-items: flex-end; }
.chart .col div { width: 100%; background: var(--brand); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; }
.chartfoot { display: flex; justify-content: space-between; margin-top: 4px; font-size: 11px; }
.mapbox { height: calc(100vh - 290px); min-height: 380px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.linkrow { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); color: var(--ink); text-decoration: none; }
.linkrow:last-child { border-bottom: 0; }
.linkrow:hover { background: #fafafb; }
.linkrow strong { font-weight: 500; }
.switchrow { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; cursor: pointer; }
.switchrow input { margin-top: 4px; accent-color: var(--brand); width: 16px; height: 16px; }
.switchrow strong { font-weight: 500; }

/* ---------- v3: icons, collapsible menu, toolbars, composer, phone preview */
.nav i { font-size: 18px; }
.head h2 i { color: var(--brand); vertical-align: -2px; margin-right: 2px; }
button.group { display: flex; align-items: center; justify-content: space-between; width: calc(100% - 20px); background: none; border: 0; cursor: pointer; padding: 0; }
button.group i { transition: transform .15s; }
button.group.closed i { transform: rotate(-90deg); }
.tag i { vertical-align: -1px; }
.tag.gold { background: #fff1cc; color: #8a5a00; }
.btn i { vertical-align: -2px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 10px; }
.searchbox { position: relative; }
.searchbox i { position: absolute; left: 10px; top: 9px; color: var(--faint); }
.searchbox .search { padding-left: 32px; }
.filter { display: flex; align-items: center; gap: 6px; height: 34px; padding: 0 4px 0 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); font-size: 13px; color: var(--muted); }
.filter select { border: 0; background: transparent; height: 30px; color: var(--ink); cursor: pointer; }
.tablewrap { overflow-x: auto; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--ink); }
th i { font-size: 12px; opacity: .7; }
.compose { display: grid; grid-template-columns: minmax(320px, 1fr) 300px; gap: 16px; align-items: start; }
.compose .history { grid-column: 1 / -1; }
.form .field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.form label { font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; }
.form input, .form select, .form textarea { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--surface); }
.form textarea { min-height: 80px; resize: vertical; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.actionsrow { display: flex; gap: 8px; }
.statusline { margin-bottom: 12px; display: flex; gap: 8px; align-items: center; }
.histrow { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.histrow:last-child { border-bottom: 0; }
.histrow strong { font-weight: 500; }
.phone { width: 270px; height: 540px; border-radius: 36px; background: #111; padding: 10px; box-shadow: 0 10px 30px rgba(0, 0, 0, .12); position: sticky; top: 20px; }
.phone-screen { width: 100%; height: 100%; border-radius: 28px; overflow: hidden; background: #eef0f3; position: relative; }
.phone-screen.dark { background: linear-gradient(160deg, #3a2a6e, #151226); padding: 36px 10px; }
.phone-screen.dim { background: #20202a; display: grid; place-items: center; padding: 14px; }
.notif { background: rgba(255, 255, 255, .94); border-radius: 18px; padding: 12px 14px; }
.notif-app { font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.notif-app .dot { width: 14px; height: 14px; border-radius: 4px; background: var(--brand); display: inline-block; }
.notif-title { font-weight: 500; margin-top: 4px; font-size: 13px; }
.notif-body { font-size: 12px; color: var(--muted); }
.fake-map { position: absolute; inset: 0; background: repeating-linear-gradient(45deg, #e6e9ee 0 12px, #edf0f4 12px 24px); }
.fake-sheet { position: absolute; left: 0; right: 0; bottom: 0; height: 58%; background: #fff; border-radius: 20px 20px 0 0; padding: 14px 10px; }
.fake-search { height: 30px; border-radius: 10px; background: #eceef2; margin-bottom: 10px; }
.banner-card { display: flex; gap: 6px; background: rgba(88, 23, 213, .07); border-radius: 14px; padding: 10px 12px; }
.banner-card i { color: var(--muted); font-size: 13px; }
.bc-title { font-weight: 500; font-size: 13px; }
.bc-body { font-size: 12px; color: var(--muted); margin-top: 2px; }
.bc-btn { display: inline-block; margin-top: 8px; background: var(--brand); color: #fff; font-size: 11px; padding: 5px 10px; border-radius: 99px; }
.bc-btn.wide { display: block; text-align: center; padding: 8px; }
.popup-card { width: 100%; background: #fff; border-radius: 18px; overflow: hidden; }
.popup-card img, .popup-img { width: 100%; aspect-ratio: 1; object-fit: cover; display: grid; place-items: center; background: #eceef2; color: var(--muted); font-size: 12px; }
.popup-text { padding: 12px; }
@media (max-width: 900px) { .compose { grid-template-columns: 1fr; } .phone { position: static; margin: 0 auto; } }

/* Resumen: north star, deltas and weekly bars */
.northstar { margin-bottom: 12px; }
.northstar .metric.star { cursor: default; background: linear-gradient(135deg, #5817d5, #7c4dff); color: #fff; border: 0; }
.northstar .metric.star .label, .northstar .metric.star .line2 { color: rgba(255, 255, 255, .85); }
.northstar .metric.star .value { font-size: 44px; font-weight: 700; }
.northstar .metric.star .delta.up { color: #b9f6ca; }
.northstar .metric.star .delta.down { color: #ffcdd2; }
.metric .help { margin-top: 6px; font-size: 12px; }
.delta { font-size: 13px; font-weight: 500; }
.delta.up { color: #1b7f4e; }
.delta.down { color: #c62828; }
.inlinebar { display: flex; align-items: center; gap: 8px; min-width: 160px; }
.inlinebar span { display: block; height: 10px; border-radius: 5px; background: #5817d5; }
.inlinebar b { font-weight: 500; }
.head .sub { color: var(--muted); font-size: 13px; margin-left: 10px; }
