/* BUUNIX BuuFather — compact dark ops UI */
:root {
  --bg: #0b0e14;
  --surface: #11151d;
  --surface2: #171c26;
  --surface3: #1e2431;
  --border: #232a37;
  --border2: #2e3648;
  --text: #e6e9f0;
  --muted: #8b93a7;
  --faint: #5c6478;
  --accent: #3bb2e6;
  --accent-soft: rgba(59, 178, 230, .12);
  --brand-blue: #3bb2e6;
  --green: #3ecf8e;
  --green-soft: rgba(62, 207, 142, .1);
  --red: #ff5d5d;
  --red-soft: rgba(255, 93, 93, .1);
  --amber: #f5b544;
  --amber-soft: rgba(245, 181, 68, .1);
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  --accent-hi: #6ee0ff;
  --grad-accent: linear-gradient(135deg, #4cc2f1, #2b96d9);
  --ring: 0 0 0 3px rgba(59, 178, 230, .22);
  --font: 'Inter', 'Noto Sans KR', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  --mono: ui-monospace, 'Cascadia Code', 'SF Mono', Consolas, 'Noto Sans KR', monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
::selection { background: rgba(110, 139, 255, .35); }
a { color: var(--accent); text-decoration: none; }
button { font-family: inherit; }
input, textarea, select {
  font-family: inherit;
  font-size: 13.5px;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border2);
  border-radius: 8px;
  padding: 8px 10px;
  outline: none;
  transition: border-color .15s;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
input::placeholder, textarea::placeholder { color: var(--faint); }
textarea { resize: vertical; min-height: 70px; }
label { display: block; font-size: 11.5px; font-weight: 600; color: var(--muted); margin: 10px 0 4px; text-transform: uppercase; letter-spacing: .04em; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--surface3); color: var(--text);
  border: 1px solid var(--border2); border-radius: 8px;
  padding: 7px 14px; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { background: #242c3d; border-color: #3a4459; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #0b0e14; }
.btn-primary:hover { background: #849bff; border-color: #849bff; }
.btn-danger { background: transparent; border-color: rgba(255, 93, 93, .4); color: var(--red); }
.btn-danger:hover { background: var(--red-soft); border-color: var(--red); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface3); color: var(--text); border-color: transparent; }
.btn-sm { padding: 4px 9px; font-size: 12px; border-radius: 6px; }

/* ---------- Shell layout ---------- */
.shell { display: grid; grid-template-rows: minmax(0, 1fr); height: 100vh; height: 100dvh; }
.main { display: grid; grid-template-columns: 218px 1fr; min-height: 0; }

/* Sidebar */
.sidebar {
  display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 14px 10px 10px; min-height: 0;
}
.brand { display: flex; align-items: center; gap: 9px; padding: 2px 8px 14px; }
.brand .b-sub { font-size: 10.5px; color: var(--muted); margin-top: 0; }
.logo-row { display: flex; align-items: center; gap: 3px; line-height: 1; }
.logo-word { font-weight: 800; font-size: 16.5px; letter-spacing: .07em; color: #fff; }
.logo-chev { flex: 0 0 auto; margin-top: 1px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-btn {
  display: flex; align-items: center; gap: 10px;
  background: transparent; border: none; color: var(--muted);
  padding: 8px 10px; border-radius: 8px; font-size: 13.5px; font-weight: 600;
  cursor: pointer; text-align: left; width: 100%;
  transition: background .15s, color .15s;
}
.nav-btn:hover { background: var(--surface2); color: var(--text); }
.nav-btn.active { background: var(--accent-soft); color: var(--accent); }
.nav-btn .badge { margin-left: auto; }
.badge {
  background: var(--red); color: #fff; font-size: 10.5px; font-weight: 700;
  border-radius: 999px; padding: 1px 6px; min-width: 18px; text-align: center;
}
.sidebar .spacer { flex: 1; }
.userchip {
  display: flex; align-items: center; gap: 9px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 10px; margin-top: 8px;
}
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12px; flex: 0 0 auto;
}
.userchip .u-name { font-size: 12.5px; font-weight: 600; line-height: 1.2; }
.userchip .u-role { font-size: 10.5px; color: var(--muted); text-transform: capitalize; }
.userchip .btn-ghost { margin-left: auto; padding: 4px 6px; }

/* Content area / views */
.content { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.view { display: none; flex: 1; min-height: 0; }
.view.active { display: flex; flex-direction: column; }
.view-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px 10px;
}
.view-head h1 { font-size: 16px; margin: 0; font-weight: 700; }
.view-head .sub { color: var(--muted); font-size: 12.5px; }

/* ---------- Ask view ---------- */
.ask-wrap { flex: 1; display: flex; flex-direction: column; min-height: 0; max-width: 820px; width: 100%; margin: 0 auto; padding: 0 20px; }
.thread { flex: 1; overflow-y: auto; padding: 10px 2px 16px; display: flex; flex-direction: column; gap: 14px; }
.msg { display: flex; gap: 10px; max-width: 100%; }
.msg .m-body { min-width: 0; }
.msg-user { flex-direction: row-reverse; }
.msg-user .m-body {
  background: var(--accent-soft); border: 1px solid rgba(110, 139, 255, .25);
  border-radius: 12px 12px 3px 12px; padding: 9px 13px; max-width: 78%;
}
.msg-bot .m-body {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px 12px 12px 3px; padding: 11px 14px; max-width: 88%;
}
.m-meta { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.src-chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--surface3); border: 1px solid var(--border2);
  border-radius: 999px; padding: 2px 10px; font-size: 11.5px; font-weight: 600;
  color: var(--muted); cursor: pointer; transition: color .15s, border-color .15s;
}
.src-chip:hover { color: var(--accent); border-color: var(--accent); }
.src-chip .code { font-family: var(--mono); color: var(--accent); font-size: 10.5px; }
.tts-btn.on { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.mode-note { font-size: 11.5px; color: var(--amber); background: var(--amber-soft); border: 1px solid rgba(245,181,68,.3); padding: 2px 9px; border-radius: 999px; }
.ask-empty { margin: auto; text-align: center; max-width: 560px; }
.ask-empty .big { font-size: 34px; margin-bottom: 6px; }
.ask-empty h2 { font-size: 17px; margin: 0 0 4px; }
.ask-empty p { color: var(--muted); margin: 0 0 16px; }
.sugg { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.sugg button {
  background: var(--surface); border: 1px solid var(--border2); color: var(--muted);
  border-radius: 999px; padding: 6px 13px; font-size: 12.5px; cursor: pointer;
  transition: color .15s, border-color .15s;
}
.sugg button:hover { color: var(--accent); border-color: var(--accent); }
.ask-inputrow { display: flex; gap: 8px; padding: 10px 0 16px; align-items: flex-end; }
.ask-inputrow textarea { flex: 1; min-height: 44px; max-height: 140px; border-radius: 12px; padding: 11px 14px; }
.ask-inputrow .btn-primary { height: 44px; padding: 0 18px; border-radius: 12px; }
.ai-off {
  font-size: 12px; color: var(--amber); background: var(--amber-soft);
  border: 1px solid rgba(245, 181, 68, .3); border-radius: 8px; padding: 6px 10px; margin-bottom: 8px;
}

/* Markdown output (renderMarkdown in common.js) */
.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 10px; }
.md ul, .md ol { margin: 4px 0 10px; padding-left: 22px; }
.md li { margin: 3px 0; }
.md li > ul, .md li > ol { margin: 3px 0 4px; }
.md h3, .md h4, .md h5, .md h6 { color: var(--text); line-height: 1.4; margin: 18px 0 6px; font-weight: 700; }
.md h3 { font-size: 15px; }
.md h4 { font-size: 14px; }
.md h5 { font-size: 13.5px; }
.md h6 { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.md a { color: var(--accent); text-decoration: underline; text-decoration-color: rgba(59, 178, 230, .4); text-underline-offset: 2px; }
.md a:hover { text-decoration-color: currentColor; }
.md code { font-family: var(--mono); font-size: 12px; background: var(--surface3); border-radius: 4px; padding: 1px 5px; }
.md pre { background: var(--surface3); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin: 8px 0 12px; overflow-x: auto; max-width: 100%; }
.md pre code { background: none; padding: 0; white-space: pre; overflow-wrap: normal; }
.md blockquote { margin: 10px 0; padding: 8px 14px; border-left: 3px solid var(--green); background: var(--green-soft); border-radius: 0 6px 6px 0; }
.md blockquote > :last-child { margin-bottom: 0; }
.md blockquote.callout-warn { border-left-color: var(--amber); background: var(--amber-soft); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
.md del { color: var(--faint); }
.md strong { color: #fff; }
/* Tables scroll inside their own box, never the page. */
.md-table { max-width: 100%; overflow-x: auto; margin: 10px 0 14px; border: 1px solid var(--border); border-radius: 10px; }
.md-table table { border-collapse: collapse; width: 100%; font-size: 12.5px; line-height: 1.5; }
.md-table th, .md-table td { padding: 8px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); min-width: 110px; max-width: 380px; overflow-wrap: break-word; }
.md-table th { background: var(--surface2); color: var(--text); font-weight: 700; font-size: 11.5px; }
.md-table tr:last-child td { border-bottom: 0; }
.md-table .al-c { text-align: center; }
.md-table .al-r { text-align: right; }
.cite-chip {
  display: inline-block; margin: 0 2px; padding: 0 6px; vertical-align: 1px; white-space: nowrap; cursor: pointer;
  font: 600 10.5px/1.6 var(--mono); color: var(--accent); background: var(--accent-soft);
  border: 1px solid rgba(59, 178, 230, .3); border-radius: 6px; transition: background .15s, border-color .15s;
}
.cite-chip:hover { background: rgba(59, 178, 230, .2); border-color: var(--accent); }
.is-opening { opacity: .6; cursor: progress; }

/* ---------- Chips ---------- */
.chips { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 20px 10px; }
.chip {
  background: var(--surface); border: 1px solid var(--border2); color: var(--muted);
  border-radius: 999px; padding: 3px 11px; font-size: 12px; font-weight: 600; cursor: pointer;
  transition: all .15s;
}
.chip:hover { color: var(--text); }
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chip .n { opacity: .6; font-weight: 400; }

/* Copy buttons */
.copy-btn {
  flex: 0 0 auto; background: transparent; border: 1px solid var(--border2); color: var(--muted);
  border-radius: 6px; padding: 2px 8px; font-size: 10.5px; cursor: pointer; transition: all .15s;
}
.copy-btn:hover { color: var(--green); border-color: var(--green); }
.copy-btn.copied { color: var(--green); border-color: var(--green); }

/* ---------- Chat view ---------- */
.chat-grid { flex: 1; display: grid; grid-template-columns: 250px 1fr; min-height: 0; }
.conv-list { border-right: 1px solid var(--border); overflow-y: auto; padding: 6px 8px; }
.conv-sec { font-size: 10.5px; font-weight: 700; color: var(--faint); text-transform: uppercase; letter-spacing: .06em; padding: 10px 8px 4px; }
.conv {
  display: flex; align-items: center; gap: 9px; width: 100%;
  background: transparent; border: none; color: var(--muted);
  padding: 7px 9px; border-radius: 8px; cursor: pointer; text-align: left;
  font-size: 13px; font-weight: 600; transition: background .15s, color .15s;
}
.conv:hover { background: var(--surface2); color: var(--text); }
.conv.active { background: var(--accent-soft); color: var(--accent); }
.conv .badge { margin-left: auto; }
.presence { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: 0 0 auto; }
.presence.on { background: var(--green); box-shadow: 0 0 6px rgba(62, 207, 142, .7); }
.role-tag {
  font-size: 9px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; border-radius: 4px; padding: 1px 5px;
  background: var(--amber-soft); color: var(--amber); border: 1px solid rgba(245, 181, 68, .35);
}
.chat-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 9px; padding: 12px 16px; border-bottom: 1px solid var(--border); font-weight: 700; font-size: 14px; }
.chat-head .sub { font-size: 11.5px; color: var(--muted); font-weight: 400; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 3px; }
.cmsg { display: flex; gap: 10px; padding: 3px 6px; border-radius: 8px; }
.cmsg:hover { background: var(--surface); }
.cmsg .c-body { min-width: 0; flex: 1; }
.cmsg .c-head { display: flex; align-items: baseline; gap: 8px; }
.cmsg .c-name { font-weight: 700; font-size: 13px; }
.cmsg .c-name.admin { color: var(--amber); }
.cmsg .c-time { font-size: 10.5px; color: var(--faint); }
.cmsg .c-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.cmsg.mine .c-name { color: var(--accent); }
.cmsg.compact { padding-top: 0; }
.cmsg.compact .avatar, .cmsg.compact .c-head { display: none; }
.cmsg.compact .c-body { padding-left: 38px; }
.day-sep { display: flex; align-items: center; gap: 10px; color: var(--faint); font-size: 11px; margin: 10px 0 4px; }
.day-sep::before, .day-sep::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.typing-line { min-height: 18px; font-size: 11.5px; color: var(--faint); padding: 0 16px 4px; font-style: italic; }
.chat-inputrow { display: flex; gap: 8px; padding: 8px 16px 14px; }
.chat-inputrow input { flex: 1; border-radius: 10px; padding: 10px 13px; }
.chat-empty { margin: auto; text-align: center; color: var(--muted); }

/* ---------- Login ---------- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: radial-gradient(1200px 600px at 50% -10%, rgba(110, 139, 255, .08), transparent), var(--bg); }
.login-card {
  width: 360px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 30px 28px; box-shadow: var(--shadow);
}
.login-card .brand { justify-content: center; padding-bottom: 6px; }
.login-card .logo-word { font-size: 26px; }
.login-card h1 { font-size: 15px; text-align: center; margin: 4px 0 2px; color: var(--muted); font-weight: 600; }
.login-card .sub { text-align: center; color: var(--muted); font-size: 12.5px; margin-bottom: 18px; }
.login-card input { width: 100%; padding: 10px 12px; }
.login-card .btn-primary { width: 100%; margin-top: 16px; height: 40px; }
.form-err { color: var(--red); font-size: 12.5px; min-height: 18px; margin-top: 10px; text-align: center; }
.login-foot { text-align: center; color: var(--faint); font-size: 11px; margin-top: 16px; }

/* ---------- Admin ---------- */
.admin-main { display: grid; grid-template-columns: 218px 1fr; height: 100vh; height: 100dvh; }
.panel { flex: 1; overflow-y: auto; padding: 18px 24px 30px; min-width: 0; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 18px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px;
}
.stat .s-num { font-size: 24px; font-weight: 800; }
.stat .s-label { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.stat.accent .s-num { color: var(--accent); }
.stat.green .s-num { color: var(--green); }
.stat.amber .s-num { color: var(--amber); }
table.tbl { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.tbl-wrap { overflow-x: auto; border-radius: var(--radius); }
.tbl th {
  text-align: left; font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); background: var(--surface2); padding: 8px 12px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.tbl td { padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tr.clickable { cursor: pointer; }
.tbl tr.clickable:hover td { background: var(--surface2); }
.pill { display: inline-block; font-size: 10.5px; font-weight: 700; border-radius: 999px; padding: 2px 9px; }
.pill-green { background: var(--green-soft); color: var(--green); }
.pill-red { background: var(--red-soft); color: var(--red); }
.pill-amber { background: var(--amber-soft); color: var(--amber); }
.pill-accent { background: var(--accent-soft); color: var(--accent); }
.pill-gray { background: var(--surface3); color: var(--muted); }
.sec-head { display: flex; align-items: center; gap: 10px; margin: 4px 0 12px; }
.sec-head h2 { font-size: 15px; margin: 0; }
.sec-head .grow { flex: 1; }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.tab {
  background: transparent; border: 1px solid var(--border2); color: var(--muted);
  border-radius: 8px; padding: 5px 14px; font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.tab.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.mono { font-family: var(--mono); font-size: 11.5px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 11.5px; }
.expand-row td { background: var(--surface2); }
.pw-reveal {
  font-family: var(--mono); font-size: 15px; background: var(--surface3);
  border: 1px dashed var(--accent); border-radius: 8px; padding: 10px 14px;
  text-align: center; letter-spacing: .04em; margin: 10px 0;
}

/* ---------- Modal & toast ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(4, 6, 10, .7); backdrop-filter: blur(2px);
  display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50;
  overflow-y: auto;
}
.modal {
  background: var(--surface); border: 1px solid var(--border2); border-radius: 14px;
  width: 100%; max-width: 640px; padding: 20px 22px; box-shadow: var(--shadow);
}
.modal.wide { max-width: 760px; }
.modal-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 6px; }
.modal-head h2 { font-size: 15px; margin: 0; line-height: 1.4; }
.modal-head .x { margin-left: auto; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.toast-wrap { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast {
  background: var(--surface3); border: 1px solid var(--border2); color: var(--text);
  border-radius: 10px; padding: 10px 14px; font-size: 12.5px; box-shadow: var(--shadow);
  animation: slidein .2s ease; max-width: 320px;
}
.toast.err { border-color: rgba(255, 93, 93, .5); }
.toast.ok { border-color: rgba(62, 207, 142, .5); }
@keyframes slidein { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

.spin {
  display: inline-block; width: 14px; height: 14px; border: 2px solid var(--faint);
  border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite;
  vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--border2); }

/* ---------- Bottom tab bar (mobile) ---------- */
.bottomnav { display: none; }

@media (max-width: 860px) {
  .main, .admin-main { grid-template-columns: 64px 1fr; }
  .sidebar .logo-word, .sidebar .b-sub, .nav-btn span.txt, .userchip .u-meta, .sidebar .adminlink span.txt { display: none; }
  .nav-btn { justify-content: center; }
  .chat-grid { grid-template-columns: 200px 1fr; }
}

/* ---------- Phone layout ---------- */
@media (max-width: 700px) {
  body { font-size: 14px; }
  input, textarea, select { font-size: 16px; } /* prevents iOS zoom-on-focus */
  .btn { padding: 8px 14px; }

  .main { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .content { padding-bottom: calc(58px + env(safe-area-inset-bottom, 0px)); }

  .bottomnav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    background: rgba(17, 21, 29, .97); backdrop-filter: blur(10px);
    border-top: 1px solid var(--border);
    padding: 5px 4px calc(5px + env(safe-area-inset-bottom, 0px));
  }
  .bn-btn {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px;
    background: none; border: none; color: var(--muted); font-size: 19px;
    padding: 3px 0 1px; cursor: pointer; position: relative; min-height: 44px;
  }
  .bn-btn .bn-label { font-size: 10px; font-weight: 700; letter-spacing: .02em; }
  .bn-btn.active { color: var(--accent); }
  .bn-btn .bn-avatar { width: 22px; height: 22px; font-size: 10px; }
  .bn-badge {
    position: absolute; top: 0; left: calc(50% + 8px);
    background: var(--red); color: #fff; font-size: 9.5px; font-weight: 700;
    border-radius: 999px; padding: 0 5px; min-width: 15px; line-height: 15px;
  }

  .view-head { padding: 10px 14px 8px; }
  .chips { padding-left: 14px; padding-right: 14px; }
  .ask-wrap { padding: 0 12px; }
  .ask-inputrow { padding-bottom: 10px; }
  .msg-bot .m-body { max-width: 96%; }
  .msg-user .m-body { max-width: 88%; }

  /* Chat becomes single-pane: list first, then conversation with a back button */
  .chat-grid { grid-template-columns: 1fr; }
  .chat-pane { display: none; }
  .chat-grid.show-pane .conv-list { display: none; }
  .chat-grid.show-pane .chat-pane { display: flex; }
  .conv-list { border-right: none; padding: 8px 10px; }
  .conv { padding: 11px 10px; }
  .chat-head { padding: 10px 12px; }
  .chat-msgs { padding: 12px 10px; }
  .chat-inputrow { padding: 8px 10px 12px; }

  .modal-backdrop { padding: 10px 8px calc(10px + env(safe-area-inset-bottom, 0px)); }
  .modal { padding: 16px 14px; border-radius: 12px; }
  .modal-actions { flex-wrap: wrap; }

  /* Admin on a phone: keep the icon rail, tighten the panel */
  .admin-main { grid-template-columns: 56px 1fr; }
  .panel { padding: 12px 12px 30px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .sec-head { flex-wrap: wrap; }

  .login-card { width: 100%; max-width: 380px; padding: 24px 18px; }
}

/* ============================================================
   Visual upgrade layer — atmosphere, motion, and polish.
   Overrides base rules by cascade; keep after all base blocks.
   ============================================================ */

body {
  background:
    radial-gradient(1100px 520px at 88% -12%, rgba(59, 178, 230, .075), transparent 62%),
    radial-gradient(900px 520px at -12% 112%, rgba(59, 178, 230, .05), transparent 62%),
    var(--bg);
  background-attachment: fixed;
}

/* Focus visibility */
button:focus-visible, a:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 8px; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59, 178, 230, .12); }

/* Buttons */
.btn { transition: background .16s, border-color .16s, box-shadow .16s, transform .06s, filter .16s; }
.btn-primary {
  background: var(--grad-accent); border: none; color: #04121c; font-weight: 700;
  box-shadow: 0 2px 12px rgba(59, 178, 230, .28);
}
.btn-primary:hover { background: var(--grad-accent); filter: brightness(1.1); box-shadow: 0 4px 18px rgba(59, 178, 230, .4); }
.btn-danger:hover { box-shadow: 0 2px 12px rgba(255, 93, 93, .18); }

/* Sidebar & nav */
.sidebar { background: linear-gradient(180deg, rgba(255, 255, 255, .012), transparent 30%), var(--surface); }
.nav-btn { transition: background .16s, color .16s, box-shadow .16s; }
.nav-btn.active {
  background: linear-gradient(90deg, rgba(59, 178, 230, .17), rgba(59, 178, 230, .05));
  box-shadow: inset 0 0 0 1px rgba(59, 178, 230, .22);
}
.userchip { background: linear-gradient(180deg, rgba(255, 255, 255, .02), transparent), var(--surface2); }
.avatar { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .06); }

/* View transitions */
.view.active { animation: viewin .24s ease; }
@keyframes viewin { from { opacity: 0; transform: translateY(7px); } }
.view-head h1 { font-size: 17px; letter-spacing: -.01em; }

/* Ask view */
.ask-empty .big {
  width: 76px; height: 76px; margin: 0 auto 14px; display: flex; align-items: center; justify-content: center;
  font-size: 36px; border-radius: 26px;
  background: linear-gradient(135deg, rgba(59, 178, 230, .2), rgba(59, 178, 230, .04));
  border: 1px solid rgba(59, 178, 230, .32);
  box-shadow: 0 10px 40px rgba(59, 178, 230, .16), inset 0 1px 0 rgba(255, 255, 255, .07);
}
.sugg button { transition: color .16s, border-color .16s, transform .12s, box-shadow .16s; }
.sugg button:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(59, 178, 230, .12); }
.msg { animation: msgin .26s ease; }
@keyframes msgin { from { opacity: 0; transform: translateY(9px); } }
.msg-bot .m-body {
  background: linear-gradient(180deg, rgba(59, 178, 230, .045), transparent 45%), var(--surface);
  border-left: 2px solid rgba(59, 178, 230, .4);
}
.msg-bot > .avatar { background: linear-gradient(135deg, rgba(59, 178, 230, .28), rgba(59, 178, 230, .08)); box-shadow: 0 0 14px rgba(59, 178, 230, .18); }
.msg-user .m-body { background: linear-gradient(135deg, rgba(59, 178, 230, .16), rgba(59, 178, 230, .09)); }
.ask-inputrow textarea { transition: border-color .16s, box-shadow .16s; }
.src-chip { transition: color .16s, border-color .16s, transform .1s, box-shadow .16s; }
.src-chip:hover { transform: translateY(-1px); box-shadow: 0 3px 10px rgba(59, 178, 230, .14); }
.thread, .chat-msgs { scroll-behavior: smooth; }

/* Chips */
.chip { transition: color .16s, border-color .16s, background .16s, transform .1s; }
.chip:hover { transform: translateY(-1px); }

/* Copy buttons */
.copy-btn { transition: color .14s, border-color .14s, background .14s; }
.copy-btn:hover { background: rgba(62, 207, 142, .08); }

/* Chat */
.conv { transition: background .15s, color .15s, transform .1s; }
.conv:hover { transform: translateX(2px); }
.presence.on { animation: presencein .3s ease; }
@keyframes presencein { from { transform: scale(.4); } }
.cmsg { animation: msgin .2s ease; border-radius: 10px; }
.chat-head { background: linear-gradient(180deg, rgba(255, 255, 255, .012), transparent), transparent; }
.chat-inputrow input { border-radius: 12px; }

/* Modals & toasts */
.modal-backdrop { animation: fadein .16s ease; }
@keyframes fadein { from { opacity: 0; } }
.modal { animation: modalin .22s cubic-bezier(.2, .8, .3, 1.1); box-shadow: 0 30px 80px rgba(0, 0, 0, .55), 0 0 0 1px rgba(255, 255, 255, .03); }
@keyframes modalin { from { opacity: 0; transform: translateY(10px) scale(.98); } }
.pw-reveal { box-shadow: 0 0 24px rgba(59, 178, 230, .1); }

/* Admin */
.stat {
  background: linear-gradient(180deg, rgba(255, 255, 255, .02), transparent 45%), var(--surface);
  transition: transform .16s, box-shadow .16s, border-color .16s;
}
.stat:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(0, 0, 0, .32); border-color: var(--border2); }
.stat .s-num {
  background: linear-gradient(135deg, #ffffff, #9fb3c8);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}
.stat.accent .s-num { background: linear-gradient(135deg, var(--accent-hi), var(--accent)); -webkit-background-clip: text; background-clip: text; }
.stat.green .s-num { background: linear-gradient(135deg, #7fe8b8, var(--green)); -webkit-background-clip: text; background-clip: text; }
.stat.amber .s-num { background: linear-gradient(135deg, #ffd58a, var(--amber)); -webkit-background-clip: text; background-clip: text; }
.tbl tbody tr { transition: background .12s; }
.tbl tbody tr:hover td { background: rgba(59, 178, 230, .035); }

/* Login */
.login-body {
  background:
    radial-gradient(900px 500px at 50% -12%, rgba(59, 178, 230, .16), transparent 64%),
    radial-gradient(700px 400px at 90% 110%, rgba(59, 178, 230, .06), transparent 60%),
    var(--bg);
}
.login-card {
  background: linear-gradient(180deg, rgba(255, 255, 255, .025), transparent 35%), var(--surface);
  border-color: var(--border2);
  box-shadow: 0 30px 90px rgba(0, 0, 0, .55), 0 0 40px rgba(59, 178, 230, .06);
  animation: modalin .3s ease;
}

/* Anchored sign-out at the bottom of the side panel */
.logout-nav { margin-top: 6px; color: var(--muted); }
.logout-nav:hover { background: var(--red-soft); color: var(--red); }

/* Scrollbars */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #232b3a; border: 2px solid transparent; background-clip: padding-box; border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: #2f394d; background-clip: padding-box; }

/* Bottom nav (phone) active indicator */
@media (max-width: 700px) {
  .bn-btn { transition: color .16s, transform .1s; }
  .bn-btn.active::before {
    content: ''; position: absolute; top: -6px; left: 50%; transform: translateX(-50%);
    width: 22px; height: 3px; border-radius: 0 0 4px 4px;
    background: var(--accent); box-shadow: 0 2px 10px rgba(59, 178, 230, .8);
  }
}
