:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #e2e4e9;
  --text: #1c1f26;
  --muted: #6b7280;
  --accent: #2f6fed;
  --accent-dark: #1e4fbd;
  --bubble-user: #eef1f6;
  --bubble-bot: #e6f0ff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

.view { min-height: 100vh; }
/* #login-view fija display:flex más abajo, que por especificidad de ID
   le gana al [hidden] del navegador (display:none) — sin esto, el login
   nunca se ocultaba al entrar aunque la sesión sí se creara. */
#login-view[hidden], #app-view[hidden] { display: none; }

/* ---- Login ---- */
#login-view {
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.06);
}

.login-card h1 { margin: 0; font-size: 20px; }
.subtitle { margin: 0 0 8px; color: var(--muted); font-size: 13px; }

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.login-card input, .filters input {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}

button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 10px 14px;
  background: var(--accent);
  color: white;
  font-size: 14px;
}
button:hover { background: var(--accent-dark); }

.link-btn {
  background: transparent;
  color: var(--accent);
  padding: 6px 8px;
}
.link-btn:hover { background: rgba(47,111,237,0.08); }

.error { color: #d33; font-size: 13px; min-height: 16px; margin: 0; }

/* ---- App shell ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 16px; margin: 0; }
.topbar-right { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); }

.layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  height: calc(100vh - 53px);
}

.list-panel {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.filters input { flex: 1 1 100px; }
.filters button { flex: 0 0 auto; }

.conversations-list {
  overflow-y: auto;
  flex: 1;
}

.conv-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.conv-item:hover { background: #fafbfc; }
.conv-item.active { background: #eef3ff; }

.conv-item .conv-top {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
}
.conv-item .conv-preview {
  margin-top: 4px;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-item .conv-meta {
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
}

.thread-panel { overflow: hidden; display: flex; flex-direction: column; }
.thread-empty { margin: auto; color: var(--muted); font-size: 14px; }

.thread-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}
.muted { color: var(--muted); font-weight: normal; }

.thread-messages {
  overflow-y: auto;
  flex: 1;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  max-width: 60%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.4;
}
.msg .msg-time { display: block; font-size: 10px; color: var(--muted); margin-top: 4px; }
.msg.user { align-self: flex-start; background: var(--bubble-user); border-bottom-left-radius: 2px; }
.msg.assistant { align-self: flex-end; background: var(--bubble-bot); border-bottom-right-radius: 2px; }
.msg.system { align-self: center; background: transparent; color: var(--muted); font-style: italic; }
