/* ============================================================================
   ollamyn · estilos globales
   Estética limpia y profesional (tipo Claude/ChatGPT), sin recuadros con borde.
   Paleta cálida, soporte claro/oscuro, tipografía del sistema.
   ============================================================================ */

:root {
  --bg: #fbfbfa;
  --surface: #f2f1ee;
  --surface-2: #e9e8e4;
  --text: #2a2823;
  --muted: #78746c;
  --accent: #c15f3c;
  --accent-hover: #a94f30;
  --danger: #c0392b;
  --border: rgba(0, 0, 0, 0.08);
  --ring: rgba(193, 95, 60, 0.28);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.06);
  --radius: 12px;
  --radius-sm: 9px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  --maxw: 46rem;
}

:root[data-theme="dark"],
:root:not([data-theme="light"]) {
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1b19;
    --surface: #262521;
    --surface-2: #34322c;
    --text: #ecebe7;
    --muted: #a5a199;
    --accent: #d97757;
    --accent-hover: #e08a6d;
    --danger: #e57368;
    --border: rgba(255, 255, 255, 0.1);
    --ring: rgba(217, 119, 87, 0.32);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 32px rgba(0, 0, 0, 0.4);
  }
}

:root[data-theme="dark"] {
  --bg: #1c1b19;
  --surface: #262521;
  --surface-2: #34322c;
  --text: #ecebe7;
  --muted: #a5a199;
  --accent: #d97757;
  --accent-hover: #e08a6d;
  --danger: #e57368;
  --border: rgba(255, 255, 255, 0.1);
  --ring: rgba(217, 119, 87, 0.32);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 32px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Marca --- */
.brand {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  font-size: 1.15rem;
  color: var(--text);
}
.brand .dot {
  width: 22px; height: 22px; border-radius: 7px;
  background: var(--accent);
  display: inline-block;
  position: relative;
}
.brand .dot::after {
  content: ""; position: absolute; inset: 6px 6px auto auto;
  width: 8px; height: 8px; border-radius: 50%; background: var(--bg);
}

/* --- Botones --- */
.btn {
  appearance: none; border: none; cursor: pointer;
  font: inherit; font-weight: 550;
  padding: .72rem 1.15rem;
  border-radius: var(--radius-sm);
  background: var(--accent); color: #fff;
  transition: background .15s ease, transform .05s ease, opacity .15s ease;
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
}
.btn:hover { background: var(--accent-hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.full { width: 100%; }
.btn.ghost {
  background: transparent; color: var(--text);
}
.btn.ghost:hover { background: var(--surface); }
.btn.subtle {
  background: var(--surface); color: var(--text);
}
.btn.subtle:hover { background: var(--surface-2); }

/* --- Campos --- */
.field { margin-bottom: 1rem; }
.field label {
  display: block; font-size: .82rem; font-weight: 550;
  color: var(--muted); margin-bottom: .35rem;
}
.input-wrap { position: relative; display: flex; align-items: center; }
.input {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: .78rem .9rem;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
.input::placeholder { color: var(--muted); opacity: .7; }
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--ring);
  background: var(--bg);
}
.input.has-toggle { padding-right: 2.9rem; }

/* botón mostrar/ocultar dentro del input */
.toggle-visibility {
  position: absolute; right: .5rem;
  background: none; border: none; cursor: pointer;
  color: var(--muted); padding: .4rem; border-radius: 7px;
  display: inline-flex; line-height: 0;
}
.toggle-visibility:hover { color: var(--text); background: var(--surface-2); }

.checkbox {
  display: flex; align-items: center; gap: .55rem;
  font-size: .9rem; color: var(--muted); cursor: pointer; user-select: none;
}
.checkbox input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

.hint { font-size: .8rem; color: var(--muted); margin-top: .3rem; }
.hint.error { color: var(--danger); }

/* Mensaje de alerta */
.alert {
  font-size: .88rem;
  padding: .7rem .85rem;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
  margin-bottom: 1rem;
  display: none;
}
.alert.show { display: block; }
.alert.ok { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }

/* --- Toggle de tema (esquina) --- */
.theme-toggle {
  position: fixed; top: 1rem; right: 1rem; z-index: 30;
  background: var(--surface); border: none; color: var(--muted);
  width: 38px; height: 38px; border-radius: 10px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.theme-toggle:hover { color: var(--text); background: var(--surface-2); }

/* ============================================================================
   Landing
   ============================================================================ */
.landing {
  min-height: 100%;
  display: flex; flex-direction: column;
}
.landing header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.25rem clamp(1rem, 5vw, 3rem);
}
.landing main {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center;
  padding: 2rem 1.25rem 5rem;
  gap: 1.3rem;
}
.landing h1 {
  font-size: clamp(2.2rem, 6vw, 3.6rem);
  line-height: 1.05; letter-spacing: -0.03em;
  margin: 0; max-width: 16ch;
}
.landing h1 .grad { color: var(--accent); }
.landing .lede {
  font-size: clamp(1.05rem, 2.5vw, 1.25rem);
  color: var(--muted); max-width: 46ch; margin: 0;
}
.landing .cta { display: flex; gap: .75rem; margin-top: .5rem; flex-wrap: wrap; justify-content: center; }
.landing footer {
  text-align: center; color: var(--muted); font-size: .82rem;
  padding: 1.5rem;
}

/* ============================================================================
   Auth (login / registro) — columna centrada, sin recuadro con borde
   ============================================================================ */
.auth {
  min-height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 2rem 1.25rem;
}
.auth-inner { width: 100%; max-width: 380px; }
.auth-head { text-align: center; margin-bottom: 1.75rem; }
.auth-head .brand { justify-content: center; font-size: 1.35rem; margin-bottom: 1.1rem; }
.auth-head h2 { margin: 0 0 .3rem; font-size: 1.5rem; letter-spacing: -0.02em; }
.auth-head p { margin: 0; color: var(--muted); font-size: .95rem; }
.auth-switch {
  text-align: center; margin-top: 1.4rem; font-size: .9rem; color: var(--muted);
}
.auth-switch button {
  background: none; border: none; color: var(--accent); font: inherit; font-weight: 550; cursor: pointer; padding: 0;
}
.auth-switch button:hover { text-decoration: underline; }
.row-between { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.1rem; }

/* ============================================================================
   Chat
   ============================================================================ */
.chat-layout { display: flex; height: 100dvh; overflow: hidden; }

/* Sidebar */
.sidebar {
  width: 264px; flex-shrink: 0;
  background: var(--surface);
  display: flex; flex-direction: column;
  padding: .75rem;
  transition: margin-left .22s ease;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: .35rem .35rem .75rem; }
.new-chat {
  width: 100%; justify-content: flex-start; gap: .6rem;
  background: transparent; color: var(--text); font-weight: 550;
  border: 1px solid var(--border);
}
.new-chat:hover { background: var(--surface-2); }
.chat-list { flex: 1; overflow-y: auto; margin-top: .75rem; display: flex; flex-direction: column; gap: 2px; }
.chat-list::-webkit-scrollbar { width: 8px; }
.chat-list::-webkit-scrollbar-thumb { background: var(--surface-2); border-radius: 8px; }
.chat-item {
  display: flex; align-items: center; gap: .5rem;
  padding: .55rem .6rem; border-radius: 9px; cursor: pointer;
  color: var(--text); font-size: .9rem;
  white-space: nowrap; overflow: hidden;
}
.chat-item:hover { background: var(--surface-2); }
.chat-item.active { background: var(--surface-2); font-weight: 550; }
.chat-item .title { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.chat-item .del {
  opacity: 0; background: none; border: none; color: var(--muted); cursor: pointer;
  padding: 2px; border-radius: 6px; line-height: 0;
}
.chat-item:hover .del { opacity: 1; }
.chat-item .del:hover { color: var(--danger); background: var(--bg); }

.sidebar-foot { border-top: 1px solid var(--border); padding-top: .6rem; margin-top: .4rem; }
.user-chip {
  display: flex; align-items: center; gap: .6rem; padding: .5rem .55rem; border-radius: 9px;
  cursor: pointer; position: relative;
}
.user-chip:hover { background: var(--surface-2); }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
  background: var(--accent); color: #fff; font-weight: 600; font-size: .82rem;
  display: inline-flex; align-items: center; justify-content: center; text-transform: uppercase;
}
.user-chip .uname { flex: 1; font-size: .9rem; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

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

/* Encabezado de grupo de chats por fecha (Hoy / Ayer / Anteriores...) */
.section-label {
  font-size: .72rem; font-weight: 650; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); padding: .9rem .6rem .35rem;
}
.chat-list .section-label:first-child { padding-top: .25rem; }

/* --- Selector de modelo personalizado (estilo Claude) --- */
.model-picker { position: relative; }
.model-btn {
  display: inline-flex; align-items: center; gap: .5rem;
  font: inherit; font-weight: 600; color: var(--text);
  background: transparent; border: none; cursor: pointer;
  padding: .45rem .6rem; border-radius: 10px;
}
.model-btn:hover { background: var(--surface); }
.dot-status { width: 8px; height: 8px; border-radius: 50%; background: #2ecc71; flex-shrink: 0; }
.dot-status.off { background: var(--muted); opacity: .5; }
.model-menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 40;
  width: min(340px, 86vw);
  background: var(--bg);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: .4rem;
  max-height: min(70vh, 460px); overflow-y: auto;
}
.model-option {
  display: flex; align-items: center; gap: .7rem;
  padding: .6rem .65rem; border-radius: 10px; cursor: pointer; width: 100%;
  background: none; border: none; text-align: left; font: inherit; color: var(--text);
}
.model-option:hover { background: var(--surface); }
.model-option .info { flex: 1; min-width: 0; }
.model-option .n { font-weight: 600; display: flex; align-items: center; gap: .45rem; }
.model-option .n .engine {
  font-size: .68rem; font-weight: 600; color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  padding: .05rem .4rem; border-radius: 999px;
}
.model-option .d { font-size: .8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-option .check { color: var(--accent); opacity: 0; flex-shrink: 0; }
.model-option.selected .check { opacity: 1; }
.model-option.disabled { opacity: .5; cursor: not-allowed; }
.model-option.disabled:hover { background: none; }
.model-option .badge-off {
  font-size: .66rem; color: var(--muted); border: 1px solid var(--border);
  padding: .05rem .4rem; border-radius: 999px; white-space: nowrap;
}

/* --- Botón flotante "ir al final" --- */
.scroll-down {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: 104px; z-index: 12;
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border);
  box-shadow: var(--shadow); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: opacity .15s ease, transform .15s ease;
}
.scroll-down:hover { background: var(--surface); transform: translateX(-50%) translateY(-1px); }
.scroll-down[hidden] { display: none; }
.topbar {
  display: flex; align-items: center; gap: .75rem;
  padding: .7rem 1rem; border-bottom: 1px solid var(--border);
}
.icon-btn {
  background: none; border: none; color: var(--muted); cursor: pointer;
  width: 36px; height: 36px; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { color: var(--text); background: var(--surface); }
.menu-btn { display: none; }
.model-select {
  font: inherit; font-weight: 550; color: var(--text);
  background: var(--surface); border: none; border-radius: 9px;
  padding: .5rem 2rem .5rem .8rem; cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2378746c' stroke-width='2.2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .6rem center;
}
.model-select:focus { outline: none; box-shadow: 0 0 0 4px var(--ring); }

/* Mensajes (sin scroll-behavior:smooth: el auto-scroll durante el streaming
   se controla por JS para que no dé saltos ni "pelee" con el usuario) */
.messages { flex: 1; overflow-y: auto; overflow-anchor: none; }
.messages-inner { max-width: var(--maxw); margin: 0 auto; padding: 1.5rem 1.25rem 2rem; }
.msg { display: flex; gap: .85rem; padding: 1rem 0; }
.msg .who {
  width: 28px; height: 28px; border-radius: 7px; flex-shrink: 0; margin-top: 2px;
  display: inline-flex; align-items: center; justify-content: center; font-size: .72rem; font-weight: 650; color: #fff;
}
.msg.user .who { background: var(--surface-2); color: var(--text); }
.msg.assistant .who { background: var(--accent); }
.msg .body { min-width: 0; flex: 1; }
.msg .name { font-size: .8rem; font-weight: 600; color: var(--muted); margin-bottom: .2rem; }
.msg .content { word-wrap: break-word; overflow-wrap: anywhere; }
.msg.user .content { white-space: pre-wrap; } /* respeta los saltos de línea del usuario */
.msg .content .cursor { display: inline-block; width: 7px; height: 1.05em; background: var(--accent); vertical-align: text-bottom; margin-left: 1px; animation: blink 1s steps(2) infinite; border-radius: 1px; }
@keyframes blink { 50% { opacity: 0; } }

/* --- Markdown en las respuestas de la IA --- */
.msg.assistant .content > :first-child { margin-top: 0; }
.msg.assistant .content > :last-child { margin-bottom: 0; }
.msg.assistant .content p { margin: 0 0 .75em; }
.msg.assistant .content h1,
.msg.assistant .content h2,
.msg.assistant .content h3,
.msg.assistant .content h4 { margin: 1em 0 .45em; line-height: 1.25; font-weight: 650; letter-spacing: -0.01em; }
.msg.assistant .content h1 { font-size: 1.4em; }
.msg.assistant .content h2 { font-size: 1.25em; }
.msg.assistant .content h3 { font-size: 1.1em; }
.msg.assistant .content h4 { font-size: 1em; }
.msg.assistant .content ul,
.msg.assistant .content ol { margin: .3em 0 .8em; padding-left: 1.4em; }
.msg.assistant .content li { margin: .25em 0; }
.msg.assistant .content li > ul,
.msg.assistant .content li > ol { margin: .2em 0; }
.msg.assistant .content a { color: var(--accent); text-decoration: underline; }
.msg.assistant .content strong { font-weight: 650; }
.msg.assistant .content code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: .88em;
  background: var(--surface-2);
  padding: .12em .38em;
  border-radius: 6px;
}
/* Bloque de código con cabecera (lenguaje + Copiar) */
.msg.assistant .content .code-block {
  margin: .55em 0 .95em;
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface-2);
}
.msg.assistant .content .code-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: .3rem .5rem .3rem .9rem;
  font-size: .72rem; color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.msg.assistant .content .code-lang { letter-spacing: .02em; }
.msg.assistant .content .code-copy {
  display: inline-flex; align-items: center; gap: .35rem;
  background: none; border: none; cursor: pointer;
  color: var(--muted); font: inherit; font-size: .72rem;
  padding: .25rem .45rem; border-radius: 7px;
  transition: color .12s ease, background .12s ease;
}
.msg.assistant .content .code-copy:hover { color: var(--text); background: var(--surface); }
.msg.assistant .content .code-copy .ico { display: inline-flex; line-height: 0; }
.msg.assistant .content .code-copy.copied { color: #2ecc71; }
.msg.assistant .content pre {
  margin: 0;
  padding: .6rem 1rem .85rem;
  overflow-x: auto;
}
.msg.assistant .content pre code {
  background: none;
  padding: 0;
  font-size: .86em;
  line-height: 1.55;
  white-space: pre;
}
.msg.assistant .content blockquote {
  margin: .5em 0 .8em;
  padding: .2em 0 .2em .9em;
  border-left: 3px solid var(--border);
  color: var(--muted);
}
.msg.assistant .content hr { border: none; border-top: 1px solid var(--border); margin: 1em 0; }
/* barra de scroll fina en los bloques de código */
.msg.assistant .content pre::-webkit-scrollbar { height: 8px; }
.msg.assistant .content pre::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }

/* Estado vacío */
.empty {
  height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: .5rem; padding: 2rem; color: var(--text);
}
.empty .brand { font-size: 1.6rem; margin-bottom: .5rem; }
.empty p { color: var(--muted); margin: 0; }

/* Composer */
.composer { padding: .5rem 1rem 1.25rem; }
.composer-inner {
  max-width: var(--maxw); margin: 0 auto;
  display: flex; align-items: flex-end; gap: .5rem;
  background: var(--surface);
  border-radius: 16px;
  padding: .55rem .55rem .55rem 1rem;
  box-shadow: var(--shadow);
}
.composer textarea {
  flex: 1; resize: none; border: none; background: none; color: var(--text);
  font: inherit; line-height: 1.5; max-height: 200px; padding: .35rem 0;
  outline: none;
}
.composer textarea::placeholder { color: var(--muted); }
.send-btn {
  width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
  background: var(--accent); color: #fff; border: none; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .15s ease, opacity .15s ease;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { opacity: .4; cursor: not-allowed; }
.composer-note { max-width: var(--maxw); margin: .5rem auto 0; text-align: center; font-size: .74rem; color: var(--muted); }

/* Overlay móvil */
.scrim { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 15; }

@media (max-width: 760px) {
  .sidebar {
    position: fixed; z-index: 20; top: 0; bottom: 0; left: 0;
    box-shadow: var(--shadow);
  }
  .sidebar.hidden { margin-left: -280px; }
  .menu-btn { display: inline-flex; }
  .scrim.show { display: block; }
}
