/* Peak Panel: claro (por defecto) y oscuro de Peak (negro, blanco y grises). Sin fuentes ni recursos externos. */
:root {
  --bg: #f3f4f6; --bg2: #eceef1; --panel: #ffffff; --panel2: #f7f8fa; --text: #0e1116; --muted: #657084; --line: #e3e6eb;
  --btn: #0e1116; --btn-text: #ffffff; --good: #12805c; --good-bg: #e3f4ec; --bad: #d92d20; --bad-bg: #fdecea; --gray-bg: #eceff3; --gray: #566074;
  --bubble-in: #ffffff; --bubble-bot: #0e1116; --bubble-bot-text: #ffffff; --bubble-staff: #e7ebf1; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 6px 24px rgba(16, 24, 40, .05);
  --bar1: #0e1116; --bar2: #a9b1bf; --focus: #3b6cff;
  --radius: 16px; --nav-w: 228px; --top-h: 64px; --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Noto Sans Arabic", sans-serif;
}
[data-theme="dark"] {
  --bg: #050506; --bg2: #0b0b0d; --panel: rgba(255, 255, 255, .055); --panel2: rgba(255, 255, 255, .035); --text: #f3f3f5; --muted: #9b9ba6; --line: rgba(255, 255, 255, .09);
  --btn: #f3f3f5; --btn-text: #08080a; --good: #5fd3a2; --good-bg: rgba(95, 211, 162, .14); --bad: #ff7a70; --bad-bg: rgba(255, 122, 112, .14); --gray-bg: rgba(255, 255, 255, .08); --gray: #b8b8c2;
  --bubble-in: rgba(255, 255, 255, .07); --bubble-bot: #f3f3f5; --bubble-bot-text: #08080a; --bubble-staff: rgba(255, 255, 255, .13); --shadow: 0 1px 0 rgba(255, 255, 255, .06) inset, 0 10px 40px rgba(0, 0, 0, .45);
  --bar1: #f3f3f5; --bar2: #5d5d68; --focus: #8fb0ff;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
[data-theme="dark"] body {
  background: radial-gradient(1200px 600px at 78% -10%, rgba(255, 255, 255, .07), transparent 60%), radial-gradient(900px 500px at -10% 110%, rgba(255, 255, 255, .045), transparent 55%), #050506;
  background-attachment: fixed;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
h1 { font-size: 26px; } h2 { font-size: 18px; } h3 { font-size: 15px; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 8px; }
.muted { color: var(--muted); } .tiny { font-size: 12px; } .center { text-align: center; }
button, input, select { font: inherit; color: inherit; }

/* botones y campos */
.btn { appearance: none; border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 10px 18px; border-radius: 999px; cursor: pointer; font-weight: 600; transition: transform .12s ease, background .12s ease, opacity .12s; }
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.primary { background: var(--btn); color: var(--btn-text); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.small { padding: 7px 14px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; transform: none; }
a.btn { display: inline-block; text-decoration: none; text-align: center; }
.icon-btn { appearance: none; border: 1px solid var(--line); background: var(--panel); width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; }
.icon-btn svg { width: 20px; height: 20px; }
input[type=text], input[type=password], input:not([type]), input[type=search] { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); }
input::placeholder { color: var(--muted); }
label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.error { color: var(--bad); font-size: 14px; margin: 0; }

/* acceso */
.login { min-height: 100svh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: min(420px, 100%); display: grid; gap: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 30px 26px; box-shadow: var(--shadow); }
[data-theme="dark"] .login-card { backdrop-filter: blur(22px) saturate(140%); -webkit-backdrop-filter: blur(22px) saturate(140%); }
.login-card p { margin: 0; }
.theme-float { position: fixed; top: 14px; right: 14px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand > div { display: grid; line-height: 1.15; }
.brand strong { font-size: 16px; }
.logo { width: 30px; height: 30px; color: var(--text); flex: none; }
.brand.big { font-weight: 700; font-size: 18px; } .brand.big .logo { width: 36px; height: 36px; }

/* estructura */
.shell { min-height: 100svh; display: grid; grid-template-columns: var(--nav-w) 1fr; grid-template-rows: var(--top-h) 1fr; grid-template-areas: "top top" "nav view"; }
.top { grid-area: top; display: flex; align-items: center; justify-content: space-between; padding: 0 22px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); position: sticky; top: 0; z-index: 5; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.nav { grid-area: nav; padding: 18px 14px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: var(--top-h); align-self: start; height: calc(100svh - var(--top-h)); }
.nav a { position: relative; display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 12px; text-decoration: none; color: var(--muted); font-weight: 600; }
.nav a svg { width: 22px; height: 22px; flex: none; }
.nav a:hover { background: var(--gray-bg); color: var(--text); }
.nav a.active { background: var(--panel); color: var(--text); border: 1px solid var(--line); box-shadow: var(--shadow); padding: 10px 13px; }
.badge { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--bad); color: #fff; font-size: 12px; display: grid; place-items: center; font-style: normal; }
.view { grid-area: view; padding: 26px 28px 60px; min-width: 0; max-width: 1180px; width: 100%; }
.page-head { display: flex; align-items: end; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }

/* tarjetas y chips */
.card { min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
[data-theme="dark"] .card { backdrop-filter: blur(20px) saturate(140%); -webkit-backdrop-filter: blur(20px) saturate(140%); }
.grid { display: grid; gap: 14px; }
.stats { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 14px; }
.stat .n { font-size: 34px; font-weight: 750; letter-spacing: -.02em; line-height: 1.1; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.stat .l { font-weight: 650; } .stat .s { color: var(--muted); font-size: 13px; }
.two { grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 650; background: var(--gray-bg); color: var(--gray); white-space: nowrap; }
.chip.good { background: var(--good-bg); color: var(--good); } .chip.bad { background: var(--bad-bg); color: var(--bad); } .chip.demo { background: var(--text); color: var(--bg); }
.banner { display: flex; gap: 10px; align-items: flex-start; background: var(--gray-bg); border: 1px dashed var(--line); border-radius: 14px; padding: 12px 14px; margin-bottom: 14px; color: var(--text); font-size: 14px; }
.banner b { font-weight: 700; }
.attn { display: grid; gap: 8px; margin-top: 10px; }
.attn a { display: flex; justify-content: space-between; gap: 4px 10px; align-items: center; flex-wrap: wrap; text-decoration: none; padding: 10px 12px; border-radius: 12px; background: var(--bad-bg); }
.attn a span:first-child { font-weight: 650; }

/* piloto de clínica fundadora */
.pilot-card { margin-bottom: 14px; }
.pilot-card .page-head { align-items: center; }
.meters { display: grid; grid-template-columns: 1fr 1fr; gap: 18px 28px; }
.meter-row { display: grid; gap: 7px; align-content: start; }
.meter-top { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; }
.meter-top span { color: var(--muted); font-variant-numeric: tabular-nums; } .meter-top b { color: var(--text); }
.meter { height: 10px; border-radius: 999px; background: var(--gray-bg); overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: 999px; background: var(--btn); transition: width .7s cubic-bezier(.2, .8, .2, 1); }
@media (max-width: 640px) { .meters { grid-template-columns: 1fr; } }

/* gráfico */
.chart { display: grid; grid-template-columns: repeat(var(--cols, 6), 1fr); gap: 10px; align-items: end; height: 190px; margin-top: 14px; }
.chart .col { display: grid; grid-template-rows: 1fr auto; height: 100%; min-width: 0; }
.chart .bars { display: flex; gap: 4px; align-items: end; justify-content: center; border-bottom: 1px solid var(--line); }
.chart .bar { width: 34%; max-width: 26px; border-radius: 6px 6px 0 0; min-height: 3px; transition: height .5s cubic-bezier(.2, .8, .2, 1); }
.chart .b1 { background: var(--bar1); } .chart .b2 { background: var(--bar2); }
.chart .m { text-align: center; font-size: 12px; color: var(--muted); padding-top: 6px; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* listas */
.list { display: grid; grid-template-columns: minmax(0, 1fr); }
.row { display: flex; gap: 12px; align-items: center; padding: 12px 6px; border-bottom: 1px solid var(--line); text-decoration: none; }
.row:last-child { border-bottom: 0; }
.row .when { min-width: 74px; font-variant-numeric: tabular-nums; font-weight: 700; }
.row .what { flex: 1; min-width: 0; } .row .what strong { display: block; } .row .what span { color: var(--muted); font-size: 13px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.day { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 18px 0 4px; }
.seg { display: inline-flex; background: var(--gray-bg); border-radius: 999px; padding: 4px; gap: 2px; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg button { appearance: none; border: 0; background: transparent; padding: 7px 13px; border-radius: 999px; font-weight: 650; font-size: 13px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.chat-list .seg { display: flex; justify-content: space-between; } .chat-list .seg button { padding: 7px 10px; flex: 1; }
.ibadge { width: 20px; height: 20px; border-radius: 50%; background: var(--text); color: var(--bg); display: inline-grid; place-items: center; font-size: 12px; font-weight: 800; flex: none; font-style: normal; margin-top: 1px; }
.seg button.on { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.empty { text-align: center; padding: 38px 10px; color: var(--muted); }

/* chats */
.chats { display: grid; grid-template-columns: 360px 1fr; gap: 14px; align-items: start; }
.chat-list { padding: 8px; max-height: calc(100svh - var(--top-h) - 150px); overflow: auto; }
.chat-list .tools { padding: 8px 8px 10px; display: grid; gap: 10px; position: sticky; top: 0; background: var(--panel); z-index: 1; border-radius: 12px; }
.chat-item { display: grid; grid-template-columns: 40px minmax(0, 1fr); gap: 11px; align-items: start; padding: 10px; border-radius: 12px; text-decoration: none; }
.chat-item:hover, .chat-item.active { background: var(--gray-bg); }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 750; background: var(--gray-bg); color: var(--text); flex: none; }
.chat-item .t { display: flex; justify-content: space-between; align-items: center; gap: 8px; } .chat-item .t strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .t .tm { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; flex: none; }
.chat-item .p { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px; }
.chat-item .c { margin-top: 5px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--bad); display: inline-block; }
.thread { display: grid; grid-template-rows: auto 1fr; min-height: 420px; max-height: calc(100svh - var(--top-h) - 150px); padding: 0; overflow: hidden; }
.thread-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.thread-head .who { display: flex; align-items: center; gap: 10px; }
.thread-body { overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: min(78%, 520px); padding: 9px 13px; border-radius: 16px; white-space: pre-wrap; word-break: break-word; }
.msg small { display: block; margin-top: 3px; opacity: .65; font-size: 11px; }
.msg.patient { align-self: flex-start; background: var(--bubble-in); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.msg.assistant { align-self: flex-end; background: var(--bubble-bot); color: var(--bubble-bot-text); border-bottom-right-radius: 5px; }
.msg.staff { align-self: flex-end; background: var(--bubble-staff); border-bottom-right-radius: 5px; }
.msg .lbl { font-size: 11px; font-weight: 700; opacity: .7; margin-bottom: 2px; display: block; }
.sep { align-self: center; font-size: 12px; color: var(--muted); padding: 6px 0; }
.note { background: var(--gray-bg); border-radius: 12px; padding: 10px 12px; font-size: 13px; margin: 0 0 6px; }
.icon-btn.back { display: none; flex: none; text-decoration: none; }
.icon-btn.back svg { width: 18px; height: 18px; }

/* privacidad */
.facts { display: grid; gap: 12px; }
.fact { display: grid; grid-template-columns: 30px 1fr; gap: 12px; align-items: start; }
.fact svg { width: 24px; height: 24px; } .fact p { margin: 2px 0 0; color: var(--muted); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }

/* estado del asistente (arriba) y pantalla de ayuda */
.chip.status { text-decoration: none; cursor: pointer; }
.chip.status .sdot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
.chip.status .short { display: none; }
.nav a .short { display: none; }
.help-grid { display: grid; gap: 14px; max-width: 860px; }
.status-line { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; } .status-line h2 { margin: 0; }
.faqs { margin-top: 8px; }
.faq { border-top: 1px solid var(--line); padding: 12px 0; } .faq:first-child { border-top: 0; padding-top: 4px; }
.faq summary { cursor: pointer; font-weight: 650; list-style-position: outside; }
.faq p { margin: 8px 0 2px; color: var(--muted); }
.faq a { color: var(--text); }

.toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%); width: max-content; text-align: center; background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 999px; font-weight: 650; z-index: 20; box-shadow: var(--shadow); max-width: 92vw; }

/* celular y tablet: la barra de navegación pasa abajo y los chats se ven de a uno */
@media (max-width: 980px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two { grid-template-columns: minmax(0, 1fr); }
  .chats { grid-template-columns: 1fr; }
  .chats.in-thread .chat-list { display: none; } .chats:not(.in-thread) .thread { display: none; }
  .chat-list, .thread { max-height: none; } .thread { min-height: calc(100svh - var(--top-h) - 150px); }
  .icon-btn.back { display: grid; }
  .view.thread-mode .page-head, .view.thread-mode .banner { display: none; }
  .view.thread-mode .thread { min-height: calc(100svh - var(--top-h) - 120px); }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; grid-template-areas: "top" "view"; }
  .nav { position: fixed; z-index: 6; left: 0; right: 0; bottom: 0; top: auto; height: auto; flex-direction: row; justify-content: space-around; padding: 6px 6px calc(6px + var(--safe-b)); background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border-top: 1px solid var(--line); gap: 0; }
  .nav a { flex-direction: column; gap: 3px; padding: 7px 6px; font-size: 11px; flex: 1; align-items: center; text-align: center; }
  .nav a.active { background: transparent; border: 0; box-shadow: none; padding: 7px 6px; color: var(--text); }
  .nav a .badge { position: absolute; top: 2px; right: calc(50% - 22px); margin: 0; }
  .view { padding: 18px 16px calc(96px + var(--safe-b)); }
  .toast { bottom: calc(84px + var(--safe-b)); }
  .top { padding: 0 14px; } h1 { font-size: 23px; }
  .brand strong { max-width: 38vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #logout { display: none; }
}
@media (max-width: 460px) {
  .stat .n { font-size: 28px; } .card { padding: 14px; } .msg { max-width: 88%; }
  .chip.demo { display: none; }
  .chip.status .long { display: none; } .chip.status .short { display: inline; }
  .nav a .long { display: none; } .nav a .short { display: inline; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
