/* Panel de la clínica — demo con datos ficticios */
:root {
  --bg: #F0F7FF; --surface: #FFFFFF; --surface-2: #F6F9FD; --line: #DCE6F2;
  --ink: #0B1D35; --muted: #5B6B82; --accent: #2563EB; --accent-2: #0EA5E9;
  --ok: #16A34A; --warn: #D97706; --bad: #DC2626;
  --hatch: rgba(11,29,53,.05);
  --p1: #0EA5E9; --p2: #8B5CF6; --p3: #F59E0B;
  --shadow: 0 4px 24px rgba(11,29,53,.08);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #071426; --surface: #0E1F38; --surface-2: #122743; --line: #1E3557;
    --ink: #E6EEF9; --muted: #8FA3BF; --accent: #60A5FA; --accent-2: #38BDF8;
    --hatch: rgba(255,255,255,.035); --shadow: 0 4px 24px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #071426; --surface: #0E1F38; --surface-2: #122743; --line: #1E3557;
  --ink: #E6EEF9; --muted: #8FA3BF; --accent: #60A5FA; --accent-2: #38BDF8;
  --hatch: rgba(255,255,255,.035); --shadow: 0 4px 24px rgba(0,0,0,.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
button { font: inherit; color: inherit; }

.demo-bar { display: flex; flex-wrap: wrap; gap: 6px 16px; justify-content: space-between; align-items: center;
  padding: 8px 16px; background: linear-gradient(90deg, #2563EB, #0EA5E9); color: #fff; font-size: 13.5px; }
.demo-bar a { color: #fff; font-weight: 600; text-decoration: none; margin-left: 14px; white-space: nowrap; }
.demo-bar a:first-child { margin-left: 0; }

/* La página no hace scroll: lo hace cada vista dentro de su hueco (y la agenda, dentro de su rejilla) */
body { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.app { display: grid; grid-template-columns: 248px 1fr; flex: 1; min-height: 0; }
.sidebar { background: var(--surface); border-right: 1px solid var(--line); padding: 18px 14px; display: flex; flex-direction: column; gap: 18px;
  min-height: 0; overflow-y: auto; }
.brand { display: flex; gap: 10px; align-items: center; padding: 0 6px; }
.brand-logo { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; font-weight: 800; color: #fff;
  background: linear-gradient(135deg, #2563EB, #0EA5E9); }
.brand-name { font-weight: 700; }
.brand-sub { font-size: 12.5px; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; color: var(--ink); text-decoration: none; }
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); font-weight: 600; }
.nav .ico { width: 20px; text-align: center; opacity: .8; }
.badge { margin-left: auto; background: var(--bad); color: #fff; border-radius: 99px; font-size: 11.5px; font-weight: 700; padding: 1px 7px; }
.badge:empty { display: none; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; font-size: 13px; color: var(--muted); }
.side-foot p { margin: 0 4px 4px; }
.side-back { font-size: 12.5px; text-align: center; color: var(--muted); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); text-decoration: none; cursor: pointer; font-weight: 600; font-size: 14px; }
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.icon-btn { border: 1px solid var(--line); background: var(--surface); border-radius: 9px; width: 36px; height: 36px; cursor: pointer; display: grid; place-items: center; }

.main { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 24px; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.topbar h1 { font-size: 18px; margin: 0; flex: 1; }
.menu-btn { display: none; }
.view { padding: 20px 24px 40px; min-width: 0; flex: 1; min-height: 0; overflow-y: auto; }
.view.view-fit { display: flex; flex-direction: column; overflow: hidden; padding-bottom: 16px; }
.view-fit > * { flex: none; }
.view-fit > .ag-wrap { flex: 1 1 auto; min-height: 0; overflow: auto; }
.view-fit > .conv { flex: 1 1 auto; height: auto; min-height: 0; grid-template-rows: minmax(0, 1fr); }
.view-fit .chat, .view-fit .conv-list { min-height: 0; }

/* Tarjetas genéricas */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { padding: 14px 16px 0; font-weight: 700; }
.card-b { padding: 12px 16px 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Inicio */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 14px; margin-bottom: 16px; }
.kpi { padding: 14px 16px; }
.kpi .n { font-size: 30px; font-weight: 800; line-height: 1.1; margin: 4px 0; }
.kpi .l { font-size: 13px; color: var(--muted); }
.grid-2 { display: grid; grid-template-columns: 1.3fr 1fr; gap: 14px; }
.occ-row { display: grid; grid-template-columns: 120px 1fr 44px; gap: 10px; align-items: center; margin: 10px 0; font-size: 14px; }
.bar { height: 10px; border-radius: 99px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--line); }
.bar > span { display: block; height: 100%; border-radius: 99px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 10px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.list li:last-child { border-bottom: 0; }
.list .t { font-variant-numeric: tabular-nums; font-weight: 700; width: 48px; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }

.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 600; padding: 1px 7px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); white-space: nowrap; }
.chip.wa { color: #15803D; border-color: color-mix(in srgb, #16A34A 40%, transparent); }
.chip.voz { color: #7C3AED; border-color: color-mix(in srgb, #8B5CF6 40%, transparent); }
:root[data-theme="dark"] .chip.wa { color: #4ADE80; } :root[data-theme="dark"] .chip.voz { color: #C4B5FD; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .chip.wa { color: #4ADE80; } :root:not([data-theme="light"]) .chip.voz { color: #C4B5FD; } }

/* Agenda */
.ag-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.ag-date { font-weight: 700; font-size: 16px; margin-left: 6px; }
.ag-date::first-letter { text-transform: uppercase; }
.ag-date small { display: block; font-weight: 500; color: var(--muted); font-size: 12.5px; }
.ag-toolbar .spacer { flex: 1; }
.ag-wrap { overflow-x: auto; }
.ag { display: grid; min-width: 620px; }
.ag-head { display: contents; }
.ag-colh { padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; }
.ag-colh .who { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; }
.ag-colh .sub { font-size: 12px; color: var(--muted); }
.ag-times, .ag-col { position: relative; }
.ag-times div { position: absolute; right: 8px; font-size: 11.5px; color: var(--muted); transform: translateY(-50%); font-variant-numeric: tabular-nums; }
.ag-col { border-left: 1px solid var(--line); }
.ag-hline { position: absolute; left: 0; right: 0; border-top: 1px solid var(--line); }
.ag-off { position: absolute; left: 0; right: 0; background: repeating-linear-gradient(135deg, var(--hatch) 0 6px, transparent 6px 12px); }
.ag-now { position: absolute; left: 0; right: 0; border-top: 2px solid var(--bad); z-index: 3; }
.ag-now::before { content: ""; position: absolute; left: -5px; top: -6px; width: 10px; height: 10px; border-radius: 50%; background: var(--bad); }
.appt { position: absolute; left: 4px; right: 4px; border-radius: 8px; padding: 4px 8px; font-size: 12px; line-height: 1.3; overflow: hidden; cursor: pointer; text-align: left;
  border: 1px solid color-mix(in srgb, var(--pc) 45%, transparent); border-left: 4px solid var(--pc);
  background: color-mix(in srgb, var(--pc) 13%, var(--surface)); z-index: 2; }
.appt:hover { filter: brightness(1.04); box-shadow: var(--shadow); }
.appt .h { font-weight: 700; font-variant-numeric: tabular-nums; display: flex; gap: 4px; align-items: center; }
.appt .n { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appt .s { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appt .tags { position: absolute; right: 6px; top: 4px; display: flex; gap: 3px; }
.appt.realizada, .appt.pasada { opacity: .62; }
.appt.novino { border-left-color: var(--bad); border-style: dashed; border-left-style: solid; }
.appt.cancelada { opacity: .5; }
.appt.cancelada .n, .appt.cancelada .h span:first-child { text-decoration: line-through; }
.st { font-size: 10.5px; font-weight: 700; padding: 0 5px; border-radius: 99px; }
.st.realizada { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.st.novino { background: color-mix(in srgb, var(--bad) 16%, transparent); color: var(--bad); }
.st.cancelada, .st.pasada { background: var(--surface-2); color: var(--muted); }
.st.primera { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: 7px 12px; cursor: pointer; font-weight: 600; font-size: 13.5px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: #fff; }
.ag-dayh { border: 0; border-bottom: 1px solid var(--line); text-align: left; cursor: pointer; font: inherit; color: inherit; }
.ag-dayh .who { text-transform: capitalize; }
.ag-dayh.hoy .who { color: var(--accent); }
.appt.mini { padding: 2px 4px; font-size: 11px; border-left-width: 3px; }
.appt.mini .h { font-size: 10.5px; }
.mes-h, .mes-g { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.mes-h div { padding: 8px 10px; font-size: 12.5px; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--line); }
.mes-d { display: flex; flex-direction: column; gap: 4px; align-items: stretch; text-align: left; min-height: 92px; padding: 8px 10px; border: 0;
  border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); background: none; cursor: pointer; font: inherit; color: inherit; }
.mes-d:hover { background: var(--surface-2); }
.mes-d:nth-child(7n) { border-right: 0; }
.mes-d .num { font-weight: 700; }
.mes-d.hoy .num { color: #fff; background: var(--accent); border-radius: 99px; width: 26px; height: 26px; display: grid; place-items: center; }
.mes-d .cnt { font-size: 13px; font-weight: 600; }
.mes-d.fuera { opacity: .4; }
.mes-d.cerrado { cursor: default; background: repeating-linear-gradient(135deg, var(--hatch) 0 6px, transparent 6px 12px); }
.legend { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 12px; font-size: 12.5px; color: var(--muted); align-items: center; }
.legend span { display: inline-flex; gap: 5px; align-items: center; }
.closed { padding: 48px 16px; text-align: center; color: var(--muted); }

/* Horarios */
.team { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.sched-row { display: grid; grid-template-columns: 36px 1fr 96px; gap: 8px; align-items: center; font-size: 13px; padding: 3px 0; }
.sched-track { position: relative; height: 8px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); }
.sched-track span { position: absolute; top: -1px; bottom: -1px; border-radius: 99px; }
.sched-row .r { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 13px; flex: none; }
.pro-h { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.pro-h .sub { font-size: 12.5px; color: var(--muted); }
.svc { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; }

/* Conversaciones */
.conv { display: grid; grid-template-columns: 320px 1fr; height: calc(100vh - 170px); min-height: 460px; overflow: hidden; }
.conv-list { border-right: 1px solid var(--line); overflow-y: auto; }
.conv-item { display: flex; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; background: none; border-left: 0; border-right: 0; border-top: 0; width: 100%; text-align: left; }
.conv-item:hover, .conv-item.active { background: var(--surface-2); }
.conv-item .mid { flex: 1; min-width: 0; }
.conv-item .nm { font-weight: 700; font-size: 14px; display: flex; justify-content: space-between; gap: 6px; }
.conv-item .nm small { font-weight: 500; color: var(--muted); font-size: 12px; }
.conv-item .pv { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item .unread { background: var(--ok); color: #fff; border-radius: 99px; font-size: 11px; font-weight: 700; padding: 0 6px; align-self: center; }
.chat { display: flex; flex-direction: column; min-width: 0; }
.chat-h { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: center; }
.chat-h .back { display: none; }
.chat-b { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px;
  background: color-mix(in srgb, var(--surface-2) 70%, var(--bg)); }
.msg { max-width: 78%; padding: 7px 10px 5px; border-radius: 10px; font-size: 14px; white-space: pre-wrap; box-shadow: 0 1px 1px rgba(0,0,0,.06); }
.msg.in { align-self: flex-start; background: var(--surface); border-top-left-radius: 3px; }
.msg.out { align-self: flex-end; background: color-mix(in srgb, #22C55E 20%, var(--surface)); border-top-right-radius: 3px; }
.msg time { display: block; text-align: right; font-size: 11px; color: var(--muted); margin-top: 2px; }
.sys { align-self: center; font-size: 12px; color: var(--muted); background: var(--surface); border: 1px solid var(--line); padding: 3px 10px; border-radius: 99px; margin: 6px 0; text-align: center; }
.chat-f { padding: 10px 16px; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--muted); text-align: center; }

/* Consultas */
.q { padding: 14px 16px; margin-bottom: 12px; }
.q .top { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--muted); }
.q .text { font-size: 15px; margin: 6px 0; font-weight: 600; }
.q .ans { border-left: 3px solid var(--ok); padding: 4px 10px; margin-top: 8px; font-size: 14px; }
.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tabs button { border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 5px 12px; cursor: pointer; font-size: 13.5px; }
.tabs button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.note { font-size: 13px; color: var(--muted); background: var(--surface); border: 1px dashed var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 14px; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(4,12,24,.5); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal[hidden] { display: none; }
.modal-card { background: var(--surface); border-radius: 14px; width: min(420px, 100%); padding: 20px; position: relative; box-shadow: var(--shadow); }
.modal-close { position: absolute; right: 12px; top: 12px; }
.modal-card h3 { margin: 0 0 4px; padding-right: 40px; }
.dl { display: grid; grid-template-columns: 110px 1fr; gap: 6px 10px; font-size: 14px; margin-top: 12px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; }

.scrim { display: none; }

/* Formularios y acciones del panel real (fase 2) */
.frm { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.frm label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; }
.frm input, .frm select, .resp textarea { font: inherit; font-weight: 400; padding: 9px 10px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--ink); width: 100%; }
.frm-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.frm-err { color: var(--bad); font-size: 13px; margin: 0; min-height: 1em; }
.frm-acc { display: flex; gap: 8px; margin-top: 16px; }
.btn-peligro { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, transparent); }
.btn-peligro[type="submit"] { background: var(--bad); color: #fff; border-color: var(--bad); }
.link-btn { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; font-size: 12.5px; font-weight: 600; padding: 0 4px; }
.bloq-h { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.bloq-row { margin-top: 8px; }
.resp { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.resp textarea { resize: vertical; }
.resp .btn { align-self: flex-start; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60; max-width: min(460px, calc(100% - 32px));
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow); }
.modal-card { max-height: calc(100dvh - 32px); overflow-y: auto; }

.ag-bloq { position: absolute; left: 6px; right: 6px; top: 40%; text-align: center; font-weight: 700; font-size: 13px; color: var(--muted);
  background: var(--surface); border: 1px dashed var(--line); border-radius: 8px; padding: 8px; z-index: 2; }
.tour-on { outline: 3px solid var(--accent) !important; outline-offset: 3px; border-radius: 10px; }
.tour-box { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); width: min(480px, calc(100% - 32px)); z-index: 45;
  background: var(--surface); border: 1px solid var(--accent); border-radius: 14px; padding: 14px 16px; box-shadow: 0 10px 40px rgba(4,12,24,.3); }
.tour-box[hidden] { display: none; }
.tour-box p { margin: 6px 0 12px; font-size: 15px; }
.tour-acc { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
@media (max-width: 800px) { #tour-btn { padding: 7px 10px; font-size: 13px; } .tour-box { bottom: 12px; } }

@media (max-width: 1000px) {
  .kpis { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; height: 100vh; width: 270px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .scrim.open { display: block; position: fixed; inset: 0; background: rgba(4,12,24,.45); z-index: 30; }
  .menu-btn { display: grid; }
  .topbar { padding: 12px 16px; }
  .view { padding: 16px 16px 32px; }
  .demo-bar a { margin-left: 0; margin-right: 12px; }
  .conv { grid-template-columns: 1fr; height: calc(100vh - 190px); }
  .conv.has-chat .conv-list { display: none; }
  .conv:not(.has-chat) .chat { display: none; }
  .chat-h .back { display: grid; }
  .ag { min-width: 0; }
  .ag-wrap { margin: 0 -16px; padding: 0 0 0 0; }
  .msg { max-width: 88%; }
  .ag-toolbar .spacer { display: none; }
  .ag-date { flex-basis: 100%; order: -1; margin: 0 0 4px; }
  .mes-d { min-height: 64px; padding: 6px; gap: 2px; }
  .mes-d .cnt { font-size: 11.5px; }
  .mes-d .small { display: none; }
}
@media (max-width: 420px) {
  .kpi .n { font-size: 24px; }
  .occ-row { grid-template-columns: 90px 1fr 38px; }
}

/* Llamadas en Conversaciones */
.msg.voz { border: 1px dashed var(--line); }
.sys.llamada { font-weight: 600; }
