/**
 * NorthPathOS · Agenda grid CSS (ticket 853, batch 5e)
 *
 * Week/day hourly grid chrome, lanes, cards and shading. Every color here is
 * a var(--agenda-*) token from lib/agenda-tokens.css (batch 5d) or an
 * existing generic app token (--text/--surface-2/--border-color/etc, already
 * used across the rest of the admin UI) -- NO hex literal anywhere in this
 * file (enforced by a dedicated test, same idiom as
 * admin/tests/agenda-tokens.test.mjs). Layout math (pixel positions/heights)
 * is computed in admin/modules/agenda-grid.js and applied as inline
 * style="top:...;height:..." -- this file only supplies color/border/shape.
 */

/* F4 (tickets 853 and 855, 5f live-fix batch, 2026-09-25): ticket 853 5f's original
   .ag-page rule reserved an unconditional 80px right-hand gutter for the
   floating chat/quick-action FAB, at EVERY viewport width. lib/
   components.css's .fab-host is `display:none` outside its OWN
   `@media (max-width: 768px)` rule -- the FAB does not exist at all at
   desktop or tablet widths (1440/1280/1024px), so that unconditional
   padding was pure dead space there: measured live, .ag-main's right edge
   sat 80px inside its own 1401px-wide container at 1440px, with the day
   panel both open and collapsed -- the exact "empty strip" the operator
   flagged. Fixed by reserving the gutter ONLY inside the SAME breakpoint
   the FAB actually renders in, so desktop/tablet always get the full
   width and mobile still keeps real clearance from the real button. */
@media (max-width: 768px) { .ag-page { padding-right: 80px; } }
@media (max-width: 480px) { .ag-page { padding-right: 64px; } }

/* ticket 853 5f toolbar: row 1 = nav left, view dropdown + actions right;
   row 2 = the three filters directly under the nav. */
.ag-toolbar {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  margin-top: .75rem;
  margin-bottom: .5rem;
}
.ag-toolbar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem;
}
.ag-toolbar-row1 { justify-content: space-between; }
.ag-toolbar-actions {
  display: flex;
  align-items: center;
  gap: .4rem;
  flex-wrap: wrap;
  margin-left: auto;
}
.ag-view-select { width: auto; min-width: 7.5rem; }
.ag-nav, .ag-filters {
  display: flex;
  align-items: center;
  gap: .4rem;
  flex-wrap: wrap;
}
.ag-toolbar-row2 { justify-content: flex-start; }
.ag-filter { min-width: 150px; flex: 0 1 220px; }
.ag-view-on { font-weight: 700; background: var(--agenda-accent-soft); }
.ag-own-scope-label {
  font-size: .82rem;
  font-weight: 600;
  padding: .35rem .7rem;
  border-radius: 6px;
  background: var(--surface-2, transparent);
}
.ag-notice {
  padding: .5rem .75rem;
  border-radius: 6px;
  border: 1px solid var(--agenda-grid-border);
  background: var(--agenda-accent-soft);
  color: var(--agenda-accent-text);
  font-size: .85rem;
  font-weight: 600;
}

/* Grid: fills the available width (sidebar open or collapsed, any window
   size); scrolls horizontally only when the lanes' minimum widths no
   longer fit. No gap under the toolbar, no blank block under the grid. */
.ag-grid-scroll {
  margin-top: 0;
  overflow-x: auto;
  overflow-y: auto;
  max-height: calc(100vh - 180px);
  border: 1px solid var(--agenda-grid-border);
  border-radius: 8px;
  background: var(--agenda-grid-bg);
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.ag-grid-body {
  display: flex;
  position: relative;
  width: 100%;
  min-width: max-content;
}

.ag-time-col {
  position: sticky;
  left: 0;
  z-index: 10;
  background: var(--agenda-grid-bg);
  flex: 0 0 72px; /* room for 12h labels ('12:00 p. m.') */
  width: 72px;
  border-right: 1px solid var(--agenda-grid-border);
}
.ag-time-head {
  padding: 0;
  position: sticky;
  top: 0;
  z-index: 13;
  background: var(--agenda-grid-bg);
}
.ag-time-body {
  position: relative;
  z-index: 3;
}
.ag-hour-label {
  position: absolute;
  right: 6px;
  transform: translateY(-50%);
  font-size: .68rem;
  line-height: 1;
  color: var(--text-muted, var(--g500, inherit));
  white-space: nowrap;
}

.ag-day-cols {
  display: flex;
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
}
.ag-day-view { flex-direction: column; }

.ag-day-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
  border-right: 1px solid var(--agenda-grid-border);
}
.ag-day-closed { background: var(--agenda-offhours-bg); }
.ag-day-closed .ag-day-head { color: var(--text-muted, inherit); }
.ag-day-today .ag-day-head { background: var(--agenda-today-tint); }

.ag-day-head {
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 .4rem;
  font-size: .78rem;
  font-weight: 700;
  border-bottom: 1px solid var(--agenda-grid-border);
  position: sticky;
  top: 0;
  z-index: 12;
  background: var(--agenda-grid-bg);
}
.ag-lane-heads {
  display: flex;
  height: 28px;
  border-bottom: 1px solid var(--agenda-grid-border);
  position: sticky;
  top: 28px;
  z-index: 11;
  background: var(--agenda-grid-bg);
}
.ag-lane-head {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .68rem;
  font-weight: 700;
  border-right: 1px solid var(--agenda-grid-border);
}
.ag-doctor-col-head {
  display: flex;
  align-items: center;
  gap: .35rem;
  padding: 0 .5rem;
  font-size: .78rem;
  font-weight: 600;
  border-right: 1px solid var(--agenda-grid-border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ag-doctor-strip {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.ag-day-body {
  position: relative;
}
.ag-lanes-row {
  display: flex;
  position: absolute;
  width: 100%;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}
.ag-lane {
  position: relative;
  border-right: 1px solid var(--agenda-grid-border);
  cursor: pointer;
}
.ag-lane-empty { cursor: pointer; }
.ag-lane-empty-label {
  padding: 1.5rem 1rem;
  font-size: .85rem;
  color: var(--text-muted, var(--g500, inherit));
}

.ag-hour-line, .ag-halfhour-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 0;
  border-top: 1px solid var(--agenda-hour-line);
  pointer-events: none;
}
.ag-halfhour-line { border-top: 1px dashed var(--agenda-halfhour-line); }

.ag-today-tint {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  background: var(--agenda-today-tint);
  pointer-events: none;
}

.ag-now-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 0;
  border-top: 2px solid var(--agenda-now-line);
  z-index: 5;
  pointer-events: none;
}

.ag-offhours {
  position: absolute;
  left: 0;
  right: 0;
  background: var(--agenda-offhours-bg);
  pointer-events: none;
}
.ag-blocked {
  position: absolute;
  left: 0;
  right: 0;
  background: var(--agenda-blocked-bg);
  background-image: repeating-linear-gradient(
    45deg,
    var(--agenda-blocked-stripe),
    var(--agenda-blocked-stripe) 4px,
    transparent 4px,
    transparent 9px
  );
  pointer-events: none;
}

.ag-card {
  position: absolute;
  left: 2px;
  right: 2px;
  border-radius: 4px;
  border: 1px solid;
  border-left-width: 4px;
  padding: 2px 4px;
  font-size: .68rem;
  line-height: 1.15;
  overflow: hidden;
  cursor: grab;
  z-index: 2;
  user-select: none;
  touch-action: none; /* issue 853 drag fix: a touch drag moves the card, not the page */
}
.ag-card-dragging { opacity: .45; cursor: grabbing; }
.ag-card-pending { opacity: .7; }
.ag-card-cancelled { cursor: pointer; }

/* issue 853 drag fix: snapped ghost in the target lane + floating label near the pointer. */
.ag-drag-ghost {
  position: absolute;
  left: 2px;
  right: 2px;
  border: 2px dashed var(--agenda-accent);
  border-radius: 4px;
  background: var(--agenda-accent-soft);
  color: var(--agenda-accent-text);
  font-size: .68rem;
  font-weight: 700;
  padding: 1px 3px;
  overflow: hidden;
  pointer-events: none;
  z-index: 6;
}
.ag-drag-preview {
  position: fixed;
  max-width: 240px;
  padding: .3rem .55rem;
  border-radius: 6px;
  border: 1px solid var(--agenda-grid-border);
  background: var(--agenda-grid-bg);
  color: var(--agenda-accent-text);
  font-size: .75rem;
  font-weight: 600;
  box-shadow: 0 4px 14px var(--shadow, transparent);
  pointer-events: none;
  z-index: 50;
}
.ag-drag-preview-out { color: var(--agenda-card-cancelled-text); }
.ag-card:focus-visible { outline: 2px solid var(--agenda-accent); }
.ag-card-time { font-weight: 700; }
/* R2-B1: "Historia pendiente" link on an attended visit with no note (lib/pending-note-marker.js). */
.ag-card-pending { display: inline-block; margin-top: .125rem; padding: 0 .375rem; border-radius: 4px; border: 1px solid var(--agenda-accent); background: var(--agenda-grid-bg); color: var(--agenda-accent-text); font-size: .6875rem; font-weight: 700; line-height: 1.4; text-decoration: none; white-space: nowrap; position: relative; z-index: 2; }
.ag-card-pending:hover, .ag-card-pending:focus-visible { background: var(--agenda-accent); color: var(--agenda-grid-bg); outline: none; }
.ag-card-short .ag-card-pending { margin-top: 0; flex: 0 0 auto; }
.ag-card-patient { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Candidate 5: a short block (under 40 px) is one line: start time, then the patient name, truncated; the end time is hidden there. */
.ag-card-short { display: flex; align-items: center; gap: .35rem; white-space: nowrap; padding-top: 0; padding-bottom: 0; }
.ag-card-short .ag-card-time { flex: 0 0 auto; }
.ag-card-short .ag-card-end { display: none; }
.ag-card-short .ag-card-patient { flex: 1 1 auto; min-width: 0; }

.ag-card-presencial {
  background: var(--agenda-card-presencial-bg);
  border-color: var(--agenda-card-presencial-border);
  color: var(--agenda-card-presencial-text);
}
.ag-card-teleconsulta {
  background: var(--agenda-card-teleconsulta-bg);
  border-color: var(--agenda-card-teleconsulta-border);
  color: var(--agenda-card-teleconsulta-text);
}
.ag-card-cancelled {
  background: var(--agenda-card-cancelled-bg);
  border-color: var(--agenda-card-cancelled-border);
  color: var(--agenda-card-cancelled-text);
  text-decoration: line-through;
}

.ag-resize-handle {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 5px;
  cursor: ns-resize;
}

.ag-more-lanes {
  border: none;
  background: var(--agenda-accent-soft);
  color: var(--agenda-accent-text);
  border-radius: 4px;
  font-size: .68rem;
  font-weight: 700;
  padding: .1rem .4rem;
  cursor: pointer;
}
.ag-less-lanes { background: transparent; }

.ag-create-results {
  max-height: 160px;
  overflow-y: auto;
  border: 1px solid var(--agenda-grid-border);
  border-radius: 6px;
  margin-top: .3rem;
}
.ag-create-result {
  padding: .35rem .5rem;
  font-size: .8rem;
  cursor: pointer;
}
.ag-create-result:hover { background: var(--agenda-accent-soft); }

.ag-detail-card {
  /* issue 853 drag fix: anchored next to the clicked card; left/top set by showDetailCard(). */
  position: fixed;
  left: 0;
  top: 0;
  width: 280px;
  max-width: calc(100vw - 16px);
  background: var(--agenda-grid-bg);
  border: 1px solid var(--agenda-grid-border);
  border-radius: 8px;
  padding: .85rem;
  box-shadow: 0 4px 18px var(--shadow, transparent);
  z-index: 40;
}
.ag-detail-row { font-size: .82rem; margin-bottom: .3rem; }
.ag-detail-phone-label { opacity: .7; margin-right: .25rem; }
.ag-detail-actions {
  display: flex;
  gap: .4rem;
  justify-content: flex-end;
  margin-top: .5rem;
}

/* ticket 853 5f: form error line (no hex fallback). */
.ag-form-err { color: var(--red, var(--agenda-card-cancelled-text)); font-size: .8rem; margin-top: .4rem; }
.ag-create-when {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: .5rem;
}
.ag-block-allday { display: inline-flex; align-items: center; gap: .4rem; font-size: .85rem; margin: .35rem 0; }

/* ticket 853 5f legend: doctor colour keys (token swatches), tags, and the
   card kinds the grid draws. */
.ag-legend {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem 1.25rem;
  margin-top: .6rem;
  padding: .5rem .75rem;
  border-radius: 6px;
  background: var(--surface-2, transparent);
  font-size: .75rem;
}
.ag-legend-group { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem .75rem; }
.ag-legend-label { font-weight: 700; color: var(--text-muted, var(--g500, inherit)); }
.ag-legend-item { display: inline-flex; align-items: center; gap: .35rem; }
.ag-legend-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 1px solid var(--agenda-grid-border);
  text-decoration: none;
}
.ag-legend-blocked {
  background: var(--agenda-blocked-bg);
  background-image: repeating-linear-gradient(
    45deg,
    var(--agenda-blocked-stripe),
    var(--agenda-blocked-stripe) 2px,
    transparent 2px,
    transparent 5px
  );
}
.ag-legend-tag {
  padding: .1rem .5rem;
  border-radius: 99px;
  border: 1px solid var(--agenda-grid-border);
}

/* ticket 853 5f bottom cards (honest "no disponible" states). */
.ag-bottom-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
  gap: .75rem;
  margin-top: .75rem;
}
.ag-bottom-card { margin: 0; }
.ag-bottom-card .section-card-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }

/* ticket 853 5f item 2: 12h/24h segmented toggle + hours toggle in row 2. */
.ag-seg {
  display: inline-flex;
  border: 1px solid var(--agenda-grid-border);
  border-radius: 6px;
  overflow: hidden;
}
.ag-seg-btn { border-radius: 0; padding: .3rem .6rem; font-size: .8rem; }
.ag-seg-on { font-weight: 700; background: var(--agenda-accent-soft); color: var(--agenda-accent-text); }

/* ticket 853 5f items 4 and 9: grid + collapsible day panel, full width. */
.ag-main {
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  width: 100%;
}
.ag-grid-wrap {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.ag-hours-more {
  display: block;
  width: 100%;
  border: 1px dashed var(--agenda-grid-border);
  background: var(--agenda-accent-soft);
  color: var(--agenda-accent-text);
  font-size: .75rem;
  font-weight: 700;
  padding: .2rem;
  cursor: pointer;
}
.ag-hours-more-top { border-radius: 8px 8px 0 0; border-bottom: 0; }
.ag-hours-more-bottom { border-radius: 0 0 8px 8px; border-top: 0; }
@keyframes ag-hours-reveal {
  from { opacity: .35; transform: scaleY(.97); }
  to { opacity: 1; transform: scaleY(1); }
}
.ag-hours-anim { animation: ag-hours-reveal .22s ease-out; transform-origin: top; }
@media (prefers-reduced-motion: reduce) { .ag-hours-anim { animation: none; } }

.ag-day-panel {
  flex: 0 0 17rem;
  max-width: 17rem;
  border: 1px solid var(--agenda-grid-border);
  border-radius: 8px;
  background: var(--agenda-grid-bg);
  overflow: hidden;
}
.ag-day-panel-collapsed { flex: 0 0 auto; max-width: 2.5rem; }
.ag-day-panel-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .4rem;
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--agenda-grid-border);
  background: transparent;
  color: inherit;
  font-weight: 700;
  font-size: .82rem;
  padding: .6rem .75rem;
  cursor: pointer;
  text-align: left;
}
.ag-day-panel-collapsed .ag-day-panel-toggle {
  writing-mode: vertical-rl;
  border-bottom: 0;
  padding: .75rem .5rem;
  min-height: 12rem;
}
.ag-day-panel-list {
  list-style: none;
  margin: 0;
  padding: .4rem 0;
  max-height: 42vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

/* ── Mini Month Calendar (in Day Panel) ────────────────────────── */
.ag-mini-cal-host { padding: .5rem; border-bottom: 1px solid var(--agenda-grid-border); }
.ag-mini-cal { font-size: .75rem; user-select: none; }
.ag-mini-cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .35rem; }
.ag-mini-cal-title { font-weight: 700; font-size: .78rem; color: var(--text-primary, var(--text)); }
.ag-mini-nav { background: transparent; border: 1px solid var(--agenda-grid-border); border-radius: 4px; padding: .1rem .4rem; cursor: pointer; color: var(--text-muted); font-size: .8rem; }
.ag-mini-nav:hover { background: var(--surface-hover, var(--surface-2)); color: var(--text); }
.ag-mini-cal-dows { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; font-weight: 600; font-size: .68rem; color: var(--text-muted); margin-bottom: .25rem; }
.ag-mini-cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.ag-mini-day { background: transparent; border: none; border-radius: 4px; padding: .25rem 0; font-size: .72rem; text-align: center; cursor: pointer; color: var(--text); }
.ag-mini-day:hover { background: var(--surface-hover, var(--surface-2)); }
.ag-mini-today { font-weight: 700; border: 1px solid var(--agenda-accent, var(--brand-primary)); }
.ag-mini-selected { background: var(--agenda-accent, var(--brand-primary)) !important; color: var(--agenda-accent-contrast, var(--white, currentColor)) !important; font-weight: 700; }
.ag-mini-in-week { background: var(--agenda-accent-soft, var(--surface-2)); }
.ag-mini-blank { cursor: default; }
.ag-day-panel-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: .1rem .5rem;
  padding: .35rem .75rem;
  font-size: .8rem;
  border-bottom: 1px solid var(--agenda-grid-border);
}
.ag-day-panel-time { font-weight: 700; white-space: nowrap; }
.ag-day-panel-type { font-size: .72rem; color: var(--text-muted, var(--g500, inherit)); }
.ag-day-panel-title { grid-column: 1 / -1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-day-panel-empty { padding: .75rem; font-size: .8rem; }
.ag-day-col .ag-day-head { cursor: pointer; }
@media (max-width: 900px) {
  .ag-main { flex-direction: column; }
  .ag-day-panel, .ag-day-panel-collapsed { flex: 1 1 auto; max-width: none; width: 100%; }
  .ag-day-panel-collapsed .ag-day-panel-toggle { writing-mode: horizontal-tb; min-height: 0; }
}

/* ticket 853 5f item 3: legend kind swatches (same app tokens the month
   dots use; no hex). */
.ag-legend-cita { background: var(--purple, var(--agenda-accent)); }
.ag-legend-tarea { background: var(--accent, var(--agenda-accent)); }
.ag-legend-consulta { background: var(--success, var(--agenda-accent-soft)); }

/* ticket 853 5f item 5: Enlace de Reserva row. */
.ag-booking-row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.ag-booking-url { flex: 1 1 14rem; min-width: 0; font-size: .78rem; }

/* ── ticket 885: unified "+ Crear" panel (lib/crear-panel.js) and grid events.
   Tokens only (var(--agenda-*) and the theme palette); no colour literals. */
.ag-blocked.ag-event-interactive { pointer-events: auto; cursor: pointer; z-index: 1; }
.ag-blocked.ag-event-interactive:focus-visible { outline: 2px solid var(--agenda-accent); outline-offset: -2px; }
.ag-blocked[data-draggable] { cursor: grab; touch-action: none; }
.ag-blocked.ag-event-free { background-image: none; border-left: 3px solid var(--agenda-blocked-stripe); }
.ag-event-label {
  display: block; padding: 2px 4px; font-size: .66rem; font-weight: 600; line-height: 1.15;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--agenda-accent-text);
}
.ag-event-dragging { opacity: .7; cursor: grabbing; }
.ag-event-pending { opacity: .6; }

.cp-overlay { z-index: 1000; padding: 1rem; }
.cp-panel [hidden] { display: none !important; }
.cp-panel.modal-box {
  max-width: 600px; width: 100%; max-height: calc(100vh - 2rem); overflow-y: auto;
  padding: 1.25rem 1.5rem 1.5rem; display: flex; flex-direction: column; gap: 1rem; box-sizing: border-box;
}
.cp-head { display: flex; align-items: flex-start; gap: .75rem; }
.cp-head-text { flex: 1 1 auto; min-width: 0; }
.cp-title { font-size: 1.3rem; font-weight: 700; margin: 0; line-height: 1.3; }
.cp-context { font-size: .85rem; color: var(--text-muted, inherit); margin-top: .2rem; }
.cp-x {
  flex: 0 0 auto; width: 44px; height: 44px; border-radius: 8px; border: 1px solid var(--agenda-grid-border);
  background: transparent; color: inherit; font-size: 1.25rem; line-height: 1; cursor: pointer;
}
.cp-x:focus-visible, .cp-tile:focus-visible, .cp-day:focus-visible, .cp-mday:focus-visible,
.cp-week-arrow:focus-visible, .cp-link:focus-visible, .cp-result:focus-visible { outline: 2px solid var(--agenda-accent); outline-offset: 2px; }
.cp-tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; }
.cp-tile {
  display: flex; align-items: center; gap: .6rem; text-align: left; min-height: 44px; padding: .6rem .75rem;
  border-radius: 10px; border: 2px solid var(--agenda-grid-border); background: transparent; color: inherit; cursor: pointer;
}
.cp-tile-on { border-color: var(--agenda-accent); background: var(--agenda-accent-soft); }
.cp-tile-icon { flex: 0 0 auto; }
.cp-tile-text { display: flex; flex-direction: column; min-width: 0; }
.cp-tile-name { font-size: .95rem; font-weight: 700; }
.cp-tile-sub { font-size: .75rem; color: var(--text-muted, inherit); line-height: 1.35; }
.cp-body { display: flex; flex-direction: column; gap: .85rem; }
.cp-field { display: flex; flex-direction: column; gap: .35rem; min-width: 0; }
.cp-field > label, .cp-label { font-size: .82rem; font-weight: 600; }
.cp-field .field-input { min-height: 44px; box-sizing: border-box; width: 100%; }
.cp-muted { color: var(--text-muted, inherit); font-weight: 400; }
.cp-hint { font-size: .75rem; color: var(--text-muted, inherit); }
.cp-hint.cp-bad, .cp-bad { color: var(--red, var(--agenda-card-cancelled-text)); }
.cp-note { font-size: .82rem; color: var(--text-muted, inherit); line-height: 1.45; margin: 0; }
.cp-field-err, .cp-form-err { color: var(--red, var(--agenda-card-cancelled-text)); font-size: .8rem; }
.cp-grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; }
.cp-grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .6rem; }
.cp-svc-line { display: flex; align-items: center; flex-wrap: wrap; gap: .45rem; font-size: .82rem; }
.cp-chip {
  padding: .2rem .6rem; border-radius: 999px; font-weight: 600;
  background: var(--agenda-card-presencial-bg); color: var(--agenda-card-presencial-text);
}
.cp-link {
  min-height: 28px; padding: .1rem .35rem; border: 0; background: transparent; color: var(--agenda-accent-text);
  font-size: .78rem; font-weight: 600; text-decoration: underline; cursor: pointer; align-self: flex-start;
}
.cp-adjust { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; }
.cp-adjust[hidden] { display: none; }
.cp-when { display: grid; grid-template-columns: 236px minmax(0, 1fr); gap: .75rem; }
.cp-when-right { display: flex; flex-direction: column; gap: .65rem; min-width: 0; }
.cp-week {
  display: flex; flex-direction: column; gap: .35rem; padding: .5rem; border: 1px solid var(--agenda-grid-border);
  border-radius: 8px; background: var(--agenda-grid-bg);
}
.cp-week-nav { display: flex; align-items: center; justify-content: space-between; font-size: .75rem; font-weight: 600; }
.cp-week-arrow { min-width: 32px; min-height: 32px; border: 0; background: transparent; color: inherit; cursor: pointer; font-size: 1rem; }
.cp-week-days, .cp-month-days, .cp-month-head { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px; }
.cp-month-head { font-size: .68rem; color: var(--text-muted, inherit); text-align: center; margin-top: .25rem; }
.cp-day, .cp-mday {
  min-height: 44px; padding: 2px 0; border-radius: 6px; border: 1px solid var(--agenda-grid-border);
  background: transparent; color: inherit; font-size: .8rem; line-height: 1.2; cursor: pointer;
}
.cp-mday { min-height: 32px; border-color: transparent; }
.cp-dow { display: block; font-size: .62rem; opacity: .8; }
.cp-day-today { border-color: var(--agenda-accent); }
.cp-day-on { background: var(--agenda-accent); border-color: var(--agenda-accent); color: var(--on-accent); font-weight: 700; }
.cp-mday-pad { min-height: 32px; }
.cp-search {
  display: flex; align-items: center; gap: .5rem; min-height: 44px; padding: 0 .4rem 0 .6rem;
  border: 1px solid var(--agenda-grid-border); border-radius: 8px; background: var(--agenda-grid-bg);
}
.cp-search .cp-search-input { flex: 1 1 auto; border: 0; background: transparent; min-height: 42px; }
.cp-search-icon { flex: 0 0 auto; color: var(--text-muted, inherit); }
.cp-new-patient { white-space: nowrap; }
.cp-listbox { display: flex; flex-direction: column; border: 1px solid var(--agenda-grid-border); border-radius: 8px; overflow: hidden; }
.cp-result {
  display: flex; align-items: center; gap: .6rem; min-height: 44px; padding: .4rem .7rem; border: 0;
  border-bottom: 1px solid var(--agenda-grid-border); background: transparent; color: inherit; text-align: left; cursor: pointer;
}
.cp-result:hover { background: var(--agenda-accent-soft); }
.cp-result-main { flex: 1 1 auto; min-width: 0; }
.cp-result-phone { font-size: .8rem; }
.cp-hit { font-size: .68rem; font-weight: 600; border: 1px solid var(--agenda-grid-border); border-radius: 999px; padding: .1rem .5rem; color: var(--text-muted, inherit); }
.cp-listbox .cp-hint { padding: .35rem .7rem; }
.cp-empty { padding: .6rem .7rem; border: 1px dashed var(--agenda-grid-border); border-radius: 8px; font-size: .82rem; color: var(--text-muted, inherit); }
.cp-picked {
  display: flex; align-items: center; gap: .6rem; min-height: 44px; padding: .35rem .4rem .35rem .7rem; box-sizing: border-box;
  border: 1px solid var(--agenda-card-presencial-border); border-radius: 8px; background: var(--agenda-card-presencial-bg);
}
.cp-picked-text { flex: 1 1 auto; min-width: 0; font-size: .88rem; }
.cp-newpat { border: 1px solid var(--agenda-grid-border); border-radius: 8px; padding: .6rem .75rem; margin: 0; }
.cp-newpat legend { font-size: .82rem; font-weight: 600; padding: 0 .3rem; }
.cp-newpat-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .5rem; }
.cp-check {
  display: flex; align-items: center; gap: .7rem; min-height: 44px; padding: .6rem .8rem; box-sizing: border-box;
  border: 1px solid var(--agenda-grid-border); border-radius: 10px; background: var(--agenda-grid-bg); font-size: .88rem; cursor: pointer;
}
.cp-check input { width: 20px; height: 20px; margin: 0; }
.cp-risk { font-size: .82rem; }
.cp-risk-box {
  display: flex; gap: .75rem; align-items: flex-start; padding: .7rem .85rem;
  border: 1px solid var(--agenda-grid-border); border-radius: 10px; background: var(--agenda-grid-bg);
}
.cp-risk-chip { flex: 0 0 auto; min-width: 64px; text-align: center; padding: .4rem .6rem; border-radius: 999px; font-weight: 700; color: var(--on-accent); }
.cp-risk-low { background: var(--green, var(--agenda-status-completed)); }
.cp-risk-medium { background: var(--amber, var(--agenda-status-scheduled)); }
.cp-risk-high { background: var(--red, var(--agenda-status-no-show)); }
.cp-risk-text { display: flex; flex-direction: column; gap: .2rem; line-height: 1.45; }
.cp-risk-title { font-weight: 600; }
.cp-foot { display: flex; justify-content: flex-end; gap: .6rem; }
.cp-foot .btn { min-height: 44px; }
@media (max-width: 560px) {
  .cp-grid2, .cp-grid3, .cp-adjust, .cp-when { grid-template-columns: minmax(0, 1fr); }
  .cp-panel.modal-box { padding: 1rem; }
}

/* ── Nueva cita form (#/agenda/record/__new__, agenda.js renderComposer) ──
   2026-10-01 layout fix, CSS/markup only. The shared .field-grid bottom-
   aligns its groups (align-items:end / justify-content:flex-end), so a field
   with a hint or summary under its control pushed its own label out of line
   with its neighbour. Here every group is top-aligned, labels share one line
   height, controls share one height, and every hint keeps a reserved line
   (setFieldError() empties it before hiding it, so the reserved box is blank
   when there is nothing to say). */
#agenda-composer .ag-composer-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-areas:
    "pat  pat  pat  pat"
    "date time dur  doc"
    "step step mod  ."
    "proc proc proc proc";
  gap: .5rem 1rem;
  align-items: start;
}
#agenda-composer .ag-composer-grid > .field-group { justify-content: flex-start; min-width: 0; }
#agenda-composer .ag-c-pat  { grid-area: pat; }
#agenda-composer .ag-c-date { grid-area: date; }
#agenda-composer .ag-c-time { grid-area: time; }
#agenda-composer .ag-c-dur  { grid-area: dur; }
#agenda-composer .ag-c-doc  { grid-area: doc; }
#agenda-composer .ag-c-step { grid-area: step; }
#agenda-composer .ag-c-mod  { grid-area: mod; }
#agenda-composer .ag-c-proc { grid-area: proc; }
#agenda-composer .ag-composer-grid > .field-group > label { line-height: 1.2rem; min-height: 1.2rem; margin: 0; }
#agenda-composer .ag-composer-grid > .field-group > input.field-input,
#agenda-composer .ag-composer-grid > .field-group > select.field-input { height: 2.5rem; box-sizing: border-box; width: 100%; }
#agenda-composer .ag-field-err {
  display: block !important;
  min-height: 1.1rem;
  line-height: 1.1rem;
  margin: .15rem 0 0;
  font-size: .75rem;
  font-weight: 600;
  color: var(--red);
}
#agenda-composer .ag-end-time-summary { min-height: 1.1rem; line-height: 1.1rem; margin: 0; font-size: .8rem; color: var(--text-muted); }
#agenda-composer .ag-create-results:empty { display: none; }
#agenda-composer .ag-c-newpat { align-self: flex-start; width: auto; margin-top: .25rem; }
@media (min-width: 769px) {
  /* clear of the fixed bottom-right buttons (create "+" and chat, right:20px) */
  #agenda-composer { padding-right: 4.5rem; padding-bottom: 4rem; }
}
@media (max-width: 1100px) {
  #agenda-composer .ag-composer-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-areas: "pat pat" "date time" "dur doc" "step step" "mod ." "proc proc";
  }
}
@media (max-width: 600px) {
  #agenda-composer .ag-composer-grid {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "pat" "date" "time" "dur" "doc" "step" "mod" "proc";
  }
}

/* V2-7 (5 Oct 2026): appointment colours. The clinic stores a palette NAME (lib/appointment-colours.js); each name maps to the
   --agenda-pal-<name>-bg / -border / -text tokens of lib/agenda-tokens.css (light, dark, premium). Tokens only, no colour literals. */
.ag-pal-green { background: var(--agenda-pal-green-bg); border-color: var(--agenda-pal-green-border); color: var(--agenda-pal-green-text); }
.ag-pal-purple { background: var(--agenda-pal-purple-bg); border-color: var(--agenda-pal-purple-border); color: var(--agenda-pal-purple-text); }
.ag-pal-gold { background: var(--agenda-pal-gold-bg); border-color: var(--agenda-pal-gold-border); color: var(--agenda-pal-gold-text); }
.ag-pal-blue { background: var(--agenda-pal-blue-bg); border-color: var(--agenda-pal-blue-border); color: var(--agenda-pal-blue-text); }
.ag-pal-teal { background: var(--agenda-pal-teal-bg); border-color: var(--agenda-pal-teal-border); color: var(--agenda-pal-teal-text); }
.ag-pal-orange { background: var(--agenda-pal-orange-bg); border-color: var(--agenda-pal-orange-border); color: var(--agenda-pal-orange-text); }
.ag-pal-rose { background: var(--agenda-pal-rose-bg); border-color: var(--agenda-pal-rose-border); color: var(--agenda-pal-rose-text); }
.ag-pal-slate { background: var(--agenda-pal-slate-bg); border-color: var(--agenda-pal-slate-border); color: var(--agenda-pal-slate-text); }
.cal-dot.ag-pal-dot-green { background: var(--agenda-pal-green-border); }
.cal-dot.ag-pal-dot-purple { background: var(--agenda-pal-purple-border); }
.cal-dot.ag-pal-dot-gold { background: var(--agenda-pal-gold-border); }
.cal-dot.ag-pal-dot-blue { background: var(--agenda-pal-blue-border); }
.cal-dot.ag-pal-dot-teal { background: var(--agenda-pal-teal-border); }
.cal-dot.ag-pal-dot-orange { background: var(--agenda-pal-orange-border); }
.cal-dot.ag-pal-dot-rose { background: var(--agenda-pal-rose-border); }
.cal-dot.ag-pal-dot-slate { background: var(--agenda-pal-slate-border); }
.ag-colour-legend { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem 1rem; margin: 0 0 .6rem; padding: .25rem 0; font-size: .8rem; line-height: 1.6; }
.ag-colour-legend-item { display: inline-flex; align-items: center; gap: .4rem; }
.ag-colour-legend-swatch { display: inline-block; width: .9rem; height: .9rem; border-radius: 3px; border: 1px solid; flex: 0 0 auto; }
.ag-colour-editor { margin-top: 1.5rem; padding: 1.5rem; border: 1px solid var(--agenda-grid-border); border-radius: 8px; background: var(--agenda-grid-bg); }
.ag-colour-editor h3 { margin: 0 0 .5rem; }
.ag-colour-help { margin: 0 0 .75rem; line-height: 1.6; }
.ag-colour-row { display: flex; align-items: center; gap: .75rem; margin: .5rem 0; }
.ag-colour-label { min-width: 8rem; font-weight: 600; }
.ag-colour-select { max-width: 14rem; }
.ag-colour-actions { display: flex; align-items: center; gap: .75rem; margin-top: 1rem; }
.ag-colour-status { font-size: .85rem; line-height: 1.6; }
.ag-card-returning .ag-card-time, .ag-card-new .ag-card-time { font-weight: 700; }
.ag-newflag { display: inline-flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.ag-newflag-opt { min-height: 36px; padding: .25rem .75rem; border-radius: 6px; border: 2px solid var(--agenda-grid-border); background: transparent; color: inherit; cursor: pointer; }
.ag-newflag-opt[aria-checked="true"] { border-color: var(--agenda-accent); background: var(--agenda-accent-soft); font-weight: 700; }
.ag-newflag-opt:focus-visible { outline: 2px solid var(--agenda-accent); outline-offset: 2px; }
.ag-newflag-line { margin: .35rem 0 0; font-size: .85rem; line-height: 1.6; }
