/* AmChat - shared styles. Rebrand by changing --accent* below. */
:root {
  --accent: #0b6e7f;
  --accent-hover: #09596a;
  --accent-contrast: #ffffff;
  --accent-soft: #e3f1f4;
  --bg: #f5f7f9;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --border: #d7dde3;
  --text: #1b2630;
  --text-muted: #5b6874;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --success: #12703d;
  --success-soft: #e2f4ea;
  --warn-bg: #fff4cc;
  --warn-border: #e0a800;
  --warn-text: #5a4300;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 12px rgba(16, 24, 40, .06);
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --header-h: 52px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --accent: #4fb3c6;
    --accent-hover: #6cc4d5;
    --accent-contrast: #06232a;
    --accent-soft: #12333b;
    --bg: #11161b;
    --surface: #182027;
    --surface-2: #202a33;
    --border: #2d3944;
    --text: #e6ebef;
    --text-muted: #97a4b0;
    --danger: #ff8a7d;
    --danger-soft: #3a1c19;
    --success: #6fd49b;
    --success-soft: #153324;
    --warn-bg: #3b3210;
    --warn-border: #c99a00;
    --warn-text: #ffe28a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 12px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.5;
  background: var(--bg); color: var(--text); overflow-x: hidden;
}
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--text-muted); }

/* ---- Buttons & forms ---- */
button { font: inherit; color: inherit; cursor: pointer; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  padding: .45em .9em; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); text-decoration: none; line-height: 1.3;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.92); background: var(--danger); }
@media (prefers-color-scheme: dark) { .btn-danger { color: #2a0a07; } }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: .25em .6em; font-size: 13px; }
.icon-btn { width: 36px; height: 36px; padding: 0; }

label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 4px; }
input[type=text], input[type=email], input[type=password], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: .5em .7em;
}
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.field { margin-bottom: 12px; }
.check { display: flex; align-items: center; gap: .5em; font-weight: 400; font-size: 14px; margin: 0; }
.check input { width: auto; }
.form-error { color: var(--danger); background: var(--danger-soft); border-radius: 8px; padding: .5em .75em; margin: 0 0 12px; font-size: 14px; }
.form-ok { color: var(--success); background: var(--success-soft); border-radius: 8px; padding: .5em .75em; margin: 0 0 12px; font-size: 14px; }

/* ---- Dialog ---- */
dialog {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text);
  padding: 0; width: min(480px, calc(100vw - 32px)); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(10, 15, 20, .5); }
.dlg-body { padding: 20px; }
.dlg-body h2 { font-size: 18px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.checklist { max-height: 40vh; overflow: auto; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; display: grid; gap: 6px; }

/* ---- Header ---- */
.app-header {
  height: calc(var(--header-h) + env(safe-area-inset-top)); display: flex; align-items: center; gap: 8px;
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  background: var(--surface); border-bottom: 1px solid var(--border); position: relative; z-index: 20;
}
.app-title { font-weight: 700; font-size: 16px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.brand-dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--accent); margin-right: 8px; }
.spacer { flex: 1; }
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px; z-index: 30;
}
.menu .menu-who { padding: 6px 10px; font-size: 13px; color: var(--text-muted); border-bottom: 1px solid var(--border); margin-bottom: 4px; overflow-wrap: anywhere; }
.menu a, .menu button {
  display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: none;
  border-radius: 6px; text-decoration: none; color: var(--text);
}
.menu a:hover, .menu button:hover { background: var(--surface-2); }

/* ---- Chat layout ---- */
.chat-app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.chat-body { flex: 1; display: flex; min-height: 0; position: relative; }
.sidebar {
  width: 270px; flex: none; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
.sidebar-head { padding: 12px; }
.sidebar-head .btn { width: 100%; }
.conv-list { list-style: none; margin: 0; padding: 0 8px 12px; overflow-y: auto; flex: 1; }
.conv-item { display: flex; align-items: center; border-radius: 8px; }
.conv-item:hover, .conv-item.active { background: var(--surface-2); }
.conv-item.active { background: var(--accent-soft); }
.conv-open { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 8px 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border-radius: 8px; }
.conv-del { opacity: 0; flex: none; }
.conv-item:hover .conv-del, .conv-item:focus-within .conv-del, .conv-item.active .conv-del { opacity: 1; }
@media (hover: none) { .conv-del { opacity: 1; } }
.sidebar-empty { padding: 8px 12px; color: var(--text-muted); font-size: 14px; }
.sidebar-toggle { display: none; }
.scrim { display: none; }

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0; }
.messages { flex: 1; overflow-y: auto; padding: 20px 16px; scroll-behavior: smooth; }
.messages-inner { max-width: 820px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }

.empty-state { max-width: 640px; margin: 8vh auto 0; text-align: center; }
.empty-state h2 { font-size: 24px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 14px; }
.chip-btn {
  padding: .5em .9em; border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  font-size: 14px; text-align: left;
}
.chip-btn:hover { border-color: var(--accent); background: var(--accent-soft); }

.msg { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.msg-user { align-items: flex-end; }
.msg-user .bubble {
  background: var(--accent); color: var(--accent-contrast); padding: .55em .9em; border-radius: 14px 14px 4px 14px;
  max-width: 85%; white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg-assistant { flex-direction: row; align-items: flex-start; gap: 10px; }
.msg-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.msg-label { font-size: 12px; color: var(--text-muted); }

/* Assistant avatar in each answer: the animated "a" mascot (newest answer live, older ones a still, see chat.js Mascot). */
.mascot-msg { width: 44px; height: 44px; margin: -4px 0 0 -6px; }
.mascot-still svg, .mascot-still svg * { animation-play-state: paused !important; }

/* "Thinking" dots in the status line */
.typing { display: inline-flex; gap: 3px; align-items: center; flex: none; color: var(--accent); }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: dot-bounce 1.2s ease-in-out infinite; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes dot-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .45; } 30% { transform: translateY(-4px); opacity: 1; } }
.answer { min-width: 0; overflow-wrap: anywhere; }
.answer > :first-child { margin-top: 0; }
.answer > :last-child { margin-bottom: 0; }
.answer pre { background: var(--surface-2); border: 1px solid var(--border); padding: 10px 12px; border-radius: 8px; overflow-x: auto; font-family: var(--mono); font-size: 13px; }
.answer code { font-family: var(--mono); font-size: .92em; background: var(--surface-2); padding: .1em .35em; border-radius: 4px; }
.answer pre code { background: none; padding: 0; }
.answer table { border-collapse: collapse; display: block; overflow-x: auto; max-width: 100%; }
.answer th, .answer td { border: 1px solid var(--border); padding: 4px 8px; text-align: left; }
.answer th { background: var(--surface-2); }
.answer blockquote { margin: .6em 0; padding-left: 12px; border-left: 3px solid var(--border); color: var(--text-muted); }

.status-line { display: flex; align-items: center; gap: 8px; color: var(--text-muted); font-size: 14px; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 3s; }
  .typing i { animation: none; }
  .messages { scroll-behavior: auto; }
}
@media (max-width: 600px) { .mascot-msg { width: 36px; height: 36px; margin: -2px 0 0 -4px; } }

.notice-error { background: var(--danger-soft); color: var(--danger); border: 1px solid var(--danger); border-radius: 8px; padding: .6em .85em; font-size: 14px; }
.notice-error a { color: inherit; font-weight: 600; }

.figure-card { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); max-width: min(520px, 100%); overflow: hidden; }
.figure-open { display: block; width: 100%; padding: 0; border: 0; background: var(--surface-2); cursor: zoom-in; }
.figure-open img { display: block; max-width: 100%; width: 100%; max-height: 420px; object-fit: contain; background: #fff; }
.figure-meta { padding: 8px 12px; font-size: 13px; }
.figure-caption { margin: 0 0 2px; }

.sources { font-size: 13px; color: var(--text-muted); }
.sources ul { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.sources a { display: inline-block; padding: 2px 10px; border: 1px solid var(--border); border-radius: 999px; text-decoration: none; background: var(--surface); }
.sources a:hover { border-color: var(--accent); }
.sources .src-plain { display: inline-block; padding: 2px 10px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); }

.feedback { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 13px; color: var(--text-muted); }
.feedback .btn[aria-pressed=true] { background: var(--accent-soft); border-color: var(--accent); }
.feedback-box { display: flex; gap: 6px; width: 100%; max-width: 520px; }
.feedback-box input { flex: 1; min-width: 0; }

/* ---- Composer ---- */
.limit-notice { max-width: 820px; margin: 0 auto 8px; background: var(--warn-bg); color: var(--warn-text);
  border: 1px solid var(--warn-border); border-radius: 8px; padding: .5em .85em; font-size: 14px; }
.composer-wrap { border-top: 1px solid var(--border); background: var(--surface);
  padding: 12px max(16px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
.composer { max-width: 820px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { resize: none; max-height: 180px; min-height: 42px; line-height: 1.4; }
.composer .btn { height: 42px; }
.footer-line { max-width: 820px; margin: 6px auto 0; font-size: 12px; color: var(--text-muted); text-align: center; overflow-wrap: anywhere; }

/* ---- Mascot (animated "a" avatar; states are swapped by chat.js, see Mascot) ---- */
.mascot { display: inline-block; flex: none; line-height: 0; }
.mascot img, .mascot svg { display: block; width: 100%; height: 100%; pointer-events: none; user-select: none; }
.mascot-head { width: 44px; height: 44px; margin: 0 -2px 0 -4px; }
.mascot-lg { width: 150px; height: 150px; margin-bottom: 4px; }
.mascot-login { display: block; width: 96px; height: 96px; margin: 0 auto 8px; }
.is-empty .mascot-head { display: none; }   /* the big one on the welcome screen shows the state instead */
@media (max-width: 480px) { .mascot-lg { width: 120px; height: 120px; } .brand-dot { display: none; } }
@media (max-height: 500px) { .mascot-lg { width: 72px; height: 72px; } .mascot-login { width: 64px; height: 64px; } }
/* The mascot always animates, also with the OS 'reduce motion' setting (product decision). */

/* ---- Lightbox ---- */
.lightbox { position: fixed; inset: 0; z-index: 100; background: rgba(8, 12, 16, .92); display: flex; flex-direction: column; }
.lb-bar { display: flex; gap: 8px; padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left)); align-items: center; color: #e6ebef; }
.lb-bar .btn { background: #26323c; color: #e6ebef; border-color: #3a4854; }
.lb-title { flex: 1; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-stage { flex: 1; overflow: auto; display: flex; padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); touch-action: pan-x pan-y pinch-zoom; }
.lb-stage img { margin: auto; background: #fff; }
.lb-stage.fit img { max-width: 100%; max-height: 100%; object-fit: contain; }
.lb-stage.full img { max-width: none; max-height: none; }

/* ---- Pinout ---- */
.pinout { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; max-width: 760px; }
.pinout-warn { background: var(--warn-bg); color: var(--warn-text); border-bottom: 2px solid var(--warn-border); padding: 10px 14px; font-weight: 600; font-size: 14px; display: flex; gap: 10px; align-items: flex-start; }
.pinout-warn svg { flex: none; margin-top: 2px; }
.pinout-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; padding: 12px 14px 0; }
.pinout-head h3 { margin: 0; font-size: 16px; }
.pinout-head .conn { font-family: var(--mono); font-size: 13px; color: var(--text-muted); }
.pinout-diagram { padding: 10px 14px; overflow-x: auto; color: var(--text); }
.pinout-diagram svg { display: block; max-width: none; height: auto; }
.pinout-diagram .p-body { fill: var(--surface-2); stroke: currentColor; stroke-width: 1.5; }
.pinout-diagram .p-pin { fill: var(--surface); stroke: currentColor; stroke-width: 1.5; }
.pinout-diagram .p-num { fill: currentColor; font: 600 11px var(--mono); text-anchor: middle; dominant-baseline: central; }
.pinout-diagram .p-sig { fill: currentColor; font: 12px var(--font); dominant-baseline: central; }
.pinout-table-wrap { overflow-x: auto; padding: 0 14px 10px; }
.pinout table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
.pinout th, .pinout td { border-bottom: 1px solid var(--border); padding: 5px 8px; text-align: left; vertical-align: top; }
.pinout th { color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.pinout td.pin, .pinout td.sig { font-family: var(--mono); white-space: nowrap; }
.pinout-foot { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; padding: 0 14px 12px; font-size: 13px; color: var(--text-muted); }

/* ---- Auth page ---- */
.auth-wrap { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; }
.auth-card h1 { font-size: 20px; }
.auth-card .btn { width: 100%; }
.lang-row { display: flex; justify-content: flex-end; margin-bottom: 8px; }

/* ---- Admin ---- */
.admin-main { max-width: 1600px; margin: 0 auto; padding: 16px; }
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab { padding: 8px 14px; border: 0; border-bottom: 3px solid transparent; background: none; white-space: nowrap; color: var(--text-muted); }
.tab[aria-selected=true] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.panel-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 16px; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table.data { border-collapse: collapse; width: 100%; font-size: 14px; }
table.data th, table.data td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.data th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); background: var(--surface-2); white-space: nowrap; }
table.data tr:last-child td { border-bottom: 0; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { white-space: nowrap; }
.cell-path { font-family: var(--mono); font-size: 12px; color: var(--text-muted); overflow-wrap: anywhere; }
.badge { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-pending { background: var(--warn-bg); color: var(--warn-text); }
.badge-indexed { background: var(--success-soft); color: var(--success); }
.badge-error { background: var(--danger-soft); color: var(--danger); cursor: help; }
.badge-off { background: var(--surface-2); color: var(--text-muted); }
.chip { display: inline-block; padding: 0 8px; margin: 1px 2px 1px 0; border-radius: 6px; background: var(--accent-soft); font-size: 12px; }
.drop {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 22px 12px; text-align: center;
  border: 2px dashed var(--border); border-radius: var(--radius); background: var(--surface); width: 100%;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.upload-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.stat .v { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat .k { font-size: 13px; color: var(--text-muted); }
.notice-warn { background: var(--warn-bg); color: var(--warn-text); border: 1px solid var(--warn-border); border-radius: 8px; padding: .6em .85em; margin-bottom: 16px; }
.excerpt { max-width: 420px; overflow-wrap: anywhere; white-space: pre-wrap; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: .5em 1em; border-radius: 8px; z-index: 200; max-width: calc(100vw - 32px); }
.toast.err { background: var(--danger); color: #fff; }

/* ---- Mobile ---- */
@media (max-width: 760px) {
  .sidebar-toggle { display: inline-flex; }
  .sidebar { position: absolute; z-index: 15; top: 0; bottom: 0; left: 0; transform: translateX(-100%); transition: transform .2s; width: min(300px, 86vw); box-shadow: var(--shadow); }
  .chat-app.drawer-open .sidebar { transform: none; }
  .chat-app.drawer-open .scrim { display: block; position: absolute; inset: 0; z-index: 14; background: rgba(10, 15, 20, .45); }
  .app-title { font-size: 15px; }
  .upload-grid { grid-template-columns: 1fr; }
  .msg-user .bubble { max-width: 92%; }
  .empty-state { margin-top: 3vh; }
}
/* ---- Touch / small screens: 44px targets, 16px inputs (no iOS focus zoom), safe areas ---- */
@media (max-width: 1024px), (pointer: coarse) {
  input[type=text], input[type=email], input[type=password], select, textarea { font-size: 16px; }
}
@media (max-width: 760px), (pointer: coarse) {
  .btn, .btn-sm, .chip-btn, .menu a, .menu button, .tab { min-height: 44px; }
  .icon-btn { width: 44px; height: 44px; }
  .conv-open { min-height: 44px; }
  .composer .btn { height: 44px; }
  .composer textarea { min-height: 44px; }
  .menu { min-width: min(240px, calc(100vw - 24px)); }
  .feedback { gap: 8px; }
  .answer a, .sources a { padding-block: .2em; }
}
@media (max-width: 760px) {
  .app-header { gap: 6px; padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
  .sidebar { padding-left: env(safe-area-inset-left); }
  .conv-list { padding-bottom: calc(12px + env(safe-area-inset-bottom)); overscroll-behavior: contain; }
  .messages { padding: 14px max(12px, env(safe-area-inset-right)) 14px max(12px, env(safe-area-inset-left)); overscroll-behavior: contain; }
  .messages-inner { gap: 14px; }
  .empty-state h2 { font-size: 20px; }
  .composer-wrap { padding-top: 8px; }
  .footer-line { font-size: 11px; }
  .pinout-diagram, .pinout-table-wrap { padding-left: 10px; padding-right: 10px; }
  .pinout-head, .pinout-foot { padding-left: 10px; padding-right: 10px; }
  .auth-card { padding: 18px; }
}
@media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }

/* ---- Admin chips (direct = filled, inherited = outlined) ---- */
.chip-via { background: transparent; border: 1px dashed var(--accent); cursor: help; }
.chip-implied { background: transparent; border: 1px solid var(--border); color: var(--text-muted); }
.chip-all { color: var(--text-muted); font-size: 13px; }

/* ---- amium logo, right end of the header (header is fixed: chat = app layout, admin = sticky) ---- */
.brand-logo { display: flex; align-items: center; flex: none; margin-left: 6px; }
.brand-logo img { display: block; height: 22px; width: auto; }
body > .app-header { position: sticky; top: 0; }
@media (prefers-color-scheme: dark) { .brand-logo img { filter: invert(1); } }
@media (max-width: 480px) { .brand-logo img { height: 16px; } }
@media (max-width: 359px) { .brand-logo { display: none; } }

/* ---- language selector ---- */
.langsel { position: relative; display: inline-flex; align-items: center; gap: 6px; flex: none; }
.langsel-btn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 8px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px; cursor: pointer;
  font: inherit; font-size: 13px; font-weight: 600;
}
.langsel-btn:hover { background: var(--surface-2); }
.langsel-caret { font-size: 10px; color: var(--text-muted); }
.lang-flag { display: block; flex: none; width: 22px; height: 15px; border-radius: 3px; box-shadow: 0 0 0 1px rgba(0, 0, 0, .18); }
.langsel-pop {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 40; min-width: 170px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.langsel-pop[hidden] { display: none; }
.langsel-list { list-style: none; margin: 0; padding: 0; outline: none; }
.langsel-list li {
  display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 0 10px; border-radius: 6px; cursor: pointer;
}
.langsel-list li:hover, .langsel-list li.active { background: var(--surface-2); }
.langsel-list:focus-visible li.active { outline: 2px solid var(--accent); outline-offset: -2px; }
.langsel-list li[aria-selected="true"] { font-weight: 700; box-shadow: inset 3px 0 0 var(--accent); }
.langsel-form { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.langsel-form button {
  min-height: 40px; padding: 0 8px; border: 0; background: var(--surface); color: var(--text-muted);
  font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.langsel-form button + button { border-left: 1px solid var(--border); }
.langsel-form button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.langsel-form-in { display: none; margin: 6px 4px 2px; width: calc(100% - 8px); }
.langsel-form-in button { flex: 1; }
@media (max-width: 480px) {
  .langsel > .langsel-form { display: none; }     /* phones: formality toggle lives inside the dropdown */
  .langsel-form-in { display: inline-flex; }
  .langsel-btn { padding: 0 6px; gap: 4px; }
}
