:root {
  color-scheme: light;
  --accent: #2563eb;
  --ink: #182232;
  --muted: #596578;
  --line: #dce2e9;
  --surface: #f4f6f9;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--surface);
  font-size: 16px;
  line-height: 1.5;
}
* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(1.35rem, 2.2vw, 2.25rem); line-height: 1.2; letter-spacing: -.035em; }
h2 { font-size: 1.4rem; letter-spacing: -.025em; }
h3 { font-size: 1.05rem; }
button, input, textarea, select { font: inherit; }
button, .button { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 44px; border: 1px solid transparent; border-radius: 9px; padding: .65rem 1rem; background: var(--ink); color: #fff; font-weight: 650; text-decoration: none; cursor: pointer; text-align: center; }
button:hover, .button:hover { filter: brightness(.93); }
button:disabled { opacity: .5; cursor: default; }
.secondary { color: var(--ink); background: #fff; border-color: var(--line); }
.danger { background: #b42333; color: #fff; }
.danger.secondary { color: #a11d2d; background: #fff; border-color: #e9bec5; }
input, textarea, select { min-width: 0; width: 100%; color: var(--ink); background: #fff; border: 1px solid #b7c0ce; border-radius: 9px; padding: .75rem; }
textarea { resize: vertical; min-height: 52px; max-height: 160px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.muted, .connection { color: var(--muted); font-size: .9rem; }
.error { color: #a11d2d; font-size: .9rem; overflow-wrap: anywhere; }
.error:empty { display: none; }
.brand-copy { min-width: 0; overflow-wrap: anywhere; }
.brand-copy p { margin-top: .25rem; }
.brand-mark { flex: 0 0 16px; width: 16px; height: 40px; border-radius: 5px; background: var(--accent); }
.header-actions, .conversation-top { display: flex; align-items: center; justify-content: space-between; gap: .75rem; min-width: 0; }
.header-actions { flex-wrap: wrap; }
.eyebrow { color: var(--muted); font-size: .85rem; font-weight: 650; margin-bottom: .25rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.chat-page { height: 100vh; height: 100dvh; }
.chat-shell { width: min(100%, 860px); height: 100%; margin: auto; display: flex; flex-direction: column; background: #fff; border-inline: 1px solid var(--line); }
.chat-header { display: flex; align-items: center; flex-wrap: wrap; gap: 1rem; padding: 1.25rem; border-bottom: 1px solid var(--line); border-top: 5px solid var(--accent); }
.chat-header .brand-copy { flex: 1; }
.chat-header h1 { font-size: 1.4rem; }
.messages { display: flex; flex-direction: column; gap: .9rem; padding: 1.25rem; overflow-y: auto; overflow-x: hidden; min-height: 0; flex: 1; overscroll-behavior: contain; }
.bubble { padding: .75rem 1rem; border-radius: 12px; max-width: min(88%, 620px); flex: 0 0 auto; min-width: 0; overflow-wrap: anywhere; }
.bubble p { white-space: pre-wrap; }
.incoming { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 3px; }
.outgoing { align-self: flex-end; background: color-mix(in srgb, var(--accent) 12%, white); border: 1px solid color-mix(in srgb, var(--accent) 32%, white); border-bottom-right-radius: 3px; }
.system-message { align-self: center; background: #f0f2f5; color: var(--muted); text-align: center; }
.message-author { display: block; font-size: .75rem; color: var(--muted); font-weight: 650; margin-bottom: .25rem; }
.message-time { display: block; font-size: .7rem; color: var(--muted); margin-top: .35rem; }
.chat-footer { padding: .75rem 1.25rem max(.75rem, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: #fff; }
.chat-footer > p { margin-bottom: .4rem; }
.chat-footer .connection { font-size: .75rem; margin: .35rem 0 0; }
.composer { display: flex; align-items: stretch; gap: .65rem; min-width: 0; }
.composer textarea { flex: 1; }
.composer button { flex-shrink: 0; align-self: flex-end; }
.panel-page { max-width: 1920px; margin: auto; padding: 2rem clamp(1rem, 3vw, 3.5rem); }
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; border-top: 5px solid var(--accent); padding-top: 1.3rem; margin-bottom: 1.5rem; }
.page-error { margin-bottom: 1rem; }
.page-retry { margin-bottom: 1rem; }
.login-card { max-width: 420px; margin: 8vh auto; padding: 2rem; background: #fff; border: 1px solid var(--line); border-radius: 14px; }
.login-card > p { margin: .6rem 0 1.5rem; }
.stack { display: flex; flex-direction: column; gap: .65rem; }
.stack button { margin-top: .75rem; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 1.25rem 1.5rem; border-top: 4px solid var(--accent); min-width: 0; }
.kpi-value { display: block; font-size: clamp(2.25rem, 4.2vw, 5rem); font-weight: 750; letter-spacing: -.05em; line-height: 1.15; margin-top: .35rem; overflow-wrap: anywhere; }
.section-heading { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .75rem; margin: 1.6rem 0 .8rem; }
.workspace { display: grid; grid-template-columns: minmax(260px, 32%) minmax(0, 1fr); height: clamp(420px, 49vh, 650px); background: #fff; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.conversation-sidebar { min-width: 0; overflow-y: auto; border-right: 1px solid var(--line); }
.conversation-item { width: 100%; display: flex; flex-direction: column; align-items: stretch; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; text-align: left; background: #fff; color: var(--ink); gap: .45rem; padding: 1rem; font-weight: 400; }
.conversation-item.selected { background: color-mix(in srgb, var(--accent) 8%, white); box-shadow: inset 4px 0 var(--accent); }
.conversation-top { flex-wrap: wrap; }
.conversation-top strong, .conversation-top h3 { min-width: 0; overflow-wrap: anywhere; }
.tag { display: inline-block; border: 1px solid var(--line); border-radius: 5px; padding: .12rem .45rem; font-size: .75rem; background: #f4f6f9; color: var(--muted); overflow-wrap: anywhere; }
.preview { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; font-size: .95rem; }
.unread { font-size: .75rem; font-weight: 700; align-self: flex-start; color: var(--ink); background: color-mix(in srgb, var(--accent) 15%, white); padding: .15rem .4rem; border-radius: 5px; }
.conversation-detail { min-width: 0; min-height: 0; }
.detail-inner { display: flex; flex-direction: column; height: 100%; }
.detail-header { display: flex; align-items: center; flex-wrap: wrap; gap: .75rem; padding: 1rem; border-bottom: 1px solid var(--line); }
.detail-header .brand-copy { flex: 1; }
.detail-composer { padding: .85rem; border-top: 1px solid var(--line); }
.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); overflow-wrap: anywhere; }
.mobile-back { display: none; }
.records-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 350px), 1fr)); gap: 1rem; }
.record-card { background: #fff; padding: 1.2rem; border: 1px solid var(--line); border-radius: 12px; min-width: 0; overflow-wrap: anywhere; transition: background-color .25s; }
.record-card > p { margin-top: .5rem; }
.record-new { background: color-mix(in srgb, var(--accent) 12%, white); box-shadow: inset 0 0 0 2px var(--accent); }
.record-data { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr); gap: .4rem .75rem; margin: 1rem 0; }
.record-data dt { color: var(--muted); }
.record-data dd { margin: 0; white-space: pre-wrap; }
.record-actions { display: flex; flex-wrap: wrap; gap: .6rem; }
.status-nuevo { color: #805000; background: #fff5d6; border-color: #e8d294; }
.status-confirmado { color: #146039; background: #e9f8ed; border-color: #b7dcc3; }
.status-cancelado { color: #983043; background: #fcecf0; border-color: #edc0cb; }
.reset-confirm { background: #fff; border: 2px solid #b42333; border-radius: 12px; padding: 1.5rem; margin-top: 1.5rem; }
.reset-confirm p { margin: .75rem 0 1rem; }
@media (min-width: 1600px) { .panel-page { font-size: 18px; } .kpi .muted { font-size: 1.1rem; } .conversation-item { padding: 1.2rem; } }
@media (max-width: 700px) {
  .panel-page { padding: .75rem; }
  .panel-header { align-items: flex-start; flex-wrap: wrap; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; }
  .kpi { padding: .8rem; }
  .kpi .muted { font-size: .8rem; }
  .workspace { display: block; height: 65vh; height: 65dvh; min-height: 360px; }
  .conversation-sidebar { height: 100%; border-right: 0; }
  .conversation-detail { display: none; height: 100%; }
  .workspace.show-detail .conversation-sidebar { display: none; }
  .workspace.show-detail .conversation-detail { display: block; }
  .mobile-back { display: inline-flex; }
  .detail-header { padding: .65rem; }
  .detail-header #mode-toggle { width: 100%; }
  .messages { padding: .85rem; }
  .chat-header { padding: .85rem; gap: .65rem; }
  .chat-header .button { width: 100%; }
  .chat-footer { padding-inline: .75rem; }
  .bubble { max-width: 92%; }
  .composer { gap: .45rem; }
  .composer button { padding-inline: .7rem; }
  .login-card { padding: 1.25rem; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }
.bubble.pending { opacity: .65; }
