:root {
  --ink: #1c2430;
  --ink-soft: #5b6472;
  --bg: #eef2f6;
  --surface: #ffffff;
  --surface-alt: #f6f8fb;
  --border: #e1e6ec;
  --accent: #2f6f5e;
  --accent-dark: #234f42;
  --accent-soft: #e4f0ec;
  --accent-contrast: #ffffff;
  --user-bubble: #2f6f5e;
  --user-bubble-text: #ffffff;
  --assistant-bubble: #f6f8fb;
  --assistant-bubble-text: #1c2430;
  --danger: #b3261e;
  --danger-soft: #fbeceb;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-soft: 0 4px 16px rgba(28, 36, 48, 0.06), 0 1px 3px rgba(28, 36, 48, 0.08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

/* Garantiza que el atributo [hidden] siempre gane, aunque el componente
   tenga su propia regla "display: flex/grid/etc" con la misma
   especificidad (los estilos de autor ganan por defecto a la hoja de
   estilos del navegador, así que sin esto un elemento con "hidden" pero
   con su propio display declarado se seguiría viendo). */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font-family: inherit; font-size: inherit; color: inherit; }

.chat-app {
  max-width: 1080px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

@media (min-width: 860px) {
  .chat-app {
    margin: 24px auto;
    min-height: calc(100vh - 48px);
    border-radius: var(--radius-lg);
    overflow: hidden;
  }
}

/* ── Cuerpo: sidebar + chat ─────────────────────────────────────────── */

.app-body {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}

.sidebar-toggle {
  display: none;
  align-items: center;
  gap: 6px;
}

.btn--icon {
  background: none;
  padding: 4px 8px;
  font-size: 1rem;
  line-height: 1;
}
.btn--icon:hover { background: var(--surface-alt); border-radius: var(--radius-sm); }

.sidebar-backdrop {
  display: none;
}

.sidebar__header {
  display: none;
}

.sidebar {
  width: 300px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--surface-alt);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
}

/* En escritorio, el panel de categorías vive dentro del sidebar tal cual;
   se reutilizan las mismas clases que antes iban bajo el historial. */
.sidebar .suggested-panel {
  border: none;
  background: none;
  padding: 0;
}

@media (max-width: 899px) {
  .sidebar-toggle { display: inline-flex; }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(20, 26, 33, 0.45);
    z-index: 30;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }
  .sidebar-backdrop.is-visible {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
  }
  .sidebar__title { margin: 0; font-size: 1rem; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 31;
    width: min(320px, 86vw);
    max-width: 320px;
    border-right: 1px solid var(--border);
    box-shadow: var(--shadow-soft);
    transform: translateX(-100%);
    transition: transform 0.22s ease;
  }
  .sidebar.is-open {
    transform: translateX(0);
  }
}

/* ── Header ─────────────────────────────────────────────────────────── */

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.chat-header__identity {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.chat-header__avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-contrast);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.chat-header__title {
  font-size: 1rem;
  margin: 0;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-header__status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #3bb273;
  display: inline-block;
}

.chat-header__actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.lang-switch {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.lang-switch__btn {
  border: none;
  background: var(--surface);
  padding: 6px 12px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.75rem;
  color: var(--ink-soft);
  transition: background 0.15s ease, color 0.15s ease;
}

.lang-switch__btn:hover { background: var(--surface-alt); }
.lang-switch__btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.lang-switch__btn.is-active { background: var(--accent); color: var(--accent-contrast); }

.eu-pending-notice {
  margin: 0;
  padding: 8px 20px;
  font-size: 0.78rem;
  color: var(--ink-soft);
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
}

/* ── Buttons ────────────────────────────────────────────────────────── */

.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease, box-shadow 0.15s ease;
}

.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn--primary { background: var(--accent); color: var(--accent-contrast); }
.btn--primary:hover { background: var(--accent-dark); }
.btn--primary:disabled { background: #a9c2ba; cursor: not-allowed; }

.btn--ghost { background: var(--surface-alt); color: var(--ink); font-size: 0.82rem; padding: 8px 14px; }
.btn--ghost:hover { background: var(--border); }

.btn--link { background: none; color: var(--accent-dark); text-decoration: underline; padding: 4px 2px; font-weight: 600; font-size: 0.85rem; }
.btn--link:hover { color: var(--accent); }

/* ── Chat history ───────────────────────────────────────────────────── */

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 16px 20px 0;
  gap: 12px;
}

.chat-history {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-bottom: 8px;
  min-height: 120px;
}

.welcome-card {
  background: var(--accent-soft);
  border-radius: var(--radius-md);
  padding: 18px 20px;
}

.welcome-card h2 { margin: 0 0 6px; font-size: 1.05rem; color: var(--accent-dark); }
.welcome-card p { margin: 0; color: var(--ink-soft); font-size: 0.92rem; }

.msg {
  max-width: 82%;
  padding: 11px 15px;
  border-radius: var(--radius-md);
  line-height: 1.5;
  font-size: 0.94rem;
  animation: msg-in 0.18s ease;
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg--user {
  align-self: flex-end;
  background: var(--user-bubble);
  color: var(--user-bubble-text);
  border-bottom-right-radius: 4px;
}

.msg--assistant {
  align-self: flex-start;
  background: var(--assistant-bubble);
  color: var(--assistant-bubble-text);
  border-bottom-left-radius: 4px;
  width: 100%;
}

.msg--assistant p:first-child { margin-top: 0; }
.msg--assistant p:last-child { margin-bottom: 0; }
.msg--assistant pre {
  background: #10241d;
  color: #e8f3ee;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-size: 0.82rem;
}
.msg--assistant code {
  background: rgba(0,0,0,0.06);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.85em;
}
.msg--assistant pre code { background: none; padding: 0; }
.msg--assistant a { color: var(--accent-dark); }
.msg--assistant ul, .msg--assistant ol { padding-left: 1.3em; }

.msg__actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.msg-session-notice {
  align-self: center;
  font-size: 0.78rem;
  color: var(--ink-soft);
  background: var(--surface-alt);
  border-radius: 999px;
  padding: 4px 12px;
}

.sources {
  margin-top: 10px;
  border-top: 1px dashed var(--border);
  padding-top: 8px;
}

.sources summary {
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent-dark);
}

.sources ul { margin: 8px 0 0; padding-left: 1.1em; font-size: 0.85rem; color: var(--ink-soft); }
.sources a { color: var(--accent-dark); }

/* ── Typing / error ─────────────────────────────────────────────────── */

.typing-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 4px 0;
  color: var(--ink-soft);
  font-size: 0.82rem;
}

.typing-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--ink-soft);
  animation: typing-bounce 1.1s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.error-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid rgba(179, 38, 30, 0.25);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.88rem;
}

/* ── Suggested questions ────────────────────────────────────────────── */

.suggested-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-alt);
  padding: 12px;
}

.suggested-panel__toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.search-input {
  flex: 1;
  min-width: 140px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
  background: var(--surface);
}
.search-input:focus-visible { outline: 2px solid var(--accent); }

.categories-grid {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.category-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  overflow: hidden;
}
.category-item.is-expanded {
  border-color: var(--accent);
}

.category-card {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  border: none;
  background: none;
  border-radius: 0;
  padding: 10px 12px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: background 0.15s ease;
}
.category-card:hover { background: var(--surface-alt); }
.category-card:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.category-card:disabled { cursor: default; }
.category-card__icon { font-size: 1.2rem; flex-shrink: 0; }
.category-card__title { font-size: 0.85rem; font-weight: 600; line-height: 1.25; flex: 1; }
.category-card__chevron {
  flex-shrink: 0;
  color: var(--ink-soft);
  transition: transform 0.18s ease;
}
.category-item.is-expanded .category-card__chevron {
  transform: rotate(-180deg);
  color: var(--accent);
}

.category-questions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 10px 10px 34px;
  animation: cat-expand 0.15s ease;
}

@keyframes cat-expand {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.question-chip {
  text-align: left;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.question-chip:hover { background: var(--accent-soft); border-color: var(--accent); }
.question-chip:focus-visible { outline: 2px solid var(--accent); }
.question-chip__pending { color: var(--ink-soft); font-size: 0.72rem; }

.search-no-results { font-size: 0.85rem; color: var(--ink-soft); margin: 6px 2px; }

/* ── Composer ───────────────────────────────────────────────────────── */

.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}

.composer__input {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  max-height: 140px;
  background: var(--surface-alt);
}
.composer__input:focus-visible { outline: 2px solid var(--accent); }

.composer__send { flex-shrink: 0; }

.disclaimer {
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.72rem;
  margin: 0 0 12px;
}

/* ── Scrollbars (discreto) ──────────────────────────────────────────── */

.chat-history::-webkit-scrollbar, .sidebar::-webkit-scrollbar { width: 8px; }
.chat-history::-webkit-scrollbar-thumb, .sidebar::-webkit-scrollbar-thumb {
  background: var(--border); border-radius: 999px;
}

/* ── Responsive ─────────────────────────────────────────────────────── */

@media (max-width: 480px) {
  .chat-header { padding: 12px 14px; }
  .chat-main { padding: 12px 14px 0; }
  .msg { max-width: 92%; }
  .chat-header__title { font-size: 0.92rem; }
}
