/* Spanish Tiles AI — UI */

:root {
  --primary: #2c5aa0;
  --primary-dark: #1e3f7a;
  --accent: #e74c3c;
  --warm: #f39c12;
  --bg: #f7f8fb;
  --surface: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --code-bg: #f1f5f9;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ---------- LOGIN ---------- */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  background: linear-gradient(135deg, #f7f8fb 0%, #e8eef7 100%);
}
.login-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 40px 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
}
.brand {
  text-align: center;
  margin-bottom: 28px;
}
.brand h1 {
  margin: 16px 0 4px;
  font-size: 26px;
  color: var(--text);
}
.brand p {
  color: var(--text-muted);
  margin: 0;
  font-size: 14px;
}
.brand-logo {
  display: block;
  width: 100%;
  max-width: 280px;
  height: auto;
  margin: 0 auto 8px;
  object-fit: contain;
}
.alert {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 14px;
}
form label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-top: 16px;
  margin-bottom: 6px;
}
form input {
  width: 100%;
  padding: 11px 14px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
form input:focus { border-color: var(--primary); }
form button {
  width: 100%;
  margin-top: 24px;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  color: white;
  background: var(--primary);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}
form button:hover { background: var(--primary-dark); }
.footer-note {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 24px;
}

/* ---------- APP LAYOUT ---------- */
.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 280px;
  background: #1e293b;
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.2s;
}
.sidebar-head {
  padding: 14px 16px;
  border-bottom: 1px solid #334155;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand-small {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 15px;
}
.brand-logo-small {
  display: block;
  height: 32px;
  width: auto;
  max-width: 160px;
  object-fit: contain;
  /* Logo is dark text on transparent — invert to white on dark sidebar */
  filter: brightness(0) invert(1);
}
.icon-btn {
  background: none;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  font-size: 22px;
  padding: 0;
  width: 30px;
  height: 30px;
  display: none;
}
.new-chat-btn {
  margin: 14px 16px 8px;
  padding: 10px;
  border: 1px solid #475569;
  border-radius: 8px;
  background: transparent;
  color: #e2e8f0;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  text-align: center;
}
.new-chat-btn:hover { background: #334155; }
.conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
}
.conv-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  border-radius: 6px;
  margin-bottom: 2px;
  color: #cbd5e1;
  text-decoration: none;
  font-size: 14px;
}
.conv-item:hover { background: #334155; color: #fff; }
.conv-item.active { background: #475569; color: #fff; }
.conv-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.del-btn {
  background: none;
  border: none;
  color: inherit;
  opacity: 0.5;
  cursor: pointer;
  font-size: 18px;
  padding: 0 4px;
  visibility: hidden;
}
.conv-item:hover .del-btn { visibility: visible; opacity: 1; }
.empty-hint {
  color: #64748b;
  font-size: 13px;
  text-align: center;
  margin-top: 20px;
}
.sidebar-foot {
  padding: 12px 16px;
  border-top: 1px solid #334155;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.user-info { font-size: 13px; overflow: hidden; }
.user-name { font-weight: 600; }
.user-email {
  color: #94a3b8;
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.logout-btn {
  background: transparent;
  color: #cbd5e1;
  border: 1px solid #475569;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  flex-shrink: 0;
}
.logout-btn:hover { background: #334155; }

/* Chat main */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.chat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.chat-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}
.chat-head .icon-btn { color: var(--text); display: none; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}
.welcome {
  max-width: 700px;
  margin: 40px auto;
  text-align: center;
}
.welcome-logo {
  display: block;
  width: 100%;
  max-width: 220px;
  height: auto;
  margin: 0 auto 16px;
  object-fit: contain;
  opacity: 0.95;
}
.welcome h1 {
  margin: 0 0 8px;
  font-size: 24px;
  color: var(--text);
  font-weight: 600;
}
.welcome p {
  color: var(--text-muted);
  font-size: 16px;
  margin-bottom: 32px;
}
.welcome-hint {
  margin-top: 28px;
  font-size: 13px;
  color: var(--text-muted);
  background: #eff6ff;
  border: 1px solid #dbeafe;
  border-radius: 10px;
  padding: 10px 14px;
  display: inline-block;
}
.tts-btn {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  font-size: 18px !important;
  margin-left: auto;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  transition: background 0.15s;
}
.tts-btn:hover { background: #f1f5f9; }
.tts-btn[aria-pressed="true"] { background: #dbeafe; }
.chat-head { gap: 12px; }
.suggestions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 24px;
}
.suggest {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 14px 16px;
  border-radius: 10px;
  text-align: left;
  font-size: 14px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
  color: var(--text);
}
.suggest:hover { border-color: var(--primary); }
.suggest:active { transform: scale(0.98); }

.msg {
  max-width: 800px;
  margin: 0 auto 20px;
}
.msg-role {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.msg-content {
  font-size: 15px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg-user .msg-content {
  background: #e0e7ff;
  padding: 12px 16px;
  border-radius: 10px;
  display: inline-block;
  max-width: 100%;
}
.msg-assistant .msg-content {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 14px 18px;
  border-radius: 10px;
}
.msg-content code {
  background: var(--code-bg);
  padding: 2px 5px;
  border-radius: 3px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
}
.msg-content pre {
  background: var(--code-bg);
  padding: 12px;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 13px;
}
.msg-content table {
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 13px;
  width: 100%;
}
.msg-content th, .msg-content td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}
.msg-content th { background: #f1f5f9; font-weight: 600; }
.msg-content h1, .msg-content h2, .msg-content h3 { margin: 16px 0 8px; }
.msg-content ul, .msg-content ol { margin: 8px 0; padding-left: 24px; }

.tool-call {
  font-size: 12px;
  color: var(--text-muted);
  background: #fef3c7;
  border-left: 3px solid var(--warm);
  padding: 6px 10px;
  border-radius: 4px;
  margin: 6px 0;
  font-family: ui-monospace, monospace;
}

/* Composer */
.composer {
  display: flex;
  gap: 8px;
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.composer textarea {
  flex: 1;
  padding: 10px 14px;
  font-size: 15px;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 10px;
  resize: none;
  outline: none;
  max-height: 200px;
  background: var(--bg);
}
.composer textarea:focus { border-color: var(--primary); }
.composer button {
  width: auto;            /* override form button width:100% */
  margin-top: 0;          /* override form button margin */
  flex: 0 0 auto;
  background: var(--primary);
  color: white;
  border: none;
  padding: 0 20px;
  height: 44px;
  min-width: 88px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.15s, transform 0.05s;
}
.composer button:hover { background: var(--primary-dark); }
.composer button:active { transform: scale(0.97); }
.composer button:disabled { background: #94a3b8; cursor: not-allowed; }
.composer textarea {
  min-height: 44px;       /* match button height */
}
.composer-hint {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  margin: 0;
  padding: 4px 0 8px;
  background: var(--surface);
}

/* Inline charts (Phase 2) */
.chart-wrap {
  margin: 14px 0;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
.chart-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 10px;
}
.chart-canvas-holder {
  position: relative;
  width: 100%;
  height: 320px;
}

.typing {
  display: inline-block;
  animation: blink 1s steps(1) infinite;
  color: var(--primary);
}
@keyframes blink { 50% { opacity: 0; } }

/* Mobile */
@media (max-width: 800px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    transform: translateX(-100%);
    z-index: 10;
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .icon-btn { display: inline-flex !important; align-items: center; justify-content: center; }
  .messages { padding: 16px; }
  .composer { padding: 12px 16px; }
}
