:root {
  --bg: #ffffff;
  --surface: #f7f7f8;
  --surface-strong: #ececf1;
  --text: #1f1f23;
  --muted: #6b6b73;
  --border: #dedee4;
  --accent: #111827;
  --accent-contrast: #ffffff;
  --danger: #b42318;
  --sidebar-width: 280px;
  --content-width: 860px;
  --radius: 14px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #212121;
    --surface: #171717;
    --surface-strong: #2f2f2f;
    --text: #ececec;
    --muted: #a5a5ad;
    --border: #3b3b3f;
    --accent: #f4f4f5;
    --accent-contrast: #171717;
    --danger: #ff8a80;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { min-height: 100vh; }
button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
[hidden] { display: none !important; }

.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-shell { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar-width) 1fr; }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 12px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 30;
}
.sidebar__header { min-height: 44px; display: flex; align-items: center; justify-content: space-between; padding: 0 6px; }
.brand, .login-card__brand { text-decoration: none; font-weight: 800; letter-spacing: -0.03em; }
.brand span, .login-card__brand span { font-weight: 500; color: var(--muted); }
.new-chat-button {
  margin-top: 8px;
  min-height: 44px;
  display: flex;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  padding: 0 13px;
  text-align: left;
}
.new-chat-button:hover { background: var(--surface-strong); }
.conversation-list { flex: 1; min-height: 0; overflow-y: auto; margin-top: 14px; }
.conversation-item {
  width: 100%;
  min-height: 42px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 6px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  padding: 6px 8px 6px 11px;
  cursor: pointer;
}
.conversation-item:hover, .conversation-item.is-active { background: var(--surface-strong); }
.conversation-item__title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; font-size: .9rem; border: 0; background: transparent; color: inherit; padding: 7px 3px; cursor: pointer; }
.conversation-item__delete { border: 0; background: transparent; color: var(--muted); cursor: pointer; border-radius: 8px; width: 30px; height: 30px; }
.conversation-item__delete:hover { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); }
.conversation-item__menu-button { display: grid; place-items: center; width: 36px; height: 36px; padding: 0; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; font-size: 1.5rem; line-height: 1; }
.conversation-item__menu-button:hover:not(:disabled), .conversation-item__menu-button[aria-expanded="true"] { background: var(--bg); color: var(--text); }
.conversation-item__menu-button:disabled { opacity: .45; cursor: default; }
.conversation-item__menu-button:focus-visible, .conversation-menu__action:focus-visible, .conversation-title-form button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Fuera del contenedor con scroll: el menú no se recorta en la última tarjeta. */
.conversation-menu { position: fixed; z-index: 40; min-width: min(190px, calc(100vw - 16px)); max-width: calc(100vw - 16px); max-height: calc(100vh - 16px); max-height: calc(100dvh - 16px); overflow-y: auto; padding: 6px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg); color: var(--text); box-shadow: 0 8px 28px rgba(0,0,0,.18); }
.conversation-menu__action { display: block; width: 100%; min-height: 44px; padding: 10px 12px; border: 0; border-radius: 7px; background: transparent; color: inherit; text-align: left; overflow-wrap: anywhere; cursor: pointer; font-size: .88rem; }
.conversation-menu__action:hover, .conversation-menu__action:focus-visible { background: var(--surface-strong); }
.conversation-title-dialog { width: min(440px, calc(100% - 32px)); max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); padding: 24px; border: 1px solid var(--border); border-radius: 18px; background: var(--bg); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.2); overflow-y: auto; }
.conversation-title-dialog::backdrop { background: rgba(0,0,0,.48); }
.conversation-title-form { display: grid; gap: 10px; min-width: 0; }
.conversation-title-form h2 { margin: 0 0 8px; font-size: 1.2rem; overflow-wrap: anywhere; }
.conversation-title-form label { font-size: .85rem; font-weight: 650; }
.conversation-title-form input { width: 100%; min-width: 0; height: 46px; padding: 0 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--text); outline: none; }
.conversation-title-form input:focus { border-color: var(--muted); box-shadow: 0 0 0 3px color-mix(in srgb, var(--muted) 14%, transparent); }
.conversation-title-form input[aria-invalid="true"] { border-color: var(--danger); }
.conversation-title-form__hint { margin: 0; color: var(--muted); font-size: .78rem; line-height: 1.5; }
.conversation-title-form__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; margin-top: 10px; }
.conversation-title-form__actions button { flex: 1 1 110px; min-height: 46px; height: auto; margin: 0; padding: 12px; overflow-wrap: anywhere; }
.secondary-button { border: 1px solid var(--border); border-radius: 11px; background: var(--bg); color: var(--text); cursor: pointer; }
.secondary-button:hover:not(:disabled) { background: var(--surface-strong); }
.conversation-title-form button:disabled, .conversation-title-form input:disabled { opacity: .5; cursor: default; }
.sidebar__footer { border-top: 1px solid var(--border); padding: 12px 4px 2px; }
.sidebar-user { display: flex; gap: 10px; align-items: center; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--accent); color: var(--accent-contrast); display: grid; place-items: center; font-size: .72rem; font-weight: 800; }
.sidebar-user__copy { min-width: 0; display: flex; flex-direction: column; }
.sidebar-user__copy strong, .sidebar-user__copy small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user__copy small { color: var(--muted); }
.sidebar-links, .sidebar-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 11px; font-size: .76rem; color: var(--muted); }
.sidebar-links a { text-decoration: none; }
.sidebar-links a:hover { text-decoration: underline; }
.sidebar-actions { justify-content: space-between; }
.text-button { border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 3px 0; }
.text-button:hover { color: var(--text); }

.chat-layout { min-width: 0; min-height: 100vh; position: relative; display: flex; flex-direction: column; }
.topbar { height: 56px; display: flex; align-items: center; justify-content: space-between; padding: 0 18px; position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid transparent; }
.topbar > div { display: flex; align-items: baseline; gap: 7px; }
.version, .model-badge { color: var(--muted); font-size: .75rem; }
.model-badge { border: 1px solid var(--border); border-radius: 999px; padding: 5px 9px; }
.icon-button { border: 0; background: transparent; color: var(--text); cursor: pointer; font-size: 1.25rem; width: 38px; height: 38px; border-radius: 8px; }
.icon-button:hover { background: var(--surface-strong); }
.mobile-only { display: none; }

.empty-state { flex: 1; display: grid; place-items: center; align-content: center; text-align: center; padding: 40px 20px 180px; }
.empty-state__logo { width: 56px; height: 56px; display: grid; place-items: center; background: var(--accent); color: var(--accent-contrast); border-radius: 18px; font-weight: 800; }
.empty-state h1 { margin: 18px 0 8px; font-size: clamp(1.6rem, 4vw, 2.3rem); letter-spacing: -0.04em; }
.empty-state p { max-width: 560px; color: var(--muted); line-height: 1.6; margin: 0; }

.messages { flex: 1; padding: 22px 16px 190px; }
.message { width: 100%; }
.message__inner { max-width: var(--content-width); margin: 0 auto; display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 14px; padding: 18px 0; }
.message__avatar { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; font-size: .65rem; font-weight: 800; background: var(--surface-strong); }
.message--assistant .message__avatar { background: var(--accent); color: var(--accent-contrast); }
.message__role { font-size: .76rem; font-weight: 700; color: var(--muted); margin-bottom: 7px; }
.message__content { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.7; font-size: .98rem; }
.message__meta { margin-top: 7px; color: var(--muted); font-size: .7rem; }
.message__attachments { display: grid; gap: 8px; margin-top: 12px; }
.message-file { display: flex; align-items: center; justify-content: space-between; gap: 12px; max-width: 560px; border: 1px solid var(--border); background: var(--surface); border-radius: 12px; padding: 10px 11px; }
.message-file__copy { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.message-file__copy strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .84rem; }
.message-file__copy small { color: var(--muted); font-size: .7rem; }
.message-file__download { flex: 0 0 auto; min-height: 32px; border: 1px solid var(--border); border-radius: 9px; background: var(--bg); color: var(--text); cursor: pointer; padding: 0 10px; font-size: .75rem; }
.message-file__download:hover:not(:disabled) { background: var(--surface-strong); }
.message-file__download:disabled { opacity: .5; cursor: default; }

.message--pending .message__content::after { content: ""; display: inline-block; width: 8px; height: 8px; margin-left: 8px; border-radius: 50%; background: var(--muted); animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: .25; transform: scale(.75); } }

.composer-wrap { position: fixed; left: var(--sidebar-width); right: 0; bottom: 0; z-index: 15; padding: 18px 16px 12px; background: linear-gradient(to top, var(--bg) 70%, transparent); }
.composer { max-width: var(--content-width); margin: 0 auto; min-height: 58px; display: grid; grid-template-columns: 42px minmax(0, 1fr) 42px; align-items: end; gap: 8px; border: 1px solid var(--border); background: var(--bg); border-radius: 18px; padding: 8px; box-shadow: 0 8px 28px rgba(0,0,0,.08); }
.composer.is-dragover { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent), 0 8px 28px rgba(0,0,0,.08); }
.composer textarea { width: 100%; max-height: 190px; resize: none; border: 0; outline: 0; background: transparent; color: var(--text); padding: 8px 0; line-height: 1.45; }
.attachment-button, .send-button { width: 40px; height: 40px; border: 0; border-radius: 12px; cursor: pointer; font-size: 1.2rem; }
.attachment-button { background: var(--surface-strong); color: var(--text); }
.attachment-button:hover:not(:disabled) { background: color-mix(in srgb, var(--surface-strong) 75%, var(--text) 8%); }
.send-button { background: var(--accent); color: var(--accent-contrast); }
.attachment-button:disabled, .send-button:disabled { opacity: .35; cursor: default; }
.pending-attachments { grid-column: 1 / -1; display: flex; gap: 7px; flex-wrap: wrap; padding: 2px 2px 0; }
.pending-file { min-width: 0; max-width: 100%; display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 6px 7px 6px 10px; font-size: .76rem; }
.pending-file__info { min-width: 0; max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pending-file__remove { width: 24px; height: 24px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer; }
.pending-file__remove:hover:not(:disabled) { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); }
.pending-file__remove:disabled { opacity: .4; cursor: default; }
.composer-note { max-width: var(--content-width); margin: 8px auto 0; text-align: center; color: var(--muted); font-size: .7rem; }

.login-view { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at top, var(--surface-strong), var(--bg) 45%); }
.login-card { width: min(100%, 430px); border: 1px solid var(--border); border-radius: 22px; background: var(--bg); padding: 32px; box-shadow: 0 20px 60px rgba(0,0,0,.08); }
.login-card__brand { font-size: 1.15rem; }
.login-card h1 { margin: 28px 0 8px; letter-spacing: -0.035em; }
.login-card > p { color: var(--muted); line-height: 1.55; margin: 0 0 22px; }
.login-form { display: grid; gap: 9px; }
.login-form label { font-size: .82rem; font-weight: 650; margin-top: 7px; }
.login-form input { height: 46px; border: 1px solid var(--border); border-radius: 11px; background: var(--bg); color: var(--text); padding: 0 13px; outline: none; }
.login-form input:focus { border-color: var(--muted); box-shadow: 0 0 0 3px color-mix(in srgb, var(--muted) 14%, transparent); }
.primary-button { margin-top: 12px; height: 46px; border: 0; border-radius: 11px; background: var(--accent); color: var(--accent-contrast); font-weight: 700; cursor: pointer; }
.primary-button:disabled { opacity: .5; }
.form-error { color: var(--danger); font-size: .82rem; line-height: 1.4; margin-top: 6px; }
.login-language { display: flex; justify-content: flex-end; margin-top: 16px; }
.login-footer { display: flex; justify-content: center; flex-wrap: wrap; gap: 14px; margin-top: 22px; font-size: .75rem; color: var(--muted); }
.login-footer a { text-decoration: none; }
.login-footer a:hover { text-decoration: underline; }
.sidebar-backdrop { display: none; }

@media (max-width: 820px) {
  .mobile-only { display: inline-grid; place-items: center; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; width: min(86vw, 310px); transform: translateX(-105%); transition: transform .2s ease; box-shadow: 8px 0 34px rgba(0,0,0,.14); }
  .sidebar.is-open { transform: translateX(0); }
  .conversation-item__menu-button { width: 44px; height: 44px; }
  .sidebar-backdrop { position: fixed; inset: 0; z-index: 25; background: rgba(0,0,0,.38); }
  .sidebar-backdrop:not([hidden]) { display: block; }
  .composer-wrap { left: 0; }
  .topbar { padding: 0 10px; }
  .message__inner { grid-template-columns: 30px minmax(0, 1fr); gap: 10px; }
}

@media (max-width: 520px) {
  .login-view { padding: 0; background: var(--bg); }
  .login-card { min-height: 100vh; border: 0; border-radius: 0; padding: 28px 20px; box-shadow: none; }
  .messages { padding-left: 12px; padding-right: 12px; }
  .composer-wrap { padding-left: 10px; padding-right: 10px; }
  .composer-note { font-size: .65rem; }
  .pending-file { width: 100%; }
  .pending-file__info { max-width: none; flex: 1; }
  .message-file { align-items: flex-start; }
  .conversation-title-dialog { padding: 20px; }
}


.model-badge--unavailable {
  border-style: dashed;
  opacity: .82;
}

.composer textarea:disabled {
  cursor: not-allowed;
  opacity: .62;
}

/* Workspace panels share the existing sidebar; the rail remains available when collapsed. */
.app-shell { --rail-width: 64px; --divider-width: 8px; grid-template-columns: var(--rail-width) var(--sidebar-width) var(--divider-width) minmax(0, 1fr); }
.workspace-rail { position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; gap: 8px; padding: 10px 4px; background: var(--surface); border-right: 1px solid var(--border); z-index: 45; }
.workspace-rail button { min-height: 56px; border: 0; border-radius: 10px; background: transparent; color: var(--text); cursor: pointer; display: flex; align-items: center; flex-direction: column; justify-content: center; }
.workspace-rail button > span { font-size: 1.45rem; }
.workspace-rail small { font-size: .65rem; }
.workspace-rail button.is-active, .workspace-rail button:hover { background: var(--surface-strong); }
.workspace-divider { position: sticky; top: 0; height: 100dvh; background: var(--surface); cursor: col-resize; touch-action: none; border-inline: 1px solid var(--border); }
.workspace-divider:hover, .workspace-divider:focus-visible { background: var(--muted); }
.app-shell .composer-wrap { left: calc(var(--rail-width) + var(--sidebar-width) + var(--divider-width)); }
.app-shell.panel-hidden { grid-template-columns: var(--rail-width) minmax(0, 1fr); }
.panel-hidden .sidebar, .panel-hidden .workspace-divider { display: none; }
.app-shell.panel-hidden .composer-wrap { left: var(--rail-width); }
.performance-panel { flex: 1; overflow-y: auto; min-height: 0; padding: 8px 2px; }
.performance-panel h2 { font-size: 1.1rem; }
.performance-note { font-size: .76rem; color: var(--muted); line-height: 1.5; }
.performance-field { display: grid; grid-template-columns: minmax(0, 1fr); gap: 5px; padding: 12px 0; border-bottom: 1px solid var(--border); font-size: .8rem; }
.performance-field__label { font-weight: 600; }
.performance-field select { width: 100%; min-width: 0; padding: 8px 4px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); font: inherit; }
.performance-field__help { margin: 2px 0 0; color: var(--muted); font-size: .73rem; line-height: 1.5; overflow-wrap: anywhere; }
.performance-estimate { font-size: .85rem; font-weight: 600; line-height: 1.5; }
.performance-panel > a, #performance-status { font-size: .8rem; }
.conversation-item { grid-template-columns: minmax(0, 1fr) auto; }
.conversation-item__cost { grid-column: 1 / -1; justify-self: end; text-align: right; font-size: .62rem; color: var(--muted); overflow-wrap: anywhere; }
.conversation-menu__action--danger { color: var(--danger); }
.topbar { height: auto; min-height: 64px; gap: 8px; }
.topbar .chat-cost-header { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; min-width: 0; text-align: right; }
#chat-cost { font-size: .7rem; color: var(--muted); }
.message__content a { text-decoration: underline; overflow-wrap: anywhere; }
@media (max-width: 820px) {
  .app-shell, .app-shell.panel-hidden { --rail-width: 56px; grid-template-columns: var(--rail-width) minmax(0, 1fr); }
  .app-shell .sidebar { left: var(--rail-width); width: min(380px, calc(100vw - var(--rail-width))); height: 100dvh; }
  .app-shell .workspace-divider { display: none; }
  .app-shell .composer-wrap { left: var(--rail-width); }
  .sidebar-backdrop { left: var(--rail-width); }
  .topbar .model-badge { max-width: 155px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
@media (max-width: 520px) {
  .topbar > div:not(.chat-cost-header) { display: none; }
  .performance-field { font-size: .75rem; }
}

/* Conversation explorer: native disclosure controls, nested lists and visible hierarchy guides. */
.explorer-toolbar { margin-top: 14px; min-width: 0; }
.explorer-toolbar__heading { display: flex; align-items: center; justify-content: space-between; gap: 4px; }
.explorer-toolbar__heading strong { font-size: .67rem; letter-spacing: .06em; color: var(--muted); }
.explorer-toolbar__buttons { display: flex; gap: 1px; }
.explorer-toolbar button, .explorer-folder__menu { border: 0; background: transparent; color: var(--text); cursor: pointer; border-radius: 5px; }
.explorer-toolbar__buttons button { min-width: 28px; min-height: 32px; padding: 3px; }
.explorer-toolbar button:hover, .explorer-folder__menu:hover { background: var(--surface-strong); }
.explorer-root { width: 100%; text-align: left; min-height: 32px; padding: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .8rem; }
.explorer-hint { font-size: .68rem; color: var(--muted); line-height: 1.4; margin: 4px 6px; }
.explorer-status { margin: 0; font-size: .75rem; line-height: 1.4; color: var(--muted); overflow-wrap: anywhere; }
.explorer-status:not(:empty) { padding: 8px 4px; }
.explorer-tree, .explorer-children { list-style: none; padding: 0; margin: 0; }
.explorer-children { margin-left: 11px; padding-left: 10px; border-left: 1px solid var(--border); }
.explorer-folder__row { display: flex; align-items: center; gap: 6px; min-height: 36px; cursor: pointer; border-radius: 6px; padding: 2px 4px; list-style: none; }
.explorer-folder__row::-webkit-details-marker { display: none; }
.explorer-folder__row::before { content: '›'; flex: 0 0 10px; text-align: center; font-size: 1.1rem; transition: transform .12s; }
.explorer-folder[open] > .explorer-folder__row::before { transform: rotate(90deg); }
.explorer-folder__row:hover, .explorer-folder__row.is-selected { background: var(--surface-strong); }
.explorer-folder__icon { position: relative; width: 15px; height: 11px; border: 1.4px solid currentColor; border-radius: 2px; color: var(--muted); flex-shrink: 0; }
.explorer-folder__icon::before { content: ''; position: absolute; top: -4px; left: -1.4px; width: 7px; height: 3px; border: 1.4px solid currentColor; border-bottom: 0; border-radius: 2px 2px 0 0; }
.explorer-folder__name { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .83rem; }
.explorer-folder__menu { min-width: 30px; min-height: 32px; font-size: 1.3rem; }
.explorer-folder__empty { color: var(--muted); font-size: .72rem; padding: 8px; }
.explorer-tree .conversation-item { padding: 3px 4px 3px 8px; gap: 0 3px; }
.explorer-tree .conversation-item__title { font-size: .8rem; }
.explorer-tree .conversation-item__cost { font-size: .58rem; }
.conversation-list { overflow: auto; }
.explorer-children > li { min-width: 160px; }
.is-drop-target { outline: 2px solid var(--accent); outline-offset: -2px; background: var(--surface-strong) !important; }
.explorer-dialog-field { display: grid; gap: 8px; min-width: 0; }
.explorer-dialog-field input, .explorer-dialog-field select { width: 100%; min-width: 0; border: 1px solid var(--border); border-radius: 8px; padding: 10px; color: var(--text); background: var(--bg); font: inherit; }
.explorer-dialog-context { margin: 0; color: var(--muted); font-size: .85rem; overflow-wrap: anywhere; }
.explorer-toolbar button:focus-visible, .explorer-folder__row:focus-visible, .explorer-folder__menu:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
@media (max-width: 820px) {
  .explorer-toolbar__buttons button { min-width: 36px; min-height: 44px; }
  .explorer-folder__menu { min-width: 44px; min-height: 44px; }
  .explorer-folder__row { min-height: 44px; }
}

@media (max-height: 560px) {
  .sidebar { overflow-y: auto; }
  .conversation-list, .performance-panel { flex: 1 0 140px; }
}
