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

.hidden { display: none !important; }

:root {
  --paper:       #F3EDE1;
  --paper-2:     #EDE7D9;
  --paper-3:     #E5DFD1;
  --ink:         #181612;
  --ink-2:       #3A3730;
  --ink-3:       #6B655C;
  --ink-4:       #9B9489;
  --accent:      #3D5BFF;
  --accent-dim:  rgba(61,91,255,.12);
  --white:       #FFFFFF;
  --border:      #D5CFC3;
  --border-2:    #C4BEB2;
  --sidebar-bg:  #17150F;
  --sidebar-2:   #211F18;
  --sidebar-3:   #2C2920;
  --sidebar-text:#EDE7D9;
  --sidebar-dim: #9B9489;
  --error:       #C0392B;
  --error-bg:    #FDECEA;
  --success:     #27AE60;
  --success-bg:  #EAF7EF;
  --radius:      10px;
  --radius-lg:   16px;
  --shadow-sm:   0 1px 4px rgba(0,0,0,.08);
  --shadow:      0 4px 16px rgba(0,0,0,.12);
  --shadow-lg:   0 12px 40px rgba(0,0,0,.18);
  --font-ui:     'DM Sans', sans-serif;
  --font-brand:  'Cormorant Garamond', Georgia, serif;
  --font-mono:   'JetBrains Mono', 'Courier New', monospace;
  --transition:  0.18s ease;
}

html, body {
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.tool-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tool-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

button { cursor: pointer; font-family: var(--font-ui); border: none; background: none; }
input, textarea, select { font-family: var(--font-ui); }
  font-size: .92rem;
  color: #243f9a;
  margin-bottom: 2px;


.tool-subtitle {
  font-size: .8rem;
  color: var(--ink-3);
  line-height: 1.45;
}
/* ─────────────────────────────────────────────────────────────────────────
   GRAIN TEXTURE OVERLAY
  flex-shrink: 0;
body::after {
  content: '';
  position: fixed;
  inset: 0;
  font-size: .8rem;
  color: #2847b9;
  pointer-events: none;
  list-style: none;
  padding: 7px 10px;
  border: 1px solid rgba(61,91,255,0.18);
  border-radius: 999px;
  background: rgba(61,91,255,0.06);
  transition: background var(--transition), border-color var(--transition), color var(--transition), transform .1s ease;
  z-index: 9000;
}

  color: #1f3f9a;
  background: rgba(61,91,255,0.1);
  border-color: rgba(61,91,255,0.28);
}

.tool-details > summary:active {
  transform: translateY(1px);
   LOADING SCREEN

.tool-details > summary::-webkit-details-marker {
  display: none;
}

.tool-details > summary::after {
  content: '▾';
  display: inline-block;
  margin-left: 8px;
  font-size: .75rem;
}

.tool-details[open] > summary::after {
  content: '▴';
──────────────────────────────────────────────────────────────────────────── */
#loading-screen {
  position: fixed; inset: 0; background: var(--paper);
  display: flex; align-items: center; justify-content: center;
  z-index: 8000; flex-direction: column; gap: 20px;
  transition: opacity 0.4s ease;
}
#loading-screen.fade-out { opacity: 0; pointer-events: none; }
.loader-brand {
  font-family: var(--font-brand);
  font-size: 2.4rem;
  color: var(--ink);
  letter-spacing: 0.02em;
}
.loader-dots { display: flex; gap: 6px; }
.loader-dots span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent); opacity: 0.4;
  animation: dotpulse 1.2s ease-in-out infinite;
}
.loader-dots span:nth-child(2) { animation-delay: .2s; }
.loader-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes dotpulse { 0%,80%,100% { opacity:.2; transform:scale(.8); } 40% { opacity:1; transform:scale(1); } }

/* ─────────────────────────────────────────────────────────────────────────
   AUTH SCREEN
──────────────────────────────────────────────────────────────────────────── */
#auth-screen {
  position: fixed; inset: 0; background: var(--paper);
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 28px;
  animation: fadeIn .35s ease;
}
.auth-brand {
  text-align: center;
}
.auth-brand h1 {
  font-family: var(--font-brand);
  font-size: 3rem;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.01em;
  line-height: 1;
}
.auth-brand p {
  color: var(--ink-3);
  font-size: .88rem;
  margin-top: 6px;
  font-weight: 300;
  letter-spacing: .04em;
}
.auth-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 40px;
  width: 100%; max-width: 400px;
  box-shadow: var(--shadow);
}
.auth-tabs {
  display: flex; gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 28px;
}
.auth-tab {
  flex: 1; padding: 10px 0;
  font-size: .9rem; font-weight: 500;
  color: var(--ink-3); background: none;
  border-bottom: 2px solid transparent;
  transition: var(--transition);
  margin-bottom: -1px;
}
.auth-tab.active { color: var(--ink); border-bottom-color: var(--accent); }
.auth-form { display: flex; flex-direction: column; gap: 16px; }
.auth-form.hidden { display: none; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: .83rem; font-weight: 500; color: var(--ink-2); }
.form-control {
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  font-size: .9rem;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
.form-control:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.btn-primary {
  padding: 11px 20px;
  background: var(--ink);
  color: var(--paper);
  border-radius: var(--radius);
  font-size: .9rem; font-weight: 500;
  transition: background var(--transition), transform .1s;
  border: none;
}
.btn-primary:hover { background: var(--ink-2); }
.btn-primary:active { transform: scale(.98); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.auth-error {
  padding: 9px 12px;
  background: var(--error-bg);
  color: var(--error);
  border-radius: var(--radius);
  font-size: .85rem;
  display: none;
}
.auth-error.show { display: block; }

/* ─────────────────────────────────────────────────────────────────────────
   APP LAYOUT
──────────────────────────────────────────────────────────────────────────── */
#app {
  display: flex; height: 100vh; width: 100%;
  animation: fadeIn .3s ease;
}
@keyframes fadeIn { from { opacity:0; transform:translateY(6px); } to { opacity:1; transform:none; } }

/* ─────────────────────────────────────────────────────────────────────────
   SIDEBAR
──────────────────────────────────────────────────────────────────────────── */
#sidebar {
  width: 260px; min-width: 260px;
  background: var(--sidebar-bg);
  display: flex; flex-direction: column;
  height: 100vh; overflow: hidden;
  transition: transform .25s ease;
  position: relative; z-index: 100;
}
.sidebar-header {
  padding: 20px 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.sidebar-logo {
  font-family: var(--font-brand);
  font-size: 1.45rem;
  color: var(--sidebar-text);
  letter-spacing: .02em;
  display: block;
  margin-bottom: 14px;
}
.sidebar-logo em { font-style: italic; color: var(--accent); }
#new-chat-btn {
  width: 100%; padding: 9px 14px;
  background: var(--sidebar-3);
  color: var(--sidebar-text);
  border-radius: var(--radius);
  font-size: .85rem; font-weight: 500;
  text-align: left;
  display: flex; align-items: center; gap: 8px;
  transition: background var(--transition);
  border: 1px solid rgba(255,255,255,.07);
}
#new-chat-btn:hover { background: var(--sidebar-2); }
#new-chat-btn svg { opacity: .7; flex-shrink: 0; }

.sidebar-section-label {
  font-size: .7rem; font-weight: 600;
  color: var(--sidebar-dim);
  text-transform: uppercase;
  letter-spacing: .1em;
  padding: 16px 16px 6px;
}
#conv-list {
  flex: 1; overflow-y: auto;
  padding: 0 8px 8px;
}
#conv-list::-webkit-scrollbar { width: 3px; }
#conv-list::-webkit-scrollbar-track { background: transparent; }
#conv-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 2px; }

.conv-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--sidebar-dim);
  font-size: .85rem;
  transition: background var(--transition), color var(--transition);
  position: relative; overflow: hidden;
  margin-bottom: 1px;
  user-select: none;
}
.conv-item:hover { background: var(--sidebar-3); color: var(--sidebar-text); }
.conv-item.active { background: var(--sidebar-2); color: var(--sidebar-text); }
.conv-item svg { flex-shrink: 0; opacity: .5; }
.conv-item-title {
  flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-size: .84rem;
}
.conv-item-actions {
  display: none; gap: 2px; flex-shrink: 0;
}
.conv-item:hover .conv-item-actions,
.conv-item.active .conv-item-actions { display: flex; }
.conv-action-btn {
  width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 5px;
  color: var(--sidebar-dim);
  transition: background var(--transition), color var(--transition);
}
.conv-action-btn:hover { background: rgba(255,255,255,.1); color: var(--sidebar-text); }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid rgba(255,255,255,.06);
}
.user-card {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 6px;
  border-radius: var(--radius);
}
.user-avatar {
  width: 32px; height: 32px;
  background: var(--sidebar-3);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--sidebar-text);
  font-weight: 600; font-size: .85rem;
  flex-shrink: 0;
}
.user-info-text { flex: 1; min-width: 0; }
.user-name {
  font-size: .84rem; font-weight: 500;
  color: var(--sidebar-text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-credits {
  font-size: .75rem; color: var(--sidebar-dim);
  font-family: var(--font-mono);
}
.user-footer-btns {
  display: flex; gap: 6px; margin-top: 8px;
}
.sidebar-btn {
  flex: 1; padding: 8px 10px;
  background: var(--sidebar-3);
  color: var(--sidebar-dim);
  border-radius: var(--radius);
  font-size: .8rem; font-weight: 500;
  transition: background var(--transition), color var(--transition);
  border: 1px solid rgba(255,255,255,.05);
  display: flex; align-items: center; justify-content: center; gap: 5px;
}
.sidebar-btn:hover { background: var(--sidebar-2); color: var(--sidebar-text); }

/* ─────────────────────────────────────────────────────────────────────────
   MAIN AREA
──────────────────────────────────────────────────────────────────────────── */
#main {
  flex: 1; display: flex; flex-direction: column;
  height: 100vh; overflow: hidden;
  background: var(--paper);
  position: relative;
}

/* ─────────────────────────────────────────────────────────────────────────
   EMPTY STATE
──────────────────────────────────────────────────────────────────────────── */
#empty-state {
  flex: 1; display: flex;
  flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 40px;
  text-align: center;
}
.empty-icon {
  width: 56px; height: 56px; background: var(--paper-2);
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  color: var(--ink-4); margin-bottom: 4px;
}
.empty-title { font-family: var(--font-brand); font-size: 1.6rem; color: var(--ink); }
.empty-sub { font-size: .88rem; color: var(--ink-3); max-width: 300px; line-height: 1.5; }

/* ─────────────────────────────────────────────────────────────────────────
   CHAT VIEW
──────────────────────────────────────────────────────────────────────────── */
#chat-view { display: flex; flex-direction: column; height: 100%; overflow: hidden; }

#chat-header {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--paper);
  flex-shrink: 0;
}
#conv-title-display {
  flex: 1; font-size: 1rem; font-weight: 500; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  cursor: text;
}
.rename-input {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 2px solid var(--accent);
  outline: none;
  font-size: 1rem; font-weight: 500; color: var(--ink);
  padding: 2px 0;
}
#header-actions { display: flex; gap: 6px; flex-shrink: 0; }
.header-btn {
  padding: 6px 10px;
  border-radius: var(--radius);
  font-size: .8rem; font-weight: 500;
  color: var(--ink-3);
  display: flex; align-items: center; gap: 5px;
  transition: background var(--transition), color var(--transition);
}
.header-btn:hover { background: var(--paper-2); color: var(--ink); }
.header-btn.danger:hover { background: var(--error-bg); color: var(--error); }

/* ─────────────────────────────────────────────────────────────────────────
   MESSAGES
──────────────────────────────────────────────────────────────────────────── */
#messages {
  flex: 1; overflow-y: auto;
  padding: 26px 20px;
  display: flex; flex-direction: column; gap: 18px;
  scroll-behavior: smooth;
}
#messages::-webkit-scrollbar { width: 4px; }
#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 2px; }

.msg {
  display: flex; gap: 12px; max-width: 860px;
  width: 100%;
  margin: 0 auto;
  animation: msgSlide .2s ease;
}
@keyframes msgSlide { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:none; } }
.msg.user { flex-direction: row-reverse; align-self: flex-end; }
.msg.assistant { align-self: flex-start; }
.msg.system { align-self: center; }

.msg-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .72rem; font-weight: 600;
  flex-shrink: 0; margin-top: 2px;
}
.msg.user .msg-avatar { background: #D8D2C6; color: var(--ink-2); }
.msg.assistant .msg-avatar { background: #E7F0FF; color: #2242d8; }
.msg.system .msg-avatar { background: var(--paper-3); color: var(--ink-3); }
.msg.tool .msg-avatar { background: var(--paper-2); color: var(--ink-2); }

.msg-body { max-width: calc(100% - 42px); }
.msg-bubble {
  padding: 12px 14px;
  border-radius: var(--radius-lg);
  font-size: .9rem; line-height: 1.65;
  word-break: break-word;
}
.msg.user .msg-bubble {
  background: #ECE7DD;
  color: var(--ink);
  border: 1px solid #DFD8CC;
  border-bottom-right-radius: 8px;
}
.msg.assistant .msg-bubble {
  background: transparent;
  color: var(--ink);
  border: none;
  border-bottom-left-radius: 8px;
  box-shadow: none;
  padding-left: 2px;
}
.msg.system .msg-bubble {
  background: var(--paper-3);
  color: var(--ink-3);
  font-size: .83rem;
  border-radius: var(--radius);
  font-style: italic;
}

.msg.tool .msg-bubble {
  background: var(--paper-2);
  color: var(--ink-2);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.tool-bubble pre {
  background: var(--paper-2);
}

.tool-bubble h3 {
  font-family: var(--font-ui);
  font-size: .86rem;
  font-weight: 700;
  letter-spacing: .02em;
  text-transform: uppercase;
  color: #2f4ec9;
  margin-top: 0;
}

.tool-header {
  font-weight: 600;
  font-size: .88rem;
  color: #2847b9;
  margin-bottom: 6px;
}

.tool-details {
  margin-top: 4px;
}

.tool-details > summary {
  cursor: pointer;
  font-size: .8rem;
  color: var(--ink-3);
  user-select: none;
}

.tool-details > summary:hover {
  color: var(--ink);
}

.tool-details-body {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(61,91,255,0.12);
}

.tool-inline {
  display: block;
}

.tool-inline > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  font-size: .83rem;
  color: var(--ink-3);
  line-height: 1.4;
}

.tool-inline > summary::-webkit-details-marker {
  display: none;
}

.tool-inline > summary::after {
  content: '▸';
  margin-left: 8px;
  color: var(--ink-4);
  font-size: .78rem;
}

.tool-inline[open] > summary::after {
  content: '▾';
}

.tool-inline > summary:hover {
  color: var(--ink);
}

.tool-inline-body {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  color: var(--ink-2);
}

.tool-bubble ul,
.tool-bubble ol {
  margin-bottom: 0;
}

.msg-bubble h1,.msg-bubble h2,.msg-bubble h3 {
  font-family: var(--font-brand);
  margin: .8em 0 .3em;
  line-height: 1.3;
}
.msg-bubble h1 { font-size: 1.35rem; }
.msg-bubble h2 { font-size: 1.15rem; }
.msg-bubble h3 { font-size: 1rem; }
.msg-bubble p { margin-bottom: .6em; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble ul,.msg-bubble ol { padding-left: 1.4em; margin-bottom: .6em; }
.msg-bubble li { margin-bottom: .2em; }
.msg-bubble code {
  font-family: var(--font-mono);
  font-size: .82em;
  background: var(--paper-2);
  padding: .15em .4em;
  border-radius: 4px;
  color: var(--ink-2);
}
.msg-bubble pre {
  /* Use a light background and dark text for better readability */
  background: var(--paper-2);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 14px 16px;
  overflow-x: auto;
  margin: .7em 0;
  font-family: var(--font-mono);
  font-size: .82em;
  line-height: 1.55;
  border: 1px solid var(--border-2);
}
.msg-bubble pre code {
  background: none; padding: 0;
  color: inherit; font-size: inherit;
}

/* Make sure highlight.js token backgrounds are transparent so theme colors show on the light background */
.msg-bubble pre .hljs,
.msg-bubble pre code.hljs {
  background: transparent !important;
  color: inherit !important;
}
.msg-bubble blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  margin: .6em 0;
  color: var(--ink-3);
}
.msg-bubble a { color: var(--accent); }
.msg-bubble table { border-collapse: collapse; width: 100%; margin: .6em 0; font-size: .88em; }
.msg-bubble th,.msg-bubble td { padding: 7px 12px; border: 1px solid var(--border); text-align: left; }
.msg-bubble th { background: var(--paper-2); font-weight: 600; }
.msg-bubble hr { border: none; border-top: 1px solid var(--border); margin: .8em 0; }

.msg-meta {
  margin-top: 5px;
  display: flex; gap: 10px; align-items: center;
  font-size: .73rem; color: var(--ink-4);
  font-family: var(--font-mono);
  flex-wrap: wrap;
}
.msg.user .msg-meta { justify-content: flex-end; }
.meta-chip {
  display: flex; align-items: center; gap: 3px;
  padding: 2px 6px; background: var(--paper-2);
  border-radius: 4px;
}
.msg.user .meta-chip { background: rgba(255,255,255,.1); color: rgba(243,237,225,.6); }

.streaming-cursor {
  display: inline-block;
  width: 2px; height: 1em;
  background: var(--accent);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink .7s step-end infinite;
}
@keyframes blink { 0%,100% { opacity:1; } 50% { opacity:0; } }

.msg-error {
  font-size: .83rem; color: var(--error);
  display: flex; align-items: center; gap: 5px;
  padding: 8px 12px;
  background: var(--error-bg);
  border-radius: var(--radius);
}

/* ─────────────────────────────────────────────────────────────────────────
   INPUT AREA
──────────────────────────────────────────────────────────────────────────── */
#input-area {
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border);
  background: var(--paper);
  flex-shrink: 0;
}
.input-row {
  display: flex; gap: 10px; align-items: flex-end;
}
.input-wrapper {
  flex: 1; position: relative;
  background: var(--white);
  border: 1px solid #D9D2C6;
  border-radius: var(--radius-lg);
  transition: border-color var(--transition), box-shadow var(--transition);
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
#prompt-input {
  width: 100%; padding: 13px 16px;
  background: none; border: none; outline: none;
  font-size: .9rem; color: var(--ink); line-height: 1.55;
  resize: none;
  min-height: 52px; max-height: 200px;
  display: block;
}
#prompt-input::placeholder { color: var(--ink-4); }

.input-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 12px 8px;
}
.model-selector-wrap { position: relative; }
.model-select-btn {
  min-width: 168px;
  appearance: none;
  padding: 5px 24px 5px 10px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--paper);
  color: var(--ink-2);
  font-size: .78rem; font-weight: 500;
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition);
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.model-select-btn:focus,
.model-select-btn:hover {
  border-color: var(--accent);
}
.model-caret {
  position: absolute; right: 8px; top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--ink-4);
  display: flex;
}
.model-menu {
  position: absolute;
  left: 0;
  bottom: calc(100% + 10px);
  width: min(360px, 78vw);
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  z-index: 1200;
}
.model-menu-main {
  padding: 8px;
  border-bottom: 1px solid var(--border);
  background: var(--white);
}
.model-menu-main .model-menu-item {
  border-radius: 8px;
  border-bottom: none;
}
.model-menu-main .model-menu-item + .model-menu-item {
  margin-top: 6px;
}
.model-menu-other {
  border-top: 1px solid var(--border);
  background: var(--paper);
}
.model-menu-other[open] {
  background: var(--white);
}
.model-menu-other > summary {
  cursor: pointer;
  list-style: none;
  padding: 11px 12px;
  font-size: .82rem;
  font-weight: 600;
  color: var(--ink-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.model-menu-other > summary::-webkit-details-marker {
  display: none;
}
.model-menu-other > summary::after {
  content: '▾';
  font-size: .8rem;
  color: var(--ink-4);
}
.model-menu-other[open] > summary::after {
  content: '▴';
}
.model-menu-search {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  background: var(--paper);
}
.model-menu-search input {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--white);
  color: var(--ink);
  font-size: .85rem;
  outline: none;
}
.model-menu-search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.model-menu-list {
  max-height: 280px;
  overflow-y: auto;
}
.model-menu-item {
  display: block;
  width: 100%;
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid rgba(213, 207, 195, .5);
  background: var(--white);
  color: var(--ink);
  transition: background var(--transition), color var(--transition);
}
.model-menu-item:hover,
.model-menu-item.active {
  background: var(--paper-2);
}
.model-menu-item-title {
  display: block;
  font-size: .88rem;
  font-weight: 500;
}
.model-menu-item-meta {
  display: block;
  margin-top: 2px;
  font-size: .74rem;
  color: var(--ink-3);
  line-height: 1.4;
}
.model-menu-empty {
  padding: 12px;
  font-size: .82rem;
  color: var(--ink-3);
  font-style: italic;
}
#send-btn {
  width: 38px; height: 38px;
  background: var(--ink);
  color: var(--paper);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition), transform .1s;
  border: none;
}
#send-btn:hover:not(:disabled) { background: var(--accent); }
#send-btn:active:not(:disabled) { transform: scale(.93); }
#send-btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }
#send-btn.loading { background: var(--ink-2); animation: pulse .8s ease infinite; }
@keyframes pulse { 0%,100% { transform:scale(1); } 50% { transform:scale(.95); } }

/* ─────────────────────────────────────────────────────────────────────────
   MODAL
──────────────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(3px);
  z-index: 1000;
  animation: fadeIn .2s ease;
}
.modal-box {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1001;
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 32px 36px;
  width: 100%; max-width: 460px;
  box-shadow: var(--shadow-lg);
  animation: modalIn .25s ease;
}
@keyframes modalIn { from { opacity:0; transform:translate(-50%,-53%); } to { opacity:1; transform:translate(-50%,-50%); } }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px;
}
.modal-title {
  font-family: var(--font-brand);
  font-size: 1.5rem; font-weight: 600;
}
.modal-close {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  color: var(--ink-3); font-size: 1.2rem;
  transition: background var(--transition);
}
.modal-close:hover { background: var(--paper); }
.modal-section { margin-bottom: 28px; }
.modal-section:last-child { margin-bottom: 0; }
.modal-section-title {
  font-size: .83rem; font-weight: 600; color: var(--ink-3);
  text-transform: uppercase; letter-spacing: .06em;
  margin-bottom: 14px;
}
.modal-form { display: flex; flex-direction: column; gap: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
.btn-secondary {
  padding: 9px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .87rem; font-weight: 500;
  color: var(--ink-2);
  background: var(--paper);
  transition: background var(--transition);
}
.btn-secondary:hover { background: var(--paper-2); }
.inline-msg {
  font-size: .82rem;
  padding: 8px 11px;
  border-radius: var(--radius);
  display: none;
}
.inline-msg.show { display: block; }
.inline-msg.error { background: var(--error-bg); color: var(--error); }
.inline-msg.success { background: var(--success-bg); color: var(--success); }

/* ─────────────────────────────────────────────────────────────────────────
   TOAST
──────────────────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 24px; right: 24px;
  z-index: 9999; display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: .87rem; font-weight: 500;
  box-shadow: var(--shadow);
  animation: toastIn .25s ease;
  pointer-events: auto;
  max-width: 320px;
}
@keyframes toastIn { from { opacity:0; transform:translateY(10px); } to { opacity:1; transform:none; } }
.toast.success { background: var(--success-bg); color: var(--success); border: 1px solid #A3D9B5; }
.toast.error { background: var(--error-bg); color: var(--error); border: 1px solid #F5A9A1; }
.toast.info { background: var(--white); color: var(--ink-2); border: 1px solid var(--border); }

/* ─────────────────────────────────────────────────────────────────────────
   CONFIRM DIALOG
──────────────────────────────────────────────────────────────────────────── */
.confirm-dialog {
  position: fixed; inset: 0; z-index: 2000;
  display: flex; align-items: center; justify-content: center;
}
.confirm-overlay { position: absolute; inset: 0; background: rgba(0,0,0,.4); }
.confirm-box {
  position: relative; z-index: 1;
  background: var(--white); border-radius: var(--radius-lg);
  padding: 28px 32px;
  width: 100%; max-width: 360px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  animation: modalIn .2s ease;
}
.confirm-box h3 { font-family: var(--font-brand); font-size: 1.25rem; margin-bottom: 10px; }
.confirm-box p { font-size: .88rem; color: var(--ink-3); margin-bottom: 22px; }
.confirm-btns { display: flex; gap: 10px; justify-content: center; }
.btn-danger {
  padding: 9px 20px;
  background: var(--error);
  color: #fff;
  border-radius: var(--radius);
  font-size: .87rem; font-weight: 500;
  transition: opacity var(--transition);
}
.btn-danger:hover { opacity: .88; }

/* ─────────────────────────────────────────────────────────────────────────
   MOBILE
──────────────────────────────────────────────────────────────────────────── */
#mobile-header {
  display: none;
  align-items: center; gap: 12px;
  padding: 12px 16px;
  background: var(--paper);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.mobile-brand {
  font-family: var(--font-brand);
  font-size: 1.1rem;
  font-weight: 600;
}
.hamburger {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius);
  color: var(--ink-2);
  transition: background var(--transition);
}
.hamburger:hover { background: var(--paper-2); }
#sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.4); z-index: 99;
}

@media (max-width: 700px) {
  #sidebar { position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-100%); z-index: 200; }
  #sidebar.open { transform: none; }
  #sidebar-overlay { display: block; }
  #mobile-header { display: flex; }
  #chat-header { padding: 10px 14px; }
  #messages { padding: 16px 12px; }
  #input-area { padding: 10px 12px 14px; }
  .auth-card { padding: 28px 24px; }
  .modal-box { padding: 24px 22px; margin: 0 16px; }
  .model-menu {
    width: min(320px, calc(100vw - 24px));
  }
}
