:root {
  color-scheme: dark;
  --bg: #0c0f14;
  --bg-2: #141a22;
  --panel: rgba(20, 26, 34, 0.85);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text: #e6eef6;
  --muted: #9aa6b2;
  --accent: #ffb347;
  --accent-2: #7fd1b9;
  --warning: #ff6b6b;
  --glow: rgba(255, 179, 71, 0.35);
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

* {
  box-sizing: border-box;
}

*:focus-visible {
  outline: 2px solid rgba(127, 209, 185, 0.85);
  outline-offset: 2px;
}

*::-webkit-scrollbar {
  width: 10px;
}

*::-webkit-scrollbar-track {
  background: rgba(8, 10, 14, 0.6);
}

*::-webkit-scrollbar-thumb {
  background: rgba(127, 209, 185, 0.35);
  border-radius: 999px;
  border: 2px solid rgba(8, 10, 14, 0.6);
}

*::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 179, 71, 0.5);
}

* {
  scrollbar-color: rgba(127, 209, 185, 0.45) rgba(8, 10, 14, 0.6);
  scrollbar-width: thin;
}

body {
  margin: 0;
  font-family: "Space Grotesk", system-ui, sans-serif;
  background: radial-gradient(circle at 15% 15%, #1b2330 0%, #0c0f14 45%, #090b10 100%);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  overflow-y: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 80% 20%, rgba(127, 209, 185, 0.12), transparent 50%),
    radial-gradient(circle at 10% 80%, rgba(255, 179, 71, 0.18), transparent 55%);
  pointer-events: none;
  z-index: 0;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    radial-gradient(circle at 20% 30%, rgba(255, 179, 71, 0.2) 2px, transparent 2px),
    radial-gradient(circle at 60% 70%, rgba(255, 179, 71, 0.15) 2px, transparent 2px),
    radial-gradient(circle at 80% 15%, rgba(255, 179, 71, 0.18) 2px, transparent 2px),
    radial-gradient(circle at 15% 85%, rgba(255, 179, 71, 0.12) 2px, transparent 2px),
    radial-gradient(circle at 90% 50%, rgba(255, 179, 71, 0.14) 2px, transparent 2px),
    radial-gradient(circle at 45% 45%, rgba(127, 209, 185, 0.1) 2px, transparent 2px),
    radial-gradient(circle at 70% 25%, rgba(255, 179, 71, 0.1) 2px, transparent 2px);
  background-size: 48px 48px, 48px 48px, 200px 180px, 220px 200px, 180px 220px, 190px 170px, 210px 190px, 240px 210px, 195px 205px;
  background-position: 0 0, 0 0, 10px 20px, 50px 80px, 120px 30px, 20px 150px, 160px 90px, 80px 100px, 40px 60px;
  pointer-events: none;
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  padding: 24px;
  padding-top: calc(24px + env(safe-area-inset-top));
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
  height: var(--app-height, 100vh);
  min-height: var(--app-height, 100vh);
  display: flex;
  flex-direction: column;
  max-width: none;
  margin: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  gap: 16px;
  flex: 0 0 auto;
  padding: 12px 14px;
  border-radius: 22px;
  background: rgba(10, 12, 16, 0.58);
  border: 1px solid rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.topbar.minimal {
  margin-bottom: 12px;
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  background: conic-gradient(from 130deg, #ffb347, #7fd1b9, #ffb347);
  box-shadow: 0 0 20px rgba(255, 179, 71, 0.35);
}

.brand h1 {
  font-family: "Fraunces", serif;
  font-size: 28px;
  margin: 0;
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.status {
  display: flex;
  align-items: center;
}

.status.compact {
  align-items: center;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.agent-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(9, 12, 16, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.agent-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.agent-switch select {
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(9, 12, 16, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.12);
  min-height: 32px;
}

.pane-controls {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.pane-controls select {
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(9, 12, 16, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.12);
  min-height: 32px;
  font-size: 12px;
}

/* addPaneBtn uses default .icon-btn styling */
.pane-controls .icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  font-size: 18px;
  min-height: 0;
  padding: 0;
}

.role-pill {
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 179, 71, 0.18);
  border: 1px solid rgba(255, 179, 71, 0.45);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
}

.role-pill.admin {
  background: rgba(127, 209, 185, 0.18);
  border-color: rgba(127, 209, 185, 0.45);
  color: var(--accent-2);
}

.channel-switch select {
  background: rgba(9, 12, 16, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 12px;
  font-size: 12px;
}

.channel-switch select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.brand.compact .brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 12px;
}

.brand.compact h1 {
  font-size: 22px;
}

.icon-btn {
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(9, 12, 16, 0.6);
  color: var(--text);
  width: 40px;
  height: 40px;
  border-radius: 12px;
  font-size: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.icon-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.25);
}

.status-pill {
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  position: relative;
  overflow: hidden;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.status-pill:hover {
  border-color: rgba(255, 255, 255, 0.22);
}

.status-pill.working {
  background: rgba(255, 179, 71, 0.12);
  border-color: rgba(255, 179, 71, 0.55);
  color: var(--accent);
}

.status-pill.working::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.14), transparent);
  transform: translateX(-120%);
  animation: status-sweep 1.35s ease-in-out infinite;
  pointer-events: none;
}

.status-pill.connected {
  background: rgba(127, 209, 185, 0.25);
  border-color: rgba(127, 209, 185, 0.8);
  color: var(--accent-2);
}

.status-pill.error {
  background: rgba(255, 107, 107, 0.25);
  border-color: rgba(255, 107, 107, 0.8);
  color: var(--warning);
}

@keyframes status-sweep {
  0% {
    transform: translateX(-120%);
  }
  60% {
    transform: translateX(120%);
  }
  100% {
    transform: translateX(120%);
  }
}

.status-meta {
  color: var(--muted);
  font-size: 12px;
}

.chat-page {
  position: relative;
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.pane-grid {
  position: relative;
  z-index: 1;
  flex: 1;
  display: grid;
  grid-template-columns: repeat(var(--pane-cols, 1), minmax(0, 1fr));
  gap: 12px;
  min-height: 0;
}

.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: rgba(20, 26, 34, 0.22);
  border: 1px solid var(--panel-border);
  border-radius: 22px;
  padding: 18px;
  box-shadow: var(--shadow);
  min-height: 0;
  position: relative;
  overflow: hidden;
  backdrop-filter: blur(10px) saturate(1.15);
  -webkit-backdrop-filter: blur(10px) saturate(1.15);
}

.chat-panel.pane {
  /* These vars are used by both the input stack and the scroll-to-bottom button. */
  --send-btn-size: 44px;
  --attach-btn-size: 36px;
  --action-gap: 8px;
  --actions-height: calc(var(--send-btn-size) + var(--attach-btn-size) + var(--action-gap));

  gap: 10px;
  padding: 14px;
  padding-bottom: 6px;
}

.pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 16px;
  background: rgba(9, 12, 16, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.08);
  position: relative;
  z-index: 2;
}

.pane-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.pane-name {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  white-space: nowrap;
}

.pane-agent {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.pane-agent select {
  padding: 6px 10px;
  border-radius: 999px;
  min-height: 32px;
  font-size: 12px;
  max-width: 220px;
}

.pane-agent .agent-label {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  background: rgba(9, 12, 16, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text);
}

.pane-header-right {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.status-pill.pane-status {
  padding: 5px 12px;
  font-size: 11px;
  cursor: default;
}

.pane-close {
  width: 34px;
  height: 34px;
  border-radius: 12px;
  min-height: 0;
  padding: 0;
  font-size: 16px;
}

input,
textarea,
select {
  background: rgba(11, 14, 19, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 10px;
  font-family: "Space Grotesk", sans-serif;
  font-size: 16px; /* Prevent mobile browsers from auto-zooming inputs on focus. */
  line-height: 1.35;
}

textarea {
  resize: none;
}

.chat-input-row textarea[data-pane-input] {
  min-height: var(--actions-height);
}

button {
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(9, 12, 16, 0.55);
  color: var(--text);
  cursor: pointer;
  transition:
    transform 0.18s ease,
    box-shadow 0.18s ease,
    background 0.18s ease,
    border-color 0.18s ease,
    filter 0.18s ease;
  min-height: 44px;
  touch-action: manipulation;
  user-select: none;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

button:disabled:hover {
  transform: none;
  box-shadow: none;
}

button.primary {
  background: linear-gradient(135deg, rgba(255, 179, 71, 0.92), rgba(127, 209, 185, 0.72));
  border-color: rgba(255, 179, 71, 0.7);
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.28), 0 12px 30px rgba(255, 179, 71, 0.18);
  color: rgba(12, 15, 20, 0.96);
  font-weight: 700;
  letter-spacing: 0.01em;
}

button.secondary {
  border-color: rgba(127, 209, 185, 0.35);
  background: rgba(9, 12, 16, 0.6);
}

button.secondary:hover {
  border-color: rgba(127, 209, 185, 0.6);
}

button:hover {
  transform: translateY(-1px);
  border-color: rgba(255, 255, 255, 0.22);
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.28);
}

button:active {
  transform: translateY(0);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.24);
}

button.primary:hover {
  filter: brightness(1.03) saturate(1.05);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.btn-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.attach-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

button.send-btn {
  width: 44px;
  min-width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 999px;
  display: grid;
  place-items: center;
}

button.send-btn.primary {
  background: linear-gradient(135deg, rgba(127, 209, 185, 0.95), rgba(83, 168, 146, 0.95));
  border-color: rgba(127, 209, 185, 0.75);
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.26), 0 10px 22px rgba(127, 209, 185, 0.18);
  color: rgba(255, 255, 255, 0.96);
}

button.send-btn.primary:hover {
  filter: brightness(1.03) saturate(1.04);
}

button.send-btn .btn-icon {
  width: 20px;
  height: 20px;
  transform: translateY(-1px);
}

.button-row {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

.hint {
  font-size: 12px;
  color: var(--muted);
}

.label {
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-right: 6px;
}

.flux-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  opacity: 0.9;
  pointer-events: none;
  z-index: 0;
}

.pulse-meta {
  position: absolute;
  top: 16px;
  right: 16px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(9, 12, 16, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  z-index: 2;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

/* Landing page */
.landing-overlay {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  z-index: 25;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.landing-bg-video {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
}

.landing-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.landing-scroll {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: center;
  padding: 40px 20px 60px;
  min-height: 100%;
}

.landing-card {
  width: min(560px, 94vw);
  background: rgba(12, 15, 20, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 24px;
  padding: 36px 40px 40px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  text-align: center;
}

.landing-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding-bottom: 8px;
}

.landing-social {
  display: flex;
  gap: 12px;
  margin-bottom: 4px;
}

.landing-social-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  color: var(--muted);
  text-decoration: none;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.25);
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}

.landing-social-btn:hover {
  color: var(--accent-2);
  border-color: rgba(127, 209, 185, 0.4);
  background: rgba(127, 209, 185, 0.08);
}

.social-icon {
  width: 20px;
  height: 20px;
}

.landing-social-btn .social-icon {
  width: 22px;
  height: 22px;
}

.social-link-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  color: var(--muted);
}

.social-link-icon .social-icon {
  width: 20px;
  height: 20px;
}

.social-link-icon:hover {
  color: var(--accent-2);
}

.landing-crab-logo {
  max-width: 240px;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.landing-title {
  margin: 0;
  font-family: "Fraunces", serif;
  font-size: 26px;
  font-weight: 600;
  letter-spacing: 0.2em;
  color: var(--text);
}

.landing-tagline {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.landing-section {
  width: 100%;
  text-align: left;
  padding: 16px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.landing-section:first-of-type {
  border-top: none;
  padding-top: 0;
}

.landing-section h3 {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent-2);
}

.landing-section p,
.landing-section li {
  margin: 0 0 8px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--muted);
}

.landing-section p:last-child,
.landing-section li:last-child {
  margin-bottom: 0;
}

.landing-section ul {
  margin: 0;
  padding-left: 20px;
}

.landing-section code {
  font-size: 12px;
  padding: 2px 6px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 6px;
  color: var(--accent-2);
  word-break: break-all;
}

.landing-footer {
  margin-top: 32px;
  padding-top: 20px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.landing-launch-btn {
  padding: 14px 48px;
  font-size: 16px;
  font-weight: 600;
  border-radius: 14px;
  margin-top: 12px;
}

/* Top bar logo and social */
.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  flex-shrink: 0;
}

.topbar-social {
  display: flex;
  align-items: center;
  gap: 16px;
}

.social-link {
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.15s ease;
}

.social-link:hover {
  color: var(--accent-2);
}

.site-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 10px 20px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  background: rgba(8, 10, 14, 0.6);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  z-index: 5;
}

.login-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 10, 14, 0.85);
  z-index: 30;
  transition: opacity 0.22s ease, visibility 0.22s ease;
  backdrop-filter: blur(14px);
}

.login-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.login-card {
  width: min(420px, 90vw);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 24px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-card h2 {
  margin: 0;
  font-size: 20px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.login-brand-img {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  flex: 0 0 auto;
}

.login-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.login-subtitle {
  margin-top: 2px;
  opacity: 0.9;
}

.login-copy {
  line-height: 1.45;
}

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.login-error {
  min-height: 18px;
  color: var(--warning);
  font-size: 12px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 14, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.18s ease, visibility 0.18s ease;
  backdrop-filter: blur(12px);
}

.modal.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.modal-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: 18px;
  width: min(520px, 92vw);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px) scale(0.99);
  transition: transform 0.18s ease, opacity 0.18s ease;
}

.modal.open .modal-card {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.modal-body label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 12px;
}

.modal-body .hint {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}


.chat-thread {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  padding: 8px 4px 8px;
  margin-bottom: 0;
  border-radius: 0;
  background: transparent;
  border: none;
  position: relative;
  z-index: 1;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.scroll-down {
  position: absolute;
  right: 18px;
  bottom: calc(var(--actions-height, 88px) + 22px);
  width: 44px;
  height: 44px;
  padding: 0;
  min-height: 0;
  border-radius: 14px;
  background: rgba(9, 12, 16, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text);
  display: grid;
  place-items: center;
  font-size: 18px;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
  z-index: 3;
  backdrop-filter: blur(10px);
}

.scroll-down.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.38);
}

.scroll-down:hover {
  transform: translateY(-1px);
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.38);
}

.chat-bubble {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 14px;
  border-radius: 14px;
  max-width: min(78%, 680px);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.2);
}

.chat-bubble.user {
  align-self: flex-end;
  background: linear-gradient(135deg, rgba(127, 209, 185, 0.24), rgba(83, 168, 146, 0.3));
  border: 1px solid rgba(127, 209, 185, 0.4);
}

.chat-bubble.assistant {
  align-self: flex-start;
  background: rgba(20, 24, 32, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(8px) saturate(1.1);
  -webkit-backdrop-filter: blur(8px) saturate(1.1);
}

.chat-bubble.streaming {
  border-color: rgba(255, 179, 71, 0.5);
  box-shadow: 0 0 18px rgba(255, 179, 71, 0.2);
}

.chat-bubble.queued {
  border-style: dashed;
  border-color: rgba(255, 255, 255, 0.22);
  box-shadow: 0 0 0 rgba(0, 0, 0, 0);
}

.chat-bubble.sending {
  border-style: dashed;
  border-color: rgba(127, 209, 185, 0.55);
}

.chat-bubble.failed {
  border-style: dashed;
  border-color: rgba(255, 86, 86, 0.6);
}

.chat-actions-row {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.chat-action {
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(8, 10, 14, 0.3);
  color: rgba(255, 255, 255, 0.85);
  cursor: pointer;
}

.chat-action:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-action.delete {
  border-color: rgba(255, 86, 86, 0.35);
}

.chat-bubble.thinking {
  opacity: 0.85;
  border-style: dashed;
}

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

.thinking-dots {
  display: inline-block;
  min-width: 12px;
  margin-left: 6px;
  color: var(--accent);
}


.chat-meta {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.chat-text {
  font-size: 15px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.chat-text a {
  color: var(--accent-2);
  text-decoration: none;
}

.chat-text a:hover {
  text-decoration: underline;
}

.chat-text pre {
  background: rgba(8, 10, 14, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 10px 12px;
  border-radius: 12px;
  overflow-x: auto;
}

.chat-text code {
  background: rgba(8, 10, 14, 0.6);
  padding: 2px 6px;
  border-radius: 6px;
  font-family: "JetBrains Mono", "SFMono-Regular", ui-monospace, monospace;
  font-size: 0.9em;
}

.chat-text ul,
.chat-text ol {
  padding-left: 20px;
  margin: 6px 0;
}

.chat-text img {
  max-width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  display: block;
  margin-top: 8px;
}

.chat-input-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.attachment-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.file-input {
  display: none;
}

.attachment-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.command-hints {
  display: none;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(8, 10, 14, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 12px;
  color: var(--muted);
}

.command-hints.visible {
  display: flex;
}

.command-hint {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.command-hint code {
  color: var(--accent);
  font-family: "JetBrains Mono", "SFMono-Regular", ui-monospace, monospace;
  font-size: 12px;
}

.attachment-pill {
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.attachment-pill button {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
}

.chat-input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: stretch;
  gap: 12px;
  margin-top: auto;
  position: relative;
  z-index: 1;
  padding: 10px;
  border-radius: 16px;
  background: rgba(8, 10, 14, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.08);
  flex: 0 0 auto;
  backdrop-filter: blur(10px) saturate(1.1);
  -webkit-backdrop-filter: blur(10px) saturate(1.1);
}

.chat-actions {
  display: flex;
  flex-direction: column;
  gap: var(--action-gap);
  align-items: stretch;
  height: var(--actions-height);
}

.chat-actions button {
  width: var(--send-btn-size);
  min-width: var(--send-btn-size);
}

.chat-actions .send-btn {
  height: var(--send-btn-size);
  min-height: var(--send-btn-size);
}

.chat-actions .attach-btn {
  height: var(--attach-btn-size);
  min-height: var(--attach-btn-size);
  padding: 0;
  border-radius: 999px;
  display: grid;
  place-items: center;
  gap: 0;
}

.chat-actions .attach-btn .btn-icon {
  width: 18px;
  height: 18px;
}

@media (max-width: 1024px) {
  .app {
    padding: 18px;
  }

  .chat-panel {
    padding: 16px;
  }

  .chat-bubble {
    max-width: 88%;
  }
}

@media (max-width: 768px) {
  body {
    overflow-y: hidden;
  }

  .app {
    padding: 8px 8px calc(10px + env(safe-area-inset-bottom));
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 4;
    width: 100%;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    border-radius: 14px;
    background: rgba(10, 12, 16, 0.88);
    border: 1px solid rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(12px);
  }

  .topbar-actions {
    width: auto;
    flex-wrap: wrap;
    justify-content: flex-end;
    margin-left: auto;
  }

  .chat-page {
    flex: 1;
    min-height: 0;
  }

  .pane-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .chat-panel {
    border-radius: 16px;
    padding: 10px;
  }

  .chat-thread {
    padding: 6px 2px 8px;
    margin-bottom: 0;
  }

  .chat-input-row {
    grid-template-columns: 1fr auto;
    gap: 10px;
    padding: 10px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    box-shadow: 0 -12px 30px rgba(0, 0, 0, 0.3);
  }

  .chat-panel.pane {
    --send-btn-size: 40px;
    --attach-btn-size: 34px;
    --action-gap: 6px;
    padding-bottom: 4px;
  }

  .scroll-down {
    right: 14px;
    bottom: calc(var(--actions-height, 74px) + 18px);
  }

  textarea {
    font-size: 17px;
    line-height: 1.4;
    min-height: 56px;
  }

  .brand h1 {
    font-size: 18px;
  }

  .brand .logo {
    width: 34px;
    height: 34px;
  }
}

@media (hover: none) and (pointer: coarse) {
  /* Prevent iOS Safari keyboard focus from scrolling the page behind the app. */
  body {
    position: fixed;
    inset: 0;
    width: 100%;
  }

  .app {
    position: fixed;
    left: 0;
    right: 0;
    top: var(--app-offset-top, 0px);
    height: var(--app-height, 100vh);
    min-height: var(--app-height, 100vh);
    max-width: none;
    margin: 0;
  }
}

@media (max-width: 480px) {
  .app {
    padding: 10px;
  }

  .brand {
    gap: 10px;
  }

  .brand.compact h1 {
    font-size: 18px;
  }

  .status-pill {
    font-size: 10px;
  }

  .role-pill {
    font-size: 10px;
  }

  .icon-btn {
    width: 36px;
    height: 36px;
  }

  .chat-text {
    font-size: 14px;
  }

  .chat-bubble {
    max-width: 100%;
    padding: 10px 12px;
  }

  textarea {
    min-height: 64px;
  }
}

@media (max-width: 360px) {
  .topbar-actions {
    gap: 6px;
  }

  .channel-switch select {
    font-size: 11px;
    padding: 6px 8px;
  }

  .status-pill,
  .role-pill {
    padding: 5px 10px;
  }
}

@media (max-width: 540px), (hover: none) and (pointer: coarse) {
  .topbar {
    padding: 6px 8px;
    gap: 4px;
    border-radius: 12px;
  }

  .topbar-actions {
    gap: 6px;
  }

  .status-pill,
  .role-pill {
    padding: 4px 8px;
    font-size: 9px;
    letter-spacing: 0.06em;
  }

  .icon-btn {
    width: 34px;
    height: 34px;
    border-radius: 10px;
  }

  .chat-panel {
    padding: 8px;
    border-radius: 14px;
    background: rgba(14, 18, 24, 0.6);
  }

  .chat-thread {
    padding: 4px 2px 72px;
    margin-bottom: 6px;
  }

  .chat-input-row {
    padding: 8px;
    gap: 8px;
    border-radius: 14px;
  }

  .attachment-row {
    gap: 6px;
  }

  .chat-input-row {
    --send-btn-size: 40px;
    --attach-btn-size: 34px;
    --action-gap: 6px;
  }

  .chat-actions button {
    width: var(--send-btn-size);
    min-width: var(--send-btn-size);
  }

  button.send-btn {
    width: 40px;
    min-width: 40px;
    height: 40px;
    min-height: 40px;
  }

  button.send-btn .btn-icon {
    width: 18px;
    height: 18px;
  }

  textarea {
    min-height: 48px;
    font-size: 16px;
  }
}
