:root {
  color-scheme: dark;
  --black: #000000;
  --panel: #030816;
  --panel-2: #071224;
  --panel-3: #0a1a33;
  --line: rgba(96, 165, 250, 0.2);
  --line-soft: rgba(148, 197, 255, 0.11);
  --text: #f4f9ff;
  --muted: #9db4d0;
  --muted-2: #6f87a5;
  --blue: #1688ff;
  --blue-2: #35c4ff;
  --blue-soft: rgba(22, 136, 255, 0.16);
  --danger: #fb7185;
  --sidebar-width: 286px;
  --topbar-height: 66px;
  --composer-width: 790px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--black);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--blue-2);
  outline-offset: 2px;
}

svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
  flex: 0 0 auto;
}

svg.stroke-icon,
svg.stroke-icon * {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app {
  display: flex;
  height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(circle at 58% -12%, rgba(20, 105, 255, 0.16), transparent 34rem),
    radial-gradient(circle at 100% 85%, rgba(0, 174, 255, 0.07), transparent 26rem),
    #000;
}

.scrim {
  display: none;
}

/* ---------- Hotbar / sidebar ---------- */
.sidebar {
  width: var(--sidebar-width);
  flex: 0 0 var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: rgba(2, 7, 20, 0.97);
  border-right: 1px solid var(--line-soft);
  transition: margin-left 260ms ease, transform 260ms ease;
  z-index: 40;
}

.app.sidebar-collapsed .sidebar {
  margin-left: calc(var(--sidebar-width) * -1);
}

.sidebar-main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 14px 12px 10px;
}

.brand-row {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 2px 10px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 4px;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.brand-name {
  font-size: 1.12rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.logo-frame {
  display: inline-grid;
  place-items: center;
  overflow: hidden;
  background: transparent;
  flex: 0 0 auto;
}

.logo-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scale(1.34);
}

.brand-logo {
  width: 42px;
  height: 42px;
}

.icon-button {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.35rem;
  line-height: 1;
}

.icon-button:hover {
  color: white;
  background: rgba(59, 130, 246, 0.12);
  border-color: var(--line-soft);
}

.sidebar-nav {
  display: grid;
  gap: 4px;
  margin-top: 7px;
}

.nav-item,
.account-button {
  width: 100%;
  min-height: 43px;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 11px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: #dbeafe;
  cursor: pointer;
  text-align: left;
}

.nav-item:hover,
.account-button:hover {
  background: rgba(37, 99, 235, 0.12);
}

.nav-item-primary {
  border-color: rgba(59, 165, 255, 0.24);
  background: rgba(14, 116, 233, 0.12);
  font-weight: 700;
}

.nav-item kbd {
  margin-left: auto;
  padding: 3px 6px;
  border: 1px solid var(--line-soft);
  border-bottom-color: rgba(148, 197, 255, 0.25);
  border-radius: 6px;
  color: var(--muted-2);
  background: rgba(255, 255, 255, 0.03);
  font: 0.68rem ui-monospace, monospace;
}

.nav-item.is-active {
  color: #fff;
  background: rgba(14, 116, 233, 0.2);
  border-color: rgba(53, 196, 255, 0.3);
}

.recent-section {
  flex: 1;
  min-height: 100px;
  display: flex;
  flex-direction: column;
  margin-top: 24px;
  overflow: hidden;
}

.recent-section h2 {
  margin: 0 10px 8px;
  color: var(--muted-2);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.recent-list {
  display: grid;
  gap: 2px;
  overflow-y: auto;
  padding-right: 2px;
}

.recent-item {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
}

.recent-open {
  flex: 1;
  min-width: 0;
  padding: 9px 34px 9px 10px;
  overflow: hidden;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #cbd8ea;
  cursor: pointer;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recent-open:hover,
.recent-item.is-active .recent-open {
  background: rgba(59, 130, 246, 0.12);
  color: white;
}

.recent-delete {
  position: absolute;
  right: 5px;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted-2);
  cursor: pointer;
  opacity: 0;
}

.recent-item:hover .recent-delete,
.recent-delete:focus-visible {
  opacity: 1;
}

.recent-delete:hover {
  color: #fecdd3;
  background: rgba(244, 63, 94, 0.13);
}

.recent-delete svg {
  width: 15px;
  height: 15px;
}

.recent-empty {
  margin: 5px 10px;
  color: var(--muted-2);
  font-size: 0.84rem;
  line-height: 1.45;
}

.sidebar-bottom {
  padding: 10px 12px 13px;
  border-top: 1px solid var(--line-soft);
  display: grid;
  gap: 4px;
  background: rgba(1, 5, 14, 0.95);
}

.account-button {
  min-height: 51px;
}

.avatar {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, #0757d8, #38bdf8);
  box-shadow: 0 0 18px rgba(14, 165, 233, 0.28);
  color: white;
  font-weight: 900;
  flex: 0 0 auto;
}

.account-copy {
  display: grid;
  min-width: 0;
  overflow: hidden;
  line-height: 1.14;
}

.account-copy strong,
.account-copy small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-copy small {
  margin-top: 3px;
  color: var(--muted-2);
}

/* ---------- Main ---------- */
.main {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-height);
  flex: 0 0 var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 18px;
  border-bottom: 1px solid rgba(96, 165, 250, 0.08);
  background: rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(16px);
  z-index: 20;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.current-view {
  min-width: 0;
  display: grid;
  gap: 1px;
}

.current-view strong {
  max-width: min(46vw, 520px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.98rem;
}

.brain-badge {
  color: #73bfff;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
}

.temporary-button {
  min-height: 39px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(7, 18, 36, 0.74);
  color: #dbeafe;
  cursor: pointer;
}

.temporary-button svg {
  width: 19px;
  height: 19px;
}

.temporary-button:hover {
  border-color: rgba(53, 196, 255, 0.48);
  background: rgba(14, 116, 233, 0.17);
}

.temporary-button[aria-pressed="true"] {
  color: white;
  border-color: rgba(53, 196, 255, 0.75);
  background: linear-gradient(135deg, rgba(2, 132, 255, 0.72), rgba(14, 165, 233, 0.45));
  box-shadow: 0 0 24px rgba(14, 165, 233, 0.2);
}

.chat-view,
.library-view {
  position: relative;
  flex: 1;
  min-height: 0;
}

.scroll-area {
  height: 100%;
  overflow-y: auto;
  scroll-behavior: smooth;
  padding: 30px 24px 190px;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 24px 170px;
  text-align: center;
  pointer-events: none;
  transition: opacity 240ms ease, transform 300ms ease;
}

.app:not(.is-empty) .empty-state {
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
}

.eyebrow {
  margin: 0 0 9px;
  color: var(--blue-2);
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0.22em;
}

.empty-state h1,
.library-heading h1 {
  margin: 0;
  font-size: clamp(2.1rem, 5vw, 3.6rem);
  line-height: 1.04;
  letter-spacing: -0.045em;
}

.greeting-title {
  max-width: 980px;
  font-size: clamp(2.3rem, 4.6vw, 3.9rem) !important;
  line-height: 1.08 !important;
  text-wrap: balance;
}

.greeting-name {
  background: linear-gradient(
    90deg,
    #ffffff 0%,
    #e2f5ff 34%,
    #a9e2ff 68%,
    #6fc6ff 100%
  );
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
}

.message-list {
  width: min(800px, 100%);
  margin: 0 auto;
  display: grid;
  gap: 28px;
}

.message {
  display: flex;
  gap: 12px;
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.message-user {
  justify-content: flex-end;
}

.message-user .message-body {
  max-width: min(76%, 620px);
  padding: 11px 15px;
  border: 1px solid rgba(96, 165, 250, 0.24);
  border-radius: 19px 19px 5px 19px;
  background: #0a2550;
  white-space: pre-wrap;
}

.message-assistant {
  align-items: flex-start;
}

.message-avatar {
  width: 34px;
  height: 34px;
  margin-top: 2px;
}

.message-assistant .message-body {
  flex: 1;
  min-width: 0;
  padding-top: 3px;
}

.message-author {
  margin-bottom: 3px;
  color: #bfdcff;
  font-size: 0.83rem;
  font-weight: 800;
}

.message-text {
  color: #e8f3ff;
  white-space: pre-wrap;
}

.typing-dots {
  display: inline-flex;
  gap: 5px;
  padding: 8px 0;
}

.typing-dots i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--blue-2);
  animation: typing 1s infinite ease-in-out;
}

.typing-dots i:nth-child(2) { animation-delay: 140ms; }
.typing-dots i:nth-child(3) { animation-delay: 280ms; }

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

.composer-dock {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: min(var(--composer-width), calc(100% - 40px));
  transform: translate(-50%, 0);
  padding: 12px 0 18px;
  z-index: 15;
  transition: bottom 420ms ease, transform 420ms ease;
  background: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.9) 28%);
}

.app.is-empty .composer-dock {
  bottom: 50%;
  transform: translate(-50%, 50%);
  background: transparent;
}

.temporary-notice {
  width: fit-content;
  max-width: 100%;
  margin: 0 auto 9px;
  padding: 7px 11px;
  border: 1px solid rgba(53, 196, 255, 0.32);
  border-radius: 999px;
  background: rgba(4, 42, 80, 0.82);
  color: #bfecff;
  font-size: 0.79rem;
  text-align: center;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 9px;
  padding: 9px;
  border: 1px solid rgba(96, 165, 250, 0.3);
  border-radius: 28px;
  background: rgba(6, 16, 34, 0.96);
  box-shadow: 0 18px 55px rgba(0, 60, 150, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.composer:focus-within {
  border-color: rgba(53, 196, 255, 0.72);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1), 0 18px 55px rgba(0, 60, 150, 0.28);
}

.composer textarea {
  flex: 1;
  min-height: 27px;
  max-height: 165px;
  resize: none;
  padding: 10px 8px 8px 13px;
  border: 0;
  outline: 0;
  background: transparent;
  color: white;
  line-height: 1.45;
}

.composer textarea::placeholder {
  color: #7e95b5;
}

.send-button {
  width: 43px;
  height: 43px;
  flex: 0 0 43px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, #087df2, #24b8ff);
  color: white;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(14, 165, 233, 0.3);
}

.send-button:disabled {
  background: #173154;
  color: #6885aa;
  cursor: not-allowed;
  box-shadow: none;
}

.composer-hint {
  margin: 9px 10px 0;
  color: var(--muted-2);
  font-size: 0.77rem;
  text-align: center;
}

/* ---------- Library ---------- */
.library-view {
  overflow-y: auto;
  padding: clamp(28px, 6vw, 72px) 24px;
}

.library-heading,
.library-empty {
  width: min(780px, 100%);
  margin-inline: auto;
}

.library-heading p:last-child {
  max-width: 620px;
  color: var(--muted);
  line-height: 1.6;
}

.library-empty {
  margin-top: 34px;
  padding: clamp(30px, 6vw, 58px);
  border: 1px dashed rgba(96, 165, 250, 0.35);
  border-radius: 26px;
  background: rgba(3, 14, 31, 0.68);
  text-align: center;
}

.library-empty-icon {
  font-size: 3.2rem;
}

.library-empty h2 {
  margin: 16px 0 7px;
}

.library-empty p {
  color: var(--muted);
}

.secondary-button,
.danger-button {
  min-height: 41px;
  padding: 9px 15px;
  border-radius: 11px;
  cursor: pointer;
  font-weight: 700;
}

.secondary-button {
  border: 1px solid rgba(53, 196, 255, 0.42);
  background: rgba(14, 116, 233, 0.15);
  color: #d9f3ff;
}

.danger-button {
  border: 1px solid rgba(251, 113, 133, 0.38);
  background: rgba(190, 24, 64, 0.13);
  color: #fecdd3;
}

/* ---------- Dialogs ---------- */
.modal {
  width: min(520px, calc(100vw - 28px));
  max-height: min(760px, calc(100dvh - 28px));
  overflow-y: auto;
  padding: 22px;
  border: 1px solid rgba(96, 165, 250, 0.32);
  border-radius: 22px;
  background: #04101f;
  color: var(--text);
  box-shadow: 0 30px 100px rgba(0, 0, 0, 0.75);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(5px);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.25rem;
}

.search-field input {
  width: 100%;
  min-height: 47px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #020914;
  color: white;
}

.search-results {
  display: grid;
  gap: 6px;
  margin-top: 14px;
}

.search-result {
  display: grid;
  gap: 3px;
  width: 100%;
  padding: 12px;
  border: 1px solid transparent;
  border-radius: 13px;
  background: rgba(15, 48, 95, 0.2);
  cursor: pointer;
  text-align: left;
}

.search-result:hover {
  border-color: var(--line);
  background: rgba(14, 116, 233, 0.18);
}

.search-result span {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.83rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dialog-empty,
.dialog-note,
.settings-section p {
  color: var(--muted);
  line-height: 1.55;
}

.account-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line-soft);
  border-radius: 17px;
  background: rgba(10, 42, 86, 0.34);
}

.avatar-large {
  width: 54px;
  height: 54px;
  font-size: 1.35rem;
}

.account-card p {
  margin: 4px 0 0;
  color: var(--muted);
}

.account-details {
  display: grid;
  gap: 8px;
  margin: 16px 0;
}

.account-details div {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line-soft);
}

.account-details dt { color: var(--muted); }
.account-details dd { margin: 0; font-weight: 700; text-align: right; }

.settings-section {
  padding: 16px 0;
  border-top: 1px solid var(--line-soft);
}

.settings-section h3 {
  margin: 0 0 9px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 11px 0;
  cursor: pointer;
}

.setting-row span {
  display: grid;
  gap: 3px;
}

.setting-row small {
  color: var(--muted);
}

.setting-row input {
  width: 21px;
  height: 21px;
  accent-color: var(--blue);
  flex: 0 0 auto;
}

.status-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 7px;
  border-radius: 50%;
  background: #38bdf8;
  box-shadow: 0 0 12px #38bdf8;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: min(520px, calc(100vw - 28px));
  margin: 0;
  padding: 11px 15px;
  border: 1px solid rgba(53, 196, 255, 0.42);
  border-radius: 999px;
  background: rgba(2, 23, 49, 0.97);
  color: #dff6ff;
  box-shadow: 0 16px 45px rgba(0, 0, 0, 0.5);
  z-index: 100;
  text-align: center;
}

.app.no-animations *,
.app.no-animations *::before,
.app.no-animations *::after {
  animation: none !important;
  scroll-behavior: auto !important;
  transition: none !important;
}

/* ---------- Desktop chat layout ---------- */
@media (min-width: 821px) {
  .chat-view[hidden],
  .library-view[hidden] {
    display: none !important;
  }

  .chat-view {
    display: flex;
    flex-direction: column;
  }

  .scroll-area {
    flex: 1 1 auto;
    height: auto;
    min-height: 0;
    padding: 30px 24px 28px;
  }

  .composer-dock {
    position: relative;
    left: auto;
    bottom: auto;
    flex: 0 0 auto;
    align-self: center;
    transform: none;
    background: transparent;
  }

  /* En PC, bienvenida y composer forman una sola columna centrada.
     Al estar en el flujo normal, nunca pueden montarse uno sobre otro. */
  .app.is-empty .chat-view {
    justify-content: center;
    justify-content: safe center;
    overflow-y: auto;
    padding-block: 24px;
  }

  .app.is-empty .scroll-area {
    flex: 0 1 auto;
    height: auto;
    overflow: visible;
    padding: 0 24px;
  }

  .app.is-empty .empty-state {
    position: static;
    inset: auto;
    padding: 0;
  }

  .app.is-empty .message-list {
    display: none;
  }

  .app.is-empty .composer-dock {
    position: relative;
    left: auto;
    bottom: auto;
    transform: none;
    padding: 26px 0 0;
    background: transparent;
  }
}

@media (min-width: 821px) and (max-height: 720px) {
  .app.is-empty .greeting-title {
    font-size: 2.35rem !important;
  }

  .app.is-empty .composer-dock {
    padding-top: 18px;
  }
}

/* ---------- Mobile ---------- */
@media (max-width: 820px) {
  :root {
    --topbar-height: 60px;
    --sidebar-width: min(84vw, 310px);
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    transform: translateX(-105%);
    box-shadow: 28px 0 70px rgba(0, 0, 0, 0.5);
  }

  .app.sidebar-collapsed .sidebar {
    margin-left: 0;
  }

  .app.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .scrim {
    position: fixed;
    inset: 0;
    display: block;
    border: 0;
    background: rgba(0, 0, 0, 0.62);
    opacity: 0;
    pointer-events: none;
    transition: opacity 220ms ease;
    z-index: 35;
  }

  .app.sidebar-open .scrim {
    opacity: 1;
    pointer-events: auto;
  }

  .topbar {
    padding-inline: 10px;
  }

  .current-view strong {
    max-width: 37vw;
    font-size: 0.94rem;
  }

  .brain-badge {
    max-width: 37vw;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .temporary-button {
    padding-inline: 10px;
  }

  .temporary-button span {
    display: none;
  }

  .scroll-area {
    padding: 22px 16px 175px;
  }

  .empty-state {
    justify-content: center;
    padding: 20px 20px 150px;
  }

  .greeting-title {
    max-width: 22ch;
    font-size: 2.05rem !important;
    line-height: 1.12 !important;
  }

  /* En móvil, la barra está siempre abajo: también en la entrada. */
  .composer-dock,
  .app.is-empty .composer-dock {
    bottom: 0;
    width: calc(100% - 20px);
    transform: translate(-50%, 0);
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    background: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.94) 27%);
  }

  .composer {
    border-radius: 25px;
  }

  .composer-hint {
    display: none;
  }

  .message-list {
    gap: 24px;
  }

  .message-user .message-body {
    max-width: 88%;
  }

  .modal {
    padding: 19px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
