* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #273549;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #6366f1;
  --user: #4f46e5;
}

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.hidden { display: none !important; }

/* Login */
.login {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  z-index: 10;
}
.login-card {
  text-align: center;
  padding: 2rem;
  width: min(90vw, 340px);
}
.login-logo { font-size: 3.5rem; }
.login-logo-img { width: 110px; height: 110px; border-radius: 26px; }
.header-avatar { width: 26px; height: 26px; border-radius: 8px; vertical-align: -6px; margin-right: .2rem; }
.login-card h1 { margin: .5rem 0 .25rem; }
.login-card p { color: var(--muted); margin-bottom: 1.25rem; }
.login-card input {
  width: 100%; padding: .8rem 1rem; border-radius: 12px;
  border: 1px solid var(--panel-2); background: var(--panel); color: var(--text);
  font-size: 1rem; margin-bottom: .75rem;
}
.login-card button {
  width: 100%; padding: .8rem; border-radius: 12px; border: none;
  background: var(--accent); color: white; font-size: 1rem; cursor: pointer;
}
.login-error { color: #f87171; margin-top: .75rem; min-height: 1.2em; }

/* App */
/* Anclada a la pantalla VISIBLE real del iPhone (variable --vvh medida por JS
   con visualViewport; arregla el hueco que deja el teclado al cerrarse). */
.app {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--vvh, 100dvh);
  display: flex; flex-direction: column;
}
html, body { overflow: hidden; height: 100%; position: fixed; width: 100%; }
.msg b { font-weight: 700; }
.msg code { background: rgba(255,255,255,.12); padding: 0 .3em; border-radius: 4px; }

header {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + .6rem) 1rem .6rem;
  background: var(--panel);
  border-bottom: 1px solid var(--panel-2);
}
header .title { font-weight: 600; }
header .usage { color: var(--muted); font-size: .8rem; }

.push-banner {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  background: #78350f; color: #fef3c7;
  padding: .5rem .9rem; font-size: .85rem;
}
.push-banner button {
  border: none; border-radius: 8px; padding: .4rem .7rem;
  background: var(--accent); color: white; cursor: pointer; font-size: .85rem;
  flex-shrink: 0;
}

main {
  flex: 1; overflow-y: auto;
  padding: 1rem;
  display: flex; flex-direction: column; gap: .5rem;
}

.msg {
  max-width: 85%;
  padding: .6rem .9rem;
  border-radius: 16px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: .95rem;
}
.msg.user { align-self: flex-end; background: var(--user); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--panel); border-bottom-left-radius: 4px; }
.msg.notice {
  align-self: center; background: transparent; color: var(--muted);
  border: 1px dashed var(--panel-2); font-size: .85rem; max-width: 95%;
}
.msg .time { display: block; font-size: .7rem; color: rgba(255,255,255,.5); margin-top: .25rem; }

.quote-bar {
  display: flex; align-items: center; gap: .5rem;
  background: var(--panel-2); border-left: 3px solid var(--accent);
  margin: 0 .75rem; padding: .45rem .7rem; border-radius: 10px 10px 0 0;
  font-size: .8rem; color: var(--muted);
}
.quote-bar span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quote-bar button { border: none; background: none; color: var(--muted); font-size: 1rem; cursor: pointer; }
.msg { cursor: pointer; }
.msg .quote {
  display: block; border-left: 3px solid rgba(255,255,255,.4);
  padding-left: .5rem; margin-bottom: .35rem; opacity: .75; font-size: .85em;
}

footer {
  display: flex; align-items: flex-end; gap: .5rem;
  padding: .6rem .75rem calc(env(safe-area-inset-bottom) + .6rem);
  background: var(--panel);
  border-top: 1px solid var(--panel-2);
}
footer textarea {
  flex: 1; resize: none; border: none; outline: none;
  background: var(--panel-2); color: var(--text);
  border-radius: 14px; padding: .7rem 1rem; font-size: 1rem;
  max-height: 30dvh;
  font-family: inherit;
}
footer button {
  border: none; background: var(--accent); color: white;
  width: 44px; height: 44px; border-radius: 50%;
  font-size: 1.1rem; cursor: pointer; flex-shrink: 0;
}
footer button#micBtn, footer button#attachBtn { background: var(--panel-2); }
footer button#micBtn.recording { background: #dc2626; animation: pulse 1.2s infinite; }

@keyframes pulse { 50% { opacity: .6; } }
