:root {
  --bg-primary: #0d0d0d;
  --bg-secondary: #171717;
  --bg-sidebar: #111111;
  --bg-hover: #262626;
  --text-primary: #e5e5e5;
  --text-secondary: #a3a3a3;
  --accent: #10b981;
  --accent-hover: #059669;
  --border: #262626;
  --radius: 12px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: var(--font); background: var(--bg-primary); color: var(--text-primary); overflow: hidden; }

#app { display: flex; height: 100vh; width: 100vw; }

/* Sidebar */
#sidebar {
  width: 260px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo { font-weight: 600; font-size: 1.1rem; letter-spacing: -0.5px; }
.btn-primary {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
}
.btn-primary:hover { background: var(--accent); border-color: var(--accent); color: #fff; }

.session-list { flex: 1; overflow-y: auto; padding: 8px; }
.session-item {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.15s;
}
.session-item:hover, .session-item.active { background: var(--bg-hover); color: var(--text-primary); }
.session-item .ts { font-size: 0.7rem; opacity: 0.6; display: block; margin-top: 2px; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#mode-selector {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
}
.badge {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-align: center;
}

/* Main chat */
#chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
}
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20%;
  display: flex;
  flex-direction: column;
  gap: 24px;
  scroll-behavior: smooth;
}
@media (max-width: 768px) {
  #sidebar { display: none; }
  .messages { padding: 16px; }
}

.message { display: flex; gap: 16px; max-width: 100%; }
.message.user { flex-direction: row-reverse; }
.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.9rem;
  flex-shrink: 0;
  background: var(--bg-hover);
}
.message.user .avatar { background: var(--accent); color: #fff; }
.bubble {
  background: var(--bg-secondary);
  padding: 14px 18px;
  border-radius: var(--radius);
  line-height: 1.6;
  font-size: 0.95rem;
  max-width: 100%;
  word-wrap: break-word;
}
.message.user .bubble { background: var(--bg-hover); }
.bubble pre {
  background: #000;
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  font-family: 'Fira Code', monospace;
  font-size: 0.85rem;
  margin: 8px 0;
}
.bubble code {
  background: rgba(255,255,255,0.06);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Fira Code', monospace;
  font-size: 0.9em;
}
.bubble p { margin-bottom: 0.6em; }
.bubble p:last-child { margin-bottom: 0; }

.meta {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 6px;
  display: flex;
  gap: 10px;
  align-items: center;
}
.meta .pill {
  background: var(--bg-hover);
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.7rem;
}

/* Input */
#input-area {
  padding: 16px 20% 24px;
  border-top: 1px solid var(--border);
  background: var(--bg-primary);
}
@media (max-width: 768px) { #input-area { padding: 12px 16px 16px; } }

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  transition: border-color 0.2s;
}
.input-wrapper:focus-within { border-color: var(--accent); }
#user-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.95rem;
  resize: none;
  max-height: 200px;
  line-height: 1.5;
}
.btn-send {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s;
}
.btn-send:not(:disabled) { color: var(--accent); }
.btn-send:not(:disabled):hover { color: var(--accent-hover); }
.input-meta {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 8px;
}

/* Status / thinking */
.thinking {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 0.9rem;
  padding: 8px 0;
}
.dot-flashing {
  position: relative;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: dot-flashing 1s infinite linear alternate;
  animation-delay: 0.5s;
}
.dot-flashing::before, .dot-flashing::after {
  content: ''; display: inline-block; position: absolute; top: 0;
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
  animation: dot-flashing 1s infinite alternate;
}
.dot-flashing::before { left: -10px; animation-delay: 0s; }
.dot-flashing::after { left: 10px; animation-delay: 1s; }
@keyframes dot-flashing {
  0% { opacity: 1; }
  100% { opacity: 0.2; }
}

/* Comparison table */
.comparison {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-top: 8px;
  font-size: 0.85rem;
}
.comparison table { width: 100%; border-collapse: collapse; }
.comparison th, .comparison td { padding: 6px 8px; text-align: left; color: var(--text-secondary); }
.comparison th { font-weight: 500; border-bottom: 1px solid var(--border); }
.comparison .winner { color: var(--accent); font-weight: 600; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.9rem;
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 1000;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Indicación sutil del proveedor */
.subtle-meta {
  font-size: 0.7rem;
  color: var(--text-secondary);
  opacity: 0.5;
  margin-top: 4px;
  text-align: right;
  transition: opacity 0.2s;
}
.message:hover .subtle-meta {
  opacity: 1;
}
