:root {
  color-scheme: dark;
  --bg-main: #0e1621;
  --bg-gradient: radial-gradient(circle at top left, rgba(52, 99, 159, 0.4), transparent 34%),
    radial-gradient(circle at bottom right, rgba(15, 88, 73, 0.35), transparent 30%),
    linear-gradient(180deg, #0e1621 0%, #101923 56%, #0b131d 100%);
  --bg-image: none;
  --surface: rgba(24, 37, 51, 0.92);
  --surface-strong: #17212b;
  --surface-soft: rgba(34, 51, 70, 0.9);
  --surface-ghost: rgba(255, 255, 255, 0.06);
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #f5f7fb;
  --text-soft: #adc2d8;
  --text-muted: #7490ab;
  --accent: #56a8f5;
  --accent-strong: #2c9cf0;
  --accent-soft: rgba(86, 168, 245, 0.18);
  --success: #4cc38a;
  --danger: #f26d74;
  --warning: #f8c15d;
  --bubble-in: #182533;
  --bubble-out: #2b5278;
  --shadow: 0 18px 48px rgba(1, 6, 15, 0.38);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --chat-shell-width: 72rem;
  --chat-message-width: 68rem;
  --chat-media-width: 22rem;
  --font-main: "SF Pro Display", "Segoe UI Variable", "Segoe UI", sans-serif;
  --star-color: rgba(255, 255, 255, 0.8);
  --star-glow: rgba(120, 189, 255, 0.35);
  --bg-orb-a: rgba(86, 168, 245, 0.2);
  --bg-orb-b: rgba(38, 197, 151, 0.14);
  --glass-bg: linear-gradient(180deg, rgba(30, 45, 60, 0.78), rgba(18, 28, 40, 0.72));
  --panel-bg: rgba(16, 27, 38, 0.82);
  --panel-bg-strong: rgba(20, 31, 43, 0.94);
  --control-bg: rgba(255, 255, 255, 0.06);
  --control-bg-hover: rgba(255, 255, 255, 0.1);
  --selected-bg: rgba(86, 168, 245, 0.15);
  --selected-border: rgba(86, 168, 245, 0.3);
  --banner-bg: rgba(248, 193, 93, 0.14);
  --banner-text: #ffe6ae;
  --bubble-out-bg: linear-gradient(180deg, rgba(43, 82, 120, 0.95), rgba(34, 73, 110, 0.95));
  --toggle-track: rgba(255, 255, 255, 0.1);
  --toggle-thumb: linear-gradient(180deg, #ffffff, #d9e7ff);
  --toggle-shadow: 0 10px 26px rgba(3, 15, 31, 0.35);
}

/* Light theme */
:root.light-theme {
  color-scheme: light;
  --bg-main: #f0f4f8;
  --bg-gradient: radial-gradient(circle at top left, rgba(52, 99, 159, 0.15), transparent 34%),
    radial-gradient(circle at bottom right, rgba(15, 88, 73, 0.12), transparent 30%),
    linear-gradient(180deg, #f0f4f8 0%, #e8eef4 56%, #dbe4ed 100%);
  --surface: rgba(255, 255, 255, 0.92);
  --surface-strong: #ffffff;
  --surface-soft: rgba(245, 248, 250, 0.95);
  --surface-ghost: rgba(0, 0, 0, 0.04);
  --line: rgba(0, 0, 0, 0.08);
  --line-strong: rgba(0, 0, 0, 0.16);
  --text: #1a2027;
  --text-soft: #4a5568;
  --text-muted: #718096;
  --accent: #3182ce;
  --accent-strong: #2c5282;
  --accent-soft: rgba(49, 130, 206, 0.12);
  --success: #38a169;
  --danger: #e53e3e;
  --warning: #d69e2e;
  --bubble-in: #edf2f7;
  --bubble-out: #bee3f8;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.12);
  --star-color: rgba(59, 130, 246, 0.6);
  --star-glow: rgba(59, 130, 246, 0.22);
  --bg-orb-a: rgba(72, 149, 239, 0.14);
  --bg-orb-b: rgba(33, 182, 128, 0.12);
  --glass-bg: linear-gradient(180deg, rgba(255, 255, 255, 0.82), rgba(244, 248, 252, 0.76));
  --panel-bg: rgba(255, 255, 255, 0.76);
  --panel-bg-strong: rgba(255, 255, 255, 0.92);
  --control-bg: rgba(15, 23, 42, 0.04);
  --control-bg-hover: rgba(15, 23, 42, 0.08);
  --selected-bg: rgba(49, 130, 206, 0.12);
  --selected-border: rgba(49, 130, 206, 0.22);
  --banner-bg: rgba(214, 158, 46, 0.14);
  --banner-text: #885b14;
  --bubble-out-bg: linear-gradient(180deg, rgba(205, 229, 255, 0.95), rgba(183, 216, 251, 0.95));
  --toggle-track: rgba(15, 23, 42, 0.08);
  --toggle-thumb: linear-gradient(180deg, #ffffff, #f8fbff);
  --toggle-shadow: 0 10px 22px rgba(67, 99, 141, 0.18);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  min-height: 100%;
  font-family: var(--font-main);
  background: var(--bg-main);
  color: var(--text);
}

#app {
  position: relative;
  z-index: 1;
  min-height: 100%;
}

body {
  background-image: var(--bg-gradient);
  position: relative;
  overflow-x: hidden;
}

/* Animated background layers */
body.app-shell-active {
  overflow: hidden;
}

body.app-shell-active #app {
  height: 100dvh;
  overflow: hidden;
}

/* Blurred background image */
.bg-image-layer {
  position: fixed;
  inset: 0;
  background-image: var(--bg-image);
  background-size: cover;
  background-position: center;
  filter: blur(20px) brightness(0.6);
  opacity: var(--bg-image-opacity, 0);
  z-index: 0;
  pointer-events: none;
  transition: opacity 500ms ease;
}

:root:not([style*="--bg-image"]) .bg-image-layer,
:root[style*="--bg-image: none"] .bg-image-layer {
  opacity: 0;
}

/* Floating circles */
.bg-circles {
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: 0;
  pointer-events: none;
}

.bg-circle {
  position: absolute;
  border-radius: 50%;
  background:
    radial-gradient(circle, var(--bg-orb-a) 0%, transparent 68%),
    radial-gradient(circle at 65% 65%, var(--bg-orb-b) 0%, transparent 72%);
  animation: float 20s infinite ease-in-out;
  filter: blur(12px);
}

.bg-circle:nth-child(1) {
  width: 180px;
  height: 180px;
  left: 10%;
  top: 20%;
  animation-delay: 0s;
  animation-duration: 25s;
}

.bg-circle:nth-child(2) {
  width: 240px;
  height: 240px;
  left: 70%;
  top: 60%;
  animation-delay: -5s;
  animation-duration: 30s;
}

.bg-circle:nth-child(3) {
  width: 150px;
  height: 150px;
  left: 50%;
  top: 80%;
  animation-delay: -10s;
  animation-duration: 28s;
}

.bg-circle:nth-child(4) {
  width: 200px;
  height: 200px;
  left: 30%;
  top: 40%;
  animation-delay: -15s;
  animation-duration: 32s;
}

.bg-circle:nth-child(5) {
  width: 160px;
  height: 160px;
  left: 80%;
  top: 10%;
  animation-delay: -8s;
  animation-duration: 26s;
}

@keyframes float {
  0%, 100% {
    transform: translate(0, 0) scale(1);
  }
  25% {
    transform: translate(20px, -30px) scale(1.05);
  }
  50% {
    transform: translate(-15px, 20px) scale(0.95);
  }
  75% {
    transform: translate(25px, 15px) scale(1.02);
  }
}

/* Starfall effect */
.bg-starfall {
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: 0;
  pointer-events: none;
}

.star {
  position: absolute;
  background: var(--star-color);
  border-radius: 50%;
  animation: fall linear infinite;
  box-shadow: 0 0 14px var(--star-glow);
}

@keyframes fall {
  0% {
    transform: translateY(-10vh) translateX(0);
    opacity: 0;
  }
  10% {
    opacity: 1;
  }
  90% {
    opacity: 1;
  }
  100% {
    transform: translateY(120vh) translateX(var(--star-drift, 20px));
    opacity: 0;
  }
}

.theme-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 12;
  overflow: hidden;
  width: 4.8rem;
  height: 2.9rem;
  border-radius: 999px;
  background: var(--glass-bg);
  border: 1px solid var(--line);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.35rem 0.5rem;
  cursor: pointer;
  transition: transform 180ms ease, background 180ms ease, border-color 180ms ease;
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px) saturate(150%);
}

.theme-toggle:hover {
  transform: translateY(-1px);
}

.theme-toggle:active {
  transform: translateY(0);
}

.theme-toggle-track {
  position: absolute;
  inset: 0.3rem;
  border-radius: inherit;
  background: var(--toggle-track);
}

.theme-toggle-thumb {
  position: absolute;
  top: 0.22rem;
  left: 0.22rem;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--toggle-thumb);
  box-shadow: var(--toggle-shadow);
  transition: transform 220ms ease;
}

.theme-toggle[data-theme="light"] .theme-toggle-thumb {
  transform: translateX(1.9rem);
}

.theme-toggle-icons {
  position: relative;
  z-index: 1;
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-inline: 0.12rem;
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

body.app-shell-active .theme-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  box-shadow: var(--shadow);
  width: 4.8rem;
  flex-shrink: 0;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
}

.hidden {
  display: none !important;
}

.glass {
  background: var(--glass-bg);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px) saturate(145%);
}

.eyebrow {
  margin: 0 0 0.25rem;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.stack {
  display: grid;
  gap: 1rem;
}

.field {
  display: grid;
  gap: 0.55rem;
}

.field span {
  color: var(--text-soft);
  font-size: 0.92rem;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--control-bg);
  color: var(--text);
  padding: 0.95rem 1rem;
  outline: none;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: rgba(86, 168, 245, 0.7);
  box-shadow: 0 0 0 3px rgba(86, 168, 245, 0.12);
}

.primary-button,
.ghost-button,
.icon-button,
.card-action,
.pill-button {
  border: 0;
  border-radius: 999px;
  transition: transform 180ms ease, background-color 180ms ease, opacity 180ms ease;
}

.primary-button:hover,
.ghost-button:hover,
.icon-button:hover,
.card-action:hover,
.pill-button:hover {
  transform: translateY(-1px);
}

.primary-button:disabled,
.ghost-button:disabled,
.icon-button:disabled,
.card-action:disabled,
.pill-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.primary-button {
  padding: 0.95rem 1.4rem;
  background: linear-gradient(135deg, var(--accent), #3c8fe1);
  color: #071421;
  font-weight: 700;
}

.ghost-button {
  padding: 0.78rem 1rem;
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
}

.ghost-button.compact {
  padding: 0.55rem 0.85rem;
  font-size: 0.86rem;
}

.ghost-button.danger {
  color: #ffd3d6;
  background: rgba(242, 109, 116, 0.16);
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 2.9rem;
  height: 2.9rem;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
}

.login-card {
  width: min(100%, 31rem);
  padding: 2rem;
  border-radius: var(--radius-xl);
}

.brand-badge {
  width: 4.2rem;
  height: 4.2rem;
  display: grid;
  place-items: center;
  border-radius: 1.3rem;
  background: linear-gradient(135deg, rgba(86, 168, 245, 0.95), rgba(32, 90, 177, 0.92));
  color: #08131e;
  font-weight: 800;
  font-size: 1.4rem;
  box-shadow: 0 18px 30px rgba(44, 156, 240, 0.25);
}

.login-card h1 {
  margin: 0.4rem 0 0.85rem;
  font-size: clamp(2rem, 5vw, 2.8rem);
  line-height: 1;
}

.login-copy {
  margin: 0 0 1.5rem;
  color: var(--text-soft);
  line-height: 1.55;
}

.tip-card {
  margin-top: 1.4rem;
  padding: 1rem 1.15rem;
  border-radius: var(--radius-md);
  background: rgba(86, 168, 245, 0.11);
  border: 1px solid rgba(86, 168, 245, 0.16);
}

.tip-card h2 {
  margin: 0 0 0.4rem;
  font-size: 1rem;
}

.tip-card p {
  margin: 0;
  color: var(--text-soft);
  line-height: 1.5;
}

.shell {
  height: 100dvh;
  max-height: 100dvh;
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(18rem, 24rem) 1fr;
  grid-template-rows: minmax(0, 1fr);
  gap: 1rem;
  padding: 1rem;
  overflow: hidden;
}

.sidebar {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
  border-radius: var(--radius-xl);
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.sidebar-backdrop {
  display: none;
  border: 0;
  padding: 0;
}

.shell.admin-shell .sidebar {
  grid-template-rows: auto auto minmax(9rem, 0.72fr) minmax(12rem, 1fr) auto;
  gap: 0.85rem;
}

.sidebar-head,
.section-head,
.screen-head,
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.sidebar-head h2,
.screen-head h2 {
  margin: 0;
  font-size: 1.3rem;
}

.mobile-only {
  display: none;
}

.profile-card {
  padding: 1rem 1.1rem;
  border-radius: var(--radius-lg);
  background: var(--control-bg);
  border: 1px solid var(--line);
}

.shell.admin-shell .profile-card {
  padding: 0.85rem 0.95rem;
}

.profile-card h3 {
  margin: 0;
  font-size: 1.06rem;
}

.profile-card p {
  margin: 0.35rem 0 0;
  color: var(--text-soft);
}

.profile-chip-row,
.quick-actions,
.admin-nav,
.sidebar-footer,
.message-actions,
.card-actions,
.detail-tags,
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.profile-chip,
.pill-button,
.tag {
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  background: var(--control-bg-hover);
  color: var(--text-soft);
  font-size: 0.84rem;
}

.pill-button {
  background: var(--selected-bg);
  color: var(--text);
}

.sidebar-section {
  display: grid;
  gap: 0.75rem;
  min-height: 0;
}

.chat-list,
.admin-nav {
  display: grid;
  gap: 0.55rem;
  min-height: 0;
  overflow: auto;
  padding-right: 0.2rem;
  overscroll-behavior: contain;
}

.chat-item,
.admin-link {
  width: 100%;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: var(--control-bg);
  color: inherit;
  text-align: left;
  padding: 0.9rem 1rem;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

.shell.admin-shell .chat-list,
.shell.admin-shell .admin-nav {
  gap: 0.45rem;
}

.shell.admin-shell .chat-item,
.shell.admin-shell .admin-link {
  padding: 0.78rem 0.88rem;
}

.chat-item.active,
.admin-link.active {
  background: var(--selected-bg);
  border-color: var(--selected-border);
}

.chat-item:hover,
.admin-link:hover {
  transform: translateY(-1px);
  background: var(--control-bg-hover);
}

.chat-title {
  font-weight: 700;
}

.chat-meta,
.small-copy {
  color: var(--text-muted);
  font-size: 0.84rem;
}

.sidebar-footer {
  align-self: end;
}

.main-shell {
  min-width: 0;
  width: min(100%, 76rem);
  min-height: 0;
  height: 100%;
  align-self: stretch;
  justify-self: center;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overflow: hidden;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 0 0 auto;
}

.topbar-copy {
  min-width: 0;
  flex: 1 1 auto;
  display: grid;
  gap: 0.22rem;
  overflow: hidden;
}

.topbar-copy h2,
.topbar-copy p {
  min-width: 0;
}

.topbar-sidebar-toggle,
.topbar-menu-button {
  flex-shrink: 0;
}

.topbar-menu-button {
  font-size: 1.55rem;
  line-height: 1;
  letter-spacing: 0.04em;
}

.topbar-overflow {
  position: relative;
  flex: 0 0 auto;
}

.topbar-menu {
  position: absolute;
  top: calc(100% + 0.55rem);
  right: 0;
  min-width: 12.75rem;
  padding: 0.45rem;
  border-radius: 1rem;
  border: 1px solid var(--line-strong);
  background: linear-gradient(180deg, rgba(17, 28, 40, 0.95), rgba(13, 22, 33, 0.98));
  box-shadow: 0 18px 42px rgba(4, 10, 19, 0.34);
  z-index: 12;
}

:root.light-theme .topbar-menu {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(244, 248, 252, 0.98));
}

.topbar-menu-item {
  width: 100%;
  min-height: 2.95rem;
  display: flex;
  align-items: center;
  padding: 0.78rem 0.9rem;
  border: 0;
  border-radius: 0.8rem;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}

.topbar-menu-item:hover {
  background: var(--control-bg-hover);
  transform: translateY(-1px);
}

.topbar-menu-item.danger {
  color: #ffd7da;
}

.shell.sidebar-dragging .sidebar,
.shell.sidebar-dragging .sidebar-backdrop {
  transition: none;
}

.topbar,
.system-banner,
.composer,
.empty-state,
.panel,
.detail-card,
.chat-gate,
.test-card,
.kb-file,
.stat-card,
.result-card,
.directory-item {
  border-radius: var(--radius-lg);
}

.topbar {
  min-height: 5.2rem;
  padding: 1rem 1.2rem;
}

.topbar h2,
.topbar p {
  margin: 0;
}

.system-banner {
  padding: 0.9rem 1.1rem;
  background: var(--banner-bg);
  border: 1px solid rgba(248, 193, 93, 0.2);
  color: var(--banner-text);
}

.screen {
  flex: 1 1 auto;
  align-self: stretch;
  height: 100%;
  min-height: 0;
  display: grid;
  gap: 1rem;
  overflow: hidden;
  grid-template-columns: minmax(0, 1fr);
}

#chatScreen {
  width: min(100%, var(--chat-shell-width));
  height: 100%;
  margin-inline: auto;
  min-height: 0;
  align-self: stretch;
  grid-template-rows: minmax(0, 1fr) auto auto;
}

#testsScreen,
#adminScreen {
  min-height: 0;
  align-content: start;
  overflow: auto;
  padding-right: 0.15rem;
  overscroll-behavior: contain;
}

#adminScreen {
  width: min(100%, 88rem);
  margin-inline: auto;
}

#adminContent.panel-grid {
  grid-template-columns: minmax(20rem, 26rem) minmax(0, 1fr);
  align-items: start;
}

.admin-sidebar-stack,
.admin-detail-stack {
  min-height: 0;
}

.admin-sidebar-panel .directory-list {
  min-height: 0;
  max-height: min(64dvh, 100%);
  overflow: auto;
}

.admin-panel-head {
  display: grid;
  gap: 0.25rem;
}

.admin-panel-head .eyebrow {
  margin-bottom: 0;
}

.admin-search-field {
  gap: 0.4rem;
}

.messages {
  height: 100%;
  min-height: 0;
  overflow: auto;
  padding: 0.25rem 0.35rem 0.25rem 0;
  display: grid;
  gap: 1rem;
  align-content: start;
  overscroll-behavior: contain;
}

.messages.is-empty {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  justify-content: center;
  padding-right: 0;
  min-height: 0;
}

.messages.is-empty .empty-state {
  width: min(100%, 34rem);
  margin: auto;
}

.message-row {
  display: flex;
}

.message-row.mine {
  justify-content: flex-end;
}

.message-stack {
  max-width: min(var(--chat-message-width), 100%);
  display: grid;
  gap: 0.65rem;
}

.message-meta {
  padding-inline: 0.35rem;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.message-bubble {
  padding: 0.92rem 1rem;
  border-radius: 1.3rem;
  background: var(--bubble-in);
  border: 1px solid var(--line);
  white-space: pre-wrap;
  line-height: 1.5;
}

.message-bubble.pending {
  color: var(--text-soft);
  border-style: dashed;
  opacity: 0.88;
}

.message-row.mine .message-bubble {
  background: var(--bubble-out-bg);
}

.message-bubble .rich-paragraph,
.card-body .rich-paragraph,
.card-details .rich-paragraph {
  margin: 0;
}

.message-bubble .rich-paragraph + .rich-paragraph,
.card-body .rich-paragraph + .rich-paragraph,
.card-details .rich-paragraph + .rich-paragraph,
.message-bubble .rich-list + .rich-paragraph,
.card-body .rich-list + .rich-paragraph,
.card-details .rich-list + .rich-paragraph,
.message-bubble .rich-paragraph + .rich-list,
.card-body .rich-paragraph + .rich-list,
.card-details .rich-paragraph + .rich-list,
.message-bubble .rich-list + .rich-list,
.card-body .rich-list + .rich-list,
.card-details .rich-list + .rich-list {
  margin-top: 0.55rem;
}

.message-bubble .rich-list,
.card-body .rich-list,
.card-details .rich-list {
  margin: 0;
  padding-left: 1.15rem;
}

.message-bubble .rich-list li + li,
.card-body .rich-list li + li,
.card-details .rich-list li + li {
  margin-top: 0.25rem;
}

.message-bubble .rich-code,
.card-body .rich-code,
.card-details .rich-code {
  font-family: "JetBrains Mono", "Consolas", monospace;
  font-size: 0.92em;
  padding: 0.08rem 0.35rem;
  border-radius: 999px;
  background: var(--control-bg-hover);
}

.message-attachment {
  display: grid;
  gap: 0.55rem;
  justify-items: start;
}

.message-row.mine .message-attachment {
  justify-items: end;
}

.message-attachment img,
.card-media img {
  border-radius: var(--radius-md);
}

.message-attachment img {
  display: block;
  width: auto;
  max-width: min(100%, var(--chat-media-width));
  max-height: min(44vh, 22rem);
  object-fit: contain;
  background: var(--control-bg);
}

.card-media img {
  width: 100%;
  object-fit: cover;
}

.message-actions {
  padding-inline: 0.25rem;
}

.card-action {
  padding: 0.68rem 0.92rem;
  background: var(--control-bg-hover);
  color: var(--text);
}

.card-carousel {
  position: relative;
  display: grid;
  gap: 0.6rem;
  /* Увеличиваем ширину контейнера карусели */
  max-width: 100%;
  overflow: hidden;
}

.carousel-track {
  display: grid;
  grid-auto-flow: column;
  /* Увеличиваем ширину карточек чтобы 3 помещались полностью */
  grid-auto-columns: minmax(16rem, 20rem);
  gap: 0.8rem;
  align-items: start;
  overflow-x: auto;
  padding-bottom: 0.25rem;
  padding-left: 0.4rem;
  padding-right: 0.4rem;
  scroll-snap-type: x mandatory;
  scrollbar-width: thin;
  /* Плавная прокрутка */
  scroll-behavior: smooth;
}

.carousel-track::-webkit-scrollbar {
  height: 8px;
}

.carousel-track::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.16);
  border-radius: 999px;
}

.card {
  scroll-snap-align: start;
  display: grid;
  gap: 0.75rem;
  padding: 0.9rem;
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, var(--panel-bg), var(--panel-bg-strong));
  border: 1px solid var(--line);
  /* Карточка должна занимать всю ширину ячейки грида */
  width: 100%;
  min-width: 0;
  align-self: start;
}

.card-media img {
  aspect-ratio: 4 / 3;
  max-height: 13rem;
  /* Изображение должно масштабироваться внутри карточки */
  width: 100%;
  object-fit: cover;
}

.card h4 {
  margin: 0;
  font-size: 1rem;
  /* Текст не должен вылезать за пределы карточки */
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.card.expanded {
  border-color: rgba(86, 168, 245, 0.26);
}

.card-subtitle {
  color: #79c0ff;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.card-body,
.card-details,
.detail-copy,
.panel-copy,
.test-summary,
.result-copy {
  color: var(--text-soft);
  line-height: 1.5;
}

.card-details {
  padding-top: 0.15rem;
  border-top: 1px solid var(--line);
}

.card-actions {
  justify-content: space-between;
  align-items: center;
}

.carousel-controls {
  display: flex;
  justify-content: flex-end;
  gap: 0.55rem;
}

.chat-gate {
  padding: 1rem 1.1rem;
  background: linear-gradient(135deg, rgba(248, 193, 93, 0.16), rgba(242, 109, 116, 0.12));
  border: 1px solid rgba(248, 193, 93, 0.18);
}

.chat-gate h3,
.panel h3,
.detail-card h3,
.test-card h3,
.result-card h3,
.directory-item h3 {
  margin: 0 0 0.45rem;
}

.chat-gate p,
.panel p,
.detail-card p,
.test-card p,
.result-card p,
.directory-item p {
  margin: 0;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 0.9rem;
  padding: 0.75rem;
}

.composer-field {
  display: block;
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
}

.composer textarea {
  width: 100%;
  min-height: 3rem;
  max-height: 10rem;
  resize: none;
  border: 0;
  background: transparent;
  color: var(--text);
  outline: none;
}

.composer-actions {
  display: flex;
  align-items: flex-end;
  gap: 0.6rem;
  flex: 0 0 auto;
}

.panel-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 1rem;
  min-height: 0;
}

.panel-stack {
  display: grid;
  gap: 1rem;
  align-content: start;
}

.panel,
.detail-card,
.test-card,
.result-card,
.directory-item,
.kb-file {
  padding: 1rem 1.1rem;
  background: var(--panel-bg-strong);
  border: 1px solid var(--line);
}

.panel h3,
.detail-card h3,
.test-card h3,
.directory-item h3,
.kb-file h3 {
  font-size: 1.05rem;
}

.stats-grid,
.tests-grid,
.directory-list,
.kb-list,
.results-list {
  display: grid;
  gap: 0.8rem;
}

.stats-grid {
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
}

.stat-card {
  padding: 1rem;
  background: var(--control-bg);
  border: 1px solid var(--line);
}

.stat-card strong {
  display: block;
  margin-top: 0.25rem;
  font-size: 1.3rem;
}

.directory-item,
.test-card {
  display: grid;
  gap: 0.85rem;
}

.directory-item.active {
  border-color: var(--selected-border);
  background: var(--selected-bg);
}

.status-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.status-pill {
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
}

.status-pill.admin {
  background: rgba(86, 168, 245, 0.18);
  color: #d5edff;
}

.status-pill.employee {
  background: rgba(76, 195, 138, 0.16);
  color: #d1ffe8;
}

.status-pill.mandatory {
  background: rgba(248, 193, 93, 0.18);
  color: #ffe0a0;
}

.status-pill.optional {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-soft);
}

.question-block {
  display: grid;
  gap: 0.8rem;
  padding: 1rem;
  border-radius: var(--radius-md);
  background: var(--control-bg);
  border: 1px solid var(--line);
}

.options-list {
  display: grid;
  gap: 0.7rem;
}

.option-button {
  width: 100%;
  text-align: left;
  padding: 0.8rem 0.95rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--control-bg);
  color: var(--text);
}

.option-button.selected {
  border-color: rgba(86, 168, 245, 0.54);
  background: rgba(86, 168, 245, 0.14);
}

.option-button.correct {
  border-color: rgba(76, 195, 138, 0.54);
  background: rgba(76, 195, 138, 0.14);
}

.option-button.wrong {
  border-color: rgba(242, 109, 116, 0.54);
  background: rgba(242, 109, 116, 0.14);
}

.result-card {
  display: grid;
  gap: 0.9rem;
}

.empty-state {
  padding: 2rem 1.4rem;
  text-align: center;
}

.empty-state h3 {
  margin: 0 0 0.4rem;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 40;
  min-width: 16rem;
  max-width: min(24rem, calc(100vw - 2rem));
  padding: 0.95rem 1rem;
  border-radius: 1rem;
  background: rgba(20, 31, 43, 0.96);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow);
  color: var(--text);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1080px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    position: fixed;
    inset: 0 auto 0 0;
    width: min(22rem, 92vw);
    z-index: 30;
    transform: translateX(-105%);
    transition: transform 220ms ease;
    border-radius: 0 28px 28px 0;
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 25;
    background: rgba(4, 12, 21, 0.48);
    backdrop-filter: blur(6px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 220ms ease;
  }

  .shell.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .shell.sidebar-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-only {
    display: inline-grid;
  }

  .mobile-only.sidebar-backdrop {
    display: block;
  }

  .panel-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .shell {
    height: 100dvh;
    padding: 0;
    gap: 0;
  }

  .main-shell {
    gap: 0.75rem;
    padding: 0.75rem;
  }

  .topbar,
  .system-banner,
  .composer,
  .chat-gate,
  .panel,
  .detail-card,
  .test-card,
  .kb-file,
  .directory-item,
  .result-card {
    border-radius: var(--radius-md);
  }

  .carousel-track {
    /* На мобильных показываем 1-2 карточки полностью */
    grid-auto-columns: minmax(15rem, 70vw);
    padding-left: 0.6rem;
    padding-right: 0.6rem;
  }

  .message-stack {
    max-width: 100%;
  }

  .message-attachment img {
    max-width: min(100%, 19rem);
    max-height: min(38vh, 18rem);
  }

  .composer {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: 0.55rem;
    padding: 0.65rem;
  }

  .composer-actions {
    width: auto;
    justify-content: flex-end;
    gap: 0.45rem;
  }

  .composer-field {
    min-width: 0;
  }

  .composer textarea,
  .voice-recorder-status {
    min-height: 3.05rem;
    border-radius: 1rem;
    padding: 0.88rem 0.95rem;
  }

  .composer .primary-button,
  .composer .icon-button {
    min-height: 3.05rem;
  }

  .composer .primary-button {
    min-width: 6.15rem;
    padding: 0.85rem 1rem;
    font-size: 0.93rem;
  }

  .voice-button {
    width: 3.05rem;
    min-width: 3.05rem;
  }

  .screen-head,
  .sidebar-head {
    gap: 0.55rem;
    align-items: flex-start;
  }

  .chat-list,
  .admin-nav,
  .directory-list,
  .tests-grid,
  .results-list,
  .kb-list {
    gap: 0.65rem;
    padding-right: 0;
  }

  .chat-item,
  .admin-link,
  .directory-item,
  .test-card,
  .panel,
  .detail-card,
  .kb-file,
  .result-card {
    padding: 0.9rem 0.95rem;
  }

  .primary-button,
  .ghost-button,
  .icon-button,
  .card-action,
  .pill-button {
    min-height: 3rem;
  }

  .ghost-button,
  .card-action,
  .pill-button,
  .profile-chip,
  .tag {
    font-size: 0.82rem;
  }

  .sidebar-footer,
  .profile-chip-row,
  .quick-actions,
  .message-actions,
  .card-actions,
  .toolbar {
    gap: 0.5rem;
  }

  .message-bubble,
  .voice-note {
    border-radius: 1.05rem;
  }

  .message-bubble {
    padding: 0.86rem 0.92rem;
    line-height: 1.45;
  }
}

@media (max-width: 420px) {
  .main-shell {
    padding: 0.6rem;
  }

  .topbar {
    min-height: auto;
    padding: 0.9rem 1rem;
  }

  .sidebar-head h2,
  .screen-head h2,
  .topbar h2 {
    font-size: 1.12rem;
  }

  .composer {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.5rem;
  }

  .composer-actions {
    width: auto;
    justify-content: flex-end;
    gap: 0.4rem;
  }

  .composer .primary-button,
  .voice-button {
    flex: 0 0 auto;
  }

  .voice-recorder-status {
    gap: 0.6rem;
  }
}

.theme-toggle {
  top: calc(env(safe-area-inset-top, 0px) + 1rem);
  right: calc(env(safe-area-inset-right, 0px) + 1rem);
  width: 7.4rem;
  height: 3rem;
  padding: 0.28rem 0.58rem;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(18, 28, 40, 0.9), rgba(22, 34, 47, 0.84));
  border-color: var(--line-strong);
  box-shadow: 0 18px 40px rgba(2, 10, 22, 0.28);
}

:root.light-theme .theme-toggle {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(241, 246, 251, 0.88));
}

.theme-toggle-track {
  inset: 0.2rem;
  border-radius: inherit;
  background: rgba(255, 255, 255, 0.05);
}

:root.light-theme .theme-toggle-track {
  background: rgba(15, 23, 42, 0.04);
}

.theme-toggle-thumb {
  top: 0.18rem;
  left: 0.18rem;
  width: 3.35rem;
  height: 2.24rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.28);
}

.theme-toggle[data-theme="light"] .theme-toggle-thumb {
  transform: translateX(3.62rem);
}

.theme-toggle-icons {
  padding-inline: 0.28rem;
  font-size: 0.73rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: none;
}

.theme-toggle-icons span {
  opacity: 0.64;
  transition: opacity 180ms ease, color 180ms ease;
}

.theme-toggle[data-theme="dark"] .theme-toggle-icons span:first-child,
.theme-toggle[data-theme="light"] .theme-toggle-icons span:last-child {
  opacity: 1;
  color: #09131f;
}

.field input,
.field textarea,
.field select {
  min-height: 3.2rem;
  padding: 0.95rem 1rem;
  background: var(--panel-bg-strong);
  background: color-mix(in srgb, var(--panel-bg-strong) 76%, transparent);
  border: 1px solid var(--line-strong);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
  transition: border-color 180ms ease, box-shadow 180ms ease, background-color 180ms ease;
}

.primary-button,
.ghost-button,
.icon-button,
.card-action,
.pill-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 2.95rem;
  border: 1px solid transparent;
  box-shadow: 0 10px 18px rgba(7, 15, 26, 0.08);
}

.ghost-button,
.card-action,
.pill-button {
  border-color: var(--line);
}

.profile-card,
.panel,
.detail-card,
.directory-item,
.kb-file,
.test-card,
.result-card,
.composer,
.topbar,
.system-banner {
  box-shadow: 0 18px 30px rgba(7, 15, 26, 0.12);
}

.profile-card {
  display: grid;
  gap: 0.85rem;
}

.profile-summary {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  min-width: 0;
}

.profile-meta {
  min-width: 0;
  display: grid;
  gap: 0.28rem;
}

.profile-meta h3,
.profile-meta p {
  overflow-wrap: anywhere;
}

.profile-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.profile-setting {
  display: grid;
  gap: 0.55rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--line);
}

.avatar {
  position: relative;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 50%;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  background: linear-gradient(135deg, rgba(86, 168, 245, 0.22), rgba(34, 82, 120, 0.9));
  color: #eef6ff;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-fallback {
  font-weight: 800;
  letter-spacing: 0.04em;
}

.avatar-lg {
  width: 4rem;
  height: 4rem;
}

.avatar-sm {
  width: 2.6rem;
  height: 2.6rem;
}

.avatar-bot {
  background:
    radial-gradient(circle at 30% 28%, rgba(255, 255, 255, 0.22), transparent 38%),
    linear-gradient(180deg, #2a4f72, #142334);
  color: #f4fbff;
}

.avatar-bot::before {
  content: "";
  position: absolute;
  top: 18%;
  left: 50%;
  width: 0.12rem;
  height: 0.55rem;
  transform: translateX(-50%);
  background: currentColor;
  opacity: 0.9;
}

.avatar-bot::after {
  content: "";
  position: absolute;
  inset: 32% 24% 18%;
  border: 0.12rem solid currentColor;
  border-radius: 0.55rem;
  background:
    radial-gradient(circle, currentColor 0 0.12rem, transparent 0.16rem) 32% 42% / 0.55rem 0.55rem no-repeat,
    radial-gradient(circle, currentColor 0 0.12rem, transparent 0.16rem) 68% 42% / 0.55rem 0.55rem no-repeat,
    linear-gradient(currentColor, currentColor) center 74% / 36% 0.12rem no-repeat;
  opacity: 0.92;
}

.avatar-bot.avatar-has-image::before,
.avatar-bot.avatar-has-image::after {
  content: none;
  display: none;
}

.avatar-bot .avatar-fallback {
  opacity: 0;
}

.directory-identity {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  min-width: 0;
}

.directory-copy {
  min-width: 0;
  display: grid;
  gap: 0.25rem;
}

.directory-copy h3,
.directory-copy p {
  overflow-wrap: anywhere;
}

.directory-item {
  transition: transform 180ms ease, border-color 180ms ease, background 180ms ease;
}

.directory-item:hover {
  transform: translateY(-2px);
  border-color: var(--selected-border);
}

.detail-card > .avatar-lg {
  margin-bottom: 0.9rem;
}

.message-row {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  animation: message-enter 180ms ease;
}

.message-row.mine > .avatar {
  order: 2;
}

.message-row.mine .message-stack {
  align-items: flex-end;
}

.message-stack {
  gap: 0.45rem;
}

.message-meta {
  padding-inline: 0.1rem;
  letter-spacing: 0.01em;
}

.message-footer {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding-inline: 0.2rem;
  color: var(--text-muted);
  font-size: 0.76rem;
}

.message-status {
  color: var(--text-muted);
}

.message-status.is-read {
  color: var(--accent);
}

.message-bubble {
  box-shadow: 0 14px 24px rgba(7, 15, 26, 0.08);
}

.message-row.is-pending .message-bubble {
  animation: bubble-pulse 1.35s ease-in-out infinite;
}

.composer {
  gap: 0.75rem;
  padding: 0.85rem;
  background: linear-gradient(180deg, rgba(18, 30, 42, 0.84), rgba(16, 26, 38, 0.92));
  border-color: var(--line-strong);
}

:root.light-theme .composer {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(244, 248, 252, 0.96));
}

.composer-field {
  display: block;
  padding: 0;
}

.composer textarea {
  min-height: 3.25rem;
  display: block;
  box-sizing: border-box;
  padding: 0.92rem 1rem 0.88rem;
  border: 1px solid var(--line);
  border-radius: 1.15rem;
  background: var(--control-bg);
  font-size: 1rem;
  line-height: 1.45;
  -webkit-appearance: none;
  appearance: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
  overflow-y: auto;
}

.composer textarea:focus {
  border-color: rgba(86, 168, 245, 0.68);
  box-shadow: 0 0 0 3px rgba(86, 168, 245, 0.12);
}

.composer-actions {
  align-items: stretch;
}

.composer .primary-button,
.composer .icon-button {
  min-height: 3.25rem;
}

@keyframes message-enter {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes bubble-pulse {
  0%,
  100% {
    transform: translateY(0);
    box-shadow: 0 14px 24px rgba(7, 15, 26, 0.08);
  }
  50% {
    transform: translateY(-1px);
    box-shadow: 0 18px 28px rgba(86, 168, 245, 0.12);
  }
}

@media (max-width: 1080px) {
  .theme-toggle {
    width: 6.65rem;
    height: 2.8rem;
  }

  .theme-toggle-thumb {
    width: 2.95rem;
    height: 2.05rem;
  }

  .theme-toggle[data-theme="light"] .theme-toggle-thumb {
    transform: translateX(3.08rem);
  }
}

@media (max-width: 720px) {
  .theme-toggle {
    top: calc(env(safe-area-inset-top, 0px) + 0.7rem);
    right: calc(env(safe-area-inset-right, 0px) + 0.7rem);
    width: 6.1rem;
    height: 2.55rem;
    padding-inline: 0.45rem;
  }

  .theme-toggle-thumb {
    width: 2.7rem;
    height: 1.85rem;
  }

  .theme-toggle[data-theme="light"] .theme-toggle-thumb {
    transform: translateX(2.72rem);
  }

  .theme-toggle-icons {
    font-size: 0.66rem;
  }

  .profile-summary,
  .directory-identity {
    gap: 0.7rem;
  }

  .profile-actions {
    width: 100%;
  }

  .profile-actions .ghost-button {
    width: 100%;
  }

  .message-row {
    gap: 0.55rem;
  }

  .avatar-lg {
    width: 3.5rem;
    height: 3.5rem;
  }

  .avatar-sm {
    width: 2.3rem;
    height: 2.3rem;
  }
}

/* Chat shell polish */
#chatScreen {
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  min-height: 0;
}

.messages {
  flex: 1 1 0;
  min-height: 0;
}

.messages.is-empty {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  justify-content: center;
}

.chat-gate,
.composer {
  flex: 0 0 auto;
}

.composer {
  margin-top: auto;
}

.topbar-actions {
  flex-wrap: nowrap;
  justify-content: flex-end;
}

.topbar-theme-toggle,
body.app-shell-active .theme-toggle {
  position: static;
  inset: auto;
  top: auto;
  right: auto;
  width: 10rem;
  min-width: 10rem;
  height: 2.85rem;
  margin-left: 0.25rem;
  padding: 0.22rem 0.5rem;
  box-shadow: 0 12px 24px rgba(7, 15, 26, 0.14);
}

.topbar-theme-toggle .theme-toggle-track,
body.app-shell-active .theme-toggle .theme-toggle-track {
  inset: 0.16rem;
}

.topbar-theme-toggle .theme-toggle-thumb,
body.app-shell-active .theme-toggle .theme-toggle-thumb {
  top: 0.12rem;
  left: 0.12rem;
  width: 4.8rem;
  height: 2.25rem;
  border-radius: 999px;
}

.topbar-theme-toggle[data-theme="light"] .theme-toggle-thumb,
body.app-shell-active .theme-toggle[data-theme="light"] .theme-toggle-thumb {
  transform: translateX(4.72rem);
}

.topbar-theme-toggle .theme-toggle-icons,
body.app-shell-active .theme-toggle .theme-toggle-icons {
  padding-inline: 0.4rem;
  font-size: 0.74rem;
  font-weight: 700;
}

.topbar-theme-toggle .theme-toggle-icons span,
body.app-shell-active .theme-toggle .theme-toggle-icons span {
  flex: 1 1 50%;
  text-align: center;
  color: var(--text-muted);
}

.topbar-theme-toggle[data-theme="dark"] .theme-toggle-icons span:first-child,
.topbar-theme-toggle[data-theme="light"] .theme-toggle-icons span:last-child,
body.app-shell-active .theme-toggle[data-theme="dark"] .theme-toggle-icons span:first-child,
body.app-shell-active .theme-toggle[data-theme="light"] .theme-toggle-icons span:last-child {
  color: #09131f;
}

.composer-field {
  position: relative;
}

.composer.is-recording textarea {
  display: none;
}

.voice-recorder-status {
  display: none;
  align-items: center;
  gap: 0.8rem;
  min-height: 3.2rem;
  padding: 0.85rem 1rem;
  border-radius: 1.15rem;
  background: linear-gradient(180deg, rgba(22, 32, 44, 0.92), rgba(18, 28, 40, 0.88));
  border: 1px solid var(--line);
}

.voice-recorder-status:not(.hidden) {
  display: flex;
}

.voice-recorder-dot {
  width: 0.8rem;
  height: 0.8rem;
  border-radius: 50%;
  background: #ff6f7d;
  box-shadow: 0 0 0 0 rgba(255, 111, 125, 0.34);
  animation: voice-rec-dot 1.2s ease infinite;
}

.voice-recorder-label {
  font-weight: 700;
  color: var(--text);
}

.voice-recorder-time {
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

.voice-recorder-wave {
  display: flex;
  align-items: center;
  gap: 0.18rem;
  margin-left: auto;
}

.voice-recorder-wave span {
  width: 0.22rem;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(104, 186, 255, 0.95), rgba(63, 144, 227, 0.42));
  animation: voice-wave 1.2s ease-in-out infinite;
}

.voice-recorder-wave span:nth-child(4n + 1) { height: 0.65rem; animation-delay: -0.2s; }
.voice-recorder-wave span:nth-child(4n + 2) { height: 1.2rem; animation-delay: -0.45s; }
.voice-recorder-wave span:nth-child(4n + 3) { height: 0.9rem; animation-delay: -0.7s; }
.voice-recorder-wave span:nth-child(4n + 4) { height: 1.45rem; animation-delay: -0.95s; }

.voice-button {
  width: 3.25rem;
  min-width: 3.25rem;
  padding: 0;
  border-radius: 999px;
  position: relative;
  overflow: hidden;
  background-image: url("/icons/micro.png");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 1.12rem 1.12rem;
}

.voice-button-glyph {
  display: none;
}

.voice-button.is-recording {
  color: #fff;
  background: linear-gradient(135deg, #f56472, #ff7f8d);
  background-image: none;
  box-shadow: 0 14px 24px rgba(245, 100, 114, 0.25);
}

.voice-button.is-recording::before {
  content: "";
  width: 0.86rem;
  height: 0.86rem;
  border-radius: 0.22rem;
  background: currentColor;
}

.voice-button.is-processing {
  opacity: 0.82;
}

.avatar-bot img {
  object-fit: contain;
  padding: 0.18rem;
}

.voice-note {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  min-width: 17rem;
  max-width: 100%;
  padding: 0.82rem 0.95rem;
  border-radius: 1.2rem;
  background: color-mix(in srgb, var(--bubble-in) 88%, transparent);
  border: 1px solid var(--line);
  box-shadow: 0 14px 24px rgba(7, 15, 26, 0.08);
}

.message-row.mine .voice-note {
  background: color-mix(in srgb, var(--bubble-out-bg) 90%, transparent);
}

.voice-note.pending {
  border-style: dashed;
}

.voice-note-play {
  min-width: 3rem;
  height: 3rem;
  padding: 0 0.75rem;
  border: 0;
  border-radius: 999px;
  background: rgba(86, 168, 245, 0.16);
  color: var(--text);
  font-weight: 700;
}

.voice-note-body {
  display: grid;
  gap: 0.45rem;
  flex: 1 1 auto;
  min-width: 0;
}

.voice-note-wave {
  display: flex;
  align-items: center;
  gap: 0.18rem;
}

.voice-note-wave span {
  flex: 0 0 0.22rem;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(111, 193, 255, 0.95), rgba(60, 138, 221, 0.4));
  animation: voice-wave 1.35s ease-in-out infinite;
}

.voice-note-wave span:nth-child(4n + 1) { height: 0.6rem; animation-delay: -0.2s; }
.voice-note-wave span:nth-child(4n + 2) { height: 1.25rem; animation-delay: -0.38s; }
.voice-note-wave span:nth-child(4n + 3) { height: 0.9rem; animation-delay: -0.62s; }
.voice-note-wave span:nth-child(4n + 4) { height: 1.4rem; animation-delay: -0.86s; }

.voice-note-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.voice-note-meta strong {
  color: var(--text);
  font-size: 0.9rem;
}

@keyframes voice-rec-dot {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(255, 111, 125, 0.34);
  }
  70% {
    box-shadow: 0 0 0 0.55rem rgba(255, 111, 125, 0);
  }
}

@keyframes voice-wave {
  0%, 100% {
    transform: scaleY(0.7);
    opacity: 0.68;
  }
  50% {
    transform: scaleY(1.12);
    opacity: 1;
  }
}

@media (max-width: 1080px) {
  .topbar-theme-toggle,
  body.app-shell-active .theme-toggle {
    width: 9rem;
    min-width: 9rem;
  }

  .topbar-theme-toggle .theme-toggle-thumb,
  body.app-shell-active .theme-toggle .theme-toggle-thumb {
    width: 4.25rem;
  }

  .topbar-theme-toggle[data-theme="light"] .theme-toggle-thumb,
  body.app-shell-active .theme-toggle[data-theme="light"] .theme-toggle-thumb {
    transform: translateX(4.16rem);
  }
}

@media (max-width: 720px) {
  .topbar-theme-toggle,
  body.app-shell-active .theme-toggle {
    width: 100%;
    min-width: 0;
    margin-left: 0;
  }

  .topbar-actions {
    width: auto;
    margin-left: auto;
    gap: 0.45rem;
  }

  .voice-note {
    min-width: 0;
  }

  .voice-recorder-wave {
    display: none;
  }

  .voice-button {
    background-size: 1rem 1rem;
  }

  .topbar-menu {
    min-width: 11.5rem;
  }
}

@media (max-width: 420px) {
  .composer {
    gap: 0.5rem;
    padding: 0.55rem;
  }

  .composer-actions {
    flex-wrap: nowrap;
    align-items: stretch;
  }

  .composer textarea,
  .voice-recorder-status {
    min-height: 2.95rem;
    padding: 0.76rem 0.9rem 0.72rem;
    border-radius: 0.95rem;
    font-size: 0.94rem;
    line-height: 1.32;
  }

  .composer .primary-button,
  .composer .icon-button {
    min-height: 2.95rem;
  }

  .composer .primary-button {
    min-width: 5.35rem;
    padding: 0.78rem 0.85rem;
    font-size: 0.89rem;
    white-space: nowrap;
  }

  .voice-button {
    width: 2.85rem;
    min-width: 2.85rem;
    background-size: 0.95rem 0.95rem;
  }
}

.theme-toggle {
  display: none !important;
}
