/* Estilos de la app. Colores y tipografía vienen de tokens.css. Mobile-first. */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { display: flex; flex-direction: column; min-height: 100vh; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
a { color: var(--accent); }
.muted { color: var(--ink-3); }

/* Barra superior */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); margin-right: auto; }
.brand-mark {
  width: 28px; height: 28px; border-radius: var(--r-sm);
  background: var(--accent);
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-text .eyebrow { font-size: 10px; }
.brand-text strong { font-family: var(--font-display); font-weight: 600; font-size: 17px; letter-spacing: -0.02em; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.theme-toggle {
  border: 1px solid var(--rule-strong); background: transparent; color: var(--ink-2);
  width: 34px; height: 34px; border-radius: var(--r-pill); cursor: pointer; font-size: 16px;
}

/* Layout */
.main { flex: 1; width: 100%; max-width: var(--max); margin: 0 auto; padding: 24px 16px 40px; }
.view.center { display: flex; align-items: center; justify-content: center; min-height: 40vh; }
.hero { margin: 8px 0 24px; }
.hero h1 { margin: 6px 0 8px; }
.hero .lead { margin: 0; max-width: var(--prose); }

/* Tarjetas */
.card {
  background: var(--bg); border: 1px solid var(--rule); border-radius: var(--r-lg);
  box-shadow: var(--e2); padding: 24px;
}
.login-card { max-width: 440px; margin: 6vh auto 0; }
.login-card h1 { margin: 6px 0 10px; font-size: clamp(26px, 5vw, 34px); }
.login-card .lead { font-size: 17px; margin: 0 0 20px; }
.login-card .caption { margin: 16px 0 0; }
.placeholder { border-style: dashed; box-shadow: none; background: var(--band); }
.placeholder h3 { margin: 0 0 6px; }
.placeholder p { margin: 0; }

/* Formularios */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; margin-bottom: 6px; color: var(--ink-2); font-weight: 500; }
.field input {
  width: 100%; font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--field); border-radius: var(--r-md); padding: 12px 14px;
  transition: border-color var(--dur-2) var(--ease-std), box-shadow var(--dur-2) var(--ease-std);
}
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
.form-error { color: var(--bad); margin: 0 0 12px; }

/* Botones */
.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border-radius: var(--r-pill); padding: 12px 20px; border: 1px solid transparent;
  transition: background var(--dur-2) var(--ease-std), transform var(--dur-1) var(--ease-std);
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-press); }
.btn-ghost { background: transparent; color: var(--ink-2); border-color: var(--rule-strong); padding: 8px 14px; }
.btn-ghost:hover { background: var(--band); }
.btn-block { width: 100%; }

/* Pie */
.footer {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px 16px; border-top: 1px solid var(--rule); background: var(--band);
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); display: inline-block; }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--bad); }
.sep { opacity: .5; }

@media (min-width: 720px) {
  .main { padding: 40px 24px 64px; }
  .topbar { padding: 12px 24px; }
}

/* Chat */
.chat { padding: 0; display: flex; flex-direction: column; min-height: 60vh; max-height: calc(100vh - 220px); overflow: hidden; }
.chat-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--rule); background: var(--band); }
.chat-actions { display: flex; gap: 8px; }
.chat-messages { flex: 1; overflow-y: auto; padding: 16px 14px; display: flex; flex-direction: column; gap: 12px; scroll-behavior: smooth; }
.msg { max-width: 88%; padding: 10px 14px; border-radius: var(--r-lg); line-height: 1.55; font-size: 15px; word-wrap: break-word; }
.msg p { margin: 0 0 8px; } .msg p:last-child { margin-bottom: 0; }
.msg ol, .msg ul { margin: 6px 0 8px; padding-left: 22px; } .msg li { margin: 2px 0; }
.msg-user { align-self: flex-end; background: var(--accent); color: var(--on-accent); border-bottom-right-radius: var(--r-sm); }
.msg-assistant { align-self: flex-start; background: var(--surface-2); color: var(--ink); border-bottom-left-radius: var(--r-sm); }
.msg-error { align-self: center; background: transparent; color: var(--bad); border: 1px dashed var(--bad); font-size: 14px; }
.msg-welcome { align-self: flex-start; color: var(--ink-2); background: transparent; padding-left: 4px; max-width: 100%; }
.msg-welcome p { margin: 0 0 8px; }
.examples { display: flex; flex-wrap: wrap; gap: 6px; }
.example { font: inherit; font-size: 13px; color: var(--accent); background: var(--accent-wash); border: 1px solid transparent; border-radius: var(--r-pill); padding: 6px 12px; cursor: pointer; text-align: left; }
.example:hover { border-color: var(--accent); }
.typing { display: inline-flex; gap: 4px; align-items: center; height: 1em; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-3); animation: blink 1.2s infinite var(--ease-std); }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.chat-form { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--rule); background: var(--bg); }
.chat-form textarea { flex: 1; resize: none; font: inherit; font-size: 15px; color: var(--ink); background: var(--bg); border: 1px solid var(--field); border-radius: var(--r-lg); padding: 10px 14px; max-height: 160px; line-height: 1.4; }
.chat-form textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
.chat-send { padding: 10px 18px; align-self: flex-end; }
.chat-hint { margin: 0; padding: 0 14px 10px; }
@media (max-width: 480px) { .chat-toolbar .btn-ghost { padding: 6px 10px; font-size: 13px; } .msg { max-width: 94%; } }

/* Feedback y estado de la conversación */
.chat-banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 14px; background: var(--accent-wash); color: var(--ink-2); border-bottom: 1px solid var(--rule); }
.msg-wrap { display: flex; flex-direction: column; align-self: flex-start; max-width: 88%; gap: 4px; }
.msg-wrap .msg { max-width: 100%; }
.fb { display: flex; gap: 6px; align-items: center; padding-left: 6px; }
.fb button { border: 1px solid transparent; background: transparent; color: var(--ink-3); font-size: 15px; line-height: 1; padding: 4px 7px; border-radius: var(--r-pill); cursor: pointer; transition: background var(--dur-2) var(--ease-std), color var(--dur-2) var(--ease-std); }
.fb button:hover { background: var(--surface-2); color: var(--ink); }
.fb button.active { background: var(--accent-wash); color: var(--accent); border-color: var(--accent); }
.fb button:disabled { cursor: default; opacity: .6; }
.fb-ask { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 6px 6px 0; font-size: 14px; color: var(--ink-2); }
.fb-ask .btn { padding: 6px 12px; font-size: 13px; }
.fb-comment { display: flex; gap: 6px; padding: 6px 6px 0; }
.fb-comment input { flex: 1; font: inherit; font-size: 14px; color: var(--ink); background: var(--bg); border: 1px solid var(--field); border-radius: var(--r-pill); padding: 6px 12px; }
.fb-comment input:focus { outline: none; border-color: var(--accent); }
.fb-comment .btn { padding: 6px 12px; font-size: 13px; }
.fb-thanks { font-size: 13px; color: var(--ok); padding-left: 8px; transition: opacity var(--dur-5) var(--ease-std); }
.fb-fade { animation: fbin var(--dur-3) var(--ease-std); }
.fb-dim { opacity: .55; }
@keyframes fbin { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }
.typing-label { font-size: 13px; color: var(--ink-3); margin-left: 4px; }

/* Historial de conversaciones (versión mínima) */
.chat-history { border-bottom: 1px solid var(--rule); background: var(--bg); max-height: 40vh; overflow-y: auto; }
.chat-history-title { margin: 0; padding: 10px 14px 4px; }
.chat-history-list { list-style: none; margin: 0; padding: 0 8px 8px; }
.chat-history-list li { display: flex; align-items: center; gap: 10px; padding: 8px 8px; border-radius: var(--r-md); cursor: pointer; font-size: 14px; }
.chat-history-list li:hover { background: var(--band); }
.chat-history-list li.current { background: var(--accent-wash); }
.chat-history-list .h-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
.chat-history-list .h-meta { display: flex; gap: 8px; align-items: center; flex-shrink: 0; color: var(--ink-3); font-size: 12px; font-variant-numeric: tabular-nums; }
.h-status { padding: 1px 8px; border-radius: var(--r-pill); background: var(--surface-2); color: var(--ink-2); }
.h-status.open { background: var(--accent-wash); color: var(--accent); }
.h-status.resolved { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.h-status.escalated { background: var(--surface-2); color: var(--ink-2); }
.chat-history-empty { padding: 6px 8px 10px; color: var(--ink-3); font-size: 14px; }

/* Crear ticket */
.ticket-panel { padding: 16px 14px; border-bottom: 1px solid var(--rule); background: var(--band); }
.ticket-panel h3 { margin: 4px 0 6px; }
.ticket-panel .field textarea { width: 100%; font: inherit; font-size: 14px; color: var(--ink); background: var(--bg); border: 1px solid var(--field); border-radius: var(--r-md); padding: 10px 12px; line-height: 1.5; resize: vertical; }
.ticket-panel .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
.ticket-actions { display: flex; gap: 8px; justify-content: space-between; align-items: center; flex-wrap: wrap; }
.ticket-actions-left { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ticket-actions-right { display: flex; gap: 8px; margin-left: auto; }
@media (max-width: 480px) { .attach-hint { display: none; } }
.ticket-loading { padding: 8px 0 4px; }

/* Panel de ticket abierto: ocupa la tarjeta, con su propio scroll; el chat queda oculto hasta cerrar */
.chat.ticket-open .chat-messages, .chat.ticket-open .chat-form, .chat.ticket-open .chat-hint, .chat.ticket-open .chat-history { display: none; }
.chat.ticket-open .ticket-panel { flex: 1; overflow-y: auto; border-bottom: 0; }
.ticket-panel .ticket-actions { position: sticky; bottom: 0; padding: 10px 0 2px; background: var(--band); }

/* Adjuntos del ticket */
.attach-list { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 6px; }
.attach-list:empty { display: none; }
.attach-list li { display: flex; align-items: center; gap: 8px; font-size: 14px; background: var(--bg); border: 1px solid var(--rule); border-radius: var(--r-md); padding: 6px 10px; }
.attach-list .a-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-list .a-size { color: var(--ink-3); font-size: 12px; font-variant-numeric: tabular-nums; }
.attach-list .a-remove { border: 0; background: transparent; color: var(--ink-3); cursor: pointer; font-size: 16px; line-height: 1; padding: 0 4px; }
.attach-list .a-remove:hover { color: var(--bad); }

/* Adjuntos en el chat */
.chat-clip { padding: 10px 12px; align-self: flex-end; font-size: 16px; line-height: 1; }
.chat-attach-list { list-style: none; margin: 0; padding: 6px 12px 0; display: flex; flex-wrap: wrap; gap: 6px; border-top: 1px solid var(--rule); background: var(--bg); }
.chat-attach-list:empty { display: none; }
.chat-attach-list li { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; background: var(--surface-2); border-radius: var(--r-pill); padding: 4px 10px; max-width: 100%; }
.chat-attach-list .a-name { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-attach-list .a-remove { border: 0; background: transparent; color: var(--ink-3); cursor: pointer; font-size: 14px; padding: 0 2px; }
.msg-files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.msg-files a { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; text-decoration: none; color: inherit; background: rgba(255,255,255,.18); border-radius: var(--r-md); padding: 4px 8px; }
.msg-files img { display: block; max-width: 220px; max-height: 160px; border-radius: var(--r-md); border: 1px solid rgba(255,255,255,.25); }

/* Modal del modo administrador */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(14,16,21,.55); backdrop-filter: blur(4px); }
.modal-card { width: 100%; max-width: 400px; }
.modal-card h3 { margin: 4px 0 14px; }
