:root {
  --bg: #f7f8fc;
  --surface: #ffffff;
  --surface-alt: #eef0fa;
  --text: #1e2233;
  --text-mut: #5b6178;
  --border: #e1e4f0;
  --accent: #0f5c85;
  --accent-ink: #ffffff;
  --danger: #b91c1c;
  --danger-bg: #fee2e2;
  --rapida: #15803d;
  --rapida-bg: #dcfce7;
  --investigado: #b45309;
  --investigado-bg: #fef3c7;
  --shadow: 0 1px 2px rgba(30, 34, 51, 0.05), 0 6px 16px -8px rgba(30, 34, 51, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121320;
    --surface: #181a29;
    --surface-alt: #1f2236;
    --text: #e7e8f2;
    --text-mut: #9297ae;
    --border: #2b2e45;
    --accent: #5fa8d6;
    --accent-ink: #121320;
    --danger: #fca5a5;
    --danger-bg: #3a1414;
    --rapida: #4ade80;
    --rapida-bg: #123322;
    --investigado: #fbbf24;
    --investigado-bg: #3a2c0c;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 6px 16px -8px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  display: flex;
  flex-direction: column;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
}

header.app-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(0.9rem + env(safe-area-inset-top)) 1.2rem 0.9rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

header.app-bar .brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  color: var(--accent);
}

.brand-icon {
  width: 26px;
  height: 26px;
  border-radius: 7px;
}

.login-logo {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  align-self: center;
  box-shadow: var(--shadow);
}

header.app-bar button {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-mut);
  border-radius: 8px;
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
  cursor: pointer;
}

/* ---------- login ---------- */

#login-view {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.login-card {
  width: 100%;
  max-width: 320px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 2rem 1.6rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  text-align: center;
}

.login-card input,
.login-card button,
.login-error {
  width: 100%;
}

.login-card h1 {
  margin: 0 0 0.2rem;
  font-size: 1.4rem;
  color: var(--accent);
}

.login-card p.sub {
  margin: 0;
  color: var(--text-mut);
  font-size: 0.9rem;
}

.login-card input {
  padding: 0.65rem 0.8rem;
  border-radius: 9px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

.login-card button {
  padding: 0.7rem;
  border-radius: 9px;
  border: none;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.login-error {
  color: var(--danger);
  background: var(--danger-bg);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  font-size: 0.85rem;
  display: none;
}

/* ---------- chat ---------- */

#chat-view {
  flex: 1;
  display: none;
  flex-direction: column;
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
  padding: 1rem;
  gap: 1rem;
}

#messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  overflow-y: auto;
}

.msg {
  padding: 0.8rem 1rem;
  border-radius: 12px;
  max-width: 85%;
  font-size: 0.95rem;
  line-height: 1.5;
}

.msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--accent-ink);
}

.msg.bot {
  align-self: flex-start;
  max-width: 92%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 0.9rem 1.1rem 0.8rem;
}

.msg.bot .card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}

.msg.bot .card-title {
  font-weight: 700;
  color: var(--accent);
}

.chip {
  flex: none;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.2em 0.6em;
  border-radius: 999px;
  white-space: nowrap;
}

.chip-rapida { background: var(--rapida-bg); color: var(--rapida); }
.chip-investigado { background: var(--investigado-bg); color: var(--investigado); }
.chip-prueba { background: var(--surface-alt); color: var(--text-mut); }

.msg.bot .card-body .linea {
  margin-bottom: 0.3rem;
}

.msg.bot .card-body p {
  margin: 0 0 0.5rem;
}

.msg.bot .card-body p:last-child {
  margin-bottom: 0;
}

.msg.bot .tabla-wrap {
  overflow-x: auto;
  margin: 0.4rem 0 0.7rem;
}

.msg.bot table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.88rem;
}

.msg.bot th, .msg.bot td {
  text-align: left;
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.msg.bot th {
  color: var(--text-mut);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.acciones {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px dashed var(--border);
}

.btn-accion {
  align-self: flex-start;
  background: var(--accent-soft, var(--surface-alt));
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.4rem 0.9rem;
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
}

.accion-nota {
  font-size: 0.78rem;
  color: var(--text-mut);
  font-style: italic;
}

.msg.bot .source {
  margin-top: 0.5rem;
  font-size: 0.72rem;
  color: var(--text-mut);
}

#ask-form {
  display: flex;
  gap: 0.6rem;
}

#mic-btn {
  flex: none;
  width: 2.7rem;
  height: 2.7rem;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-size: 1.15rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
}

#mic-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#mic-btn.listening {
  background: var(--accent);
  border-color: var(--accent);
  animation: pulse 1.1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(15, 92, 133, 0.35); }
  50% { box-shadow: 0 0 0 8px rgba(15, 92, 133, 0); }
}

#texto {
  flex: 1;
  padding: 0.75rem 1rem;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
}

#ask-form button {
  padding: 0.75rem 1.3rem;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  cursor: pointer;
}
