/* ============================================================
   Agenda como calendario (Gestión › Agenda) y mini-calendario del Panel.
   Solo tokens de crm.css (sin colores nuevos): ver DISENO-CRM.md. Claro y oscuro salen de los mismos tokens.
   Hoy = dorado (--accent) · tipos = tokens y mezclas de tokens.
   ============================================================ */

/* ---------- colores por tipo: cada elemento con clase t-<tipo> define --k ---------- */
.t-cita { --k: var(--info); }
.t-visita { --k: var(--earth); }
.t-entrega { --k: var(--ok); }
.t-reunion { --k: var(--primary); }
.t-llamada { --k: color-mix(in srgb, var(--info) 55%, var(--ok)); }
.t-otro { --k: var(--muted); }
.t-tarea { --k: var(--warn); }
.t-recordatorio { --k: var(--accent); }
.t-oc { --k: color-mix(in srgb, var(--ok) 55%, var(--earth)); }
.t-entrega_cliente { --k: color-mix(in srgb, var(--ok) 70%, var(--primary)); }
.t-documento { --k: var(--err); }
.t-garantia { --k: color-mix(in srgb, var(--err) 55%, var(--warn)); }

/* ---------- barra ---------- */
.cal-bar { align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.cal-nav { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.cal-title { font-family: var(--font-display); font-weight: 500; font-size: 1.3rem; letter-spacing: .01em; min-width: 0; margin-left: 6px; overflow-wrap: anywhere; }
.cal-filters select { max-width: 100%; }
.cal-card { padding: 0; overflow: hidden; }
.cal-stage { min-height: 240px; }
.cal-stage > .spinner, .cal-stage > .loading { margin: 60px auto; }
.cal-keys { margin: 10px 16px 14px; }
.cal-wknote { margin: 12px 16px 0; }

/* ---------- leyenda ---------- */
.cal-legend { list-style: none; margin: 0; padding: 10px 16px 14px; display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: var(--fs-xs); color: var(--muted); }
.cal-legend li { display: inline-flex; align-items: center; gap: 6px; }
.cal-legend i, .ag-kind i { width: 9px; height: 9px; border-radius: 3px; background: var(--k); flex: none; }

/* ---------- MES ---------- */
.cal-layout { display: grid; grid-template-columns: minmax(0, 1fr) 310px; align-items: start; }
.cal-main { min-width: 0; container-type: inline-size; }
@container (max-width: 780px) { .cal-chip b { display: none; } .cal-chip { padding-left: 7px; } }
.cal-grid { border-bottom: 1px solid var(--line); }
.cal-head, .cal-week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-head { border-bottom: 1px solid var(--line); background: var(--surface-2); }
.cal-wd { padding: 9px 10px; font-size: var(--fs-xs); font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.cal-wd.wk { color: color-mix(in srgb, var(--muted) 75%, transparent); }
.cal-week + .cal-week .cal-cell, .cal-week .cal-cell { border-top: 1px solid var(--line); }
.cal-week:first-of-type .cal-cell { border-top: 0; }
.cal-cell { position: relative; min-width: 0; min-height: 112px; padding: 6px 6px 8px; border-left: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; cursor: pointer; background: var(--surface); transition: background var(--dur-fast) var(--ease-out); }
.cal-cell:first-child { border-left: 0; }
.cal-cell.wk { background: color-mix(in srgb, var(--surface-2) 70%, var(--surface)); }
.cal-cell:hover { background: var(--surface-2); }
.cal-cell.out { background: color-mix(in srgb, var(--surface-3) 55%, var(--surface)); }
.cal-cell.out .cal-num { color: color-mix(in srgb, var(--muted) 70%, transparent); }
.cal-cell.out .cal-chip { opacity: .6; }
.cal-cell.today { box-shadow: inset 0 2px 0 var(--accent); }
.cal-cell.sel { background: color-mix(in srgb, var(--accent-soft) 60%, var(--surface)); box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--accent) 70%, var(--line-strong)); }
.cal-cell.sel.today { box-shadow: inset 0 0 0 1.5px var(--accent), inset 0 2px 0 var(--accent); }
.cal-cell:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; z-index: 1; }
.cal-top { display: flex; align-items: center; justify-content: space-between; min-height: 24px; }
.cal-num { display: inline-grid; place-items: center; min-width: 24px; height: 24px; padding: 0 4px; border-radius: 99px; font-size: var(--fs-sm); font-weight: 600; font-variant-numeric: tabular-nums; color: var(--text-2); }
.cal-cell.today .cal-num { background: var(--accent); color: var(--on-accent); font-weight: 700; }
.cal-add { width: 22px; height: 22px; display: inline-grid; place-items: center; border-radius: var(--r-sm); border: 0; background: transparent; color: var(--muted); opacity: 0; transition: opacity var(--dur-fast), background var(--dur-fast); }
.cal-add svg { width: 14px; height: 14px; }
.cal-cell:hover .cal-add, .cal-cell:focus-within .cal-add, .cal-cell.sel .cal-add { opacity: 1; }
.cal-add:hover { background: var(--surface-3); color: var(--text); }
.cal-chips { display: grid; gap: 3px; min-width: 0; }
.cal-chip { display: flex; align-items: center; gap: 5px; width: 100%; min-width: 0; height: 21px; padding: 0 6px 0 8px; border: 0; border-radius: 5px; text-align: left; font-size: 11.5px; line-height: 1; color: var(--text); background: color-mix(in srgb, var(--k) 15%, var(--surface)); box-shadow: inset 3px 0 0 var(--k); transition: background var(--dur-fast); }
.cal-chip:hover { background: color-mix(in srgb, var(--k) 26%, var(--surface)); }
.cal-chip b { font-weight: 600; font-variant-numeric: tabular-nums; color: var(--text-2); flex: none; }
.cal-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.cal-chip.done, .tg-ev.done { opacity: .62; }
.cal-chip.cancelled span, .tg-ev.cancelled span, .ag-item.cancelled .ag-title { text-decoration: line-through; }
.cal-chip.cancelled, .tg-ev.cancelled { opacity: .5; }
.cal-chip.late, .tg-ev.late { box-shadow: inset 3px 0 0 var(--err); }
.cal-more { align-self: flex-start; border: 0; background: none; padding: 1px 6px; border-radius: 99px; font-size: 11.5px; font-weight: 600; color: var(--text-2); }
.cal-more:hover { background: var(--surface-3); color: var(--text); }
.cal-dots { display: none; }

/* panel del día */
.cal-side { border-left: 1px solid var(--line); padding: 16px 16px 18px; min-width: 0; background: var(--surface); align-self: stretch; }
.cal-side-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.cal-side-head h3 { font-family: var(--font-display); font-weight: 500; font-size: 1.1rem; letter-spacing: .01em; margin-top: 2px; }
.cal-side-kicker { font-size: var(--fs-xs); font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--accent-ink); }
.cal-side-empty { text-align: center; padding: 22px 8px; color: var(--muted); }
.cal-side-empty p { margin-bottom: 10px; }

/* ---------- filas de actividad (panel del día y listas) ---------- */
.ag-ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.ag-item { display: grid; grid-template-columns: 74px minmax(0, 1fr) auto; gap: 10px; align-items: start; padding: 9px 10px 9px 12px; border-radius: var(--r-md); background: color-mix(in srgb, var(--k) 8%, var(--surface-2)); box-shadow: inset 3px 0 0 var(--k); }
.ag-item.done { opacity: .7; }
.ag-item.cancelled { opacity: .6; }
.ag-time { font-size: var(--fs-xs); font-weight: 600; color: var(--muted); padding-top: 2px; font-variant-numeric: tabular-nums; line-height: 1.35; }
.ag-main { min-width: 0; }
.ag-line { overflow-wrap: anywhere; font-weight: 600; }
.ag-title { font-weight: 600; color: var(--text); text-align: left; text-decoration: none; }
a.ag-title:hover, .ag-title.linklike:hover { text-decoration: underline; }
.ag-meta { display: flex; gap: 4px 8px; flex-wrap: wrap; margin-top: 3px; align-items: center; font-size: var(--fs-xs); }
.ag-kind { display: inline-flex; align-items: center; gap: 5px; color: var(--text-2); font-weight: 500; }
.ag-actions { display: flex; gap: 4px; }
.ag-actions .btn { width: 28px; height: 28px; padding: 0; }
.ag-actions .btn svg { width: 14px; height: 14px; }

/* ---------- SEMANA / DÍA ---------- */
.tg { border-top: 0; min-width: 0; }
.tg-row { display: grid; }
.tg-head { border-bottom: 1px solid var(--line); background: var(--surface-2); }
.tg-day { text-align: center; border-left: 1px solid var(--line); min-width: 0; }
.tg-daybtn { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px 9px; border: 0; background: none; border-radius: 0; }
.tg-daybtn:not(:disabled):hover { background: var(--surface-3); }
.tg-daybtn:disabled { cursor: default; }
.tg-wd { font-size: var(--fs-xs); font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.tg-dn { display: inline-grid; place-items: center; min-width: 32px; height: 32px; border-radius: 99px; font-family: var(--font-display); font-size: 1.2rem; font-weight: 500; font-variant-numeric: tabular-nums; }
.tg-day.today .tg-dn { background: var(--accent); color: var(--on-accent); }
.tg-day.today .tg-wd { color: var(--accent-ink); }
.tg-all { border-bottom: 1px solid var(--line); min-height: 36px; }
.tg-allbl { font-size: 10.5px; color: var(--muted); padding: 10px 6px 0 0; text-align: right; line-height: 1.2; }
.tg-allcol { border-left: 1px solid var(--line); padding: 4px; display: grid; gap: 3px; align-content: start; min-width: 0; cursor: pointer; }
.tg-allcol:hover { background: var(--surface-2); }
.tg-body { display: grid; position: relative; }
.tg-hours { position: relative; }
.tg-hours span { position: absolute; right: 8px; transform: translateY(-50%); font-size: 10.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tg-col { position: relative; border-left: 1px solid var(--line); min-width: 0; cursor: pointer; background-image: repeating-linear-gradient(to bottom, transparent 0, transparent 47px, var(--line) 47px, var(--line) 48px); }
.tg-col.today { background-color: color-mix(in srgb, var(--accent-soft) 38%, transparent); }
.tg-col:hover { background-color: color-mix(in srgb, var(--surface-2) 70%, transparent); }
.tg-ev { position: absolute; display: flex; flex-direction: column; gap: 1px; padding: 3px 6px 3px 9px; border: 0; border-radius: 6px; text-align: left; overflow: hidden; color: var(--text); background: color-mix(in srgb, var(--k) 24%, var(--surface)); box-shadow: inset 3px 0 0 var(--k), 0 0 0 1px var(--surface); font-size: 12px; line-height: 1.25; transition: background var(--dur-fast), box-shadow var(--dur-fast); }
.tg-ev.short { flex-direction: row; align-items: center; gap: 6px; padding-top: 0; padding-bottom: 0; }
.tg-ev.short span { -webkit-line-clamp: 1; }
.tg-ev:hover { background: color-mix(in srgb, var(--k) 32%, var(--surface)); z-index: 2; box-shadow: inset 3px 0 0 var(--k), var(--shadow-2); }
.tg-ev b { font-size: 11px; font-weight: 600; color: var(--text-2); font-variant-numeric: tabular-nums; }
.tg-ev span { font-weight: 600; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.tg-ev small { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tg-now { position: absolute; left: 0; right: 0; height: 2px; background: var(--accent); z-index: 3; pointer-events: none; }
.tg-now::before { content: ""; position: absolute; left: -4px; top: -3px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.tg .cal-chip { height: 20px; }
.tg.single .tg-wd { letter-spacing: .1em; }

/* ---------- AGENDA (lista cronológica) ---------- */
.ag-list { padding: 4px 0; }
.ag-day { padding: 14px 18px 10px; border-bottom: 1px solid var(--line); }
.ag-day:last-child { border-bottom: 0; }
.ag-day.today { background: color-mix(in srgb, var(--accent-soft) 45%, var(--surface)); box-shadow: inset 3px 0 0 var(--accent); }
.ag-day header { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.ag-day header h3 { font-size: var(--fs-base); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ag-day header .btn { margin-left: auto; }
.ag-date { display: grid; justify-items: center; gap: 3px; min-width: 44px; line-height: 1; }
.ag-date b { font-family: var(--font-display); font-weight: 500; font-size: 1.5rem; }
.ag-date span { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.ag-none { margin: 0 0 6px 56px; }
.cal-listwrap .empty { padding: 56px 20px; }

/* ---------- conectar calendario ---------- */
.conn { display: grid; gap: 14px; min-width: 0; }
.conn h3 { font-size: var(--fs-md); }
.conn h4 { font-size: var(--fs-sm); margin-bottom: 6px; }
.conn-card { border: 1px solid var(--line); border-radius: var(--r-lg); padding: 14px 16px; display: grid; gap: 10px; background: var(--surface-2); min-width: 0; }
.conn-card.pending { border-style: dashed; }
.conn-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.conn-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.conn-urls { display: grid; gap: 10px; }
.conn-url label { display: block; font-size: var(--fs-xs); font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.conn-url > div { display: flex; gap: 8px; }
.conn-url input { flex: 1; min-width: 0; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.conn-mine { margin-top: 8px; }
.conn-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.conn-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; font-size: var(--fs-sm); }
.conn-steps li { display: grid; grid-template-columns: 20px minmax(0, 1fr); gap: 8px; align-items: start; }
.conn-n { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 99px; background: var(--primary); color: var(--on-primary); font-size: 11px; font-weight: 700; }

/* ---------- mini-calendario y próximos eventos del Panel ---------- */
.agw { display: grid; grid-template-columns: minmax(0, 300px) minmax(0, 1fr); gap: 22px; align-items: start; }
.agw-cal { min-width: 0; }
.agw-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.agw-nav strong { font-family: var(--font-display); font-weight: 500; font-size: 1.05rem; letter-spacing: .01em; }
.agw-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px; }
.agw-wd { text-align: center; font-size: 10.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 2px 0 4px; }
.agw-day { position: relative; aspect-ratio: 1 / 1; min-height: 34px; display: grid; place-items: center; border: 0; border-radius: var(--r-md); background: none; font-size: var(--fs-sm); font-variant-numeric: tabular-nums; color: var(--text); text-decoration: none; transition: background var(--dur-fast); }
.agw-day:hover { background: var(--surface-3); }
.agw-day.out { color: color-mix(in srgb, var(--muted) 65%, transparent); }
.agw-day.today { background: var(--accent); color: var(--on-accent); font-weight: 700; }
.agw-day.today:hover { background: color-mix(in srgb, var(--accent) 88%, var(--text)); }
.agw-day i { position: absolute; bottom: 4px; left: 50%; width: 5px; height: 5px; margin-left: -2.5px; border-radius: 50%; background: var(--earth); }
.agw-day.today i { background: var(--on-accent); }
.agw-day.has-many i { box-shadow: -7px 0 0 0 var(--earth), 7px 0 0 0 var(--earth); }
.agw-day.today.has-many i { box-shadow: -7px 0 0 0 var(--on-accent), 7px 0 0 0 var(--on-accent); }
.agw-up h3 { font-size: var(--fs-sm); font-weight: 600; color: var(--muted); margin-bottom: 8px; }
.agw-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.agw-ev { display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 10px; align-items: center; padding: 7px 10px 7px 12px; border-radius: var(--r-md); background: color-mix(in srgb, var(--k) 8%, var(--surface-2)); box-shadow: inset 3px 0 0 var(--k); text-decoration: none; color: var(--text); transition: background var(--dur-fast); }
.agw-ev:hover { background: color-mix(in srgb, var(--k) 16%, var(--surface-2)); }
.agw-when { display: grid; line-height: 1.2; font-variant-numeric: tabular-nums; }
.agw-when b { font-size: var(--fs-sm); }
.agw-when span { font-size: 10.5px; color: var(--muted); }
.agw-what { min-width: 0; }
.agw-what strong { display: block; font-size: var(--fs-sm); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agw-what small { color: var(--muted); font-size: var(--fs-xs); }
.agw-empty { padding: 18px 12px; text-align: center; color: var(--muted); border: 1px dashed var(--line-strong); border-radius: var(--r-md); }
.agw-empty strong { display: block; color: var(--text); margin-bottom: 2px; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .cal-layout { grid-template-columns: minmax(0, 1fr); }
  .cal-side { border-left: 0; border-top: 1px solid var(--line); }
}
@media (max-width: 900px) {
  .agw { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 700px) {
  .cal-title { font-size: 1.1rem; }
  .cal-keys { display: none; }
  .cal-wd { padding: 7px 0; text-align: center; font-size: 10px; letter-spacing: .04em; }
  .cal-cell { min-height: 56px; padding: 4px 2px 6px; align-items: center; gap: 2px; }
  .cal-top { justify-content: center; }
  .cal-add, .cal-chips, .cal-more { display: none; }
  .cal-dots { display: flex; align-items: center; justify-content: center; gap: 3px; min-height: 8px; }
  .cal-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--k); }
  .cal-dots small { font-size: 9px; color: var(--muted); }
  .ag-item { grid-template-columns: minmax(0, 1fr) auto; }
  .ag-time { grid-column: 1 / -1; padding-top: 0; }
  .ag-actions { grid-column: 2; grid-row: 2; }
  .ag-day { padding-left: 14px; padding-right: 14px; }
  .ag-none { margin-left: 0; }
  .conn-url > div { flex-wrap: wrap; }
  .conn-url .btn { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .cal-cell, .cal-chip, .tg-ev, .agw-day, .agw-ev, .cal-add { transition: none; }
}
