/* ===== ATLAS AI — chat.css: header, messages, welcome, composer ===== */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; height: 100%; }

#chatHeader {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(8px);
  min-height: 56px;
}
#chatTitle {
  flex: 1; font-weight: 600; font-size: 15px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#headerRight { display: flex; align-items: center; gap: 6px; }

/* ===== Messages ===== */
.messages {
  flex: 1; overflow-y: auto; scroll-behavior: smooth;
  display: flex; flex-direction: column;
  padding: 18px 14px 8px;
}
.msg-col { width: 100%; max-width: 760px; margin: 0 auto; }

.msg { margin-bottom: 18px; animation: msgIn 0.22s ease; }
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } }

.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble {
  background: var(--user-bubble); border: 1px solid var(--border);
  border-radius: 16px 16px 4px 16px;
  padding: 10px 14px; max-width: 85%;
  white-space: pre-wrap; word-break: break-word;
}
[dir="rtl"] .msg.user .bubble { border-radius: 16px 16px 16px 4px; }

.msg.user .bubble img { max-width: 220px; border-radius: 10px; margin-top: 6px; display: block; }

.msg.ai .ai-name {
  display: flex; align-items: center; gap: 6px;
  font-size: 12.5px; font-weight: 600; color: var(--accent); margin-bottom: 4px;
}
.msg.ai .ai-name svg { width: 14px; height: 14px; }
.msg.ai .bubble {
  max-width: 100%; word-break: break-word;
}
.msg.ai .bubble p { margin-bottom: 10px; }
.msg.ai .bubble p:last-child { margin-bottom: 0; }
.msg.ai .bubble ul, .msg.ai .bubble ol { margin: 6px 0 10px; padding-inline-start: 22px; }
.msg.ai .bubble li { margin-bottom: 3px; }
.msg.ai .bubble h1, .msg.ai .bubble h2, .msg.ai .bubble h3 { margin: 14px 0 8px; line-height: 1.3; }
.msg.ai .bubble h1 { font-size: 1.25em; } .msg.ai .bubble h2 { font-size: 1.15em; } .msg.ai .bubble h3 { font-size: 1.05em; }
.msg.ai .bubble blockquote {
  border-inline-start: 3px solid var(--accent); padding-inline-start: 12px;
  color: var(--text-dim); margin: 8px 0;
}
.msg.ai .bubble code {
  background: var(--surface2); border-radius: 5px; padding: 1.5px 5px;
  font-size: 0.88em; font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
}
.msg.ai .bubble pre {
  background: #0d1117; color: #e2e8f0; border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px; overflow-x: auto;
  direction: ltr; text-align: left; margin: 8px 0 12px;
}
.msg.ai .bubble pre code { background: none; padding: 0; font-size: 13px; line-height: 1.5; }
.msg.ai .bubble a { color: var(--accent); }
.msg.ai .bubble hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.msg.ai .bubble table { border-collapse: collapse; margin: 8px 0 12px; display: block; overflow-x: auto; max-width: 100%; }
.msg.ai .bubble th, .msg.ai .bubble td { border: 1px solid var(--border); padding: 6px 11px; font-size: 13.5px; text-align: start; }
.msg.ai .bubble th { background: var(--surface2); }

.msg.ai .bubble .msg-img { max-width: min(420px, 100%); border-radius: 12px; display: block; margin-top: 6px; cursor: zoom-in; border: 1px solid var(--border); }

/* Message actions row */
.msg-actions {
  display: flex; align-items: center; gap: 2px; margin-top: 6px;
  opacity: 0; transition: opacity 0.15s;
}
.msg:hover .msg-actions, .msg:focus-within .msg-actions, .msg-actions.always { opacity: 1; }
.msg-actions button {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 8px; border-radius: 7px;
  color: var(--text-dim); font-size: 12px;
}
.msg-actions button:hover, .msg-actions button:focus-visible { background: var(--surface2); color: var(--text); }
.msg-actions button.active { color: var(--accent); }
.msg-actions button svg { width: 14px; height: 14px; }

/* Sources (web search) */
.sources {
  margin-top: 10px; border-top: 1px dashed var(--border); padding-top: 8px;
}
.sources .src-title { font-size: 12px; font-weight: 600; color: var(--text-dim); margin-bottom: 6px; }
.sources a {
  display: block; font-size: 12.5px; color: var(--accent);
  text-decoration: none; padding: 3px 0; overflow-wrap: anywhere;
}
.sources a:hover { text-decoration: underline; }

/* Thinking indicator */
.thinking { display: inline-flex; align-items: center; gap: 8px; color: var(--text-dim); font-size: 14px; }
.thinking .dots { display: inline-flex; gap: 4px; }
.thinking .dots i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
  animation: blink 1.2s infinite ease-in-out;
}
.thinking .dots i:nth-child(2) { animation-delay: 0.2s; }
.thinking .dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

/* Error message */
.error-box {
  background: var(--surface); border: 1px solid rgba(248, 113, 113, 0.4);
  border-radius: 12px; padding: 14px; margin-top: 4px;
}
.error-box .e-title { font-weight: 600; margin-bottom: 4px; }
.error-box .e-text { color: var(--text-dim); font-size: 13.5px; margin-bottom: 10px; }
.error-box .e-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.error-box .e-actions button {
  padding: 7px 13px; border-radius: 8px; font-size: 13px; font-weight: 500;
  border: 1px solid var(--border);
}
.error-box .e-actions .retry { background: var(--accent); color: var(--accent-ink); border: none; font-weight: 600; }

/* Load earlier */
.load-earlier {
  align-self: center; margin: 0 auto 14px; padding: 7px 14px;
  border: 1px solid var(--border); border-radius: 999px;
  color: var(--text-dim); font-size: 12.5px;
}
.load-earlier:hover { color: var(--text); background: var(--surface2); }

/* ===== Welcome screen ===== */
#welcome { margin: auto; text-align: center; padding: 24px 16px; max-width: 640px; width: 100%; }
.welcome-logo { color: var(--accent); width: 52px; height: 52px; margin: 0 auto 14px; }
.welcome-logo svg { width: 100%; height: 100%; }
.welcome-logo.big { width: 64px; height: 64px; }
#welcome h1 { font-size: 26px; margin-bottom: 6px; }
#welcome p { color: var(--text-dim); margin-bottom: 22px; }
.suggestions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.sug-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 13px 14px; text-align: start;
  display: flex; align-items: center; gap: 10px; font-size: 13.5px;
  transition: border-color 0.15s, background 0.15s;
}
.sug-card:hover, .sug-card:focus-visible { border-color: var(--accent); background: var(--accent-soft); }
.sug-card svg { width: 17px; height: 17px; color: var(--accent); }

/* ===== Composer ===== */
#composerWrap {
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
}
#offlineBanner {
  background: var(--danger); color: #fff; text-align: center;
  padding: 6px; border-radius: 8px; font-size: 13px; margin-bottom: 8px;
}
#attachPreviews { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
#attachPreviews:empty { display: none; }
.attach-chip {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 6px 10px; font-size: 12.5px; max-width: 230px;
  animation: popIn 0.15s ease;
}
.attach-chip img { width: 26px; height: 26px; border-radius: 5px; object-fit: cover; }
.attach-chip .ac-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-chip .ac-size { color: var(--text-dim); font-size: 11px; }
.attach-chip button { color: var(--text-dim); display: flex; padding: 2px; border-radius: 4px; }
.attach-chip button:hover { color: var(--danger); }
.attach-chip .ac-info { display: flex; flex-direction: column; min-width: 0; }

#composer {
  display: flex; align-items: flex-end; gap: 4px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 6px 8px;
  transition: border-color 0.15s;
}
#composer:focus-within { border-color: var(--accent); }
#input {
  flex: 1; background: none; border: none; outline: none; resize: none;
  max-height: 170px; padding: 8px 4px; font-size: 15px; line-height: 1.45;
  min-height: 40px; overflow-y: auto;
}
#modelSelect {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 9px; padding: 6px; font-size: 12.5px; color: var(--text-dim);
  max-width: 92px; margin-bottom: 3px;
}
#modelSelect:focus-visible { outline: 2px solid var(--accent); }
.send-btn {
  background: var(--accent); color: var(--accent-ink);
  width: 38px; height: 38px; min-width: 38px; border-radius: 11px;
  display: inline-flex; align-items: center; justify-content: center;
  transition: filter 0.15s, opacity 0.15s;
}
.send-btn svg { width: 18px; height: 18px; }
.send-btn:hover { filter: brightness(1.1); }
.send-btn:disabled { opacity: 0.35; cursor: default; }
.composer-hint { text-align: center; color: var(--text-dim); font-size: 11px; margin-top: 6px; }

#btnMic.listening { color: var(--accent); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { background: var(--accent-soft); } }

/* Image viewer overlay */
.img-viewer {
  position: fixed; inset: 0; z-index: 95; background: rgba(2, 8, 20, 0.9);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  cursor: zoom-out;
}
.img-viewer img { max-width: 100%; max-height: 100%; border-radius: 8px; }
