/* Faro24 · Soft UI editorial (Slate Teal + Blush Pink).
   Reglas del sistema (una sola fuente de verdad):
   - Lienzo suave (--bg: #f4f8f9) con tarjetas y paneles blancos (--surface: #ffffff) y profundidad suave (--hi / --lo).
   - RELIEVE (--raise*) = algo que se puede pulsar o que contiene cosas: botones, paneles, burbujas.
     HUNDIDO (--sink*)  = algo donde se escribe, se mide o está activado: campos, medidor, pestaña y día elegidos.
   - Paleta: negro (#000000), rosa pastel (#FCAFC1), azul petróleo (#3D7584) y azul cielo suave (#89B8BF). Ámbar y rojo solo como estados y siempre con texto: el color nunca es la única pista.
   - Escala de radios muy redondeada: controles 14px, burbujas 20px, paneles 28px, etiquetas y segmentados en píldora.
   - Siempre en claro (sin modo oscuro, decisión de Luis). Accesibilidad: texto >= 4.5:1, foco con contorno de acento (las sombras NO son indicador de foco), campos con borde >= 3:1,
     prefers-reduced-motion y forced-colors respetados. El hundido/relieve se acompaña de color o peso, no solo de sombra.
   - Tipografía redonda del sistema (ui-rounded en Mac; si no existe, la sans del sistema). Sin cargar fuentes externas. */

:root {
  /* Paleta de marca: negro #000000, rosa pastel #FCAFC1, azul petróleo #3D7584, azul cielo #89B8BF sobre lienzo claro #F4F8F9. */
  --bg: #f4f8f9;
  --surface: #ffffff;
  --surface-2: #e3eff1;
  --hi: #ffffff;
  --lo: #c2d5d9;
  --ink: #000000;
  --muted: #3d565d;
  --subtle: #5b767e;
  --line: rgb(61 117 132 / 0.18);
  --line-strong: rgb(61 117 132 / 0.45);
  --control-line: #648f9a;
  --accent: #3d7584;
  --accent-hover: #2e5b67;
  --accent-ink: #ffffff;
  --accent-weak: #fcafc1;
  --accent-weak-ink: #000000;
  --warn: #8a4a05;
  --warn-weak: #fbe6bd;
  --warn-bar: #d98a1c;
  --danger: #a82a1e;
  --danger-weak: #f8d9cf;
  --danger-bar: #cf4436;
  --focus: #3d7584;
  --scrim: rgb(15 35 42 / 0.45);

  --raise: 7px 7px 16px var(--lo), -7px -7px 16px var(--hi);
  --raise-sm: 4px 4px 10px var(--lo), -4px -4px 10px var(--hi);
  --raise-xs: 2px 2px 6px var(--lo), -2px -2px 6px var(--hi);
  --sink: inset 4px 4px 9px var(--lo), inset -4px -4px 9px var(--hi);
  --sink-sm: inset 3px 3px 6px var(--lo), inset -3px -3px 6px var(--hi);
  --sink-xs: inset 2px 2px 4px var(--lo), inset -2px -2px 4px var(--hi);
  --accent-raise: 4px 4px 10px var(--lo), -2px -2px 8px var(--hi), inset 0 1px 0 rgb(255 255 255 / 0.25);
  --accent-sink: inset 3px 3px 8px rgb(0 0 0 / 0.35), inset -2px -2px 6px rgb(255 255 255 / 0.12);

  --r-ctl: 14px;
  --r-bubble: 20px;
  --r-panel: 28px;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --gutter: clamp(16px, 2.5vw, 28px);
  --panel-pad: clamp(16px, 2.4vw, 24px);

  --font: ui-rounded, "SF Pro Rounded", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: rgb(61 117 132 / 0.16); color-scheme: light; accent-color: var(--accent); scrollbar-color: var(--line-strong) transparent; scrollbar-width: thin; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 15px/1.5 var(--font); letter-spacing: -0.003em; caret-color: var(--accent);
}
::selection { background: var(--accent); color: var(--accent-ink); }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.015em; line-height: 1.25; text-wrap: balance; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-underline-offset: 0.2em; }
.muted { color: var(--muted); }
.mono, .num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 0.92em; }
[hidden] { display: none !important; }

.skip { position: fixed; left: 12px; top: 8px; transform: translateY(calc(-100% - 16px)); background: var(--accent); color: var(--accent-ink); padding: 10px 16px; border-radius: 999px; z-index: 50; }
.skip:focus { transform: none; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
a.btn { text-decoration: none; }

/* ---------- barra superior ---------- */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s4);
  min-height: 68px; padding: 10px var(--gutter); background: var(--surface); border-bottom: 1px solid var(--line); border-radius: 0 0 var(--r-panel) var(--r-panel);
  box-shadow: 0 10px 22px -12px var(--lo);
}
.panel-topbar { display: block; }
.topbar-main { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s4); min-height: 48px; }
.topbar-main > .brand { margin-inline-end: auto; }
.brand { display: inline-flex; align-items: center; font-weight: 700; font-size: 19px; letter-spacing: -0.03em; }
.brand-icon { width: 28px; height: 28px; flex: none; margin-right: 10px; border-radius: 7px; }
.brand span { color: var(--accent); }
.topbar-tenant { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); min-width: 0; }
#owner-bar { flex: 1 1 240px; }
#admin-tools { gap: var(--s2) var(--s3); border-top: 1px solid var(--line); margin-top: var(--s2); padding-top: var(--s3); }
.admin-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); }
.label-inline { font-size: 13px; color: var(--muted); }
#tenant-select { flex: 1 1 132px; min-width: 0; max-width: 360px; }
.owner-title { font-size: 18px; font-weight: 650; letter-spacing: -0.015em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.view-switch { display: inline-flex; flex-wrap: wrap; align-items: center; gap: var(--s2); }
.seg-link {
  display: inline-flex; align-items: center; min-height: 38px; padding: 4px 16px; border-radius: 999px;
  color: var(--muted); font-weight: 600; text-decoration: none; background: var(--surface); box-shadow: var(--raise-xs);
  transition: box-shadow 0.18s ease, color 0.18s ease;
}
.seg-link:hover { color: var(--ink); }
.seg-link:active, .seg-link[aria-current="page"] { color: var(--accent); box-shadow: var(--sink-sm); }
.chip {
  display: inline-flex; align-items: center; gap: 9px; font-size: 13px; color: var(--muted);
  padding: 6px 14px; border-radius: 999px; white-space: nowrap; box-shadow: var(--sink-xs);
}
.chip::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--line-strong); }
.chip.is-ok::before { background: var(--accent); }
.chip.is-bad::before { background: var(--danger-bar); }

.banner { width: calc(100% - 2 * var(--gutter)); max-width: calc(1600px - 2 * var(--gutter)); margin: var(--s4) auto 0; padding: 12px 18px; font-size: 14px; border-radius: var(--r-ctl); overflow-wrap: anywhere; }
.banner-danger { background: var(--danger-weak); color: var(--danger); }
.banner-warn { background: var(--warn-weak); color: var(--warn); font-weight: 600; }

main { max-width: 1600px; margin: 0 auto; padding: var(--gutter) var(--gutter) 52px; display: grid; gap: var(--s6); }

/* ---------- controles ---------- */
.control, textarea.control {
  width: 100%; min-width: 0; min-height: 44px; padding: 9px 12px; background: var(--surface); color: var(--ink);
  border: 1px solid var(--control-line); border-radius: var(--r-ctl); box-shadow: var(--sink-xs);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}
textarea.control { resize: vertical; min-height: 80px; line-height: 1.45; }
.control::placeholder { color: var(--subtle); opacity: 1; }
.control:hover:not(:disabled) { border-color: var(--muted); }
.control:focus-visible { outline-offset: 2px; border-color: var(--focus); }
.control[aria-invalid="true"], .control[aria-invalid="true"]:hover { border-color: var(--danger); }
.control:disabled { background: var(--surface-2); color: var(--muted); border-color: var(--line); box-shadow: none; cursor: not-allowed; }
input[type="number"].control { font-variant-numeric: tabular-nums; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 8px 20px;
  max-width: 100%; min-width: 0; border-radius: var(--r-ctl); border: 0; font-weight: 600; cursor: pointer;
  text-align: center; overflow-wrap: anywhere;
  transition: box-shadow 0.18s ease, background-color 0.18s ease, color 0.18s ease, transform 0.12s ease;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); box-shadow: var(--accent-raise); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:active:not(:disabled) { box-shadow: var(--accent-sink); transform: translateY(1px); }
.btn-secondary { background: var(--surface); color: var(--ink); box-shadow: var(--raise-sm); }
.btn-secondary:hover:not(:disabled) { box-shadow: var(--raise); color: var(--accent); }
.btn-secondary:active:not(:disabled) { box-shadow: var(--sink-sm); transform: translateY(1px); }
.btn-secondary[aria-expanded="true"]:not(:disabled) { color: var(--accent); box-shadow: var(--sink-sm); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover:not(:disabled) { color: var(--ink); box-shadow: var(--raise-xs); background: var(--bg); }
.btn-ghost:active:not(:disabled) { box-shadow: var(--sink-xs); }
.btn-danger { background: var(--danger-weak); color: var(--danger); }
.btn-danger:hover:not(:disabled) { box-shadow: var(--raise-xs); }
.btn-danger:active:not(:disabled) { box-shadow: var(--sink-xs); }
.btn:disabled { background: var(--surface-2); color: var(--muted); cursor: not-allowed; box-shadow: none; }
/* Botón trabajando (guardar, cancelar, responder, simulador): ruedita de carga; ya está deshabilitado, así que no hay doble clic. */
.btn[aria-busy="true"] { cursor: progress; }
.btn[aria-busy="true"]::before { content: ""; width: 1em; height: 1em; flex: none; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.btn-sm { min-height: 36px; padding: 4px 16px; font-size: 14px; border-radius: 999px; }
.admin-actions .btn, #logout-btn { min-height: 40px; padding-inline: var(--s3); }

.field { display: grid; gap: 8px; margin-bottom: var(--s4); }
.field > label, .legend { font-size: 14px; font-weight: 600; }
.helper { font-size: 13px; color: var(--muted); }
.error { font-size: 14px; color: var(--danger); }

/* ---------- cuota ---------- */
.quota { background: var(--surface); border-radius: var(--r-panel); box-shadow: var(--raise); padding: 26px 30px; display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s5); }
.quota-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: var(--s4); }
.quota-head .plan { font-size: 14px; color: var(--muted); margin-top: 2px; }
.quota-actions { display: flex; flex-wrap: wrap; gap: var(--s3); align-items: center; }
.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu[open] > summary { color: var(--accent); box-shadow: var(--sink-sm); }
.menu-list {
  position: absolute; left: 0; top: calc(100% + 10px); z-index: 15; width: 250px; padding: 10px;
  background: var(--surface); border-radius: 22px; box-shadow: var(--raise); display: grid; gap: 4px;
}
.menu-list button { text-align: left; background: none; border: 0; padding: 10px 14px; border-radius: var(--r-ctl); cursor: pointer; min-height: 44px; }
.menu-list button:hover:not(:disabled), .menu-list button:active:not(:disabled) { background: var(--surface-2); color: var(--accent); }
.menu-list button:disabled { color: var(--subtle); cursor: not-allowed; }
.menu-list .hint { font-size: 12px; color: var(--muted); padding: 4px 14px 2px; }

.quota-main { display: grid; grid-template-columns: auto minmax(220px, 1fr); gap: var(--s6); align-items: center; }
.quota-count { font-size: 36px; font-weight: 700; letter-spacing: -0.03em; line-height: 1; font-variant-numeric: tabular-nums; }
.quota-count small { font-size: 15px; font-weight: 500; color: var(--muted); letter-spacing: 0; margin-left: 6px; }
.meter-wrap { display: grid; gap: 10px; }
.meter { position: relative; height: 16px; background: var(--bg); box-shadow: var(--sink-sm); border-radius: 999px; overflow: hidden; }
.meter-fill { height: 100%; width: 0; background: var(--accent); border-radius: 999px; box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.3); transition: width 0.4s ease, background-color 0.2s ease; }
.meter-tick { position: absolute; left: 80%; top: 3px; bottom: 3px; width: 2px; border-radius: 2px; background: var(--line-strong); }
.meter.is-alert .meter-fill { background: var(--warn-bar); }
.meter.is-limit .meter-fill { background: var(--danger-bar); }
.meter-legend { display: flex; justify-content: space-between; gap: var(--s2); font-size: 13px; color: var(--muted); }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 650; padding: 3px 12px; border-radius: 999px; background: var(--accent-weak); color: var(--accent-weak-ink); }
.status.is-alert { background: var(--warn-weak); color: var(--warn); }
.status.is-limit { background: var(--danger-weak); color: var(--danger); }
.quota-stats { display: flex; flex-wrap: wrap; gap: var(--s6); }
.stat { display: grid; gap: 2px; }
.stat b { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.stat span { font-size: 13px; color: var(--muted); }
.quota-note { font-size: 14px; padding: 12px 16px; border-radius: var(--r-ctl); background: var(--warn-weak); color: var(--warn); }
.quota-note.is-limit { background: var(--danger-weak); color: var(--danger); }

/* ---------- paneles ---------- */
.workspace { display: grid; gap: var(--s6); grid-template-columns: minmax(340px, 430px) minmax(0, 1fr) minmax(300px, 380px); align-items: start; grid-template-areas: "config agenda chat"; } /* la agenda (uso diario del dueño) en la columna central, la más ancha */
.area-config { grid-area: config; } .area-chat { grid-area: chat; } .area-agenda { grid-area: agenda; }
.panel { background: var(--surface); border-radius: var(--r-panel); box-shadow: var(--raise); min-width: 0; overflow-wrap: anywhere; }
.panel-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s3); padding: 20px var(--panel-pad) 16px; border-bottom: 1px solid var(--line); }
.panel-tools { display: flex; flex-wrap: wrap; gap: var(--s3); }
.panel-head p { font-size: 13px; color: var(--muted); }
.panel-body { padding: var(--panel-pad); }
.section { padding-top: var(--s5); margin-top: var(--s5); border-top: 1px solid var(--line); }
.section:first-child { padding-top: 0; margin-top: 0; border-top: 0; }
.section > h3 { margin-bottom: var(--s3); }
.row2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s3); align-items: start; }

/* configuración */
.days { display: flex; flex-wrap: wrap; gap: 10px; }
.day { position: relative; }
.day input { position: absolute; opacity: 0; inset: 0; cursor: pointer; margin: 0; }
.day span {
  display: inline-flex; align-items: center; justify-content: center; min-width: 50px; min-height: 44px; padding: 6px var(--s3); border-radius: 999px; font-size: 14px; font-weight: 600;
  background: var(--surface); box-shadow: var(--raise-xs); color: var(--muted); transition: box-shadow 0.18s ease, color 0.18s ease;
}
.day input:checked + span { background: var(--accent-weak); box-shadow: inset 0 2px 5px rgb(0 0 0 / 0.14); color: var(--accent-weak-ink); }
.day input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 3px; }
.readonly { font-size: 13px; color: var(--muted); padding: 10px 14px; box-shadow: var(--sink-sm); border-radius: var(--r-ctl); }

/* servicios en acordeón: una fila por servicio, solo uno abierto */
.svc-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s3); }
.svc-search { margin-bottom: var(--s4); }
.svc-list { display: grid; gap: 10px; }
.svc { border-radius: var(--r-ctl); background: var(--surface); box-shadow: var(--raise-xs); }
.svc.is-open { box-shadow: var(--sink-sm); }
.svc-toggle {
  width: 100%; min-height: 48px; display: grid; grid-template-columns: 14px minmax(0, 1fr) auto; align-items: center; gap: 10px;
  padding: 10px 14px; background: none; border: 0; border-radius: var(--r-ctl); color: inherit; text-align: left; cursor: pointer;
}
.svc-chev { color: var(--accent); font-size: 16px; line-height: 1; }
.svc-main { display: grid; gap: 2px; min-width: 0; }
.svc-name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.svc-sum { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.svc-act { font-size: 13px; font-weight: 650; color: var(--accent); }
.svc-toggle:hover .svc-act { text-decoration: underline; text-underline-offset: 3px; }
.svc-body { padding: 4px 14px 16px; }
.svc-body .service { padding-top: 0; border-top: 0; }
.service { padding: var(--s4) 0; border-top: 1px solid var(--line); display: grid; gap: var(--s3); }
.service:first-of-type { border-top: 0; padding-top: 0; }
.service-top { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s3); align-items: end; }
.service-top > .field { margin-bottom: 0; }
textarea.control-desc { min-height: 58px; }
.mini-label { font-size: 12px; color: var(--muted); font-weight: 500; }
.grid-rows { display: grid; gap: 8px; }
.grid-row { display: grid; gap: 8px; align-items: end; }
.cols-var, .cols-extra { grid-template-columns: minmax(0, 1fr) 92px 76px 44px; }
.grid-row > div { min-width: 0; }
.icon-btn { min-height: 44px; width: 44px; padding: 0; background: none; border: 0; color: var(--muted); cursor: pointer; border-radius: 50%; font-size: 18px; line-height: 1; transition: box-shadow 0.18s ease, color 0.18s ease; }
.icon-btn:hover { box-shadow: var(--raise-xs); color: var(--danger); }
.icon-btn:active { box-shadow: var(--sink-xs); }
.sub-head { font-size: 13px; font-weight: 650; color: var(--muted); margin-top: 4px; }
.section > .sub-head { margin: var(--s5) 0 var(--s3); }
.section > .helper + .service-actions, .section > .helper + .sub-head { margin-top: var(--s3); }
.service-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.service-actions + .row2 { margin-top: var(--s4); }
.savebar {
  position: static; display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2);
  padding: 14px var(--panel-pad); background: var(--surface); border-top: 1px solid var(--line); border-radius: 0 0 var(--r-panel) var(--r-panel);
}
.savebar.is-dirty { position: sticky; bottom: 0; z-index: 5; box-shadow: 0 -8px 18px -10px var(--lo); }
.savebar .btn { padding-inline: var(--s3); }
.savebar .spacer { flex: 1; }
.savebar .state { font-size: 13px; color: var(--muted); }
.issues { margin: 0 var(--panel-pad) var(--s3); padding: 12px 16px 12px 32px; background: var(--danger-weak); color: var(--danger); border-radius: var(--r-ctl); font-size: 14px; }

/* chat */
.area-chat, .area-agenda { display: flex; flex-direction: column; height: clamp(520px, 75dvh, 740px); }
.seg { display: inline-flex; max-width: 100%; padding: 4px; border-radius: 999px; box-shadow: var(--sink-sm); }
.seg button { border: 0; background: none; padding: 6px 14px; border-radius: 999px; cursor: pointer; font-weight: 600; color: var(--muted); min-height: 40px; transition: box-shadow 0.18s ease, color 0.18s ease; }
.seg button:hover, .seg button:active { color: var(--accent); }
.seg button[aria-checked="true"] { background: var(--surface); box-shadow: var(--raise-xs); color: var(--accent); }
.chat-tools { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s3); padding: 12px var(--panel-pad); border-bottom: 1px solid var(--line); }
.chat-tools .who { font-size: 13px; color: var(--muted); flex: 1 1 150px; }
.chat-tools select { width: auto; }
.messages {
  flex: 1; min-height: 0; overflow-y: auto; margin: var(--s4); padding: var(--panel-pad); display: flex; flex-direction: column; gap: 14px;
  background: var(--bg); border-radius: 22px; box-shadow: var(--sink);
}
.msg { max-width: 82%; padding: 11px 16px; border-radius: var(--r-bubble); white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 6px; box-shadow: var(--accent-raise); }
.msg.bot { align-self: flex-start; background: var(--surface); box-shadow: var(--raise-xs); border-bottom-left-radius: 6px; }
.msg .tag { display: block; margin-top: 6px; font-size: 12px; color: var(--muted); }
.msg.user .tag { color: var(--accent-ink); opacity: 0.85; }
.msg.system { align-self: center; max-width: 92%; background: none; color: var(--muted); font-size: 13px; text-align: center; padding: 4px 8px; }
.msg.system.is-error { color: var(--danger); }
.typing { display: inline-flex; gap: 4px; padding: 14px 16px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); opacity: 0.4; animation: blink 1.1s infinite; }
.typing i:nth-child(2) { animation-delay: 0.15s; } .typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }
.empty { padding: var(--s6) var(--s5); text-align: center; color: var(--muted); display: grid; gap: var(--s3); justify-items: center; }
.empty b { color: var(--ink); font-weight: 650; }
.chips { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }
.chips button { border: 0; background: var(--surface); box-shadow: var(--raise-xs); border-radius: 999px; padding: 7px 16px; cursor: pointer; font-size: 14px; min-height: 38px; transition: box-shadow 0.18s ease, color 0.18s ease; }
.chips button:hover:not(:disabled) { color: var(--accent); }
.chips button:active:not(:disabled) { box-shadow: var(--sink-xs); }
.chips button:disabled { background: var(--surface-2); color: var(--muted); box-shadow: none; cursor: not-allowed; }
.composer { display: flex; gap: var(--s2); align-items: flex-end; padding: 4px var(--panel-pad) var(--panel-pad); }
.composer .btn { flex-shrink: 0; padding-inline: var(--s4); white-space: nowrap; }
.composer textarea { min-height: 44px; max-height: 120px; resize: none; }

/* agenda y avisos */
.tabs { display: flex; flex-wrap: wrap; gap: var(--s1); padding: 12px var(--panel-pad); border-bottom: 1px solid var(--line); }
.tabs button { display: inline-flex; align-items: center; gap: var(--s1); border: 0; background: none; padding: 6px var(--s2); cursor: pointer; color: var(--muted); font-size: 14px; font-weight: 600; border-radius: 999px; min-height: 44px; transition: box-shadow 0.18s ease, color 0.18s ease; }
.tabs button:hover { color: var(--ink); }
.tabs button:active, .tabs button[aria-selected="true"] { color: var(--accent); box-shadow: var(--sink-sm); }
.tabs .count { display: inline-block; min-width: 20px; padding: 0 5px; font-size: 12px; line-height: 20px; border-radius: 999px; background: var(--surface-2); color: var(--muted); text-align: center; }
.tabs button[aria-selected="true"] .count { background: var(--accent-weak); color: var(--accent-weak-ink); }
.tabs .count.is-due, .tabs button[aria-selected="true"] .count.is-due { background: var(--accent); color: var(--accent-ink); }
.list { flex: 1; min-height: 0; overflow-y: auto; padding: var(--s4) var(--panel-pad) var(--panel-pad); display: grid; align-content: start; gap: var(--s4); }
.list:focus-visible, main:focus-visible { outline-offset: -4px; }
.day-title { font-size: 13px; font-weight: 650; color: var(--muted); margin-bottom: 6px; }
.event { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: var(--s3); padding: 12px 0; border-top: 1px solid var(--line); }
.event:first-of-type { border-top: 0; }
.event time { font-family: var(--mono); font-size: 13px; color: var(--muted); line-height: 1.4; white-space: nowrap; }
.event .title { font-weight: 650; }
.event .sub { font-size: 14px; color: var(--muted); }
.event.block .title { color: var(--warn); }
.event.is-new { animation: fresh 1.6s ease-out; }
@keyframes fresh { from { background: var(--accent-weak); } to { background: transparent; } }
.badge { display: inline-block; font-size: 12px; padding: 1px 10px; border-radius: 999px; background: var(--warn-weak); color: var(--warn); margin-left: 6px; font-weight: 600; }
.badge-ok { background: var(--accent-weak); color: var(--accent-weak-ink); }
.badge-bad { background: var(--danger-weak); color: var(--danger); }
.aviso { padding: 12px 0; border-top: 1px solid var(--line); display: grid; gap: 4px; }
.aviso:first-child { border-top: 0; }
.aviso .to { font-size: 13px; font-weight: 650; }
.aviso .to small { font-weight: 400; color: var(--muted); margin-left: 6px; }
.aviso p { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; }

/* acciones de la agenda: bloqueo rápido, cancelar y responder */
.block-form { padding: var(--s4) var(--panel-pad); background: var(--surface-2); border-bottom: 1px solid var(--line); }
.block-form .field { margin-bottom: var(--s3); }
.block-form .error { margin-bottom: var(--s3); }
.area-agenda:has(.block-form:not([hidden])) { position: static; height: auto; }
.area-agenda:has(.block-form:not([hidden])) .list { min-height: 160px; max-height: 50dvh; }
.event .event-act { margin-top: var(--s2); }
.event-act.is-armed:not(:disabled) { background: var(--danger-weak); color: var(--danger); box-shadow: var(--sink-xs); font-weight: 650; }
.pending { padding: 14px 0; border-top: 1px solid var(--line); display: grid; gap: 8px; }
.pending:first-child { border-top: 0; }
.pending .to { font-size: 13px; font-weight: 650; }
.pending .to small { font-weight: 400; color: var(--muted); margin-left: 6px; }
.pending p { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; }
.reply { display: grid; gap: 8px; }
.reply textarea { min-height: 64px; resize: vertical; }

/* skeleton de carga */
.skel { height: 14px; border-radius: 999px; background: linear-gradient(90deg, var(--surface-2), var(--hi), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.4s infinite; margin: 12px 0; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.toast { position: fixed; left: 50%; bottom: max(var(--s5), env(safe-area-inset-bottom)); width: max-content; max-width: calc(100% - 2 * var(--gutter)); transform: translateX(-50%); z-index: 40; pointer-events: none; }
.toast span { display: inline-block; padding: 12px 22px; background: var(--ink); color: var(--bg); border-radius: var(--r-bubble); font-size: 14px; font-weight: 550; box-shadow: 0 10px 24px -8px rgb(0 0 0 / 0.4); overflow-wrap: anywhere; animation: toast-in 0.24s cubic-bezier(0.2, 0.8, 0.2, 1); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px) scale(0.97); } }

.dialog { width: min(500px, calc(100% - 2 * var(--gutter))); max-height: calc(100dvh - 2 * var(--gutter)); padding: var(--panel-pad); border: 0; border-radius: var(--r-panel); background: var(--surface); color: var(--ink); box-shadow: 0 22px 56px -12px var(--scrim); }
.dialog::backdrop { background: var(--scrim); }
.dialog h2 { margin-bottom: 6px; } .dialog .muted { margin-bottom: var(--s4); }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--s2); margin-top: var(--s5); }
.dialog-actions .btn { padding-inline: var(--s3); }

.test-result { font-size: 14px; padding: 12px 16px; border-radius: var(--r-ctl); margin-top: var(--s3); overflow-wrap: anywhere; }
.test-result.is-ok { background: var(--accent-weak); color: var(--accent-weak-ink); }
.test-result.is-bad { background: var(--danger-weak); color: var(--danger); }

/* ---------- acceso ---------- */
.login-wrap { min-height: 60dvh; display: grid; place-items: center; }
.login-card { width: min(440px, 100%); background: var(--surface); border-radius: var(--r-panel); box-shadow: var(--raise); padding: var(--panel-pad); display: grid; gap: var(--s3); }
.login-card .field { margin-bottom: 0; }
.login-card .btn { justify-self: start; }
.code-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s2); align-items: center; }
.code-row .btn { min-height: 44px; padding-inline: var(--s3); }
.access-box { display: grid; gap: var(--s3); padding: var(--s4) var(--s5); border-radius: 20px; box-shadow: var(--sink-sm); margin-top: var(--s3); }
.access-code { font-family: var(--mono); font-size: 22px; font-weight: 600; letter-spacing: 0.08em; user-select: all; overflow-wrap: anywhere; }
.access-row { display: flex; flex-wrap: wrap; gap: var(--s3); align-items: center; }
.access-row .control { flex: 1 1 180px; }

/* ---------- responsivo ---------- */
/* En escritorio el chat y la agenda se quedan a la vista mientras editas una configuración larga. */
@media (min-width: 1280px) and (min-height: 661px) {
  .area-chat, .area-agenda { position: sticky; top: var(--s5); height: min(780px, calc(100dvh - 2 * var(--s5))); }
}
@media (max-width: 1279px) {
  .workspace { grid-template-columns: minmax(320px, 420px) minmax(360px, 1fr); grid-template-areas: "config agenda" "config chat"; }
  .area-config { align-self: start; }
}
@media (max-width: 799px) {
  :root {
    --raise: 6px 6px 13px var(--lo), -6px -6px 13px var(--hi);
    --r-panel: 24px;
  }
  .topbar { padding-block: var(--s3); }
  .admin-actions .btn { padding-inline: var(--s2); }
  #tenant-select { max-width: none; }
  .banner { margin-top: var(--s3); }
  main { padding-block: 20px 40px; gap: var(--s5); }
  .workspace { grid-template-columns: minmax(0, 1fr); grid-template-areas: "agenda" "chat" "config"; gap: var(--s5); }
  .quota { padding: var(--panel-pad); }
  .quota-main { grid-template-columns: minmax(0, 1fr); gap: var(--s3); }
  .quota-stats { gap: var(--s4) var(--s5); }
  .quota-actions { position: relative; }
  .quota-actions .menu { position: static; }
  .menu-list { width: min(250px, 100%); }
  .area-chat, .area-agenda { height: clamp(480px, 72dvh, 660px); }
  .control, textarea.control { font-size: 16px; }
  .btn, .admin-actions .btn, #logout-btn, .seg-link, .seg button, .chips button { min-height: 44px; }
  .messages { margin: var(--s3); }
  .messages .empty { padding-inline: var(--s2); }
  .panel-tools .btn { padding-inline: var(--s3); }
}
@media (max-width: 560px) {
  .topbar-main { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s2); }
  .topbar-main > :is(#owner-bar, .view-switch, .chip) { grid-column: 1 / -1; justify-self: start; max-width: 100%; }
  .owner-title { white-space: normal; overflow-wrap: anywhere; }
  .topbar-main .chip { padding-block: var(--s1); }
  .topbar-main #logout-btn { grid-column: 2; grid-row: 1; }
  .admin-actions { flex-basis: 100%; }
}
@media (max-width: 480px) {
  .quota-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; }
  .quota-actions .status { grid-column: 1 / -1; justify-self: start; }
  .quota-actions .btn { width: 100%; height: 100%; padding-inline: var(--s2); font-size: 14px; }
  .quota-actions .menu { align-self: stretch; }
  .service-top { grid-template-columns: minmax(0, 1fr); gap: var(--s2); justify-items: start; }
  .service-top > :first-child { width: 100%; }
  .cols-var, .cols-extra { grid-template-columns: repeat(2, minmax(0, 1fr)) auto; }
  .grid-row > :first-child { grid-column: 1 / -1; }
  .grid-rows > .grid-row + .grid-row { margin-top: var(--s2); }
  .savebar .spacer { display: none; }
  .savebar .state { flex: 1 0 100%; }
  .tabs button { padding-inline: var(--s1); font-size: 13px; }
  .tabs .count { min-width: 18px; }
  .block-form > .row2:first-child { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .block-form input[type="time"] { padding-inline: var(--s2); }
  .dialog-actions .btn { font-size: 14px; padding-inline: var(--s2); }
  .event { grid-template-columns: minmax(0, 1fr); gap: var(--s1); }
}
@media (max-width: 360px) {
  .block-form .row2 { grid-template-columns: minmax(0, 1fr); gap: 0; }
}
@media (min-height: 661px) {
  html:has(.area-config .savebar) { scroll-padding-bottom: 112px; }
}
@media (max-height: 660px) {
  .savebar { position: static; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (forced-colors: active) {
  .panel, .quota, .login-card, .dialog, .svc, .btn { border: 1px solid ButtonText; }
  .day input:checked + span, .seg button[aria-checked="true"], .tabs button[aria-selected="true"] { outline: 2px solid Highlight; }
}

/* ---------- Sistema (solo Super-Admin) ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
#system-btn[aria-expanded="true"] { color: var(--accent); background: var(--bg); box-shadow: var(--sink-sm); }
.system:focus-visible { outline-offset: -4px; }
.sys-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: var(--s3) var(--s4); padding: 22px var(--panel-pad) var(--s4); }
.sys-head h2 { font-size: 22px; }
.sys-head p { font-size: 14px; margin-top: 4px; max-width: 62ch; }
.sys-tabs { border-top: 1px solid var(--line); }
.sys-body { padding: var(--panel-pad); display: grid; gap: var(--s5); align-content: start; min-height: 360px; min-width: 0; }
.sys-body:focus-visible { outline-offset: -4px; }
.sys-toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--s3); }
.sys-toolbar > .helper { align-self: center; }
.sys-toolbar .field { margin: 0; flex: 1 1 170px; max-width: 260px; }
.sys-toolbar .spacer { flex: 1 1 0; }
.sys-grow { flex: 1 1 260px; }
.sys-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: var(--s4); }
.sys-stat { display: grid; gap: 2px; align-content: start; padding: var(--s4) var(--s5); border-radius: 20px; box-shadow: var(--sink-sm); min-width: 0; }
.sys-stat span, .sys-stat small { font-size: 13px; color: var(--muted); }
.sys-stat b { font-size: 20px; font-weight: 650; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }

.sys-table-wrap { overflow-x: auto; }
.sys-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.sys-table th { text-align: left; font-size: 12px; font-weight: 650; color: var(--muted); padding: 8px 12px; border-bottom: 1px solid var(--line-strong); white-space: nowrap; }
.sys-table td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.sys-table tbody tr:last-child td { border-bottom: 0; }
.sys-table tbody tr:hover td { background: var(--bg); }
.sys-table td small { display: block; margin-top: 2px; font-size: 12px; color: var(--muted); }
.sys-table td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.sys-table .badge, .sys-badges .badge, .sys-log .badge, .sys-backups .badge { margin-left: 0; white-space: nowrap; }
.sys-table td:first-child { min-width: 170px; }
.sys-badges { display: flex; flex-wrap: wrap; gap: 4px; }
.link-btn { padding: 0; min-height: 28px; background: none; border: 0; color: var(--accent); font-weight: 650; text-align: left; cursor: pointer; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 0.2em; border-radius: 4px; }
.link-btn:hover { color: var(--accent-hover); text-decoration-thickness: 2px; }
.sys-details summary { cursor: pointer; font-size: 14px; font-weight: 600; color: var(--muted); min-height: 44px; display: flex; align-items: center; }
.sys-details summary:hover { color: var(--accent); }
.sys-details ul { list-style: none; margin: 0; padding: var(--s3) var(--s4); display: grid; gap: 6px; max-width: 420px; border-radius: var(--r-ctl); box-shadow: var(--sink-xs); }
.sys-details li { display: flex; justify-content: space-between; gap: var(--s4); font-size: 13px; }

.sys-log { list-style: none; margin: 0; padding: 0; display: grid; }
.sys-log li { display: grid; gap: 4px; padding: 12px 0; border-top: 1px solid var(--line); }
.sys-log li:first-child { border-top: 0; }
.sys-log .meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; font-size: 13px; color: var(--muted); }
.sys-log time { font-variant-numeric: tabular-nums; }
.sys-log p { font-size: 14px; overflow-wrap: anywhere; }
.sys-log .code { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.sys-log-wrap { display: grid; gap: var(--s3); }

.sys-backups { list-style: none; margin: 0; padding: 0; display: grid; }
.sys-backups li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s2) var(--s4); align-items: center; padding: 14px 0; border-top: 1px solid var(--line); }
.sys-backups li:first-child { border-top: 0; }
.sys-backups .name { margin-top: 2px; font-family: var(--mono); font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.sys-backups .acts { display: flex; flex-wrap: wrap; gap: var(--s2); }

.json-view {
  margin: 0; max-height: 62dvh; overflow: auto; padding: var(--s4) var(--s5); border-radius: var(--r-ctl);
  background: var(--bg); box-shadow: var(--sink); font: 12.5px/1.55 var(--mono); white-space: pre; tab-size: 2; color: var(--ink);
}

@media (max-width: 1099px) {
  /* En pantallas angostas cada negocio es una ficha: etiqueta a la izquierda, dato a la derecha (sin scroll horizontal). */
  .sys-table thead { display: none; }
  .sys-table, .sys-table tbody, .sys-table tr, .sys-table td { display: block; width: 100%; }
  .sys-table tr { padding: var(--s3) 0; border-top: 1px solid var(--line); }
  .sys-table tbody tr:first-child { border-top: 0; }
  .sys-table td, .sys-table tbody tr:last-child td { display: grid; grid-template-columns: minmax(96px, 150px) minmax(0, 1fr); gap: 2px var(--s3); padding: 5px 0; border: 0; justify-items: start; }
  .sys-table td::before { content: attr(data-label); font-size: 12px; font-weight: 600; color: var(--muted); }
  .sys-table td > * { grid-column: 2; }
  .sys-table td small { margin-top: 0; }
  .sys-table td.num { white-space: normal; }
  .sys-table tbody tr:hover td { background: none; }
}
@media (max-width: 560px) {
  .sys-head > .btn { order: -1; }
  .sys-toolbar .field { max-width: none; flex-basis: 100%; }
  .sys-toolbar .spacer { display: none; }
  .sys-backups li { grid-template-columns: minmax(0, 1fr); }
  .json-view { padding: var(--s3); font-size: 12px; }
}
@media (forced-colors: active) {
  .sys-stat, .json-view { border: 1px solid CanvasText; }
}

/* ---------- enlaces discretos del panel ---------- */
.panel-foot { max-width: 1600px; margin: 0 auto; padding: var(--s4) var(--gutter) var(--s6); display: flex; flex-wrap: wrap; gap: var(--s2) var(--s5); font-size: 14px; }
.panel-foot a { display: inline-flex; align-items: center; min-height: 44px; color: var(--muted); }
.panel-foot a:hover, .panel-foot a:focus-visible { color: var(--accent); }
