/* Paleta: negro sobrio + dorado sutil (identidad UTN) */
:root {
  --bg: #0c0c0e;
  --surface: #151518;
  --surface-2: #1c1c21;
  --border: #26262c;
  --text: #e8e6e1;
  --muted: #98948b;
  --gold: #c9a227;
  --gold-text: #d6b14a;      /* algo más claro para texto chico sobre negro */
  --gold-hairline: rgba(201, 162, 39, 0.35);
  --gold-tint: rgba(201, 162, 39, 0.08);
  --radius: 14px;
}

* { box-sizing: border-box; }

/* Los display de autor (flex/grid) pisan el display:none del UA para [hidden];
   sin esto, #user-chip, #gate y #workspace ignoran el atributo hidden. */
[hidden] { display: none !important; }

html { color-scheme: dark; }

body {
  margin: 0;
  overflow-x: hidden;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* ---------- Header ---------- */

header {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.85rem 1.1rem calc(0.85rem - 1px);
  border-bottom: 1px solid var(--border);
  background:
    linear-gradient(to bottom, rgba(201, 162, 39, 0.05), transparent 70%),
    var(--bg);
}

.logo {
  width: 30px;
  height: 35px;
  color: var(--gold);
  flex-shrink: 0;
}

header h1 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.subtitle {
  margin: 0.1rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
  letter-spacing: 0.01em;
}

#user-chip {
  margin-left: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.15rem;
  font-size: 0.72rem;
  min-width: 0;
}

#user-email {
  color: var(--muted);
  max-width: 38vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#user-chip a {
  color: var(--gold-text);
  text-decoration: none;
}

#user-chip a:hover {
  text-decoration: underline;
}

/* ---------- Chat ---------- */

#chat {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

#chat > * {
  width: 100%;
  max-width: 46rem;
  margin-inline: auto;
  display: flex;
  flex-direction: column;
}

/* Estado vacío */
#empty-state {
  flex: 1;
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 1.4rem;
  padding: 1rem 0;
}

.watermark {
  width: 84px;
  height: 99px;
  color: var(--gold);
  opacity: 0.5;
}

.greeting {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.6;
  max-width: 32rem;
}

.suggestions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 100%;
  max-width: 30rem;
}

.chip {
  white-space: normal;   /* los botones no quiebran línea por defecto y desbordan en mobile */
  min-width: 0;
  padding: 0.65rem 1rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.chip:hover {
  border-color: var(--gold-hairline);
  background: var(--gold-tint);
}

/* Burbujas */
.bubble {
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  line-height: 1.55;
  font-size: 0.95rem;
  overflow-wrap: break-word;
}

.bubble.user {
  align-self: flex-end;
  max-width: min(85%, 46rem);
  background: var(--surface-2);
  border: 1px solid var(--gold-hairline);
  border-bottom-right-radius: 4px;
}

.bubble.bot {
  align-self: flex-start;
  max-width: min(92%, 46rem);
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* Contenido markdown dentro de la respuesta */
.bubble.bot > :first-child, .bubble.bot p:first-child { margin-top: 0; }
.bubble.bot > :last-child, .bubble.bot p:last-child { margin-bottom: 0; }

.bubble.bot h1, .bubble.bot h2, .bubble.bot h3 {
  font-size: 0.95rem;
  margin: 0.9rem 0 0.35rem;
  color: var(--gold-text);
  font-weight: 600;
}

.bubble.bot ul, .bubble.bot ol { padding-left: 1.25rem; margin: 0.4rem 0; }
.bubble.bot li { margin: 0.2rem 0; }
.bubble.bot a { color: var(--gold-text); }
.bubble.bot code {
  background: var(--surface-2);
  padding: 0.1em 0.35em;
  border-radius: 5px;
  font-size: 0.85em;
}
.bubble.bot blockquote {
  margin: 0.5rem 0;
  padding: 0.1rem 0 0.1rem 0.8rem;
  border-left: 2px solid var(--gold-hairline);
  color: var(--muted);
}

/* Indicador de escritura */
.typing {
  display: inline-flex;
  gap: 5px;
  padding: 0.35rem 0;
}

.typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: pulse 1.2s ease-in-out infinite;
}

.typing i:nth-child(2) { animation-delay: 0.18s; }
.typing i:nth-child(3) { animation-delay: 0.36s; }

@keyframes pulse {
  0%, 60%, 100% { opacity: 0.25; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

@media (prefers-reduced-motion: reduce) {
  #chat { scroll-behavior: auto; }
  .typing i { animation: none; opacity: 0.6; }
}

/* Fuentes citadas */
.sources {
  margin-top: 0.6rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--muted);
}

.sources summary {
  cursor: pointer;
  color: var(--gold-text);
  opacity: 0.8;
  user-select: none;
}

.sources summary:hover { opacity: 1; }
.sources ul { margin: 0.4rem 0 0; padding-left: 1.1rem; }
.sources li { margin: 0.15rem 0; }
.sources a { color: inherit; text-decoration: underline; }
.sources a:hover { color: var(--gold-text); }

.bubble-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.55rem;
  padding-top: 0.45rem;
  border-top: 1px solid var(--border);
}

.feedback-button {
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.72rem;
  cursor: pointer;
  padding: 0.15rem 0;
}

.feedback-button:hover { color: var(--gold-text); }
.feedback-button.reported { color: var(--gold-text); cursor: default; }

/* ---------- Input ---------- */

footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 0.75rem 1rem calc(0.6rem + env(safe-area-inset-bottom));
}

#chat-form {
  display: flex;
  gap: 0.5rem;
  max-width: 46rem;
  margin-inline: auto;
}

#question {
  flex: 1;
  padding: 0.65rem 1rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.15s ease;
}

#question::placeholder { color: var(--muted); }

#question:focus {
  outline: none;
  border-color: var(--gold-hairline);
}

#send {
  padding: 0.65rem 1.25rem;
  border: 1px solid var(--gold-hairline);
  border-radius: 999px;
  background: transparent;
  color: var(--gold-text);
  font-size: 0.95rem;
  font-family: inherit;
  font-weight: 500;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

#send:hover:not(:disabled) {
  background: var(--gold-tint);
  border-color: var(--gold);
}

#send:disabled { opacity: 0.4; cursor: wait; }

:focus-visible {
  outline: 2px solid var(--gold-hairline);
  outline-offset: 2px;
}

.disclaimer {
  margin: 0.55rem auto 0;
  max-width: 46rem;
  font-size: 0.7rem;
  color: var(--muted);
  text-align: center;
  opacity: 0.8;
}

/* ---------- Playground admin (/admin) ---------- */

.badge {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--bg);
  background: var(--gold);
  padding: 0.1rem 0.4rem;
  border-radius: 5px;
  vertical-align: middle;
}

.header-link {
  margin-left: auto;
  color: var(--gold-text);
  text-decoration: none;
  font-size: 0.8rem;
  white-space: nowrap;
}

.header-link:hover { text-decoration: underline; }

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

#token-form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  width: 100%;
  max-width: 20rem;
}

#token-form label { font-size: 0.85rem; color: var(--muted); }

#token-form input {
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
}

#token-form input:focus { outline: none; border-color: var(--gold-hairline); }

#token-form button {
  padding: 0.6rem 1rem;
  border: 1px solid var(--gold-hairline);
  border-radius: 10px;
  background: transparent;
  color: var(--gold-text);
  font-family: inherit;
  font-size: 0.95rem;
  cursor: pointer;
}

#token-form button:hover { background: var(--gold-tint); }

.gate-error { margin: 0; color: #e06b6b; font-size: 0.8rem; }

#workspace {
  flex: 1;
  display: flex;
  min-height: 0;
}

.admin-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
}

.admin-tabs button {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--muted);
  padding: 0.45rem;
  font: inherit;
  font-size: 0.75rem;
  cursor: pointer;
}

.admin-tabs button.active {
  border-color: var(--gold-hairline);
  color: var(--gold-text);
  background: var(--gold-tint);
}

#controls {
  width: 340px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--surface);
  padding: 1rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.control { display: flex; flex-direction: column; gap: 0.4rem; }

.control-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
}

.control-head label { font-size: 0.85rem; font-weight: 600; }

.control-buttons { display: flex; gap: 0.9rem; }

.linkbtn.emph {
  color: var(--gold);
  font-weight: 600;
}

.save-status {
  margin: 0;
  font-size: 0.72rem;
  color: var(--muted);
  min-height: 1em;
}

.save-status.dirty { color: var(--gold-text); }

#system-prompt {
  min-height: 220px;
  resize: vertical;
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 0.8rem;
  line-height: 1.5;
}

#system-prompt:focus { outline: none; border-color: var(--gold-hairline); }

.hint { margin: 0; font-size: 0.72rem; color: var(--muted); }

.linkbtn {
  border: none;
  background: none;
  color: var(--gold-text);
  font-family: inherit;
  font-size: 0.75rem;
  cursor: pointer;
  padding: 0;
}

.linkbtn:hover { text-decoration: underline; }

#temperature { width: 100%; accent-color: var(--gold); }

#temp-value {
  font-variant-numeric: tabular-nums;
  color: var(--gold-text);
  font-size: 0.85rem;
}

.control-actions {
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

body.admin #chat { flex: 1; min-width: 0; }

#feedback-panel {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 1.2rem;
}

.feedback-panel-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.feedback-panel-head h2 { margin: 0 0 0.25rem; font-size: 1.05rem; }
.feedback-panel-head p { margin: 0; color: var(--muted); font-size: 0.8rem; }

#feedback-list { display: flex; flex-direction: column; gap: 0.9rem; }

.feedback-empty {
  color: var(--muted);
  text-align: center;
  padding: 3rem 1rem;
}

.feedback-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  padding: 0.9rem;
}

.feedback-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.8rem;
  color: var(--muted);
  font-size: 0.7rem;
  margin-bottom: 0.75rem;
}

.feedback-turn {
  border-left: 2px solid var(--border);
  padding: 0.15rem 0 0.65rem 0.75rem;
  margin-bottom: 0.7rem;
}

.feedback-turn.reported { border-left-color: var(--gold); }
.feedback-turn:last-child { margin-bottom: 0; padding-bottom: 0; }
.feedback-role { color: var(--gold-text); font-size: 0.7rem; font-weight: 600; }
.feedback-question { margin: 0.25rem 0 0.55rem; font-weight: 600; }
.feedback-answer { color: var(--text); font-size: 0.84rem; line-height: 1.5; }
.feedback-answer > :first-child { margin-top: 0; }
.feedback-answer > :last-child { margin-bottom: 0; }
.feedback-sources { margin: 0.45rem 0 0; color: var(--muted); font-size: 0.7rem; }

@media (max-width: 720px) {
  #workspace { flex-direction: column; }
  #controls {
    width: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 45vh;
  }
  #system-prompt { min-height: 120px; }
  #feedback-panel { padding: 0.85rem; }
}
