:root,
:root[data-theme="chatgpt"] {
  color-scheme: dark;
  --bg: #212121;
  --bg-2: #212121;
  --sidebar-bg: #171717;
  --panel: #2f2f2f;
  --panel-solid: #2f2f2f;
  --panel-2: #262626;
  --panel-3: #303030;
  --text: #ececec;
  --muted: #b4b4b4;
  --muted-2: #8b8b8b;
  --line: rgba(255,255,255,.10);
  --line-strong: rgba(255,255,255,.18);
  --accent: #ffffff;
  --accent-2: #e7e7e7;
  --accent-3: #10a37f;
  --danger: #ff6b6b;
  --warn: #f4bf50;
  --user-bubble: #303030;
  --assistant-bubble: transparent;
  --shadow: 0 18px 60px rgba(0,0,0,.36);
  --radius-lg: 20px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --sidebar: 285px;
  --content: 820px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f0f0f;
  --bg-2: #141414;
  --sidebar-bg: #0b0b0b;
  --panel: #1f1f1f;
  --panel-solid: #1f1f1f;
  --panel-2: #181818;
  --panel-3: #282828;
  --text: #f2f2f2;
  --muted: #a7a7a7;
  --muted-2: #777;
  --line: rgba(255,255,255,.09);
  --line-strong: rgba(255,255,255,.17);
  --accent: #ffffff;
  --accent-2: #eeeeee;
  --accent-3: #10a37f;
  --danger: #ff6b6b;
  --warn: #f4bf50;
  --user-bubble: #2b2b2b;
  --assistant-bubble: transparent;
  --shadow: 0 18px 70px rgba(0,0,0,.46);
}

:root[data-theme="midnight"] {
  color-scheme: dark;
  --bg: #030712;
  --bg-2: #070b16;
  --sidebar-bg: #050816;
  --panel: #101626;
  --panel-solid: #101626;
  --panel-2: #0b1020;
  --panel-3: #171f33;
  --text: #eef4ff;
  --muted: #9aa8c5;
  --muted-2: #72809c;
  --line: rgba(148,163,184,.16);
  --line-strong: rgba(148,163,184,.26);
  --accent: #dbeafe;
  --accent-2: #f8fafc;
  --accent-3: #4ade80;
  --danger: #fb7185;
  --warn: #facc15;
  --user-bubble: #182033;
  --assistant-bubble: transparent;
  --shadow: 0 24px 80px rgba(0,0,0,.62);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #ffffff;
  --bg-2: #ffffff;
  --sidebar-bg: #f7f7f8;
  --panel: #ffffff;
  --panel-solid: #ffffff;
  --panel-2: #f4f4f4;
  --panel-3: #ececec;
  --text: #111111;
  --muted: #6b7280;
  --muted-2: #8a8a8a;
  --line: rgba(0,0,0,.10);
  --line-strong: rgba(0,0,0,.18);
  --accent: #111111;
  --accent-2: #262626;
  --accent-3: #10a37f;
  --danger: #dc2626;
  --warn: #b45309;
  --user-bubble: #f4f4f4;
  --assistant-bubble: transparent;
  --shadow: 0 18px 60px rgba(0,0,0,.12);
}

* { box-sizing: border-box; }
html, body, #root { min-height: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, textarea, select { font: inherit; }
button {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  background: var(--panel-2);
  color: var(--text);
  font-weight: 650;
  cursor: pointer;
  transition: background .16s ease, border-color .16s ease, transform .16s ease, opacity .16s ease;
}
button:hover:not(:disabled) { background: var(--panel-3); border-color: var(--line-strong); }
button:active:not(:disabled) { transform: scale(.985); }
button:disabled { opacity: .48; cursor: not-allowed; }
.primary, button.primary { background: var(--accent); color: var(--bg); border-color: transparent; }
.primary:hover:not(:disabled), button.primary:hover:not(:disabled) { background: var(--accent-2); }
.secondary { background: transparent; color: var(--text); border-color: var(--line); }
.secondary:hover:not(:disabled) { background: var(--panel-2); }
.danger { color: #ffd5d5; background: rgba(255,107,107,.12); border-color: rgba(255,107,107,.32); }
:root[data-theme="light"] .danger { color: #991b1b; background: #fff1f2; border-color: #fecdd3; }
.link-btn { background: transparent; border: 0; color: var(--accent-3); padding: 8px 0; }
.big { padding: 13px 16px; }

input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 12px 13px;
  outline: none;
  transition: border-color .16s ease, background .16s ease, box-shadow .16s ease;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--line-strong);
  background: var(--panel);
  box-shadow: 0 0 0 3px rgba(16,163,127,.20);
}
textarea { min-height: 100px; resize: vertical; line-height: 1.55; }
select option { background: var(--panel-solid); color: var(--text); }
label { color: var(--muted); font-size: 13px; display: grid; gap: 7px; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }
code { color: var(--accent-3); }
pre { background: rgba(0,0,0,.25); border: 1px solid var(--line); border-radius: 12px; padding: 14px; overflow: auto; white-space: pre-wrap; }

.glass { background: transparent; border: 0; box-shadow: none; backdrop-filter: none; }
.muted { color: var(--muted); }
.error, .success, .toast {
  border-radius: 12px;
  padding: 12px 14px;
  margin: 12px 0;
  border: 1px solid;
  animation: fadeUp .22s ease both;
}
.error { color: #ffd3dc; background: rgba(255,107,132,.12); border-color: rgba(255,107,132,.28); }
.success { color: #c9ffe9; background: rgba(16,163,127,.13); border-color: rgba(16,163,127,.30); }
:root[data-theme="light"] .error { color: #9f1239; background: #fff1f2; }
:root[data-theme="light"] .success { color: #065f46; background: #ecfdf5; }

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
  background: var(--bg);
}
.ambient { display: none; }
.auth-card {
  width: min(460px, 100%);
  padding: 28px;
  border-radius: 22px;
  background: var(--panel);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}
.brand-xl, .brand { display: flex; align-items: center; gap: 12px; }
.brand-xl h1 { margin: 0; font-size: 30px; letter-spacing: -.035em; }
.brand-xl p, .brand small { margin: 3px 0 0; color: var(--muted); display: block; }
.logo-orb {
  width: 46px; height: 46px; border-radius: 14px;
  display: grid; place-items: center;
  color: #111; font-weight: 900; letter-spacing: -.04em;
  background: #ececec;
}
:root[data-theme="light"] .logo-orb { background: #111; color: #fff; }
.logo-orb.small { width: 34px; height: 34px; border-radius: 10px; font-size: 12px; }
.form-grid { display: grid; gap: 13px; margin-top: 18px; }
.form-row { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: end; }
.theme-row { margin-top: 18px; display: flex; align-items: center; justify-content: space-between; color: var(--muted); gap: 12px; }
.compact-select { width: auto; min-width: 138px; padding: 8px 10px; }

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar) 1fr;
  overflow: hidden;
  background: var(--bg);
}
.sidebar {
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--sidebar-bg);
}
.sidebar-head { padding: 14px; }
.brand b { font-size: 14px; }
.mode-switch {
  margin: 0 10px 8px;
  padding: 3px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  border-radius: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
}
.mode-pill { padding: 9px; background: transparent; border: 0; color: var(--muted); box-shadow: none; }
.mode-pill.active { background: var(--panel-3); color: var(--text); border-color: var(--line); }
.sidebar-actions { display: grid; gap: 8px; padding: 0 10px 10px; }
.sidebar-actions .primary { background: var(--panel-2); color: var(--text); border-color: var(--line); }
.sidebar-actions .primary:hover { background: var(--panel-3); }
.conv-list { padding: 6px; overflow: auto; display: grid; gap: 2px; min-height: 0; }
.conv-item {
  width: 100%; text-align: left;
  padding: 10px 11px;
  border-radius: 10px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  display: grid; gap: 3px;
  box-shadow: none;
}
.conv-item span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.conv-item small { color: var(--muted-2); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.conv-item:hover { background: var(--panel-2); }
.conv-item.active { background: var(--panel-3); border-color: var(--line); }
.empty-list { color: var(--muted); padding: 14px; text-align: center; }
.sidebar-foot { margin-top: auto; padding: 10px; border-top: 1px solid var(--line); display: grid; gap: 8px; }
.tiny-label { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.chat-main {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 0;
  min-width: 0;
  background: var(--bg);
}
.chat-main::before { display: none; }
.chat-topbar {
  position: relative;
  z-index: 1;
  margin: 0;
  border-radius: 0;
  padding: 13px 22px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: color-mix(in oklab, var(--bg) 94%, transparent);
}
.eyebrow { color: var(--muted-2); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .10em; }
.topbar-main h1, .admin-hero h1 { margin: 1px 0 2px; font-size: 20px; letter-spacing: -.02em; font-weight: 700; }
.topbar-main p, .admin-hero p { margin: 0; color: var(--muted); font-size: 13px; }
.topbar-controls { display: flex; align-items: end; gap: 10px; }
.control-label { min-width: 270px; }
.messages {
  min-height: 0;
  overflow: auto;
  padding: 24px max(24px, calc((100vw - var(--sidebar) - var(--content)) / 2)) 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scroll-behavior: smooth;
}
.hero-empty {
  margin: auto;
  width: min(680px, 100%);
  text-align: center;
  color: var(--muted);
  padding: 34px 24px;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: var(--panel-2);
}
.hero-empty h2 { color: var(--text); margin: 10px 0 8px; font-size: 28px; letter-spacing: -.035em; }
.hero-icon { font-size: 38px; opacity: .9; }
.prompt-cards { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 18px; }
.prompt-cards button { background: var(--panel); border-color: var(--line); }
.msg { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 12px; max-width: var(--content); width: 100%; animation: fadeUp .20s ease both; }
.msg.user { align-self: flex-end; max-width: 720px; grid-template-columns: minmax(0, 1fr); }
.msg.user .avatar { display: none; }
.msg.assistant { align-self: center; }
.avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}
.msg.assistant .avatar { background: var(--panel-3); color: var(--text); border-color: var(--line); }
.bubble {
  padding: 0;
  border-radius: 0;
  border: 0;
  background: var(--assistant-bubble);
  box-shadow: none;
  overflow: hidden;
}
.msg.user .bubble {
  background: var(--user-bubble);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 12px 16px;
}
.msg-meta { display: none; }
.msg-content { white-space: normal; line-height: 1.68; word-wrap: break-word; font-size: 15.5px; }
.thinking .bubble { display: inline-flex; gap: 7px; align-items: center; width: auto; padding: 10px 0; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: pulseDot 1s infinite ease-in-out; }
.dot:nth-child(2) { animation-delay: .15s; }
.dot:nth-child(3) { animation-delay: .3s; }

.attachments, .pending-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.attachment-chip, .pending-chip {
  display: inline-flex; align-items: center; gap: 9px;
  max-width: 320px;
  padding: 7px 9px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text); text-decoration: none;
}
.attachment-chip img, .pending-chip img { width: 34px; height: 34px; border-radius: 9px; object-fit: cover; }
.attachment-chip b, .pending-chip b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-chip small, .pending-chip small { display: block; color: var(--muted); }
.pending-chip button { padding: 2px 7px; border-radius: 10px; background: transparent; color: var(--muted); }
.file-icon { font-size: 22px; }
.pending-row { padding: 0 2px 10px; max-width: var(--content); margin-left: auto; margin-right: auto; }

.composer {
  position: relative;
  z-index: 1;
  padding: 0 max(24px, calc((100vw - var(--sidebar) - var(--content)) / 2)) 22px;
}
.composer-inner {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: end;
  border-radius: 26px;
  padding: 8px;
  max-width: var(--content);
  margin: 0 auto;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 8px 28px rgba(0,0,0,.16);
}
.icon-btn, .send-btn {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  padding: 0;
  border-radius: 50%;
}
.icon-btn { background: transparent; color: var(--muted); border-color: transparent; }
.icon-btn:hover { background: var(--panel-3); }
.send-btn { background: var(--accent); color: var(--bg); font-size: 20px; border-color: transparent; }
.send-btn:hover:not(:disabled) { background: var(--accent-2); }
.composer textarea {
  min-height: 44px;
  max-height: 220px;
  border: 0;
  background: transparent;
  box-shadow: none;
  padding: 10px 6px;
  resize: none;
}
.composer textarea:focus { box-shadow: none; background: transparent; }
.spinner {
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.25);
  border-top-color: currentColor;
  animation: spin .8s linear infinite;
}

.admin-shell { height: 100vh; overflow: hidden; background: var(--bg); }
.admin-layout { height: 100vh; display: grid; grid-template-columns: 265px 1fr; gap: 0; }
.admin-side { padding: 14px; display: flex; flex-direction: column; min-height: 0; background: var(--sidebar-bg); border-right: 1px solid var(--line); }
.admin-tabs { margin-top: 18px; display: grid; gap: 4px; }
.tab { text-align: left; background: transparent; color: var(--muted); box-shadow: none; border-color: transparent; }
.tab.active { background: var(--panel-3); color: var(--text); border-color: var(--line); }
.admin-main { min-height: 0; overflow: auto; padding: 22px min(5vw, 56px) 46px; }
.admin-hero { margin-bottom: 16px; padding: 0 0 18px; border-bottom: 1px solid var(--line); }
.card, .provider-box {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: none;
  animation: fadeUp .22s ease both;
}
.card h2, .card h3 { margin-top: 0; letter-spacing: -.02em; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.provider-head { display: flex; justify-content: space-between; gap: 16px; align-items: start; margin-bottom: 12px; }
.table-wrap { overflow: auto; }
.table { width: 100%; border-collapse: collapse; min-width: 680px; }
.table th, .table td { padding: 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.table th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.badge { display: inline-flex; align-items: center; padding: 4px 8px; border-radius: 999px; background: var(--panel-3); color: var(--muted); font-size: 12px; font-weight: 750; }
.badge.good { color: #c9ffe9; background: rgba(16,163,127,.18); }
.badge.warn { color: #ffe8aa; background: rgba(244,191,80,.16); }
.badge.bad { color: #ffd3dc; background: rgba(255,107,107,.16); }

.pop-in { animation: popIn .28s cubic-bezier(.2,.9,.2,1) both; }
.fade-up { animation: fadeUp .20s ease both; }
@keyframes popIn { from { opacity: 0; transform: translateY(10px) scale(.99); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulseDot { 0%, 80%, 100% { opacity: .35; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-4px); } }
@keyframes floatOrb { from { transform: translate3d(0,0,0) scale(1); } to { transform: translate3d(70px,-40px,0) scale(1.08); } }

.knowledge-hint {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  padding: 8px 11px;
  border-radius: 999px;
  border: 1px solid rgba(16,163,127,.28);
  background: rgba(16,163,127,.10);
  color: #bfffe9;
  font-weight: 750;
}
:root[data-theme="light"] .knowledge-hint { color: #047857; background: #ecfdf5; }
.kb-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
}
.knowledge-hero label { max-width: 520px; margin-top: 14px; }
.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 9px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
}
.button-link:hover { border-color: var(--line-strong); background: var(--panel-3); }

@media (max-width: 980px) {
  body { overflow: auto; }
  .app-shell { height: auto; min-height: 100vh; grid-template-columns: 1fr; }
  .sidebar { min-height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .conv-list { max-height: 220px; }
  .chat-topbar { grid-template-columns: 1fr; }
  .topbar-controls { flex-wrap: wrap; }
  .control-label { min-width: min(100%, 320px); }
  .messages, .composer { padding-left: 16px; padding-right: 16px; }
  .msg, .msg.user { max-width: 100%; }
  .admin-layout { height: auto; min-height: 100vh; grid-template-columns: 1fr; }
  .admin-side { min-height: auto; }
  .admin-tabs { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-3, .grid-4, .form-row, .kb-grid { grid-template-columns: 1fr; }
  .provider-head { flex-direction: column; }
}
