/* ============ Sundey design system ============ */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
[hidden] { display: none !important; }

:root[data-theme="dark"] {
  --bg: #0b0e17;
  --bg-soft: #0f1320;
  --surface: #131826;
  --surface-2: #1a2133;
  --surface-3: #212a40;
  --border: #242d42;
  --border-soft: #1b2233;
  --text: #e8ebf4;
  --text-2: #a8b0c3;
  --text-3: #6d7689;
  --accent: #6366f1;
  --accent-2: #a855f7;
  --accent-soft: rgba(99, 102, 241, .14);
  --accent-hover: #7477f5;
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, .12);
  --success: #22c55e;
  --success-soft: rgba(34, 197, 94, .14);
  --shadow: 0 10px 34px rgba(2, 4, 10, .5);
  --shadow-sm: 0 2px 10px rgba(2, 4, 10, .35);
  --code-bg: #0d1120;
  --scrollbar: #2a3349;
}
:root[data-theme="light"] {
  --bg: #f4f5fa;
  --bg-soft: #edeff6;
  --surface: #ffffff;
  --surface-2: #f2f3fa;
  --surface-3: #e9ebf5;
  --border: #e2e5ef;
  --border-soft: #eceef6;
  --text: #1a1f2d;
  --text-2: #565e73;
  --text-3: #97a0b5;
  --accent: #5b5ef0;
  --accent-2: #9333ea;
  --accent-soft: rgba(91, 94, 240, .1);
  --accent-hover: #6b6df5;
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, .1);
  --success: #16a34a;
  --success-soft: rgba(22, 163, 74, .12);
  --shadow: 0 10px 30px rgba(23, 28, 45, .1);
  --shadow-sm: 0 2px 10px rgba(23, 28, 45, .07);
  --code-bg: #f6f7fb;
  --scrollbar: #cdd2e0;
}

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 700; }
button { font-family: inherit; }
input, textarea { font-family: inherit; }
::selection { background: var(--accent-soft); }
* { scrollbar-width: thin; scrollbar-color: var(--scrollbar) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 8px; }
*::-webkit-scrollbar-track { background: transparent; }

/* ---------- primitives ---------- */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid transparent;
  background: transparent; color: var(--text-2); cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.ic-sun { display: none; }
:root[data-theme="dark"] .ic-sun { display: block; }
:root[data-theme="dark"] .ic-moon { display: none; }

.lang-btn {
  height: 36px; padding: 0 13px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-2); font-size: 12.5px; font-weight: 700;
  letter-spacing: .06em; cursor: pointer; transition: all .15s;
}
.lang-btn:hover { color: var(--text); border-color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 18px; border-radius: 11px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s, box-shadow .15s;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: scale(.985); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none; color: #fff; box-shadow: 0 4px 14px rgba(99, 102, 241, .35);
}
.btn-primary:hover { filter: brightness(1.08); background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.btn-danger { background: var(--danger); border: none; color: #fff; }
.btn-danger:hover { filter: brightness(1.08); background: var(--danger); }
.btn-sm { height: 33px; padding: 0 13px; font-size: 13px; border-radius: 9px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn.loading::after {
  content: ""; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.35); border-top-color: #fff;
  animation: spin .7s linear infinite;
}

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.field input, .field textarea, input[type="text"], input[type="email"], input[type="password"], input[type="search"], textarea {
  width: 100%; padding: 11px 14px; border-radius: 11px;
  border: 1px solid var(--border); background: var(--bg-soft); color: var(--text);
  font-size: 14.5px; outline: none; transition: border-color .15s, box-shadow .15s;
}
:root[data-theme="light"] input, :root[data-theme="light"] textarea { background: var(--surface); }
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input::placeholder, textarea::placeholder { color: var(--text-3); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 600;
}
.badge-admin { background: var(--accent-soft); color: var(--accent); }
.badge-user { background: var(--surface-3); color: var(--text-2); }

.alert { padding: 11px 14px; border-radius: 11px; font-size: 14px; margin-bottom: 14px; }
.alert-error { background: var(--danger-soft); color: var(--danger); border: 1px solid transparent; }
.hidden { display: none !important; }
.muted { color: var(--text-2); }
.small { font-size: 12.5px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row-end { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.ta-r { text-align: right; }
.center { text-align: center; }

/* ---------- toasts ---------- */
.toasts {
  position: fixed; top: 18px; right: 18px; z-index: 1000;
  display: flex; flex-direction: column; gap: 10px; pointer-events: none;
}
.toast {
  pointer-events: auto; max-width: 340px; padding: 12px 16px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  font-size: 14px; font-weight: 500; display: flex; gap: 10px; align-items: flex-start;
  animation: toastIn .25s cubic-bezier(.2,.9,.3,1.2);
}
.toast.out { animation: toastOut .25s ease forwards; }
.toast .t-icon { flex: 0 0 auto; margin-top: 1px; }
.toast-success .t-icon { color: var(--success); }
.toast-error .t-icon { color: var(--danger); }
.toast-info .t-icon { color: var(--accent); }
@keyframes toastIn { from { opacity: 0; transform: translateX(30px) scale(.95); } }
@keyframes toastOut { to { opacity: 0; transform: translateX(30px) scale(.95); } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- modals ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 900; display: flex; align-items: center; justify-content: center;
  background: rgba(4, 6, 12, .6); backdrop-filter: blur(4px); padding: 20px;
  animation: fadeIn .18s ease;
}
:root[data-theme="light"] .modal-backdrop { background: rgba(30, 36, 55, .45); }
.modal {
  width: 100%; max-width: 560px; max-height: 88dvh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  box-shadow: var(--shadow); animation: modalIn .22s cubic-bezier(.2,.9,.3,1.1);
}
.modal-sm { max-width: 420px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px 0;
}
.modal-head h2 { font-size: 17px; }
.modal-body { padding: 20px 22px 22px; }
.modal-section { margin-bottom: 26px; }
.modal-section:last-child { margin-bottom: 0; }
.modal-section h3 {
  font-size: 14px; margin-bottom: 6px; padding-bottom: 8px; border-bottom: 1px solid var(--border-soft);
}
.modal-btns { display: flex; gap: 10px; justify-content: center; margin-top: 18px; }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes modalIn { from { opacity: 0; transform: translateY(14px) scale(.97); } }

/* ---------- brand ---------- */
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); font-weight: 800; font-size: 17px; letter-spacing: -.01em; }
.brand:hover { text-decoration: none; }
.brand img { width: 30px; height: 30px; border-radius: 9px; }
.brand-sm img { width: 26px; height: 26px; }

.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 12px; flex: 0 0 auto;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; font-weight: 700; font-size: 15px;
}
.menu-avatar { cursor: pointer; border: 2px solid transparent; transition: border-color .15s; }
.menu-avatar:hover { border-color: var(--accent); }

/* ---------- auth pages ---------- */
.auth-page {
  min-height: 100dvh; display: flex; flex-direction: column; align-items: center;
  background:
    radial-gradient(1000px 500px at 85% -10%, var(--accent-soft), transparent 60%),
    radial-gradient(800px 420px at -10% 110%, var(--accent-soft), transparent 55%),
    var(--bg);
  padding: 0 16px;
}
.auth-topbar { width: 100%; max-width: 900px; display: flex; justify-content: space-between; align-items: center; padding: 18px 6px; }
.auth-toggles { display: flex; gap: 8px; }
.auth-card {
  width: 100%; max-width: 430px; margin: auto; padding: 34px 32px 30px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow);
  animation: modalIn .3s cubic-bezier(.2,.9,.3,1.1);
}
.auth-logo { display: flex; justify-content: center; margin-bottom: 18px; }
.auth-logo img { width: 58px; height: 58px; border-radius: 16px; }
.auth-h1 { font-size: 23px; text-align: center; letter-spacing: -.02em; }
.auth-sub { color: var(--text-2); font-size: 14px; text-align: center; margin: 8px 0 22px; }
.auth-switch { text-align: center; font-size: 14px; color: var(--text-2); margin-top: 18px; }

/* ---------- app shell ---------- */
.app-shell { display: grid; grid-template-columns: 284px 1fr; height: 100dvh; }
.sidebar {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--bg-soft); border-right: 1px solid var(--border-soft);
}
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 10px; }
.side-close { display: none; }
.side-actions { padding: 4px 14px 12px; display: flex; flex-direction: column; gap: 10px; }
.btn-new { width: 100%; }
.search-box {
  display: flex; align-items: center; gap: 8px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 11px; background: var(--bg);
  color: var(--text-3); transition: border-color .15s, box-shadow .15s;
}
:root[data-theme="light"] .search-box { background: var(--surface); }
.search-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-box input { border: none !important; background: transparent !important; box-shadow: none !important; padding: 9px 0 !important; font-size: 13.5px; }

.conv-list { flex: 1; overflow-y: auto; padding: 4px 10px 10px; min-height: 0; }
.conv-group { font-size: 11.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--text-3); padding: 12px 8px 6px; }
.conv-item {
  position: relative; display: flex; flex-direction: column; gap: 2px;
  padding: 10px 12px; border-radius: 11px; cursor: pointer; margin-bottom: 2px;
  border: 1px solid transparent; transition: background .13s, border-color .13s;
}
.conv-item:hover { background: var(--surface); }
.conv-item.active { background: var(--surface); border-color: var(--border); }
.conv-item .c-title { font-size: 13.8px; font-weight: 500; line-height: 1.35; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 46px; }
.conv-item .c-meta { font-size: 11.5px; color: var(--text-3); display: flex; gap: 6px; }
.conv-item .c-snippet { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.conv-item .c-actions { position: absolute; top: 8px; right: 8px; display: none; gap: 2px; background: var(--surface-2); border-radius: 8px; padding: 2px; }
.conv-item:hover .c-actions, .conv-item.editing .c-actions { display: flex; }
.conv-item .c-actions button {
  width: 26px; height: 26px; border: none; background: transparent; color: var(--text-3);
  border-radius: 6px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.conv-item .c-actions button:hover { background: var(--surface-3); color: var(--text); }
.conv-item .c-actions .c-del:hover { color: var(--danger); }
.conv-item input.rename-input { width: 100%; margin-top: 4px; padding: 5px 8px; font-size: 13px; border-radius: 7px; }
.conv-empty { padding: 26px 14px; text-align: center; color: var(--text-3); font-size: 13px; }
.search-results .conv-item .c-actions { display: none; }

.side-foot { border-top: 1px solid var(--border-soft); padding: 12px 14px; }
.user-chip { display: flex; align-items: center; gap: 11px; padding: 8px; border-radius: 12px; }
.user-chip:hover { background: var(--surface); }
.user-chip .avatar { width: 36px; height: 36px; border-radius: 11px; }
.user-meta { display: flex; flex-direction: column; min-width: 0; }
.user-name { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11.5px; color: var(--text-3); }

.scrim { position: fixed; inset: 0; z-index: 60; background: rgba(4, 6, 12, .55); backdrop-filter: blur(2px); animation: fadeIn .18s ease; }

/* ---------- main / topbar ---------- */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100dvh; }
.topbar {
  display: flex; align-items: center; gap: 10px; height: 60px; padding: 0 16px;
  border-bottom: 1px solid var(--border-soft); background: var(--surface); flex: 0 0 auto;
}
.menu-btn { display: none; }
.top-title { font-size: 14.5px; font-weight: 600; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.model-badge {
  display: inline-flex; align-items: center; gap: 7px; margin-right: 4px;
  padding: 6px 12px; border-radius: 99px; font-size: 12px; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2);
  max-width: 170px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; flex: 0 0 auto; }
.dot-ok { background: var(--success); box-shadow: 0 0 6px var(--success); }
.dot-bad { background: var(--danger); }

.user-menu { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 80; min-width: 230px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
  padding: 6px; animation: modalIn .16s ease;
}
.menu-head { padding: 10px 12px; border-bottom: 1px solid var(--border-soft); margin-bottom: 6px; display: flex; flex-direction: column; }
.menu-head strong { font-size: 14px; }
.menu-head span { font-size: 12.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 190px; }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px;
  border: none; background: transparent; color: var(--text); font-size: 14px; font-weight: 500;
  border-radius: 9px; cursor: pointer; text-align: left; transition: background .12s;
}
.menu-item:hover { background: var(--surface-2); }
.menu-item svg { color: var(--text-3); }
.menu-danger { color: var(--danger); }
.menu-danger svg { color: var(--danger); }
.menu-danger:hover { background: var(--danger-soft); }

/* ---------- chat area ---------- */
.chat-scroll { flex: 1; overflow-y: auto; min-height: 0; scroll-behavior: smooth; }
.chat-col { max-width: 860px; margin: 0 auto; padding: 26px 20px 12px; }

.msg { display: flex; gap: 14px; margin-bottom: 26px; animation: msgIn .3s cubic-bezier(.2,.8,.3,1); }
@keyframes msgIn { from { opacity: 0; transform: translateY(10px); } }
.msg-user { justify-content: flex-end; }
.msg-user .msg-body { max-width: 78%; }
.msg-avatar {
  width: 34px; height: 34px; border-radius: 11px; flex: 0 0 auto; margin-top: 2px;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.msg-avatar img { width: 100%; height: 100%; }
.msg-user-bubble {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; padding: 13px 17px; border-radius: 16px 16px 4px 16px;
  white-space: pre-wrap; word-wrap: break-word; font-size: 14.8px; line-height: 1.55;
  box-shadow: 0 4px 14px rgba(99, 102, 241, .25);
}
.msg-content { min-width: 0; flex: 1; }
.msg-meta { display: flex; align-items: center; gap: 8px; margin-top: 9px; flex-wrap: wrap; }
.msg-time { font-size: 12px; color: var(--text-3); }
.msg-actions { display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.msg:hover .msg-actions, .msg.streamed .msg-actions { opacity: 1; }
.msg-actions button {
  display: inline-flex; align-items: center; gap: 5px; padding: 4px 9px;
  border: 1px solid transparent; background: transparent; color: var(--text-3);
  font-size: 12px; font-weight: 500; border-radius: 8px; cursor: pointer; transition: all .13s;
}
.msg-actions button:hover { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.usage-chip {
  font-size: 11.5px; color: var(--text-3); background: var(--surface-2);
  padding: 3px 9px; border-radius: 99px; border: 1px solid var(--border-soft);
}
.stop-chip {
  font-size: 11.5px; font-weight: 600; color: var(--danger);
  background: var(--danger-soft); padding: 3px 9px; border-radius: 99px;
}

/* thinking panel */
.thinking {
  border: 1px solid var(--border-soft); border-radius: 14px; background: var(--surface);
  margin-bottom: 10px; overflow: hidden; transition: border-color .2s;
}
.thinking-head {
  display: flex; align-items: center; gap: 9px; padding: 11px 14px; cursor: pointer;
  color: var(--text-2); font-size: 13px; font-weight: 600; user-select: none;
}
.thinking-head:hover { color: var(--text); }
.thinking-head .chev { transition: transform .2s; color: var(--text-3); display: inline-flex; }
.thinking.open .chev { transform: rotate(90deg); }
.thinking-body {
  max-height: 0; overflow: hidden; transition: max-height .3s ease;
}
.thinking.open .thinking-body { max-height: 320px; overflow-y: auto; }
.thinking-inner {
  padding: 4px 16px 14px; font-size: 13px; line-height: 1.65; color: var(--text-2);
  font-family: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  white-space: pre-wrap; word-wrap: break-word; border-top: 1px dashed var(--border-soft);
}
.thinking-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: 0 0 auto;
  animation: pulse 1.1s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: .25; transform: scale(.8); } 50% { opacity: 1; transform: scale(1); } }
.thinking-label { display: inline-flex; align-items: center; gap: 9px; }
.think-dots { display: inline-flex; gap: 4px; margin-left: 2px; }
.think-dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); animation: pulse 1.1s infinite; }
.think-dots i:nth-child(2) { animation-delay: .18s; }
.think-dots i:nth-child(3) { animation-delay: .36s; }

/* markdown */
.md { font-size: 14.8px; line-height: 1.65; word-wrap: break-word; overflow-wrap: break-word; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4 { margin: 20px 0 10px; line-height: 1.3; letter-spacing: -.01em; }
.md h1 { font-size: 21px; } .md h2 { font-size: 18.5px; } .md h3 { font-size: 16px; }
.md p { margin: 10px 0; }
.md ul, .md ol { margin: 10px 0; padding-left: 24px; }
.md li { margin: 5px 0; }
.md li::marker { color: var(--text-3); }
.md blockquote {
  margin: 12px 0; padding: 8px 16px; border-left: 3px solid var(--accent);
  background: var(--accent-soft); border-radius: 0 10px 10px 0; color: var(--text-2);
}
.md blockquote p { margin: 4px 0; }
.md hr { border: none; border-top: 1px solid var(--border); margin: 18px 0; }
.md a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.md table { border-collapse: collapse; margin: 14px 0; width: 100%; font-size: 13.8px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
.md th { background: var(--surface-2); font-weight: 600; }
.md code:not([class*="language-"]) {
  background: var(--surface-3); color: var(--text); padding: 2px 6px; border-radius: 6px;
  font-size: 13px; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.codeblock { margin: 14px 0; border-radius: 13px; overflow: hidden; border: 1px solid var(--border); background: var(--code-bg); }
.codeblock-head {
  display: flex; align-items: center; justify-content: space-between; padding: 7px 8px 7px 14px;
  background: var(--surface-2); border-bottom: 1px solid var(--border);
  font-size: 12px; font-weight: 600; color: var(--text-3);
}
.codeblock-head button {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-2); font-size: 12px; font-weight: 500;
  padding: 4px 11px; border-radius: 8px; cursor: pointer; transition: all .13s;
}
.codeblock-head button:hover { color: var(--text); border-color: var(--accent); }
.codeblock-head button.copied { color: var(--success); border-color: var(--success); }
.codeblock pre { margin: 0; padding: 14px 16px; overflow-x: auto; }
.codeblock pre code { font-size: 13.3px; line-height: 1.6; font-family: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace; background: transparent; padding: 0; }

.cursor {
  display: inline-block; width: 8px; height: 17px; margin-left: 2px; vertical-align: -3px;
  background: var(--accent); border-radius: 2px; animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.err-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--danger-soft); border: 1px solid var(--danger); color: var(--danger);
  padding: 12px 16px; border-radius: 13px; font-size: 14px; margin-bottom: 14px;
}
.err-banner button { border: 1px solid var(--danger); background: transparent; color: var(--danger); padding: 6px 14px; border-radius: 9px; font-weight: 600; font-size: 13px; cursor: pointer; }
.err-banner button:hover { filter: brightness(1.15); }

/* empty state */
.empty-state { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 7vh 16px 20px; animation: msgIn .4s ease; }
.empty-logo { margin-bottom: 20px; }
.empty-logo img { width: 64px; height: 64px; border-radius: 18px; box-shadow: 0 8px 30px rgba(99, 102, 241, .35); }
.empty-state h1 { font-size: 27px; letter-spacing: -.02em; }
.empty-state p { color: var(--text-2); margin: 10px 0 26px; max-width: 460px; }
.chips { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; width: 100%; max-width: 620px; }
.chip {
  text-align: left; padding: 13px 15px; border-radius: 14px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
  font-size: 13.5px; line-height: 1.45; transition: all .15s;
}
.chip:hover { border-color: var(--accent); color: var(--text); transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.chip b { display: block; color: var(--text); font-weight: 600; margin-bottom: 3px; }

/* composer */
.composer-wrap { flex: 0 0 auto; padding: 10px 16px 14px; background: linear-gradient(to top, var(--bg) 70%, transparent); }
:root[data-theme="light"] .composer-wrap { background: linear-gradient(to top, var(--bg) 70%, transparent); }
.composer {
  max-width: 860px; margin: 0 auto; display: flex; align-items: flex-end; gap: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 17px;
  padding: 10px 10px 10px 16px; box-shadow: var(--shadow-sm);
  transition: border-color .15s, box-shadow .15s;
}
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.composer textarea {
  flex: 1; border: none; background: transparent; resize: none; outline: none;
  font-size: 14.8px; line-height: 1.55; max-height: 190px; padding: 7px 0; color: var(--text);
}
.composer textarea::placeholder { color: var(--text-3); }
.send-btn {
  width: 40px; height: 40px; border-radius: 12px; border: none; cursor: pointer; flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  transition: filter .15s, transform .1s, opacity .15s;
}
.send-btn:hover { filter: brightness(1.1); }
.send-btn:active { transform: scale(.94); }
.send-btn[disabled] { opacity: .4; cursor: not-allowed; }
.send-btn.stop { background: var(--danger); }
.composer-hint { max-width: 860px; margin: 8px auto 0; text-align: center; font-size: 12px; color: var(--text-3); }

/* ---------- admin ---------- */
.admin-shell { display: flex; flex-direction: column; height: 100dvh; }
.admin-topbar {
  display: flex; align-items: center; gap: 14px; height: 62px; padding: 0 20px;
  background: var(--surface); border-bottom: 1px solid var(--border-soft); flex: 0 0 auto;
}
.page-crumb { font-size: 14px; font-weight: 600; color: var(--text-2); }
.admin-main { flex: 1; overflow-y: auto; padding: 30px 24px 60px; min-height: 0; }
.admin-inner { max-width: 1080px; margin: 0 auto; }
.admin-title { font-size: 24px; letter-spacing: -.02em; margin-bottom: 22px; }
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 26px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 18px;
  display: flex; flex-direction: column; gap: 4px; animation: msgIn .3s ease;
}
.stat-card .num { font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.stat-card .lbl { font-size: 13px; color: var(--text-2); }
.stat-card .ic { width: 34px; height: 34px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: flex; align-items: center; justify-content: center; margin-bottom: 8px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border-soft); }
.panel-head h2 { font-size: 16px; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13.8px; min-width: 860px; }
.table th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-3); padding: 12px 18px; border-bottom: 1px solid var(--border-soft); font-weight: 700;
}
.table td { padding: 13px 18px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: var(--surface-2); }
.user-cell { display: flex; align-items: center; gap: 11px; }
.user-cell .avatar { width: 34px; height: 34px; border-radius: 10px; font-size: 13px; }
.user-cell .u-name { font-weight: 600; }
.user-cell .u-you { font-size: 11px; font-weight: 700; color: var(--accent); background: var(--accent-soft); padding: 2px 7px; border-radius: 99px; }
.email-cell { color: var(--text-2); }
.role-badge { display: inline-flex; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(320px, 88vw); z-index: 70;
    transform: translateX(-105%); transition: transform .25s cubic-bezier(.3,.8,.3,1);
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .side-close { display: inline-flex; }
  .menu-btn { display: inline-flex; }
  .top-title { max-width: 45vw; }
  .model-badge { max-width: 110px; }
  .msg-user .msg-body { max-width: 88%; }
  .chips { grid-template-columns: 1fr; }
  .field-row { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
  .model-badge { display: none; }
  .top-title { max-width: 58vw; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* user message meta right-aligned */
.msg-user .msg-meta { justify-content: flex-end; margin-top: 6px; }
