/* ── Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #0f1117;
  --bg-surface:  #1a1d27;
  --bg-elevated: #22263a;
  --border:      #2e3250;
  --accent:      #4facfe;
  --accent-dim:  #2d6fbf;
  --text:        #e2e8f0;
  --text-muted:  #8892aa;
  --user-bubble: #2d3a5a;
  --ai-bubble:   #1e2233;
  --nav-h:       56px;
}

html, body { height: 100%; overflow: hidden; }
body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg); color: var(--text);
  display: flex; flex-direction: column;
  padding-top: var(--nav-h);
}

/* ── AI Topbar ────────────────────────────────────────────────────── */
.ai-topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 200;
  height: var(--nav-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 .75rem;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
}
.ai-topbar-home {
  color: var(--text-muted); text-decoration: none; font-size: .85rem;
  padding: 6px 10px; border-radius: 6px;
  transition: color .15s, background .15s; white-space: nowrap;
}
.ai-topbar-home:hover { color: var(--text); background: var(--bg-elevated); }
.ai-topbar-title {
  font-size: .95rem; font-weight: 700; color: var(--text);
  display: flex; align-items: center; gap: .4rem;
  position: absolute; left: 50%; transform: translateX(-50%);
  white-space: nowrap; pointer-events: none;
}
.ai-topbar-actions { display: flex; align-items: center; gap: .1rem; }

.ai-icon-btn {
  background: none; border: none; color: var(--text-muted);
  font-size: 1.1rem; cursor: pointer; padding: 6px 8px; border-radius: 6px;
  transition: background .2s, color .2s; line-height: 1;
  position: relative;
}
.ai-icon-btn:hover  { background: var(--bg-elevated); color: var(--text); }
.ai-icon-btn.active { background: var(--bg-elevated); color: var(--accent); }

.ai-topbar .notification-badge {
  position: absolute;
  top: 0; right: 0;
  background: #e53935; color: #fff;
  border-radius: 10px; padding: 0 5px;
  font-size: 11px; min-width: 16px; height: 16px;
  line-height: 16px; text-align: center;
  pointer-events: none;
}

/* User avatar + dropdown */
.user-menu { position: relative; }
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: none; border: 2px solid var(--border);
  overflow: hidden; cursor: pointer; padding: 0;
}
.user-avatar img { width: 100%; height: 100%; object-fit: cover; }
.user-dropdown {
  position: absolute; top: calc(100% + 8px); right: 0;
  min-width: 160px; background: var(--bg-elevated);
  border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
  display: none; flex-direction: column; overflow: hidden; z-index: 300;
}
.user-dropdown.visible { display: flex; }
.dropdown-item {
  display: block; padding: 10px 14px; color: var(--text);
  text-decoration: none; background: none; border: none;
  text-align: left; font-size: .9rem; cursor: pointer; transition: background .15s;
}
.dropdown-item:hover { background: var(--border); }
.user-dropdown hr { border: none; border-top: 1px solid var(--border); margin: 2px 0; }
.logout-btn { color: #fc8181; }

/* ── Settings Panel ───────────────────────────────────────────────── */
.ai-settings-panel {
  flex-shrink: 0;
  background: var(--bg-surface); border-bottom: 1px solid var(--border);
  max-height: 0; overflow: hidden;
  transition: max-height .3s ease;
}
.ai-settings-panel.open { max-height: 300px; }

.ai-settings-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: .75rem 1.5rem;
  padding: .9rem 1.25rem; max-width: 860px; margin: 0 auto;
}
.ai-settings-row { display: flex; flex-direction: column; gap: .3rem; }
.ai-settings-row label {
  font-size: .72rem; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .05em;
}
.ai-settings-row select,
.ai-settings-row textarea {
  background: var(--bg-elevated); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: .5rem .75rem; font-size: .88rem; font-family: inherit;
  transition: border-color .2s;
}
.ai-settings-row select:focus,
.ai-settings-row textarea:focus { outline: none; border-color: var(--accent); }
.ai-settings-row textarea { resize: vertical; min-height: 58px; max-height: 120px; line-height: 1.5; }
.ai-settings-hint { font-size: .7rem; color: var(--text-muted); }

/* ── Page Layout ──────────────────────────────────────────────────── */
.ai-page-layout {
  flex: 1;
  display: flex; flex-direction: column; overflow: hidden;
  min-height: 0;
}
.ai-chat-container {
  flex: 1; display: flex; flex-direction: column;
  max-width: 860px; margin: 0 auto; width: 100%;
  overflow: hidden;
}

/* ── Chat Header (model label only) ──────────────────────────────── */
.ai-chat-header {
  display: flex; align-items: center; gap: .65rem;
  padding: .65rem 1.25rem;
  background: var(--bg-surface); border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.ai-icon { font-size: 1.4rem; line-height: 1; }
.ai-chat-header h1 { font-size: .95rem; font-weight: 700; color: var(--text); }
.ai-subtitle { font-size: .68rem; color: var(--text-muted); margin-top: 1px; }

/* ── Messages ─────────────────────────────────────────────────────── */
.ai-messages {
  flex: 1; overflow-y: auto; padding: 1.25rem;
  display: flex; flex-direction: column; gap: .875rem;
  scroll-behavior: smooth;
}
.ai-messages::-webkit-scrollbar { width: 5px; }
.ai-messages::-webkit-scrollbar-track { background: transparent; }
.ai-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

.ai-msg { display: flex; max-width: 78%; }
.ai-msg-user  { justify-content: flex-end; align-self: flex-end; }
.ai-msg-assistant { justify-content: flex-start; align-self: flex-start; }

.ai-bubble {
  padding: .7rem 1rem; border-radius: 14px;
  font-size: .92rem; line-height: 1.6;
  word-break: break-word;
}
.ai-msg-user .ai-bubble {
  background: var(--user-bubble); border-bottom-right-radius: 4px;
}
.ai-msg-assistant .ai-bubble {
  background: var(--ai-bubble); border-bottom-left-radius: 4px;
  border: 1px solid var(--border);
}

/* Code in AI responses */
.ai-bubble pre { background: #13151f; border-radius: 6px; padding: .75rem 1rem; margin: .5rem 0; overflow-x: auto; }
.ai-bubble code { font-family: 'Cascadia Code', 'Fira Code', monospace; font-size: .84rem; }
.ai-bubble p  { margin: .35rem 0; }
.ai-bubble h1,.ai-bubble h2,.ai-bubble h3 { margin: .5rem 0 .25rem; }
.ai-bubble ul,.ai-bubble ol { padding-left: 1.3rem; margin: .35rem 0; }
.ai-bubble li { margin: .2rem 0; }

/* Streaming cursor */
.ai-cursor { display: inline-block; animation: blink .7s step-end infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* Typing dots */
.ai-typing { display: inline-flex; gap: 4px; align-items: center; padding: 4px 0; }
.ai-typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--text-muted);
  animation: dot-bounce 1.2s ease-in-out infinite;
}
.ai-typing span:nth-child(2) { animation-delay: .15s; }
.ai-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes dot-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ── Tool indicator ────────────────────────────────────────────────── */
.ai-tool-indicator {
  display: none; padding: .3rem 1.25rem;
  font-size: .78rem; color: var(--text-muted); font-style: italic;
  background: var(--bg-surface);
  flex-shrink: 0;
}
.ai-tool-indicator.visible { display: block; }

/* ── Suggestion chips ──────────────────────────────────────────────── */
.ai-chips {
  display: flex; flex-wrap: wrap; gap: .4rem;
  padding: .45rem 1.25rem;
  background: var(--bg-surface); border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.ai-chip {
  background: var(--bg-elevated); color: var(--text-muted);
  border: 1px solid var(--border); border-radius: 999px;
  padding: .25rem .8rem; font-size: .78rem; cursor: pointer;
  transition: border-color .15s, color .15s;
  white-space: nowrap; text-transform: capitalize;
}
.ai-chip:hover { border-color: var(--accent); color: var(--text); }

/* ── Input Area ───────────────────────────────────────────────────── */
.ai-input-area {
  display: flex; align-items: flex-end; gap: .5rem;
  padding: .75rem 1.25rem;
  background: var(--bg-surface); border-top: 1px solid var(--border);
  flex-shrink: 0;
}
#ai-input {
  flex: 1; resize: none; overflow: hidden;
  background: var(--bg-elevated); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: .65rem .9rem; font-size: .94rem; line-height: 1.5;
  font-family: inherit; transition: border-color .2s; min-height: 44px;
}
#ai-input:focus { outline: none; border-color: var(--accent); }
#ai-input:disabled { opacity: .5; }
.ai-send-btn {
  width: 44px; height: 44px; flex-shrink: 0;
  background: var(--accent); color: #fff; border: none; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background .2s;
}
.ai-send-btn:hover:not(:disabled) { background: var(--accent-dim); }
.ai-send-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ── Responsive ───────────────────────────────────────────────────── */
@media (max-width: 767px) {
  .ai-chat-container { max-width: 100%; }
  .ai-msg { max-width: 92%; }
  .ai-topbar-title { font-size: .9rem; }
  .ai-settings-grid { grid-template-columns: 1fr; }
}

/* ── Prompt Library Sidebar ───────────────────────────────────────── */
.ai-prompt-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.55); z-index: 250;
  backdrop-filter: blur(2px); cursor: pointer;
}
.ai-prompt-overlay.active { display: block; }

.ai-prompt-sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 260;
  width: 310px; max-width: 92vw;
  background: var(--bg-surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  transform: translateX(-100%);
  transition: transform .28s cubic-bezier(.4,0,.2,1);
  overflow: hidden;
}
.ai-prompt-sidebar.open { transform: translateX(0); }

.ai-prompt-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: .85rem 1rem .85rem 1.1rem; flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  font-size: .95rem; font-weight: 700; color: var(--text);
}

/* Category pills */
.ai-prompt-cats {
  display: flex; flex-wrap: wrap; gap: .3rem;
  padding: .65rem .9rem; flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}
.ai-prompt-cat {
  background: var(--bg-elevated); color: var(--text-muted);
  border: 1px solid var(--border); border-radius: 999px;
  padding: .18rem .7rem; font-size: .72rem; cursor: pointer;
  transition: all .15s; white-space: nowrap; font-weight: 500;
}
.ai-prompt-cat:hover  { border-color: var(--accent); color: var(--text); }
.ai-prompt-cat.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Prompt cards */
.ai-prompt-list {
  flex: 1; overflow-y: auto; padding: .65rem .9rem;
  display: flex; flex-direction: column; gap: .4rem;
}
.ai-prompt-list::-webkit-scrollbar { width: 4px; }
.ai-prompt-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

.ai-prompt-card {
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 10px; padding: .6rem .85rem;
  cursor: pointer; transition: border-color .15s, background .15s;
  display: flex; align-items: flex-start; gap: .65rem;
  text-align: left; width: 100%;
}
.ai-prompt-card:hover { border-color: var(--accent); background: #1e2338; }
.ai-prompt-card.applied {
  border-color: #48bb78; background: rgba(72,187,120,.08);
}
.ai-prompt-stamp {
  font-size: 1.5rem; line-height: 1; flex-shrink: 0; margin-top: 1px;
}
.ai-prompt-info { display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.ai-prompt-name { font-size: .82rem; font-weight: 700; color: var(--text); }
.ai-prompt-desc { font-size: .7rem; color: var(--text-muted); line-height: 1.35; }
.ai-prompt-badge {
  font-size: .62rem; color: var(--text-muted); margin-left: auto;
  flex-shrink: 0; padding-top: 2px;
}
