/* ─── Sinteca (servida localmente) ─── */
@font-face {
  font-family: 'Sinteca';
  src: url('fonts/Sinteca-Regular.woff') format('woff');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Sinteca';
  src: url('fonts/Sinteca-Medium.woff') format('woff');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Sinteca';
  src: url('fonts/Sinteca-SemiBold.woff') format('woff');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Sinteca';
  src: url('fonts/Sinteca-Bold.woff') format('woff');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Paleta oficial custo.tech */
  --purple: #4D56D1;
  --purple-soft: #D0CFF9;
  --lime: #C0E703;
  --ink: #08090A;
  --paper: #FAFAFB;
  --paper-2: #F1F1F4;
  --line: #E5E5EC;
  --line-strong: #C9C9D4;
  --text: #1A1B22;
  --text-muted: #6B6C7A;

  /* Tokens semánticos */
  --bg: var(--paper);
  --bg-surface: #FFFFFF;
  --bg-input: #FFFFFF;
  --bg-user: var(--purple);
  --text-user: #FFFFFF;
  --bg-assistant: #FFFFFF;
  --border: var(--line);
  --accent: var(--purple);
  --accent-hover: #3D45B5;
  --accent-soft: var(--purple-soft);
  --code-bg: #0F1020;
  --code-text: #E8E9F5;
  --code-inline-bg: var(--paper-2);
  --code-inline-text: #4D2178;
  --scrollbar: var(--line-strong);

  --radius: 14px;
  --radius-sm: 8px;
  --font: 'Sinteca', system-ui, -apple-system, 'Inter', sans-serif;
  --font-mono: ui-monospace, 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  --shadow-sm: 0 1px 2px rgba(15, 16, 32, 0.04);
  --shadow-md: 0 6px 24px -8px rgba(77, 86, 209, 0.18);
}

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

html, body {
  height: 100%;
  background:
    radial-gradient(900px 600px at 85% -10%, rgba(192, 231, 3, 0.10), transparent 60%),
    radial-gradient(700px 500px at -5% 100%, rgba(77, 86, 209, 0.10), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ─── Layout ─── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 880px;
  margin: 0 auto;
}

/* ─── Header ─── */
header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 20px 28px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: saturate(140%) blur(8px);
  flex-shrink: 0;
}

header .logo {
  width: 52px;
  height: 52px;
  object-fit: contain;
  display: block;
  flex-shrink: 0;
}

header .brand {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
  gap: 2px;
}

header h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.4px;
  line-height: 1;
}

header .brand-sub {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.4px;
  text-transform: lowercase;
}

@media (max-width: 600px) {
  header { padding: 16px 18px; gap: 12px; }
  header .logo { width: 44px; height: 44px; }
  header h1 { font-size: 20px; }
}

header .status {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

header .status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--line-strong);
  transition: background 0.3s;
}

header .status-dot.online {
  background: var(--lime);
  box-shadow: 0 0 0 3px rgba(192, 231, 3, 0.25);
}
header .status-dot.thinking {
  background: var(--purple);
  box-shadow: 0 0 0 3px rgba(77, 86, 209, 0.20);
  animation: pulse 1.2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

/* ─── Welcome ─── */
#welcome {
  max-width: 620px;
  margin: 56px auto 24px;
  padding: 0 8px;
  text-align: center;
  animation: fadeUp 0.35s ease;
}
#welcome.hidden { display: none; }
#welcome .welcome-logo {
  width: 96px;
  height: 96px;
  object-fit: contain;
  margin-bottom: 20px;
}
#welcome h2 {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.6px;
  margin-bottom: 10px;
  color: var(--text);
}
#welcome p {
  color: var(--text-muted);
  font-size: 15px;
  max-width: 460px;
  margin: 0 auto 28px;
  line-height: 1.55;
}
.welcome-suggestions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  max-width: 540px;
  margin: 0 auto;
}
.suggestion {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font);
  font-weight: 500;
  font-size: 14px;
  padding: 14px 16px;
  border-radius: 12px;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
  box-shadow: var(--shadow-sm);
}
.suggestion:hover {
  border-color: var(--purple);
  background: var(--bg-surface);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
  color: var(--purple);
}
@media (max-width: 600px) {
  #welcome { margin-top: 32px; }
  #welcome .welcome-logo { width: 76px; height: 76px; margin-bottom: 14px; }
  #welcome h2 { font-size: 24px; }
  #welcome p { font-size: 14px; margin-bottom: 20px; }
  .welcome-suggestions { grid-template-columns: 1fr; }
}

/* ─── Messages ─── */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 28px 24px 16px;
  scroll-behavior: smooth;
}

#messages::-webkit-scrollbar { width: 6px; }
#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 3px; }

.message {
  display: flex;
  flex-direction: column;
  margin-bottom: 22px;
  animation: fadeUp 0.22s ease;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message.user { align-items: flex-end; }
.message.assistant { align-items: flex-start; }
.message.system { align-items: center; }

.message-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 5px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

.bubble {
  max-width: 82%;
  padding: 13px 17px;
  border-radius: var(--radius);
  line-height: 1.65;
  word-break: break-word;
  box-shadow: var(--shadow-sm);
}

.message.user .bubble {
  background: var(--bg-user);
  color: var(--text-user);
  border-bottom-right-radius: 4px;
}

.message.assistant .bubble {
  background: var(--bg-assistant);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message.system .bubble {
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-style: italic;
  border: none;
  padding: 4px 0;
  box-shadow: none;
}

/* ─── Markdown dentro de bubbles ─── */
.bubble p { margin-bottom: 10px; }
.bubble p:last-child { margin-bottom: 0; }

.bubble h1, .bubble h2, .bubble h3 {
  font-weight: 700;
  margin: 16px 0 8px;
  line-height: 1.3;
  letter-spacing: -0.2px;
}
.bubble h1 { font-size: 1.3em; }
.bubble h2 { font-size: 1.15em; }
.bubble h3 { font-size: 1em; }

.bubble ul, .bubble ol {
  padding-left: 22px;
  margin-bottom: 10px;
}
.bubble li { margin-bottom: 4px; }

.bubble blockquote {
  border-left: 3px solid var(--lime);
  padding-left: 12px;
  color: var(--text-muted);
  margin: 10px 0;
}

.bubble strong { font-weight: 700; }
.bubble em { font-style: italic; }

.message.user .bubble a { color: #FFFFFF; text-decoration: underline; }
.message.assistant .bubble a { color: var(--purple); text-decoration: none; font-weight: 500; }
.message.assistant .bubble a:hover { text-decoration: underline; }

.bubble hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 12px 0;
}

/* ─── Código inline ─── */
.bubble code {
  background: var(--code-inline-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  font-family: var(--font-mono);
  font-size: 0.88em;
  color: var(--code-inline-text);
}

.message.user .bubble code {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.25);
  color: #FFFFFF;
}

/* ─── Bloques de código ─── */
.code-wrapper {
  position: relative;
  margin: 12px 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--code-bg);
}

.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--code-bg);
  padding: 7px 12px;
  font-size: 11px;
  color: #A0A1B5;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.copy-btn {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 4px;
  color: #C9C9D4;
  cursor: pointer;
  font-size: 11px;
  font-family: var(--font);
  padding: 2px 9px;
  transition: all 0.15s;
}
.copy-btn:hover { background: rgba(255, 255, 255, 0.08); color: #FFFFFF; }
.copy-btn.copied { color: var(--lime); border-color: var(--lime); }

.bubble pre {
  margin: 0;
  background: var(--code-bg);
  overflow-x: auto;
  padding: 14px 16px;
}

.bubble pre code {
  background: none;
  border: none;
  padding: 0;
  color: var(--code-text);
  font-size: 0.85em;
}

/* ─── Indicador de "escribiendo" ─── */
.typing-indicator {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 22px;
  padding: 0 0 4px;
}

.typing-dots {
  display: flex;
  gap: 4px;
  padding: 14px 16px;
  background: var(--bg-assistant);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm);
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--purple);
  animation: blink 1.4s infinite;
  opacity: 0.4;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0.25; }
  40% { opacity: 1; }
}

/* ─── Área de input ─── */
#input-area {
  padding: 16px 24px 24px;
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: saturate(140%) blur(8px);
  flex-shrink: 0;
}

#input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 11px 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

#input-wrap:focus-within {
  border-color: var(--purple);
  box-shadow: var(--shadow-md);
}

#user-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  resize: none;
  min-height: 24px;
  max-height: 160px;
  overflow-y: auto;
}

#user-input::placeholder { color: var(--text-muted); }

#user-input::-webkit-scrollbar { width: 3px; }
#user-input::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 2px; }

#send-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: none;
  background: var(--purple);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s, box-shadow 0.2s;
}

#send-btn:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: var(--shadow-md);
}
#send-btn:active:not(:disabled) { transform: scale(0.93); }
#send-btn:disabled {
  background: var(--paper-2);
  color: var(--line-strong);
  cursor: not-allowed;
}

#send-btn svg { width: 16px; height: 16px; }

.input-hint {
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  letter-spacing: 0.2px;
}

/* ─── Tema oscuro automático (si el SO lo pide) ─── */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0E0F18;
    --bg-surface: #15161F;
    --bg-input: #1B1D2A;
    --bg-assistant: #15161F;
    --border: #252736;
    --line-strong: #3A3D52;
    --text: #ECECF1;
    --text-muted: #8E90A6;
    --paper-2: #20222F;
    --code-inline-bg: #20222F;
    --code-inline-text: #C0E703;
  }

  html, body {
    background:
      radial-gradient(900px 600px at 85% -10%, rgba(192, 231, 3, 0.08), transparent 60%),
      radial-gradient(700px 500px at -5% 100%, rgba(77, 86, 209, 0.18), transparent 60%),
      var(--bg);
  }

  header,
  #input-area {
    background: rgba(21, 22, 31, 0.85);
  }

  #send-btn:disabled {
    background: var(--paper-2);
    color: var(--line-strong);
  }
}
