:root {
  /* Marca Scalify: índigo del logotipo + barras violeta y verde */
  --bg: #F3F2F8;
  --surface: #FFFFFF;
  --ink: #0B0842;
  --muted: #625F85;
  --line: #E2E0EF;
  --brand: #4B3FE0;
  --brand-rgb: 75,63,224;
  --brand-ink: #FFFFFF;
  --accent-grad: linear-gradient(135deg, #6C63E6 0%, #4B3FE0 55%, #3B2FD6 100%);
  --bar: #FFFFFF;
  --bar-ink: #0B0842;
  --theirs: #FFFFFF;
  --accent: #1E8C49;          /* verde legible sobre blanco */
  --accent-soft: #4CCB6E;     /* verde del logo, para detalles */
  --danger: #C8283F;
  --hover: rgba(var(--brand-rgb), .07);
  --radius: 18px;
  color-scheme: light;
}
body.team { --bar: #FFFFFF; }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px; line-height: 1.4;
  background: var(--bg); color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.app { height: 100%; max-width: 720px; margin: 0 auto; background: var(--bg); position: relative; }
body.team .app { max-width: 1280px; }
.screen { height: 100%; display: flex; flex-direction: column; }

/* Barra superior */
.bar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 12px 12px 16px;
  background: var(--bar); color: var(--bar-ink); min-height: 64px;
  border-bottom: 1px solid var(--line);
}
.bar h1 { font-size: 1.15rem; font-weight: 700; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-title { flex: 1; min-width: 0; }
.bar-sub { font-size: .82rem; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-logo { width: 40px; height: 40px; border-radius: 12px; }
.icon-btn { background: none; border: 0; padding: 8px; border-radius: 50%; display: grid; place-items: center; color: inherit; }
.icon-btn:hover { background: var(--hover); }
.icon-btn svg { width: 24px; height: 24px; }
.chip { background: var(--accent-grad); color: var(--brand-ink); border: 0; border-radius: 999px; padding: 6px 14px; font-weight: 600; font-size: .9rem; flex-shrink: 0; }
.hint { margin: 0; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--line); font-size: .95rem; }

/* Pantallas centradas (bienvenida, login, avisos) */
.center { margin: auto; width: 100%; max-width: 380px; padding: 24px; text-align: center; }
.center-logo { width: 88px; height: 88px; }
.center h1 { font-size: 1.9rem; margin: 12px 0 6px; letter-spacing: -0.02em; line-height: 1.15; }
.center form { display: grid; gap: 14px; margin-top: 24px; text-align: left; }
.center code { background: var(--surface); padding: 2px 6px; border-radius: 6px; font-size: .85rem; overflow-wrap: anywhere; user-select: all; }
label { display: grid; gap: 6px; font-weight: 600; font-size: .9rem; }
.field {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); font-weight: 400; font-size: 1rem;
}
.btn { background: var(--accent-grad); color: var(--brand-ink); border: 0; border-radius: 12px; padding: 13px; font-weight: 700; width: 100%; }
.btn:disabled { opacity: .6; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: .85rem; }
.error { color: var(--danger); margin: 0; min-height: 1.2em; font-size: .9rem; }

/* Listas (panel del equipo) */
.list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; background: var(--surface); }
.list li button {
  width: 100%; display: flex; align-items: center; gap: 12px; text-align: left;
  padding: 12px 16px; background: none; border: 0; border-bottom: 1px solid var(--line);
}
.list li button:hover { background: var(--bg); }
.list li button[aria-current="true"] { background: var(--bg); box-shadow: inset 4px 0 0 var(--brand); }
.row-main { flex: 1; min-width: 0; }
.row-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.row-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-time { font-size: .8rem; color: var(--muted); flex-shrink: 0; }
.row-last { color: var(--muted); font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.unread .row-name, .unread .row-last { color: var(--ink); font-weight: 700; }
.unread .row-time { color: var(--brand); font-weight: 700; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); flex-shrink: 0; }
.avatar {
  width: 46px; height: 46px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center; font-weight: 700; color: #fff; font-size: 1.1rem;
}
.bar .avatar { width: 40px; height: 40px; font-size: 1rem; }
.empty { margin: 0; padding: 48px 32px; text-align: center; color: var(--muted); flex: 1; background: var(--surface); }
.search { padding: 10px 12px; background: var(--surface); border-bottom: 1px solid var(--line); }

/* Conversación */
.messages { flex: 1; overflow-y: auto; padding: 12px 12px 8px; display: flex; flex-direction: column; gap: 2px; }
.day { align-self: center; font-size: .78rem; color: var(--muted); background: var(--surface); padding: 3px 10px; border-radius: 999px; margin: 12px 0 8px; }
.msg {
  max-width: 78%; padding: 8px 12px 6px; border-radius: var(--radius);
  background: var(--theirs); align-self: flex-start; margin-top: 8px;
  white-space: pre-wrap; overflow-wrap: anywhere;
  box-shadow: none;
}
.msg.first-theirs { border-top-left-radius: 4px; }
.msg.mine { background: var(--accent-grad); color: var(--brand-ink); align-self: flex-end; }
.msg.mine.first-mine { border-top-right-radius: 4px; }
.msg.cont { margin-top: 0; }
.msg time { display: block; text-align: right; font-size: .7rem; opacity: .7; margin-top: 2px; }
.msg.pending { opacity: .6; }
.msg.welcome { background: transparent; box-shadow: none; border: 1.5px dashed var(--line); color: var(--muted); align-self: center; text-align: center; max-width: 90%; border-radius: 14px; }

.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 10px calc(env(safe-area-inset-bottom, 0px) + 8px);
  background: var(--bg);
}
.composer textarea {
  flex: 1; resize: none; max-height: 140px; padding: 12px 16px; border-radius: 24px;
  border: 1px solid var(--line); background: var(--surface); font-size: 1rem; line-height: 1.35;
}
.send { width: 48px; height: 48px; border-radius: 50%; border: 0; background: var(--accent-grad); color: var(--brand-ink); display: grid; place-items: center; flex-shrink: 0; }
.send svg { width: 22px; height: 22px; }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 90px); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; max-width: 90%;
  font-size: .92rem; z-index: 10;
}

/* Panel del equipo: lista + conversación lado a lado en pantallas grandes */
.split { flex: 1; display: flex; min-height: 0; }
.pane { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.split:not(.has-chat) .pane-chat { display: none; }
.split.has-chat .pane-list { display: none; }
.pane-placeholder { margin: auto; color: var(--muted); padding: 24px; text-align: center; }
@media (min-width: 900px) {
  .split .pane-list { display: flex !important; flex: 0 0 360px; border-right: 1px solid var(--line); }
  .split .pane-chat { display: flex !important; }
  .only-mobile { display: none !important; }
}

@media (prefers-reduced-motion: no-preference) {
  .msg.new { animation: pop .18s ease-out; }
  @keyframes pop { from { transform: scale(.96); opacity: 0; } }
}

/* Chat dentro de la landing (modo incrustado) */
.embed-close {
  position: fixed; top: calc(env(safe-area-inset-top, 0px) + 12px); right: 10px; z-index: 5;
  width: 40px; height: 40px; border-radius: 50%; border: 0; display: none; place-items: center;
  background: var(--hover); color: var(--ink);
}
.embed-close:hover { background: rgba(var(--brand-rgb),.14); }
.embed-close svg { width: 22px; height: 22px; }
body.embedded .embed-close { display: grid; }
body.embedded .bar { padding-right: 60px; }

/* Títulos con la tipografía de la marca */
.bar h1, .center h1 { font-family: "Poppins", "Inter", sans-serif; font-weight: 700; letter-spacing: -.01em; }
.msg.mine { box-shadow: 0 6px 16px -8px rgba(var(--brand-rgb),.55); }
.msg:not(.mine):not(.welcome) { box-shadow: 0 1px 2px rgba(11,8,66,.08); }
.bar-logo { background: var(--bg); }
.msg.mine time.fail { color: #FFE1E6; font-weight: 700; opacity: 1; }

/* Aviso para activar notificaciones */
.push-bar { display: flex; align-items: center; gap: 10px; padding: 10px 8px 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); font-size: .92rem; }
.push-bar span { flex: 1; }
.push-bar .icon-btn { padding: 6px; }
.push-bar .icon-btn svg { width: 18px; height: 18px; }

/* Archivos adjuntos */
.attach-btn { width: 44px; height: 48px; border: 0; background: none; color: var(--muted); display: grid; place-items: center; flex-shrink: 0; border-radius: 50%; }
.attach-btn:hover { color: var(--brand); background: var(--hover); }
.attach-btn svg { width: 22px; height: 22px; }
.att-preview { display: flex; align-items: center; gap: 10px; margin: 0 10px; padding: 8px 8px 8px 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; position: relative; overflow: hidden; }
.att-thumb { width: 48px; height: 48px; object-fit: cover; border-radius: 10px; flex-shrink: 0; }
.att-ico { width: 44px; height: 44px; border-radius: 10px; background: var(--bg); display: grid; place-items: center; font-size: 1.4rem; flex-shrink: 0; }
.att-meta { flex: 1; min-width: 0; display: grid; }
.att-meta strong { font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att-meta small { font-size: .78rem; color: var(--muted); }
.att-bar { position: absolute; left: 0; bottom: 0; height: 3px; width: var(--p, 0%); background: var(--brand); transition: width .2s; }
.att { margin: -2px -6px 6px; }
.att:empty { display: none; }
.att-img { display: block; max-width: min(260px, 100%); max-height: 320px; border-radius: 12px; object-fit: cover; background: rgba(0,0,0,.05); }
.att-audio { display: block; width: 240px; max-width: 100%; }
.att-file { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; background: rgba(255,255,255,.14); border-radius: 12px; padding: 8px 10px; min-width: 200px; }
.msg:not(.mine) .att-file { background: var(--bg); }
.msg.mine .att-file .att-ico { background: rgba(255,255,255,.2); }
.msg.mine .att-meta small { color: rgba(255,255,255,.8); }

/* Ruleta */
.wheel { position: relative; margin: 0 auto; max-width: 100%; aspect-ratio: 1; }
.wheel svg { width: 100%; height: 100%; display: block; filter: drop-shadow(0 12px 24px rgba(11,8,66,.25)); }
.wheel-rot { transform-box: view-box; transform-origin: 150px 150px; }
.wheel-pointer { position: absolute; top: -6px; left: 50%; transform: translateX(-50%); width: 0; height: 0;
  border-left: 15px solid transparent; border-right: 15px solid transparent; border-top: 30px solid #F2B134; filter: drop-shadow(0 3px 3px rgba(0,0,0,.3)); }

.wheel-bar { background: linear-gradient(90deg, rgba(76,203,110,.14), rgba(var(--brand-rgb),.12)); font-weight: 600; }
.wheel-modal { position: fixed; inset: 0; z-index: 40; background: rgba(11,8,66,.55); display: grid; place-items: center; padding: 16px; }
.wm-card { position: relative; width: min(380px, 100%); background: var(--surface); border-radius: 22px; padding: 26px 20px 20px; text-align: center; display: grid; gap: 12px; box-shadow: 0 24px 60px rgba(11,8,66,.35); }
.wm-card h2 { margin: 0; font-family: "Poppins", "Inter", sans-serif; font-size: 1.35rem; }
.wm-card .muted { margin: -6px 0 6px; }
.wm-close { position: absolute; top: 10px; right: 10px; }
.wm-card .btn { font-size: 1.05rem; padding: 14px; }
.wm-result { margin: 0; font-weight: 700; font-size: 1.05rem; padding: 10px; border-radius: 12px; background: var(--bg); }
.wm-result.won { background: rgba(76,203,110,.16); color: #14803F; }
.wm-terms { font-size: .8rem; color: var(--muted); }

/* Asistente virtual */
.bot-head { display: flex; align-items: center; gap: 7px; margin: -2px 0 5px; font-size: .78rem; color: var(--brand); }
.bot-av { width: 22px; height: 22px; display: inline-block; flex-shrink: 0; }
.bot-av svg, .typing-av svg { width: 100%; height: 100%; display: block; }
.typing { display: flex; align-items: center; gap: 8px; padding: 4px 16px 8px; font-size: .82rem; color: var(--muted); }
.typing-av { width: 22px; height: 22px; display: inline-block; }
.typing-dots { display: inline-flex; gap: 3px; }
.typing-dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--muted); animation: tdot 1.2s infinite ease-in-out; }
.typing-dots i:nth-child(2) { animation-delay: .15s; } .typing-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes tdot { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
@media (prefers-reduced-motion: reduce) { .typing-dots i { animation: none; opacity: .6; } }

/* Raspadita */
.scratch { position: relative; margin: 0 auto; max-width: 100%; aspect-ratio: 1; border-radius: 20px; padding: 8px;
  background: linear-gradient(150deg, #FFE58A, #F2B43B 35%, #B8650C 72%, #F2B43B);
  box-shadow: 0 0 0 3px #0B0842, 0 14px 30px rgba(11,8,66,.35); }
.scratch-grid { position: absolute; inset: 8px; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); gap: 6px; padding: 6px; border-radius: 14px;
  background: radial-gradient(circle at 50% 30%, #3B2FD6, #0B0842 80%); }
.scratch-cell { display: grid; place-items: center; border-radius: 12px; background: rgba(255,255,255,.07); box-shadow: inset 0 1px 0 rgba(255,255,255,.15); transition: opacity .3s; }
.scratch-coin { --coin: #4B3FE0; width: 82%; aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, rgba(255,255,255,.55), transparent 45%), var(--coin);
  border: 3px solid #FFD66B; box-shadow: 0 3px 0 #9A5200, 0 6px 10px rgba(0,0,0,.35); }
.scratch-coin b { color: #fff; font-family: "Poppins", "Inter", sans-serif; font-weight: 800; font-size: clamp(.72rem, 3.6vw, .95rem); text-shadow: 0 1px 2px rgba(0,0,0,.6); letter-spacing: -.01em; }
.scratch.won .scratch-cell:not([data-hit]) { opacity: .35; }
.scratch.won .scratch-cell[data-hit] { animation: scratch-glow .8s ease-in-out infinite alternate; }
@keyframes scratch-glow { from { transform: scale(1); box-shadow: 0 0 0 rgba(255,214,107,0); } to { transform: scale(1.07); box-shadow: 0 0 22px rgba(255,214,107,.95); } }
.scratch-foil { position: absolute; inset: 8px; width: calc(100% - 16px); height: calc(100% - 16px); border-radius: 14px; touch-action: none; cursor: grab; transition: opacity .35s; }
.scratch-foil.gone { opacity: 0; }
.scratch-cover { position: absolute; inset: 8px; border-radius: 14px; display: grid; place-content: center; gap: 6px; text-align: center; color: #fff;
  background: radial-gradient(circle at 50% 35%, #6C63E6, #0B0842 85%); }
.scratch-cover strong { font-family: "Poppins", "Inter", sans-serif; font-size: 1.3rem; }
.scratch-cover span { font-size: .85rem; opacity: .85; }
.scratch-bar { background: linear-gradient(90deg, rgba(242,180,59,.22), rgba(var(--brand-rgb),.12)); font-weight: 600; }
.scratch-mini { width: 118px; height: 118px; flex-shrink: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 8px; border-radius: 16px;
  background: linear-gradient(150deg, #FFE58A, #F2B43B 40%, #B8650C); box-shadow: 0 0 0 2px #0B0842; }
.scratch-mini i { border-radius: 50%; background: #0B0842; border: 2px solid #FFD66B; }
.wm-big { margin: 0; font-family: "Poppins", "Inter", sans-serif; font-weight: 800; font-size: 1.7rem; color: #B8650C; animation: wm-boom .55s cubic-bezier(.2,1.6,.4,1) both; }
@keyframes wm-boom { from { transform: scale(.3); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .scratch.won .scratch-cell[data-hit], .wm-big { animation: none; } }

/* Enlaces dentro de los mensajes */
.msg a { color: inherit; text-decoration: underline; text-underline-offset: 2px; overflow-wrap: anywhere; word-break: break-word; }
.msg a:hover { opacity: .85; }
