/* =========================
   Tomiko AI â€” style.css
   ========================= */

/* --------- Variables --------- */
:root {
  --bg:#0b1220;
  --panel:#0f172a;
  --txt:#e5e7eb;
  --muted:#9ca3af;
  --brand:#1d4ed8;
  --brand-2:#0ea5e9;
  --danger:#ef4444;
  --danger-2:#b91c1c;
  --border:#1f2937;
  --composer-h:72px;
}

/* --------- Reset / Base --------- */
* { box-sizing:border-box; margin:0; padding:0; }
html, body {
  height:100%;
  min-height:100dvh;
  background:var(--bg);
  color:var(--txt);
  font-family:system-ui,-apple-system,"Segoe UI",Roboto,Inter,Arial,sans-serif;
  -webkit-font-smoothing:antialiased;
  -moz-osx-font-smoothing:grayscale;
  -webkit-text-size-adjust:100%;
 
}

/* --------- Layout general --------- */
.wrap {
  display: flex;
  height: 100vh;
  width: 100%;
  overflow: hidden;
}

/* --------- Sidebar --------- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 320px;
  height: 100vh;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  z-index: 9999;
  overflow: hidden; /* mantenemos el diseño cerrado */
}

/* Contenedor de scroll (todo el contenido menos el footer) */
.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 20px;
}

/* Header superior */
.sidebar-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 10;
}

.sidebar-head img { height: 36px; }
.sidebar-head .brand-col { display: flex; flex-direction: column; }
.sidebar-head .indicator { color: var(--muted); font-size: 13px; }

/* Botón nuevo chat */
.new-chat {
  display: block;
  margin: 16px;
  width: calc(100% - 32px);
  padding: 10px 12px;
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
  border: none;
  border-radius: 10px;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

/* Lista de chats */
.chat-list {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 20px;
}
.chat-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid #1e293b;
}
.chat-item .title {
  color: var(--txt);
  text-decoration: none;
  max-width: 75%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-item .actions button {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
}

/* Footer que siempre está abajo dentro del sidebar */
.sidebar-footer {
  flex-shrink: 0;
  margin-top: auto;
  border-top: 1px solid var(--border);
  background: var(--panel);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(6px) brightness(1.05);
}

/* Botones */
.sidebar-footer .pill {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: 999px;
  text-decoration: none;
  padding: 10px;
  color: var(--muted);
  transition: all .25s ease;
}
.sidebar-footer .pill:hover {
  border-color: var(--brand);
  color: var(--brand-2);
}
.sidebar-footer .pill.danger {
  color: #fff;
  border: none;
  background: linear-gradient(90deg, var(--danger-2), var(--danger));
}
.sidebar-footer .pill.danger:hover { opacity: .9; }


/* --------- Mensajes --------- */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  scroll-behavior: smooth;
  background: var(--bg);
  transition: padding-bottom 0.2s ease;
}


.msg {
  max-width: 70%;
  background: #111827;
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 10px;
  line-height: 1.5;
  word-break: break-word;
}

.msg.user {
  background: #1d4ed8;
  color: #fff;
  margin-left: auto;
}

.msg.assistant {
  background: #0f172a;
  color: #e5e7eb;
  transition: all 0.1s ease;
}


.msg.typing {
  font-style: italic;
  color: #9ca3af;
  background: #0f172a;
  animation: blink 1.5s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* --------- Composer --------- */
.composer {
  position: fixed;
  bottom: 40px; /* 💡 ahora la caja completa flota 40px arriba del borde */
  left: 0;
  right: 0;
  background: var(--bg);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
  min-height: calc(var(--composer-h) + 10px);
  z-index: 300;
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.35);
  border-radius: 12px 12px 0 0; /* estética más limpia */
}

/* Área de texto donde se escriben las consultas */
textarea {
  flex: 1;
  height: 56px;
  resize: none;
  background: #111827;
  color: var(--txt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-size: 16px;
  line-height: 1.4;
}

/* Botón de envío */
button.primary {
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
  border: none;
  border-radius: 10px;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  padding: 12px 16px;
  cursor: pointer;
  transition: opacity 0.2s;
}
button.primary:hover { opacity: 0.9; }

/* --------- Ajustes móviles --------- */
@media (max-width: 768px) {
  .composer {
    bottom: 30px; /* 📱 flota un poco menos en pantallas chicas */
    padding: 18px;
  }

  textarea {
    font-size: 16px;
    height: 54px;
  }

  /* Evita que los últimos mensajes queden tapados */
  .messages {
    padding-bottom: calc(var(--composer-h) + 120px);
  }
}

/* Ajuste especial para iPhone notch / PWA standalone */
@supports (padding: max(0px)) {
  .composer {
    bottom: 35px; /* mantiene margen visible en notch/PWA */
  }
}



/* --------- Login --------- */
.login-wrap { min-height:100dvh; display:grid; place-items:center; padding:24px; }
.login-card {
  width:100%; max-width:480px;
  background:var(--panel);
  border:1px solid var(--border); border-radius:14px; padding:28px;
  box-shadow:0 0 20px rgba(0,0,0,.45);
  overflow:hidden;
}
.login-card h1 {
  display:flex; align-items:center; gap:10px;
  font-size:24px; margin-bottom:20px;
}
.login-card h1 img { height:30px; }

.field { position:relative; display:flex; flex-direction:column; gap:6px; margin-bottom:14px; }
.field label { color:var(--muted); font-size:14px; }

.field input {
  display:block;
  width:100%;
  font-size:16px;
  background:#0b1220;
  color:var(--txt);
  border:1px solid var(--border);
  border-radius:10px;
  padding:12px 12px;
  transition:border-color .2s, box-shadow .2s;
}
.field input:focus {
  border-color:var(--brand-2);
  box-shadow:0 0 6px rgba(14,165,233,.4);
  outline:none;
}
.toggle-eye {
  position:absolute;
  right:12px;
  top:38px;
  cursor:pointer;
  color:#9ca3af;
  font-size:18px;
  transition:.2s;
}
.toggle-eye:hover { color:#e5e7eb; }
.actions { display:flex; justify-content:space-between; align-items:center; gap:12px; margin-top:10px; }

/* --------- Responsive --------- */
@media (max-width:768px) {
  .close-btn { display:inline-block; }

  .sidebar {
    position:fixed; top:0; left:-100%;
    height:100%; width:86%; max-width:360px;
    background:var(--panel);
    border-right:1px solid var(--border);
    transition:left .25s ease;
    box-shadow:8px 0 16px rgba(0,0,0,.3);
    z-index:200;
  }
  .sidebar.open { left:0; }

  .chat-list { flex:1; overflow:auto; min-height:0; }
  body.sidebar-open { overflow:hidden; }

  .messages { padding:14px; }
  .msg { max-width:100%; font-size:16px; padding:12px 14px; }
  .composer { padding:10px 12px; --composer-h:72px; }
  textarea { height:56px; font-size:16px; }
  button.primary { padding:12px 14px; font-size:16px; }

  .panel-wrap { padding:20px; font-size:16px; }
  .panel-title { font-size:22px; }
  .panel-card { padding:18px; }
  .kpi .value { font-size:22px; }

  .chat-item { padding:12px; }
  .chat-item .title { max-width:70%; font-size:15px; }

  .login-card { max-width:92vw; padding:22px; }
}

/* --- FIX composer offset en desktop --- */
@media (min-width:769px) {
  .composer {
    left: 320px;
  }
}

/* === FIX CHAT SCROLL EN MÃ“VILES === */
.messages {
  scroll-behavior: smooth;
  padding-bottom: calc(var(--composer-h) + 12px);
  background: var(--bg);
}


/* --------- Links --------- */
a { color:var(--brand); text-decoration:none; }
a:hover { color:var(--brand-2); }



/* === Botón Instalar App (PWA) === */
.sidebar-install-btn {
  display: none;
  width: calc(100% - 30px);
  margin: 12px 15px 18px 15px;
  padding: 10px 0;
  border: 1px solid #1e293b;
  border-radius: 8px;
  background: #111827;
  color: #e5e7eb;
  font-size: 15px;
  font-weight: 500;
  text-align: center;
  cursor: pointer;
  transition: all .25s;
}

.sidebar-install-btn:hover {
  background: #1e293b;
}

/* --- Aviso de instalación iOS (flotante sobre el composer) --- */
.ios-install-tip {
  position: fixed;
  bottom: calc(var(--composer-h, 80px) + 120px);
  left: 50%;
  transform: translateX(-50%);
  max-width: 340px;
  width: 90%;
  background: #111827;
  border: 1px solid #1e293b;
  border-radius: 12px;
  color: #e5e7eb;
  font-size: 14px;
  line-height: 1.4;
  text-align: center;
  padding: 14px 16px;
  box-shadow: 0 0 14px rgba(0,0,0,.6);
  z-index: 10000; /* por encima del composer */
}

.ios-install-close {
  margin-top: 8px;
  background: transparent;
  border: 1px solid #444;
  color: #e5e7eb;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 13px;
}
.ios-install-close:hover {
  background: #1e293b;
}

@media (max-width: 768px) {
  .ios-install-tip {
    bottom: calc(var(--composer-h, 100px) + 14px);
  }
}




/* Vista previa de archivos adjuntos */
.msg.preview {
  opacity: 0.85;
  border: 1px dashed var(--border);
}

/* === 💬 Estilo tipo ChatGPT Plus === */
/* === 💬 Estilo tipo ChatGPT Plus adaptado al sidebar === */
.composer.chatgpt-style {
  position: fixed;
  bottom: 0;
  left: 320px; /* deja espacio al sidebar */
  right: 0;
  background: var(--bg);
  padding: 18px 20px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  border-top: 1px solid var(--border);
  z-index: 300;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.3);
}

@media (max-width: 768px) {
  .composer.chatgpt-style {
    left: 0; /* en móviles ocupa todo el ancho */
    padding: 18px 14px 24px;
  }
}


.chatgpt-style .input-wrapper {
  display: flex;
  align-items: flex-end;
  background: #111827;
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 10px 14px;
  max-width: 780px;
  width: 100%;
  box-shadow: 0 4px 10px rgba(0,0,0,0.25);
}

.chatgpt-style textarea {
  flex: 1;
  resize: none;
  border: none;
  background: transparent;
  color: var(--txt);
  font-size: 16px;
  line-height: 1.5;
  outline: none;
  min-height: 28px;
  max-height: 200px;
  overflow-y: auto;
}

.composer-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: 10px;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 20px;
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  color: var(--brand-2);
  background: #1e293b;
}

.icon-btn.send {
  font-size: 22px;
  color: var(--brand);
}

.icon-btn.send:hover {
  color: var(--brand-2);
}

.chatgpt-style .hint {
  display: none; /* oculto por defecto */
}

@media (max-width: 768px) {
  .chatgpt-style .hint {
    display: block; /* solo visible en pantallas chicas */
    color: var(--muted);
    font-size: 13px;
    margin-top: 6px;
    text-align: center;
    user-select: none;
  }
}

/* === 💻 FIX escritorio: el chat no quede tapado === */
@media (min-width: 769px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 320px;
    height: 100vh;
    background: var(--panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    z-index: 200;
    overflow: hidden;
  }

  .main {
    margin-left: 320px; /* ✅ deja espacio para el sidebar */
    height: 100vh;
    display: flex;
    flex-direction: column;
  }

  .composer {
    left: 320px; /* ✅ evita que quede tapado por el sidebar */
  }
}

/* === 📱 FIX móviles: sidebar deslizable === */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: -100%; /* fuera de pantalla por defecto */
    width: 86%;
    max-width: 360px;
    height: 100dvh;
    background: var(--panel);
    border-right: 1px solid var(--border);
    transition: left .25s ease;
    z-index: 9999;
    display: flex;
    flex-direction: column;
  }

  .sidebar.open {
    left: 0; /* ✅ se muestra al abrir */
  }

  .sidebar-footer {
    position: sticky;
    bottom: 0;
    border-top: 1px solid var(--border);
    background: var(--panel);
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    box-shadow: 0 -4px 12px rgba(0,0,0,0.35);
  }

  .chat-list {
    padding-bottom: 120px;
  }

  .main {
    margin-left: 0; /* ✅ ocupa toda la pantalla en móvil */
  }

  .composer {
    left: 0; /* ✅ se centra en móvil */
  }
}

.chat-item {
  transition: background 0.2s, color 0.2s;
}
.chat-item.active {
  background: var(--brand);
  color: #fff;
}
.chat-item.active .title {
  color: #fff;
}


/* ======== FIN ======== */
