:root {
  --bg: #eef1f5;
  --sidebar: #f4f6f8;
  --card: #ffffff;
  --soft: #f7f9fc;
  --text: #1a2332;
  --muted: #7a8799;
  --line: #e3e8ef;
  --line-strong: #b7c5d8;
  --accent: #1c2430;
  --select: #2f6fed;
  --mint: #c8e6c9;
  --sky: #c5dff8;
  --sand: #f3e4b8;
  --lavender: #ddd6f3;
  --danger: #c62828;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(28, 36, 48, 0.04), 0 8px 24px rgba(28, 36, 48, 0.06);
  --font: "DM Sans", "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
}

* { box-sizing: border-box; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track, ::-webkit-scrollbar-corner { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 10px;
  border: 3px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background-color: var(--muted); }
::-webkit-scrollbar-button { display: none; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

a { color: var(--select); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--mono); font-size: 0.85em; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
strong { font-weight: 600; }
.status { min-height: 1.2em; margin: 0.5rem 0 0; font-size: 0.88rem; }
.status.error { color: var(--danger); }
.hint { font-size: 0.8rem; margin: 0.35rem 0 0.5rem; }
.callout { margin: 0; font-size: 0.88rem; }

button, input, select, textarea { font: inherit; color: var(--text); }

button, a.ghost {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
  padding: 0.55rem 0.95rem;
  border-radius: 10px;
  border: 1px solid transparent;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 600;
  text-decoration: none;
}
button.ghost, a.ghost, .ghost-file {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
  font-weight: 500;
}
button.ghost:hover, a.ghost:hover, .ghost-file:hover { background: #fff; border-color: #cfd7e3; text-decoration: none; }
button.danger, .danger { color: var(--danger); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.82rem; }
.btn-block { width: 100%; justify-content: center; }
.icon { width: 34px; justify-content: center; padding: 0.35rem 0; }
.ghost-file { display: inline-flex; align-items: center; border-radius: 10px; cursor: pointer; margin: 0; }
.ghost-file input { display: none; }

input, select, textarea {
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(47, 111, 237, 0.25); border-color: var(--select); }
input:not([type="file"]):invalid:not(:placeholder-shown) { border-color: var(--danger); }
textarea { resize: vertical; min-height: 72px; }
label { display: block; margin: 0.55rem 0; color: var(--muted); font-size: 0.86rem; font-weight: 500; }

.pill {
  display: inline-block;
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  background: #eef2f7;
  color: #4a5568;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}
.id-chip {
  font-weight: 500;
  font-size: 0.75rem;
  background: #eef5ff;
  color: #2a55b8;
  padding: 0.05rem 0.4rem;
  border-radius: 6px;
  margin-left: 0.35rem;
}

/* —— Shell —— */
.app-shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }

.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  padding: 1.1rem 0.9rem;
}
.brand { display: flex; align-items: center; gap: 0.7rem; padding: 0.35rem 0.55rem 1.1rem; }
.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--mint), var(--sky));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.5);
}
.brand strong { display: block; font-size: 0.95rem; }
.brand span { display: block; font-size: 0.75rem; color: var(--muted); }

.nav-label {
  margin: 0.85rem 0.55rem 0.35rem;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}
.side-nav { display: flex; flex-direction: column; gap: 0.2rem; flex: 1; }
.side-nav button, .side-nav .nav-link {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: #4a5568;
  font-weight: 500;
  padding: 0.65rem 0.75rem;
  border-radius: 999px;
  text-decoration: none;
}
.side-nav button:hover, .side-nav .nav-link:hover { background: rgba(255, 255, 255, 0.65); }
.side-nav button.active, .side-nav .nav-link.active { background: #fff; color: var(--text); box-shadow: var(--shadow); }
.nav-ico { width: 1.25rem; text-align: center; opacity: 0.75; font-size: 0.85rem; }

.sidebar-footer {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.admin-chip { display: flex; align-items: center; gap: 0.65rem; padding: 0.45rem 0.35rem; }
.admin-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--lavender), var(--sky));
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.85rem;
}
.admin-chip strong { display: block; font-size: 0.88rem; }
.admin-chip span { display: block; font-size: 0.72rem; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.workspace { display: flex; flex-direction: column; min-width: 0; }
.page-header { padding: 1.35rem 1.75rem 0.5rem; }
.page-header h1 { margin: 0; font-size: 1.55rem; font-weight: 700; letter-spacing: -0.02em; }
.page-header .muted { margin: 0.2rem 0 0; font-size: 0.9rem; }
.page-back { margin: 0 0 0.35rem !important; font-size: 0.85rem; }
.page-back a { color: var(--muted); }

main { padding: 0.85rem 1.75rem 2rem; display: flex; flex-direction: column; gap: 1rem; }
.tab-panel { display: none; }
.tab-panel.active { display: flex; flex-direction: column; gap: 1rem; }

.tabbar {
  display: inline-flex;
  align-self: flex-start;
  gap: 0.25rem;
  background: #e4e9f0;
  border-radius: 999px;
  padding: 0.25rem;
}
.tabbar button {
  background: transparent;
  border: none;
  color: #4a5568;
  font-weight: 500;
  border-radius: 999px;
  padding: 0.5rem 1.1rem;
}
.tabbar button.active { background: #fff; color: var(--text); box-shadow: var(--shadow); }

/* —— Cards / forms —— */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid rgba(227, 232, 239, 0.9);
  padding: 1.1rem 1.25rem 1.25rem;
}
.card-head { display: flex; align-items: flex-start; gap: 0.75rem; margin-bottom: 0.5rem; }
.card-head h2 { margin: 0; font-size: 1rem; font-weight: 650; }
.card-head .muted { margin: 0.15rem 0 0; font-size: 0.82rem; }
.card-ico {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 0.85rem;
  font-weight: 700;
  flex-shrink: 0;
}
.accent-mint { background: var(--mint); }
.accent-sky { background: var(--sky); }
.accent-sand { background: var(--sand); }

.grid-form { display: grid; grid-template-columns: 1fr 1fr; gap: 0.1rem 1rem; align-items: end; }
.grid-form .full { grid-column: 1 / -1; }
.grid-form > button { margin: 0.55rem 0; justify-self: start; }
.row-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; margin-top: 0.75rem; }

.preview-box {
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
  font-family: var(--mono);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 360px;
  overflow: auto;
}
details summary { cursor: pointer; font-weight: 600; font-size: 0.9rem; }

/* —— Home —— */
.home-hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
  background:
    radial-gradient(ellipse at 0% 0%, rgba(197, 223, 248, 0.55), transparent 55%),
    radial-gradient(ellipse at 100% 0%, rgba(200, 230, 201, 0.4), transparent 50%),
    var(--card);
}
.home-kicker { margin: 0 0 0.35rem; font-size: 0.75rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.home-hero h2 { margin: 0; font-size: 1.45rem; letter-spacing: -0.02em; }
.home-hero .muted { margin: 0.35rem 0 0; }
.home-hero-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.home-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.85rem; }
.home-stat { display: block; text-align: left; color: var(--text); border: 1px solid var(--line); }
.home-stat:hover { border-color: var(--line-strong); }
.home-stat-label { display: block; font-size: 0.78rem; font-weight: 600; color: var(--muted); margin-bottom: 0.35rem; }
.home-stat strong { display: block; font-size: 1.75rem; letter-spacing: -0.03em; line-height: 1.1; margin-bottom: 0.25rem; }
.home-stat .muted { font-size: 0.8rem; font-weight: 400; }

.home-list, .users-list, .avatar-list { display: flex; flex-direction: column; gap: 0.4rem; }
.home-list-item, .avatar-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  text-align: left;
  background: var(--soft);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  color: var(--text);
  font-weight: 500;
}
.home-list-item:hover, .avatar-row:hover { border-color: var(--line); background: #fff; }
.avatar-row { background: #fff; border-color: var(--line); padding: 0.8rem 0.9rem; }
.avatar-row:hover { border-color: var(--line-strong); box-shadow: var(--shadow); }
.home-list-avatar, .avatar-thumb {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: #e8f1fb;
  color: #3a5a7a;
  font-weight: 650;
  flex-shrink: 0;
  overflow: hidden;
}
.avatar-thumb { width: 48px; height: 48px; border-radius: 12px; }
.avatar-thumb img { width: 100%; height: 100%; object-fit: cover; }
.home-list-text { display: flex; flex-direction: column; gap: 0.1rem; min-width: 0; flex: 1; }
.home-list-text strong { font-size: 0.93rem; }
.home-list-text .muted { font-size: 0.8rem; font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.users-list-card { padding: 0.65rem !important; }

/* —— Templates —— */
.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0.75rem; margin-top: 0.75rem; }
.template-grid .empty-hint { grid-column: 1 / -1; margin: 0; }
.template-card {
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.template-preview img { width: 100%; height: 150px; object-fit: cover; border-radius: 8px; background: #e8edf3; display: block; }
.preview-empty {
  height: 150px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  font-size: 0.85rem;
}
.template-actions { display: flex; flex-wrap: wrap; gap: 0.35rem; }

/* —— Media —— */
.add-media-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.add-media-grid form { display: flex; flex-direction: column; }
.add-media-grid form button { align-self: flex-start; margin-top: 0.35rem; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 0.75rem; }
.media-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem;
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 0.35rem 0.75rem;
  align-content: start;
}
.media-thumb img, .media-icon {
  width: 72px;
  height: 72px;
  border-radius: 10px;
  object-fit: cover;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.8rem;
  background: #e8edf3;
  color: #4a5568;
}
.media-icon.kind-pdf { background: #fde2e1; color: #b3261e; }
.media-icon.kind-text { background: #e3f0e4; color: #2e6b34; }
.media-icon.kind-video_link { background: #ebe5f8; color: #5b3fa6; font-size: 1.4rem; }
.media-body { min-width: 0; display: flex; flex-direction: column; gap: 0.15rem; }
.media-body .muted { font-size: 0.78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-preview { margin: 0.25rem 0 0; font-size: 0.78rem; color: #4a5568; max-height: 3.6em; overflow: hidden; }
.media-actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 0.35rem; }
.media-text-edit { grid-column: 1 / -1; }
.media-text-edit textarea { font-size: 0.85rem; }
.media-icon.kind-video { background: #ebe5f8; color: #5b3fa6; font-size: 1.4rem; }
.media-icon.kind-model { background: #e0eefc; color: #1f5fa8; font-size: 1.1rem; font-weight: 700; }

/* 3D setup: preview + rotation / spin / animation controls, description, then the screen layout. */
.model-edit { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 0.6rem; width: 100%; max-width: 760px; }
.model-edit h4 { margin: 0.4rem 0 0; font-size: 0.9rem; }
.model-edit > label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.85rem; }
.model-setup { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(200px, 1fr); gap: 1rem; align-items: start; }
@media (max-width: 760px) { .model-setup { grid-template-columns: 1fr; } }
.model-preview { aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: radial-gradient(circle at 50% 40%, #2a3140, #0b0d12); }
.model-preview model-viewer, .layout-media.is-model model-viewer { width: 100%; height: 100%; --poster-color: transparent; }
.layout-media.is-model { background: transparent; box-shadow: none; }
.layout-media.is-model model-viewer { pointer-events: none; }
.model-controls { display: flex; flex-direction: column; gap: 0.55rem; font-size: 0.85rem; }
.model-controls label { display: flex; flex-direction: column; gap: 0.2rem; }
.model-controls label.check { flex-direction: row; align-items: center; justify-content: flex-start; gap: 0.4rem; }
.model-controls label.check input { width: auto; margin: 0; }
.model-controls input[type="range"] { width: 100%; }
.model-controls .val { color: var(--muted, #6b7280); font-variant-numeric: tabular-nums; }
.knowledge-thumb .media-icon.kind-model { font-size: 0.75rem; }

/* Screen layout editor: same fit maths as the Unreal HUD (WebHud/index.html layoutMedia). */
.media-card.editing-layout { grid-column: 1 / -1; }
.layout-edit { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 0.5rem; width: 100%; max-width: 760px; }
.layout-screen {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  overflow: hidden;
  background: #0b0d12 center / cover no-repeat;
  user-select: none;
  touch-action: none;
}
.layout-screen::after {
  content: "chat";
  position: absolute;
  right: 2%;
  bottom: 3%;
  width: 26%;
  height: 30%;
  border-radius: 6px;
  background: rgba(30, 34, 44, 0.75);
  color: rgba(255, 255, 255, 0.4);
  font-size: 0.7rem;
  display: grid;
  place-items: center;
  pointer-events: none;
}
.layout-media {
  position: absolute;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  outline: 2px solid var(--select);
  cursor: grab;
  background: #1d1a2b;
  color: #cfc4f5;
  display: grid;
  place-items: center;
  font-size: 0.75rem;
  z-index: 1;
}
.layout-media:active { cursor: grabbing; }
.layout-media img, .layout-media video { width: 100%; height: 100%; display: block; pointer-events: none; }
.hud-edit { display: grid; grid-template-columns: minmax(0, 2fr) minmax(200px, 1fr); gap: 1rem; align-items: start; }
@media (max-width: 900px) { .hud-edit { grid-template-columns: 1fr; } }
.layout-screen.hud-screen::after { display: none; }
.hud-controls { display: flex; flex-direction: column; gap: 0.55rem; font-size: 0.85rem; }
.hud-controls label { display: flex; flex-direction: column; gap: 0.2rem; }
.hud-controls input[type="range"] { width: 100%; }
.hud-chat {
  position: absolute;
  display: flex;
  flex-direction: column;
  border-radius: 7px;
  overflow: hidden;
  background: rgba(14, 16, 22, var(--hud-opacity, 0.92));
  border: 1px solid rgba(255, 255, 255, 0.12);
  outline: 2px solid var(--select);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  color: #e8eaf0;
  font-size: calc(0.5rem * var(--hud-text, 1));
  cursor: grab;
  z-index: 1;
}
.hud-chat:active { cursor: grabbing; }
.hud-chat-head { display: flex; align-items: center; gap: 0.35em; padding: 0.5em 0.8em; background: rgba(255, 255, 255, 0.05); font-weight: 600; }
.hud-chat-head .dot { width: 0.6em; height: 0.6em; border-radius: 50%; background: #37d0a0; }
.hud-chat-body { flex: 1; display: flex; flex-direction: column; gap: 0.4em; padding: 0.6em 0.8em; overflow: hidden; }
.hud-bubble { align-self: flex-start; max-width: 85%; padding: 0.35em 0.6em; border-radius: 0.6em; background: rgba(255, 255, 255, 0.07); }
.hud-bubble.user { align-self: flex-end; background: rgba(79, 140, 255, 0.2); }
.hud-chat-input { margin: 0.5em; padding: 0.4em 0.6em; border-radius: 0.5em; border: 1px solid rgba(255, 255, 255, 0.12); color: #9aa0ae; }
.layout-controls { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; font-size: 0.82rem; }
.layout-controls input[type="range"] { flex: 1; min-width: 120px; }

/* On / off switch */
.switch { position: relative; display: inline-flex; align-items: center; gap: 0.45rem; cursor: pointer; font-size: 0.8rem; color: var(--muted); flex-shrink: 0; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track { width: 36px; height: 20px; border-radius: 999px; background: #cfd6e0; position: relative; transition: background 0.15s; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,0.25); transition: transform 0.15s; }
.switch input:checked + .track { background: #2e9d5b; }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch .switch-text { min-width: 2.6rem; }
.switch input:focus-visible + .track { outline: 2px solid var(--select); outline-offset: 2px; }
.avatar-row-wrap { display: flex; align-items: center; gap: 0.75rem; }
.avatar-row-wrap .avatar-row { flex: 1; min-width: 0; }
.avatar-row.off { opacity: 0.55; }

/* —— Avatar editor —— */
.editor-bar { display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem 1rem; position: sticky; top: 0.5rem; z-index: 5; }
.editor-title { flex: 1; min-width: 0; }
.editor-title h2 { margin: 0; font-size: 1.1rem; }
.editor-title .muted { font-size: 0.82rem; }
.editor-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.span-2 { grid-column: 1 / -1; }
.section-h { margin: 0 0 0.35rem; font-size: 1rem; }

.picker { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.pick-card {
  width: 118px;
  flex-direction: column;
  align-items: stretch;
  padding: 0.35rem;
  background: var(--soft);
  border: 2px solid var(--line);
  color: var(--text);
  font-weight: 500;
  gap: 0.3rem;
}
.pick-card:hover { border-color: var(--line-strong); }
.pick-card.selected { border-color: var(--select); background: #eef5ff; }
.pick-photo {
  height: 76px;
  border-radius: 8px;
  background: #e8edf3;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.75rem;
  overflow: hidden;
}
.pick-card.none .pick-photo { font-size: 1.5rem; }
.pick-photo img { width: 100%; height: 100%; object-fit: cover; }
.pick-name { font-size: 0.8rem; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.list-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 0.75rem; margin: 1rem 0 0.45rem; }
.list-head h4 { margin: 0; font-size: 0.92rem; }
.list-head .muted { margin: 0.1rem 0 0; font-size: 0.8rem; }
.row-list { display: flex; flex-direction: column; gap: 0.4rem; counter-reset: rule; }
.edit-row { display: grid; gap: 0.4rem; align-items: center; }
.edit-row input { margin: 0; }
.rule-row { grid-template-columns: 1.6rem 1fr auto auto; }
.rule-row .drag-num::before { counter-increment: rule; content: counter(rule) "."; color: var(--muted); font-size: 0.85rem; }
.pron-row { grid-template-columns: 1fr 1fr auto; }

.provider-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.85rem; }
@media (max-width: 1400px) {
  .provider-grid { grid-template-columns: repeat(2, 1fr); }
}
.provider { border: 1px solid var(--line); border-radius: 10px; padding: 0.35rem 0.85rem 0.6rem; margin: 0; min-width: 0; }
.provider legend { font-weight: 650; font-size: 0.88rem; padding: 0 0.35rem; }

.knowledge-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 0.45rem; margin: 0.5rem 0; }
.knowledge-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--soft);
  color: var(--text);
  cursor: pointer;
}
.knowledge-item:has(input:checked) { border-color: var(--select); background: #eef5ff; }
.knowledge-item input { width: auto; margin: 0; }
.knowledge-thumb img, .knowledge-thumb .media-icon { width: 40px; height: 40px; border-radius: 8px; font-size: 0.65rem; }
.knowledge-thumb .media-icon.kind-video_link { font-size: 1rem; }
.knowledge-text { display: flex; flex-direction: column; min-width: 0; }
.knowledge-text strong { font-size: 0.86rem; }
.knowledge-text .muted { font-size: 0.74rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-link { font-size: 0.85rem; white-space: nowrap; }

/* —— Login —— */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background:
    radial-gradient(ellipse at 20% 10%, rgba(200, 230, 201, 0.55), transparent 45%),
    radial-gradient(ellipse at 80% 0%, rgba(197, 223, 248, 0.5), transparent 40%),
    var(--bg);
}
.login-card { width: min(420px, 100%); background: var(--card); border-radius: 16px; padding: 1.75rem; box-shadow: var(--shadow); border: 1px solid var(--line); }
.login-card h1 { margin: 0 0 0.35rem; font-size: 1.45rem; letter-spacing: -0.02em; }
.login-card .muted { margin: 0 0 1rem; }
.login-card button { width: 100%; justify-content: center; margin-top: 0.75rem; }

/* ---- Data tab + Analytics overview ---- */
.inline-input { display: flex; align-items: center; gap: 0.5rem; color: var(--text); margin-top: 0.35rem; }
.inline-input input { width: 7rem; margin: 0; }
.data-filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.5rem 1rem; padding: 0.75rem 1rem; }
.data-filters label { margin: 0; }
.data-filters select { min-width: 220px; }
#an-status:empty, #ov-status:empty { display: none; }
.data-range-label { margin-left: auto; font-size: 0.85rem; align-self: center; }
.segmented { display: inline-flex; background: var(--soft); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; }
.segmented button { background: transparent; border: none; padding: 0.35rem 0.75rem; border-radius: 8px; font-size: 0.85rem; color: var(--muted); box-shadow: none; }
.segmented button:hover { color: var(--text); }
.segmented button.active { background: #fff; color: var(--text); box-shadow: var(--shadow); }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 0.85rem; }
.kpi { display: flex; flex-direction: column; gap: 0.2rem; }
.kpi-label { font-size: 0.78rem; font-weight: 600; color: var(--muted); }
.kpi strong { font-size: 1.6rem; letter-spacing: -0.03em; line-height: 1.15; }
.kpi .muted { font-size: 0.78rem; }
.data-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.data-grid > .card { min-width: 0; }
.chart-box { position: relative; height: 240px; }
.chart-box.short { height: 190px; }
.chart-box.donut { height: 180px; width: 180px; flex-shrink: 0; }
.list-head.first { margin-top: 0; }
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.data-table th { text-align: left; font-weight: 600; font-size: 0.78rem; color: var(--muted); padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
.data-table td { padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.data-table tr:last-child td { border-bottom: none; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.data-table tr.clickable { cursor: pointer; }
.data-table tr.clickable:hover td, .data-table tr.clickable:focus td { background: var(--soft); }
.data-table td.clip { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
button.link { background: none; border: none; padding: 0; color: var(--select); font-weight: 500; box-shadow: none; text-align: left; cursor: pointer; }
button.link:hover { text-decoration: underline; background: none; }
.tag { display: inline-block; padding: 0.05rem 0.45rem; border-radius: 999px; background: var(--soft); border: 1px solid var(--line); font-size: 0.72rem; color: var(--muted); font-weight: 500; }
.tag.bad { color: var(--danger); border-color: #f3c7c7; background: #fdf0f0; }
.rank-list { list-style: none; margin: 0.25rem 0 0; padding: 0; counter-reset: rank; display: flex; flex-direction: column; }
.rank-list > li { display: flex; align-items: flex-start; gap: 0.6rem; padding: 0.5rem 0; border-bottom: 1px solid var(--line); counter-increment: rank; }
.rank-list > li:last-child { border-bottom: none; }
.rank-list > li::before { content: counter(rank); min-width: 1.4rem; color: var(--muted); font-size: 0.8rem; padding-top: 0.1rem; }
.rank-list > li.empty::before { content: none; }
.rank-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.15rem; }
.rank-text { font-size: 0.88rem; overflow-wrap: anywhere; }
.rank-sub { font-size: 0.76rem; }
.rank-count { font-weight: 650; font-variant-numeric: tabular-nums; font-size: 0.9rem; }
.wordings summary { font-size: 0.76rem; font-weight: 500; color: var(--muted); }
.wordings ul { margin: 0.25rem 0 0; padding-left: 1.1rem; font-size: 0.8rem; color: #4a5568; }
.chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.chip { display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.2rem 0.6rem; border-radius: 999px; background: var(--soft); border: 1px solid var(--line); font-size: 0.8rem; }
.chip-x { background: none; border: none; padding: 0 0.1rem; font-size: 1rem; line-height: 1; color: var(--muted); box-shadow: none; }
.split-row { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; }
.stat-list { display: grid; grid-template-columns: auto auto; gap: 0.35rem 1rem; margin: 0; font-size: 0.86rem; flex: 1; }
.stat-list dt { color: var(--muted); }
.stat-list dd { margin: 0; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.conv-search { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.conv-search input { flex: 1; min-width: 220px; margin: 0; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; margin-top: 0.6rem; font-size: 0.85rem; }
.row-actions.tight { margin-top: 0; }
.conv-head h3 { margin: 0.25rem 0 0; font-size: 1.05rem; }
.conv-head p { margin: 0.2rem 0 0.75rem; font-size: 0.85rem; }
.timeline { display: flex; flex-direction: column; gap: 0.6rem; max-width: 860px; }
.tl-turn { display: flex; flex-direction: column; gap: 0.3rem; }
.tl-row { display: flex; align-items: flex-start; gap: 0.6rem; }
.tl-row.avatar { padding-left: 4.6rem; }
.tl-time { width: 4rem; flex-shrink: 0; font-size: 0.74rem; color: var(--muted); font-variant-numeric: tabular-nums; padding-top: 0.45rem; }
.bubble { padding: 0.5rem 0.75rem; border-radius: 12px; font-size: 0.9rem; white-space: pre-wrap; overflow-wrap: anywhere; max-width: 100%; }
.bubble.visitor { background: #eef5ff; border: 1px solid #d6e4fb; }
.bubble.avatar { background: var(--soft); border: 1px solid var(--line); }
.tl-error { display: block; color: var(--danger); font-size: 0.8rem; margin-top: 0.25rem; }
.tl-meta { padding-left: 4.6rem; font-size: 0.74rem; }
.tl-marker { display: flex; align-items: baseline; gap: 0.6rem; font-size: 0.85rem; }
.tl-marker .tl-time { padding-top: 0; }
.tl-ico { width: 1.2rem; text-align: center; color: var(--muted); }
.tl-marker.bad .tl-ico { color: var(--danger); }
.retention-form { display: flex; align-items: flex-end; gap: 0.75rem; flex-wrap: wrap; }
.retention-form label { margin: 0; }
.retention-form button { margin-bottom: 0.1rem; }

@media (max-width: 1000px) {
  .provider-grid { grid-template-columns: 1fr; }
  .editor-grid { grid-template-columns: 1fr; }
  .data-grid { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--line); }
  .side-nav { flex-direction: row; flex-wrap: wrap; }
  .side-nav button, .side-nav .nav-link { width: auto; }
  .nav-label { width: 100%; }
  .sidebar-footer { border-top: none; padding-top: 0.5rem; }
  .grid-form, .add-media-grid { grid-template-columns: 1fr; }
  .home-stats { grid-template-columns: 1fr 1fr; }
}
