/* Complementos de interfaz sobre el design system Cittaz (formularios, modales, agenda, chat). */
:root { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font-sans); background: var(--surface); color: var(--ink); font-size: 14px; line-height: 20px; -webkit-font-smoothing: antialiased; }
a { color: var(--brand-ink); }
#root { min-height: 100%; }
.muted { color: var(--ink-muted); } .subtle { color: var(--ink-subtle); } .small { font-size: 12px; line-height: 16px; }
.row { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.between { justify-content: space-between; } .grow { flex: 1; min-width: 0; }
.stack { display: grid; gap: var(--space-4); } .stack-sm { display: grid; gap: var(--space-2); }
.mt { margin-top: var(--space-4); } .mb { margin-bottom: var(--space-4); }
.right { text-align: right; } .nowrap { white-space: nowrap; } .ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.big-num { font-size: 40px; line-height: 44px; font-weight: 300; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.mid-num { font-size: 28px; line-height: 32px; font-weight: 300; font-variant-numeric: tabular-nums; }
.panel { background: var(--surface-sunken); border-radius: var(--radius-md); padding: var(--space-4); }
.divider { height: 1px; background: var(--line); margin: var(--space-4) 0; border: 0; }
h2.section { font: var(--text-h2); margin: var(--space-6) 0 var(--space-3); }
.cz-card .cz-card-title { min-width: 0; }

/* Formularios */
.field { display: grid; gap: 6px; min-width: 0; }
.field > label, .field-label { font-size: 13px; font-weight: 500; color: var(--ink-muted); }
.field .hint { font-size: 12px; color: var(--ink-subtle); }
.input, .select, .textarea {
  font: inherit; font-size: 14px; width: 100%; min-height: 40px; padding: 8px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--surface-raised); color: var(--ink); transition: border-color .15s ease;
}
.textarea { min-height: 96px; resize: vertical; line-height: 20px; }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 1px; }
.input[type="color"] { padding: 4px; width: 64px; }
@media (pointer: coarse) { .input, .select, .textarea { font-size: 16px; min-height: var(--target-min); } }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-4); }
.form-grid .full { grid-column: 1 / -1; }
@container (max-width: 560px) { .form-grid { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 640px) { .form-grid { grid-template-columns: minmax(0, 1fr); } }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font: inherit; font-size: 13px; padding: 6px 12px; border-radius: var(--radius-pill); border: 1px solid var(--line); background: var(--surface-raised); color: var(--ink); cursor: pointer; }
.chip.on { background: var(--surface-inverse); color: var(--on-inverse); border-color: var(--surface-inverse); }
.err { color: var(--danger); font-size: 13px; }

/* Tablas */
.table-wrap { overflow-x: auto; margin: 0 calc(var(--space-5) * -1); padding: 0 var(--space-5); }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: left; font-size: 12px; font-weight: 500; color: var(--ink-muted); padding: 8px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.t td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t tr.click { cursor: pointer; } table.t tr.click:hover td { background: var(--surface-sunken); }
table.t .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.t tfoot td { font-weight: 600; border-top: 1px solid var(--line-strong); }

/* Modal y panel lateral */
.overlay { position: fixed; inset: 0; background: rgba(20,16,20,.45); z-index: 50; display: flex; justify-content: flex-end; animation: fade .15s ease; }
.overlay.center { align-items: center; justify-content: center; padding: 16px; }
@keyframes fade { from { opacity: 0; } }
.drawer { width: min(620px, 100%); height: 100%; background: var(--surface-raised); box-shadow: var(--shadow-pop); display: flex; flex-direction: column; container-type: inline-size; }
.drawer.wide { width: min(880px, 100%); }
.modal { width: min(520px, 100%); max-height: 90vh; background: var(--surface-raised); border-radius: var(--radius-lg); box-shadow: var(--shadow-pop); display: flex; flex-direction: column; container-type: inline-size; }
.sheet-head { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-5); border-bottom: 1px solid var(--line); }
.sheet-head h2 { font: var(--text-h2); margin: 0; flex: 1; min-width: 0; }
.sheet-body { padding: var(--space-5); overflow-y: auto; flex: 1; }
.sheet-foot { display: flex; gap: var(--space-2); justify-content: flex-end; padding: var(--space-4) var(--space-5); border-top: 1px solid var(--line); flex-wrap: wrap; }
@media (max-width: 640px) { .sheet-foot > * { flex: 1; } .overlay:not(.center) .drawer { border-radius: var(--radius-xl) var(--radius-xl) 0 0; height: 94%; margin-top: auto; } .overlay:not(.center) { align-items: flex-end; } }

/* Avisos */
.toasts { position: fixed; bottom: 96px; left: 50%; transform: translateX(-50%); z-index: 100; display: grid; gap: 8px; width: min(420px, calc(100% - 32px)); }
.toast { background: var(--surface-inverse); color: var(--on-inverse); padding: 12px 16px; border-radius: var(--radius-md); box-shadow: var(--shadow-pop); font-size: 14px; }
.toast.error { background: var(--danger); color: #fff; }
@media (min-width: 721px) { .toasts { bottom: 24px; } }
.empty { text-align: center; padding: var(--space-8) var(--space-4); color: var(--ink-muted); }
.loading { padding: var(--space-8); text-align: center; color: var(--ink-subtle); }
.notice { background: var(--warning-soft); color: var(--warning); border-radius: var(--radius-md); padding: 12px 16px; font-size: 13px; }
.notice.info { background: var(--brand-soft); color: var(--brand-ink); }
.notice.ok { background: var(--success-soft); color: var(--success); }

/* Filtros y barra de herramientas */
.toolbar { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; margin-bottom: var(--space-4); }
.toolbar .cz-search { flex: 1; min-width: 200px; }
.toolbar .select, .toolbar .input { width: auto; min-width: 140px; border-radius: var(--radius-pill); }
@media (max-width: 720px) { .toolbar > * { flex: 1 1 100%; } .toolbar .select, .toolbar .input { width: 100%; } }
.tabs-scroll { overflow-x: auto; margin-bottom: var(--space-4); }

/* Agenda */
.cal { display: grid; position: relative; background: var(--surface-raised); border-radius: var(--radius-lg); box-shadow: var(--shadow-card); overflow: auto; max-height: calc(100vh - 220px); }
.cal-head { position: sticky; top: 0; z-index: 3; background: var(--surface-raised); border-bottom: 1px solid var(--line); padding: 10px 8px; font-size: 13px; font-weight: 600; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-head .small { font-weight: 400; color: var(--ink-subtle); display: block; }
.cal-times { position: sticky; left: 0; z-index: 2; background: var(--surface-raised); border-right: 1px solid var(--line); }
.cal-time { height: 48px; font-size: 11px; color: var(--ink-subtle); text-align: right; padding: 0 8px; transform: translateY(-7px); font-variant-numeric: tabular-nums; }
.cal-col { position: relative; border-right: 1px solid var(--line); min-width: 140px; }
.cal-slot { height: 24px; border-bottom: 1px dashed transparent; }
.cal-slot:nth-child(2n) { border-bottom: 1px solid var(--line); }
.cal-slot:hover { background: var(--pink-50); cursor: pointer; }
:root[data-theme="dark"] .cal-slot:hover { background: var(--surface-sunken); }
.cal-closed { background: repeating-linear-gradient(-45deg, var(--surface-sunken), var(--surface-sunken) 6px, transparent 6px, transparent 12px); }
.ev { position: absolute; left: 4px; right: 4px; border-radius: 10px; padding: 4px 8px; font-size: 12px; line-height: 15px; overflow: hidden; cursor: pointer;
  background: var(--brand-soft); color: var(--ink); border-left: 4px solid var(--brand); box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.ev strong { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev.st-pendiente { background: var(--warning-soft); } .ev.st-completada { opacity: .75; } .ev.st-no_show { background: var(--danger-soft); text-decoration: line-through; }
.ev.block { background: var(--surface-sunken); border-left-color: var(--line-strong); color: var(--ink-muted); }
.now-line { position: absolute; left: 0; right: 0; height: 2px; background: var(--danger); z-index: 2; pointer-events: none; }
.month-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.month-cell { background: var(--surface-raised); border-radius: var(--radius-sm); min-height: 96px; padding: 6px; font-size: 12px; cursor: pointer; border: 1px solid var(--line); }
.month-cell.other { opacity: .45; } .month-cell.today { border-color: var(--brand); }
.month-cell .n { font-weight: 600; } .month-cell .bar { height: 4px; border-radius: 2px; background: var(--chart-bar-active); margin-top: 6px; }
.list-ev { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.list-ev:last-child { border-bottom: 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }

/* Chat */
.inbox { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: var(--space-4); height: calc(100vh - 200px); min-height: 480px; }
.inbox .cz-card { display: flex; flex-direction: column; min-height: 0; padding: 0; overflow: hidden; }
.conv-list { overflow-y: auto; flex: 1; }
.conv { display: flex; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); cursor: pointer; align-items: flex-start; }
.conv:hover, .conv.on { background: var(--surface-sunken); }
.conv .meta { min-width: 0; flex: 1; }
.msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; background: var(--surface); }
.msg { max-width: 78%; padding: 8px 12px; border-radius: 16px; font-size: 14px; line-height: 20px; white-space: pre-wrap; word-wrap: break-word; }
.msg.in { background: var(--surface-raised); align-self: flex-start; border-bottom-left-radius: 4px; box-shadow: var(--shadow-card); }
.msg.out { background: var(--surface-inverse); color: var(--on-inverse); align-self: flex-end; border-bottom-right-radius: 4px; }
.msg.out.ia { background: var(--brand); color: var(--on-brand); }
.msg.out.flujo { background: var(--pink-700); color: #fff; }
.msg .by { display: block; font-size: 11px; opacity: .75; margin-top: 4px; }
.composer { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); background: var(--surface-raised); }
.composer .textarea { min-height: 44px; height: 44px; border-radius: 22px; padding: 11px 16px; }
@media (max-width: 900px) { .inbox { grid-template-columns: minmax(0, 1fr); height: auto; } .inbox .cz-card { height: 70vh; } .inbox.has-sel .list-card { display: none; } .inbox:not(.has-sel) .chat-card { display: none; } }

/* Barras horizontales de informes */
.hbar { display: grid; grid-template-columns: minmax(100px, 200px) minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 6px 0; font-size: 13px; }
.hbar .track { height: 10px; border-radius: 5px; background: var(--surface-sunken); overflow: hidden; }
.hbar .fill { height: 100%; background: var(--chart-bar-active); border-radius: 5px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--space-4); }
.kpi { background: var(--surface-raised); border-radius: var(--radius-lg); box-shadow: var(--shadow-card); padding: var(--space-5); min-width: 0; }
.kpi .l { font-size: 13px; font-weight: 500; color: var(--ink-muted); }
.kpi .v { font-size: 32px; line-height: 38px; font-weight: 300; margin-top: 8px; font-variant-numeric: tabular-nums; }
.kpi .c { font-size: 12px; color: var(--ink-subtle); margin-top: 4px; }
.rfm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.seg { border-radius: var(--radius-md); padding: 14px; background: var(--surface-sunken); }
.stars { color: var(--brand); letter-spacing: 2px; }

/* Flujos */
.step { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; gap: 10px; align-items: start; padding: 12px; background: var(--surface-sunken); border-radius: var(--radius-md); }
.step-n { width: 28px; height: 28px; border-radius: 50%; background: var(--surface-inverse); color: var(--on-inverse); display: grid; place-items: center; font-size: 12px; font-weight: 600; }
.step-line { width: 2px; height: 14px; background: var(--line-strong); margin-left: 25px; }

/* Settings nav */
.settings { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: var(--space-5); align-items: start; }
.settings-nav { display: grid; gap: 2px; position: sticky; top: 16px; }
.settings-nav button { font: inherit; text-align: left; padding: 10px 14px; border-radius: var(--radius-pill); border: 0; background: transparent; color: var(--ink-muted); cursor: pointer; display: flex; gap: 10px; align-items: center; }
.settings-nav button:hover { background: var(--surface-sunken); color: var(--ink); }
.settings-nav button.on { background: var(--surface-inverse); color: var(--on-inverse); }
@media (max-width: 900px) { .settings { grid-template-columns: minmax(0, 1fr); } .settings-nav { position: static; display: flex; overflow-x: auto; gap: 6px; } .settings-nav button { white-space: nowrap; background: var(--surface-raised); } }

.schedule-row { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.schedule-row:last-child { border-bottom: 0; }
.range { display: inline-flex; gap: 4px; align-items: center; margin: 2px 6px 2px 0; }
.range .input { width: 96px; min-height: 34px; padding: 4px 8px; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 10px 12px; margin-top: 8px; border-radius: 999px; background: var(--surface-sunken); }
.impersonation { background: var(--warning-soft); color: var(--warning); text-align: center; padding: 6px; font-size: 13px; }
.copy { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; background: var(--surface-sunken); padding: 8px 12px; border-radius: var(--radius-sm); word-break: break-all; }
