:root {
  --bg: #0a0e1a;
  --panel: #111729;
  --panel-2: #171f38;
  --border: #232c4d;
  --text: #eef1fb;
  --text-dim: #8b93b8;
  --accent: #35c5ff;
  --accent-2: #7fe0ff;
  --accent-dim: #1b3652;
  --spark: #ff8a3d;
  --spark-2: #ffb648;
  --user-bubble: #1c2749;
  --assistant-bubble: #131a30;
  --danger: #ff5d6c;
  --success: #3ddc97;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

h1, h2, .brand span, .login-card h1 {
  font-family: 'Chakra Petch', 'Inter', sans-serif;
}

::selection { background: rgba(53, 197, 255, 0.3); }

/* ── Login ─────────────────────────────────────────────────────────────── */

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  background:
    radial-gradient(ellipse 900px 600px at 20% -10%, rgba(53, 197, 255, 0.12), transparent 60%),
    radial-gradient(ellipse 700px 500px at 100% 110%, rgba(255, 138, 61, 0.10), transparent 60%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  padding: 36px 32px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}
.brand-logo { display: block; width: 100%; max-width: 300px; margin: 0 auto 4px; }
.login-card h1 { font-size: 21px; margin: 0 0 4px; letter-spacing: 0.01em; }
.login-card .hint { color: var(--text-dim); font-size: 13.5px; margin: 0 0 22px; text-align: center; }

.field { margin-bottom: 14px; display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim); font-weight: 500; }
.field input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 11px 12px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(53, 197, 255, 0.15);
}

.login-card button, .new-chat-btn, #send-btn {
  background: linear-gradient(135deg, var(--accent), #1e9fd4);
  color: #04141c;
  border: none;
  border-radius: 7px;
  padding: 11px 18px;
  font-size: 14px;
  font-weight: 700;
  font-family: 'Chakra Petch', inherit;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.login-card button { width: 100%; margin-top: 8px; }
.login-card button:hover, .new-chat-btn:hover, #send-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(53, 197, 255, 0.35);
}
.login-card button:active, .new-chat-btn:active, #send-btn:active { transform: translateY(0); }

.flash { padding: 10px 12px; border-radius: 8px; font-size: 13.5px; margin-bottom: 14px; }
.flash.error { background: rgba(255, 93, 108, 0.12); color: #ff9aa4; border: 1px solid rgba(255, 93, 108, 0.3); }
.flash.success { background: rgba(61, 220, 151, 0.12); color: var(--success); border: 1px solid rgba(61, 220, 151, 0.3); }

/* ── Account / Users pages ────────────────────────────────────────────── */

.users-table { width: 100%; border-collapse: collapse; margin: 16px 0; font-size: 13.5px; }
.users-table th { text-align: left; padding: 8px 10px; color: var(--text-dim); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; border-bottom: 1px solid var(--border); }
.users-table td { padding: 9px 10px; border-bottom: 1px solid var(--border); }
.link-btn { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 13px; padding: 0; text-decoration: none; font-family: inherit; }
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: var(--danger); }
.row-actions { display: flex; gap: 12px; }

/* ── Chat app shell ────────────────────────────────────────────────────── */

.app {
  display: flex;
  height: 100vh;
}

.sidebar {
  width: 268px;
  flex: none;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 14px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.brand img { width: 32px; height: 32px; flex: none; }
.brand span {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.01em;
  background: linear-gradient(90deg, var(--accent-2), var(--spark-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.new-chat-btn { width: 100%; }

.search-wrap { margin-top: 12px; }
.search-wrap input {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}
.search-wrap input:focus { outline: none; border-color: var(--accent); }
.search-wrap input::-webkit-search-cancel-button { filter: invert(1) opacity(0.6); }

.conversation-list {
  flex: 1;
  overflow-y: auto;
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.conversation-list .no-results { color: var(--text-dim); font-size: 13px; padding: 10px; }

.conversation-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 9px 10px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13.5px;
  color: var(--text-dim);
}
.conversation-item:hover { background: var(--panel-2); color: var(--text); }
.conversation-item.active { background: var(--accent-dim); color: var(--text); }
.conversation-item .title {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;
  border: none; background: none; color: inherit; font: inherit; padding: 0;
}
.conversation-item .title:focus {
  outline: none; background: var(--panel-2); border-radius: 4px; text-overflow: clip;
  box-shadow: 0 0 0 1px var(--accent);
}
.conversation-item .item-actions { display: flex; gap: 2px; flex: none; }
.conversation-item .icon-btn {
  opacity: 0;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 3px 5px;
  border-radius: 4px;
}
.conversation-item:hover .icon-btn { opacity: 1; }
.conversation-item .icon-btn:hover { color: var(--text); background: rgba(255,255,255,0.06); }
.conversation-item .icon-btn.delete-btn:hover { color: var(--danger); }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 12.5px;
}
.sidebar-footer .who { color: var(--text); font-weight: 600; margin-bottom: 2px; }
.sidebar-footer a { color: var(--text-dim); text-decoration: none; }
.sidebar-footer a:hover { color: var(--accent); }

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.message-thread {
  flex: 1;
  overflow-y: auto;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.empty-state {
  margin: auto;
  color: var(--text-dim);
  font-size: 14px;
  text-align: center;
}

.message {
  max-width: 70ch;
  padding: 13px 16px;
  border-radius: 12px;
  font-size: 14.5px;
  line-height: 1.6;
}
.message.user { align-self: flex-end; background: var(--user-bubble); white-space: pre-wrap; }
.message.assistant { align-self: flex-start; background: var(--assistant-bubble); border: 1px solid var(--border); }
.message .provider-tag {
  display: block;
  margin-top: 10px;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}
.message.pending { color: var(--text-dim); font-style: italic; }

/* ── Markdown content (assistant messages) ────────────────────────────── */

.md p { margin: 0 0 10px; }
.md p:last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3 { font-family: 'Chakra Petch', inherit; margin: 16px 0 8px; line-height: 1.3; }
.md h1:first-child, .md h2:first-child, .md h3:first-child { margin-top: 0; }
.md h1 { font-size: 19px; }
.md h2 { font-size: 17px; }
.md h3 { font-size: 15px; }
.md strong { font-weight: 700; color: #fff; }
.md em { font-style: italic; }
.md ul, .md ol { margin: 0 0 10px; padding-left: 22px; }
.md li { margin-bottom: 4px; }
.md a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.md blockquote {
  margin: 0 0 10px;
  padding: 4px 12px;
  border-left: 3px solid var(--accent);
  color: var(--text-dim);
}
.md code {
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  font-size: 0.88em;
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 5px;
  border-radius: 4px;
}
.md pre {
  background: #060a14;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  overflow-x: auto;
  margin: 0 0 10px;
}
.md pre code {
  background: none;
  padding: 0;
  font-size: 13px;
  line-height: 1.5;
  color: #d5dcf0;
}

.chat-form {
  display: flex;
  gap: 10px;
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
}
.chat-form textarea {
  flex: 1;
  resize: none;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 14.5px;
  padding: 12px 14px;
  max-height: 160px;
  transition: border-color 0.15s ease;
}
.chat-form textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(53, 197, 255, 0.12);
}
#send-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; box-shadow: none !important; }

/* Rename/delete icons are reveal-on-hover, which doesn't exist on touch —
   without this they're stuck invisible (opacity: 0) with no way to tap them
   on any touch device, regardless of screen width. */
@media (hover: none), (pointer: coarse) {
  .conversation-item .icon-btn { opacity: 1; }
}

/* ── Mobile off-canvas nav ────────────────────────────────────────────── */
/* Hidden on desktop; the media query below is what actually shows/positions
   these. Kept outside the query so JS can toggle .is-open unconditionally
   without caring what breakpoint the browser happens to be at. */

.mobile-nav-toggle {
  display: none;
  align-items: center;
  gap: 8px;
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 40;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 5px 12px 5px 5px;
  cursor: pointer;
}
.mobile-nav-toggle img { width: 30px; height: 30px; flex: none; }
.mobile-nav-toggle span {
  font-family: 'Chakra Petch', inherit;
  font-size: 14px;
  font-weight: 700;
  background: linear-gradient(90deg, var(--accent-2), var(--spark-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 25;
  background: rgba(5, 8, 16, 0.6);
}
.sidebar-backdrop.is-open { display: block; }

@media (max-width: 760px) {
  .mobile-nav-toggle { display: flex; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    height: 100dvh;
    width: 280px;
    max-width: 82vw;
    z-index: 30;
    border-right: 1px solid var(--border);
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    overscroll-behavior: contain;
  }
  .sidebar.is-open { transform: translateX(0); }

  .chat-main { padding-top: 54px; }
}

/* ── Themed confirm dialog (replaces native confirm()) ────────────────── */

.theme-confirm-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(5, 8, 16, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.theme-confirm-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-top: 3px solid var(--spark);
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.theme-confirm-message {
  margin: 0 0 20px;
  font-size: 14.5px;
  line-height: 1.5;
  color: var(--text);
}
.theme-confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
.theme-confirm-btn {
  border: none;
  border-radius: 7px;
  padding: 9px 18px;
  font-size: 13.5px;
  font-weight: 700;
  font-family: 'Chakra Petch', inherit;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.theme-confirm-btn:hover { transform: translateY(-1px); }
.theme-confirm-btn.cancel { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.theme-confirm-btn.danger { background: linear-gradient(135deg, var(--danger), #c53a48); color: #fff; }
.theme-confirm-btn.danger:hover { box-shadow: 0 6px 18px rgba(255, 93, 108, 0.35); }
