/* HAL SUPREME — Professional UI (hal-pro) v=pro14
   Palette: Quantum Black #0A0A0A / HAL Blue #0A84FF / Circuit Green #00C853
   Fonts: Inter + IBM Plex Mono · Transitions 200–300ms · prefers-reduced-motion
   Responsive: mobile flex shell v2, visualViewport, reachable drawer, no Lite chrome */

:root {
  color-scheme: dark;
  --bg: #0A0A0A;
  --panel: #161616;
  --panel-2: #111111;
  --panel-3: #1c1c1c;
  --divider: #2a2a2a;
  --divider-strong: #3a3a3a;
  --text: #F5F5F7;
  --muted: #8E8E93;
  --accent: #0A84FF;
  --accent-dim: rgba(10, 132, 255, 0.16);
  --accent-glow: rgba(10, 132, 255, 0.35);
  --success: #00C853;
  --danger: #FF5252;
  --radius: 10px;
  --radius-sm: 8px;
  --grid: 16px;
  --sidebar-w: clamp(220px, 22vw, 260px);
  --header-h: 58px;
  --header-pad-y: 8px;
  --composer-min: 44px;
  --composer-h: 60px;
  --app-height: 100dvh;
  --vv-bottom-inset: 0px;
  --msg-col: min(820px, 100%);
  --bp-sidebar: 900px;
  --font: "Inter", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  --shadow-soft: 0 4px 16px rgba(0, 0, 0, 0.35);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --dur: 240ms;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #F2F3F5;
  --panel: #FFFFFF;
  --panel-2: #F7F8FA;
  --panel-3: #EEF0F3;
  --divider: #D8DCE2;
  --divider-strong: #C5CAD3;
  --text: #111111;
  --muted: #5C6570;
  --accent-dim: rgba(10, 132, 255, 0.10);
  --accent-glow: rgba(10, 132, 255, 0.22);
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.10);
  --shadow-soft: 0 4px 12px rgba(0, 0, 0, 0.06);
}

*, *::before, *::after { box-sizing: border-box; }
html {
  height: 100%;
  height: 100svh;
  height: 100dvh;
  overflow: hidden;
}
body {
  margin: 0;
  min-height: 100%;
  min-height: 100svh;
  min-height: 100dvh;
  height: 100%;
  height: 100svh;
  height: 100dvh;
  max-height: 100dvh;
  max-width: 100vw;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, textarea, input { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ——— Ambient grain + soft vignette (CSS only, GPU-cheap) ——— */
.ambient {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(10, 132, 255, 0.07), transparent 55%),
    radial-gradient(90% 70% at 100% 100%, rgba(0, 200, 83, 0.035), transparent 50%),
    radial-gradient(ellipse at center, transparent 40%, rgba(0, 0, 0, 0.45) 100%);
  opacity: 1;
}
.ambient::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 180px 180px;
  mix-blend-mode: overlay;
}

.app {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  width: 100%;
  max-width: 100vw;
  height: 100%;
  height: 100svh;
  height: 100dvh;
  min-height: 100svh;
  min-height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}

/* ——— Header ——— */
.header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 10px;
  min-height: var(--header-h);
  min-width: 0;
  width: 100%;
  max-width: 100%;
  padding: var(--header-pad-y) var(--grid);
  background: color-mix(in srgb, var(--panel-2) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--divider);
  z-index: 50;
  overflow: visible;
}

.btn-menu {
  display: none;
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  align-items: center; justify-content: center;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.btn-menu:hover { background: var(--accent-dim); color: var(--accent); }
.btn-menu svg { width: 20px; height: 20px; }

.brand {
  display: flex; align-items: center; gap: 10px;
  flex-shrink: 0;
  color: inherit;
  text-decoration: none;
}
.brand-mark {
  width: 28px; height: 28px;
  border-radius: 7px;
  box-shadow: 0 0 0 1px rgba(10,132,255,0.25);
}
.brand-name {
  font-weight: 650;
  letter-spacing: 0.04em;
  font-size: 13px;
  text-transform: uppercase;
}

/* ——— Mode control (compact trigger + popover) ——— */
.mode-control {
  position: relative;
  margin-left: 4px;
  flex-shrink: 1;
  min-width: 0;
}

.mode-trigger {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  max-width: min(300px, 100%);
  min-width: 0;
  width: auto;
  padding: 6px 12px 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--divider-strong);
  background: linear-gradient(180deg, var(--panel-3), var(--panel));
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04), 0 0 0 0 transparent;
  transition:
    border-color var(--dur) var(--ease),
    box-shadow var(--dur) var(--ease),
    background var(--dur) var(--ease),
    transform var(--dur) var(--ease);
}
.mode-trigger:hover {
  border-color: rgba(10,132,255,0.55);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.mode-trigger[aria-expanded="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim), 0 0 24px var(--accent-glow);
  background: linear-gradient(180deg, rgba(10,132,255,0.18), var(--panel));
}
.mode-trigger-kicker {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--accent-dim);
  border: 1px solid rgba(10,132,255,0.28);
  flex-shrink: 0;
}
.mode-trigger-main {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0;
  min-width: 0;
  text-align: left;
}
.mode-trigger-label {
  font-size: 14px;
  font-weight: 650;
  line-height: 1.15;
  color: var(--text);
  white-space: nowrap;
}
.mode-trigger-desc {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}
.mode-chevron {
  color: var(--muted);
  flex-shrink: 0;
  transition: transform var(--dur) var(--ease), color var(--dur) var(--ease);
}
.mode-trigger[aria-expanded="true"] .mode-chevron {
  transform: rotate(180deg);
  color: var(--accent);
}

.mode-popover {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  right: auto;
  z-index: 40;
  width: min(360px, calc(100vw - 24px));
  min-width: 0;
  max-width: min(380px, calc(100vw - 24px));
  /* JS may set --mode-pop-left / --mode-pop-right to keep in viewport */
  transform: translateX(var(--mode-pop-shift, 0px));
}
.mode-popover[hidden] { display: none !important; }
.mode-popover:not([hidden]) .mode-panel {
  animation: modeIn var(--dur) var(--ease) both;
}

.mode-panel {
  background: var(--panel);
  border: 1px solid var(--divider-strong);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
  transform-origin: top left;
}
.mode-panel-head,
.mode-panel-foot {
  padding: 10px 14px;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--panel-2);
}
.mode-panel-foot {
  text-transform: none;
  letter-spacing: 0;
  font-family: var(--mono);
  font-size: 11px;
  border-top: 1px solid var(--divider);
}

.mode-options {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 6px;
  gap: 2px;
}
.mode-option {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  text-align: left;
  color: var(--muted);
  transition: color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.mode-option:hover {
  color: var(--text);
  background: rgba(255,255,255,0.03);
}
.mode-option.active {
  color: var(--text);
}
.mode-option-icon {
  width: 28px; height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--panel-3);
  border: 1px solid var(--divider);
  font-size: 14px;
}
.mode-option.active .mode-option-icon {
  background: var(--accent-dim);
  border-color: rgba(10,132,255,0.45);
  box-shadow: 0 0 12px var(--accent-glow);
}
.mode-option-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.mode-option-label { font-weight: 650; font-size: 14px; color: inherit; }
.mode-option-desc { font-size: 12px; color: var(--muted); }
.mode-option.active .mode-option-desc { color: rgba(245,245,247,0.72); }
.mode-option-key {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--divider);
  border-radius: 6px;
  padding: 2px 6px;
  opacity: 0.85;
}

.mode-indicator {
  position: absolute;
  left: 6px; right: 6px;
  height: 48px;
  top: 6px;
  border-radius: 10px;
  background: linear-gradient(90deg, rgba(10,132,255,0.22), rgba(10,132,255,0.08));
  border: 1px solid rgba(10,132,255,0.45);
  box-shadow: inset 0 0 0 1px rgba(10,132,255,0.12), 0 0 18px var(--accent-glow);
  pointer-events: none;
  z-index: 0;
  transition: transform var(--dur) var(--ease), height var(--dur) var(--ease);
  will-change: transform;
}

@keyframes modeIn {
  from { opacity: 0; transform: translateY(-6px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}
@keyframes modeSheetIn {
  from { transform: translateY(108%); }
  to   { transform: translateY(0); }
}
@keyframes fadeSoft {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Mobile bottom sheet for modes */
.mode-sheet[hidden] { display: none !important; }
.mode-sheet {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.mode-sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.55);
  animation: fadeSoft var(--dur) var(--ease) both;
}
.mode-sheet-panel {
  position: relative;
  width: min(520px, 100%);
  max-width: 100vw;
  max-height: min(70dvh, 480px);
  background: var(--panel);
  border: 1px solid var(--divider-strong);
  border-bottom: none;
  border-radius: 18px 18px 0 0;
  box-shadow: var(--shadow);
  padding: 10px 12px calc(14px + env(safe-area-inset-bottom, 0px));
  animation: modeSheetIn var(--dur) var(--ease) both;
  overflow: auto;
}
.mode-sheet-handle {
  width: 40px; height: 4px;
  border-radius: 999px;
  background: var(--divider-strong);
  margin: 4px auto 12px;
}
.mode-sheet-title {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 6px 10px;
}
.mode-sheet-options { display: flex; flex-direction: column; gap: 4px; }
.mode-sheet .mode-option { padding: 12px; }
.mode-sheet .mode-option.active {
  background: linear-gradient(90deg, rgba(10,132,255,0.22), rgba(10,132,255,0.08));
  border: 1px solid rgba(10,132,255,0.4);
}

.header-spacer { flex: 1 1 8px; min-width: 4px; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  margin-left: auto;
}
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--divider);
  background: var(--panel);
  font-family: var(--mono);
}
.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--muted);
}
.status-pill.ok .status-dot { background: var(--success); box-shadow: 0 0 8px rgba(0,200,83,0.55); }
.status-pill.busy .status-dot { background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
.status-pill.err .status-dot { background: var(--danger); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.icon-btn {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  transition: color var(--dur) var(--ease), background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.icon-btn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover { color: var(--accent); background: var(--accent-dim); border-color: rgba(10,132,255,0.35); }
.icon-btn.on { color: var(--accent); background: var(--accent-dim); border-color: var(--accent); }

/* ——— Sidebar ——— */
.sidebar {
  grid-row: 2 / -1;
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  width: 100%;
  background: var(--panel-2);
  border-right: 1px solid var(--divider);
  overflow: hidden;
  z-index: 15;
}
.sidebar::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 2px;
  background: linear-gradient(180deg, var(--accent) 0%, var(--success) 55%, transparent 100%);
  opacity: 0.9;
  pointer-events: none;
}
.sidebar::after {
  content: "";
  position: absolute;
  left: 2px; top: 0; bottom: 0; width: 24px;
  background: linear-gradient(90deg, rgba(10,132,255,0.06), transparent);
  pointer-events: none;
}

.sidebar-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 12px 12px 12px 14px;
  gap: 12px;
  min-height: 0;
}

.btn-new {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 44px;
  flex: 0 0 auto;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  box-shadow: 0 0 0 1px rgba(10,132,255,0.35), 0 6px 18px rgba(10,132,255,0.22);
  transition: filter var(--dur) var(--ease), box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.btn-new:hover { filter: brightness(1.08); box-shadow: 0 0 0 2px var(--accent-dim), 0 8px 22px rgba(10,132,255,0.3); }
.btn-new svg { width: 16px; height: 16px; }

.history-label {
  flex: 0 0 auto;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  padding: 0 4px;
  font-weight: 600;
}

.history-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
}
.history-item {
  display: flex;
  align-items: center;
  min-height: 44px;
  text-align: left;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 13px;
  border: 1px solid transparent;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.history-item:hover { background: var(--panel); color: var(--text); }
.history-item.active {
  background: var(--accent-dim);
  border-color: rgba(10,132,255,0.4);
  color: var(--text);
}

.sidebar-links {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  gap: 6px 10px;
  font-size: 12px;
  padding-top: 8px;
  border-top: 1px solid var(--divider);
}
.sidebar-links a { color: var(--muted); }
.sidebar-links a:hover { color: var(--accent); }
.sidebar-note {
  flex: 0 0 auto;
  font-size: 11px;
  color: var(--muted);
  opacity: 0.8;
  font-family: var(--mono);
}

/* ——— Main ——— */
.main {
  grid-row: 2;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  width: 100%;
  max-width: 100%;
  background: transparent;
  position: relative;
  overflow: hidden;
}

.messages-wrap {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  width: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--grid);
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
}
.messages {
  width: 100%;
  max-width: var(--msg-col);
  margin: 0 auto;
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-bottom: 8px;
  min-width: 0;
}

.empty {
  text-align: center;
  padding: 56px 16px;
  color: var(--muted);
}
.empty h1 {
  margin: 0 0 8px;
  font-size: 24px;
  font-weight: 650;
  color: var(--text);
  letter-spacing: -0.02em;
}
.empty p { margin: 0 0 22px; font-size: 14px; }
.empty-kicker {
  display: block;
  margin-bottom: 10px;
  color: #8fc7ff;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.product-ribbon {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  padding: 9px 16px;
  border-bottom: 1px solid rgba(10,132,255,0.24);
  background: linear-gradient(90deg, rgba(10,132,255,0.12), rgba(0,200,83,0.055));
}
.product-ribbon-copy {
  display: flex;
  align-items: baseline;
  min-width: 0;
  gap: 10px;
}
.product-ribbon-copy strong {
  flex: 0 0 auto;
  color: #cfe7ff;
  font-size: 12px;
}
.product-ribbon-copy span {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.product-ribbon > a {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 13px;
  border: 1px solid rgba(10,132,255,0.42);
  border-radius: var(--radius-sm);
  color: #e2f0ff;
  background: rgba(10,132,255,0.13);
  text-decoration: none;
  font-size: 12px;
  font-weight: 700;
}
.product-ribbon > a:hover { border-color: var(--accent); background: rgba(10,132,255,0.2); }
.empty-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: -8px 0 20px;
}
.empty-actions a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid rgba(10,132,255,0.42);
  border-radius: var(--radius-sm);
  color: #d9ebff;
  background: var(--accent-dim);
  text-decoration: none;
  font-size: 13px;
  font-weight: 650;
}
.empty-actions a + a {
  border-color: var(--divider);
  color: var(--muted);
  background: transparent;
}
.empty-actions a:hover { color: #fff; border-color: var(--accent); }
.starters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}
.starter {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--divider);
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  max-width: 280px;
  text-align: left;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.starter:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.msg {
  display: flex;
  flex-direction: column;
  gap: 6px;
  animation: fadeIn var(--dur) var(--ease);
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}
.msg-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}
.msg-role { font-weight: 650; color: var(--muted); letter-spacing: 0.02em; }
.msg.user .msg-role { color: var(--text); }
.msg.assistant .msg-role { color: var(--accent); }

.msg-bubble {
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--divider);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.55;
  box-shadow: var(--shadow-soft);
}
.msg.user .msg-bubble {
  background: #141414;
  border-color: #2e2e2e;
}
.msg.assistant .msg-bubble {
  border-left: 2px solid var(--accent);
  background: linear-gradient(180deg, #141820, var(--panel));
}
.msg.error .msg-bubble {
  background: rgba(255, 82, 82, 0.12);
  border-color: rgba(255, 82, 82, 0.4);
  color: #ffb4b4;
}

.msg-bubble.md { white-space: normal; }
.msg-bubble.md p { margin: 0 0 0.75em; }
.msg-bubble.md p:last-child { margin-bottom: 0; }
.msg-bubble.md ul, .msg-bubble.md ol { margin: 0 0 0.75em; padding-left: 1.4em; }
.msg-bubble.md code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: rgba(0,0,0,0.4);
  padding: 1px 5px;
  border-radius: 4px;
}
.msg-bubble.md pre {
  position: relative;
  margin: 0.75em 0;
  padding: 12px 14px;
  background: #0c0c0c;
  border: 1px solid var(--divider);
  border-radius: var(--radius-sm);
  overflow-x: auto;
}
.msg-bubble.md pre code {
  background: none;
  padding: 0;
  font-size: 13px;
  line-height: 1.45;
}
.msg-bubble.md a { color: var(--accent); }
.msg-bubble.md blockquote {
  margin: 0.75em 0;
  padding-left: 12px;
  border-left: 3px solid var(--accent);
  color: var(--muted);
}
.msg-bubble.md img,
.msg-bubble.md video,
.msg-bubble img,
.msg-bubble video {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  margin: 8px 0;
}
.msg-bubble pre,
.msg-bubble.md pre {
  max-width: 100%;
  overflow-x: auto;
}

.code-copy {
  position: absolute;
  top: 8px; right: 8px;
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--panel);
  border: 1px solid var(--divider);
  color: var(--muted);
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.code-copy:hover { color: var(--accent); border-color: var(--accent); }

.msg-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid rgba(10,132,255,0.35);
  font-family: var(--mono);
}
.btn-copy-msg {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 6px;
  color: var(--muted);
  border: 1px solid transparent;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.btn-copy-msg:hover { color: var(--accent); border-color: var(--divider); }

.typing {
  display: inline-flex;
  gap: 4px;
  padding: 4px 0;
}
.typing span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1s ease-in-out infinite;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }

.scroll-bottom {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--divider);
  color: var(--muted);
  font-size: 12px;
  box-shadow: var(--shadow-soft);
  display: none;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.scroll-bottom.show { display: inline-flex; }
.scroll-bottom:hover { color: var(--accent); border-color: var(--accent); }

/* ——— Composer (flush, never permanently disabled) ——— */
.composer {
  grid-column: 2;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  border-top: 1px solid var(--divider);
  background: color-mix(in srgb, var(--bg) 92%, #000);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 8px var(--grid) env(safe-area-inset-bottom, 0px);
  z-index: 20;
  flex-shrink: 0;
}
.composer-inner {
  width: 100%;
  max-width: var(--msg-col);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0;
  min-width: 0;
}
.composer-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 6px;
  border-radius: 14px;
  border: 1px solid var(--divider-strong);
  background: var(--panel);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.03), var(--shadow-soft);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
  min-width: 0;
  width: 100%;
}
.composer-row:focus-within {
  border-color: rgba(10,132,255,0.55);
  box-shadow: 0 0 0 3px var(--accent-dim), var(--shadow-soft);
}
#composer-input {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  min-height: var(--composer-min);
  max-height: min(140px, 30dvh);
  resize: none;
  padding: 14px 12px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--text);
  line-height: 1.45;
}
#composer-input:focus { outline: none; }
#composer-input::placeholder { color: var(--muted); }

.btn-stop, .btn-send {
  height: var(--composer-min);
  min-width: clamp(56px, 18vw, 72px);
  padding: 0 clamp(10px, 2.5vw, 16px);
  border-radius: 10px;
  font-weight: 650;
  font-size: 14px;
  flex-shrink: 0;
  transition: filter var(--dur) var(--ease), opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.btn-send {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 6px 16px rgba(10,132,255,0.28);
}
.btn-send:hover:not(:disabled) { filter: brightness(1.08); }
.btn-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
}
.btn-stop {
  display: none;
  background: #5a2430;
  color: #fff;
}
.btn-stop.on { display: inline-flex; align-items: center; justify-content: center; }

.composer-hint { display: none !important; }
.composer-hint-legacy {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  padding: 0 4px;
}

/* ——— Footer ——— */
.footer {
  grid-column: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: 6px var(--grid) 10px;
  font-size: 11px;
  color: var(--muted);
  background: transparent;
  flex-shrink: 0;
}
.footer a { color: var(--muted); }
.footer a:hover { color: var(--accent); }
.watermark {
  opacity: 0.12;
  font-weight: 650;
  letter-spacing: 0.08em;
  pointer-events: none;
  user-select: none;
}

/* ——— Modal ——— */
.modal-root[hidden] { display: none !important; }
.modal-root {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  animation: fadeSoft var(--dur) var(--ease) both;
}
.modal-card {
  position: relative;
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--divider-strong);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 20px;
  z-index: 1;
  animation: modeIn var(--dur) var(--ease) both;
}
.modal-card h2 {
  margin: 0 0 16px;
  font-size: 16px;
  font-weight: 650;
}
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--divider);
  font-size: 14px;
}
.setting-row:last-of-type { border-bottom: none; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}
.btn-secondary {
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--divider);
  background: var(--panel-2);
  color: var(--text);
  font-weight: 500;
  transition: border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger {
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  background: rgba(255,82,82,0.15);
  border: 1px solid rgba(255,82,82,0.4);
  color: #ffb4b4;
  font-weight: 500;
}

.toggle {
  width: 40px; height: 22px;
  border-radius: 999px;
  background: var(--divider);
  position: relative;
  border: none;
  flex-shrink: 0;
  transition: background var(--dur) var(--ease);
}
.toggle::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform var(--dur) var(--ease);
}
.toggle.on { background: var(--accent); }
.toggle.on::after { transform: translateX(18px); }

/* ——— Toast ——— */
.toasts {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  min-width: 220px;
  max-width: 360px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--panel);
  border: 1px solid var(--divider-strong);
  box-shadow: var(--shadow);
  font-size: 13px;
  color: var(--text);
  animation: fadeIn var(--dur) var(--ease);
}
.toast.err {
  border-color: rgba(255,82,82,0.5);
  background: #2a1518;
  color: #ffb4b4;
}
.toast.ok { border-color: rgba(0,200,83,0.45); }

/* ——— Mid / tablet compress (before drawer) ——— */
@media (max-width: 1100px) {
  .mode-trigger-desc { display: none; }
  .mode-trigger { max-width: min(220px, 42vw); padding: 6px 10px; gap: 8px; }
  .brand-name { font-size: 12px; letter-spacing: 0.03em; }
}

@media (max-width: 1024px) {
  .status-pill .status-label { max-width: 72px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* --- Sidebar drawer + phone layout --- */
@media (max-width: 900px) {
  /* mobile-shell-v2 */
  /* visualViewport owns the shell height; the composer stays in flex flow. */
  html {
    height: 100%;
    height: var(--app-height, 100dvh);
  }
  body {
    min-height: 100%;
    height: var(--app-height, 100dvh);
    max-height: var(--app-height, 100dvh);
    overflow: hidden;
  }
  .app {
    display: flex;
    flex-direction: column;
    grid-template-columns: none;
    grid-template-rows: none;
    width: 100%;
    max-width: 100vw;
    height: var(--app-height, 100dvh);
    min-height: 0;
    max-height: var(--app-height, 100dvh);
    overflow: hidden;
  }
  .header {
    flex: 0 0 auto;
    width: 100%;
    flex-wrap: nowrap;
    min-height: var(--header-h);
    padding-top: max(var(--header-pad-y), env(safe-area-inset-top, 0px));
  }
  .btn-menu { display: inline-flex; flex-shrink: 0; }
  .sidebar {
    position: fixed;
    top: var(--header-h-current, var(--header-h));
    left: 0;
    bottom: calc(var(--composer-h, 60px) + var(--vv-bottom-inset, 0px));
    width: min(340px, calc(100vw - 24px));
    max-width: calc(100vw - 24px);
    transform: translateX(-105%);
    transition: transform var(--dur) var(--ease);
    box-shadow: var(--shadow);
    z-index: 45;
    grid-row: auto;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-dim {
    display: none;
    position: fixed;
    top: var(--header-h-current, var(--header-h));
    right: 0;
    bottom: calc(var(--composer-h, 60px) + var(--vv-bottom-inset, 0px));
    left: 0;
    background: rgba(0,0,0,0.45);
    z-index: 40;
    pointer-events: none;
  }
  .sidebar-dim.on {
    display: block;
    pointer-events: auto;
  }
  .main {
    flex: 1 1 0;
    min-height: 0;
    width: 100%;
    grid-row: auto;
    padding-bottom: 0;
  }
  .messages-wrap {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    padding: 12px 12px 8px;
  }
  .composer {
    position: relative;
    left: auto;
    right: auto;
    bottom: auto;
    grid-column: auto;
    width: 100%;
    max-width: 100vw;
    margin: 0;
    flex-shrink: 0;
    z-index: 50;
    /* ONLY safe-area on bottom — no max(8px,...), no extra 12px */
    padding: 8px 8px env(safe-area-inset-bottom, 0px);
    border-top: 1px solid var(--divider);
    box-sizing: border-box;
  }
  .composer-inner {
    gap: 0;
    max-width: 100%;
    margin: 0;
  }
  .composer-row {
    padding: 4px;
    border-radius: 12px;
    gap: 6px;
  }
  #composer-input {
    min-height: var(--composer-min);
    padding: 10px 10px;
  }
  .btn-stop, .btn-send {
    height: var(--composer-min);
  }
  .composer-hint { display: none !important; }
  .sidebar-links a {
    display: inline-flex;
    align-items: center;
    min-height: 40px;
    padding: 0 2px;
  }
  .footer {
    display: none !important;
    height: 0 !important;
    min-height: 0 !important;
    max-height: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    border: 0 !important;
    overflow: hidden !important;
    visibility: hidden !important;
    pointer-events: none !important;
  }
  .brand-name { display: none; }
  .mode-trigger-desc { display: none; }
  .mode-trigger {
    max-width: min(200px, calc(100vw - 160px));
    padding: 6px 10px;
  }
  .mode-control { flex: 1 1 auto; min-width: 0; }
  .mode-popover { display: none !important; }
  .status-pill .status-label { display: none; }
  .header-spacer { display: none; }
  .header-actions { flex-shrink: 0; }
  .toasts {
    right: 12px;
    left: 12px;
    bottom: calc(var(--composer-h, 60px) + 8px + var(--vv-bottom-inset, 0px));
    max-width: calc(100vw - 24px);
  }
}

@media (max-width: 375px) {
  .mode-trigger-kicker { display: none; }
  .btn-send, .btn-stop { min-width: 52px; padding: 0 10px; font-size: 13px; }
  .header { gap: 6px; padding-left: 10px; padding-right: 10px; }
  .icon-btn { width: 34px; height: 34px; }
}

@media (max-width: 900px) and (max-height: 520px) {
  .sidebar {
    width: min(560px, calc(100vw - 24px));
    max-width: calc(100vw - 24px);
  }
  .sidebar-inner {
    gap: 4px;
    padding: 4px 8px 4px 10px;
  }
  .btn-new { min-height: 40px; padding-block: 6px; }
  .history-label, .sidebar-note { display: none; }
  .sidebar-links {
    flex-wrap: nowrap;
    gap: 0 12px;
    min-height: 40px;
    overflow-x: auto;
    overflow-y: hidden;
    padding-top: 0;
    scrollbar-width: thin;
  }
  .sidebar-links a { flex: 0 0 auto; }
}

@media (max-width: 480px) {
  .product-ribbon { padding: 7px 10px; }
  .product-ribbon-copy { display: block; }
  .product-ribbon-copy strong, .product-ribbon-copy span { display: block; }
  .product-ribbon-copy span { max-width: 180px; margin-top: 1px; }
  .product-ribbon > a { padding-inline: 11px; }
}

@media (max-width: 320px) {
  .status-pill { padding: 4px 6px; }
  .brand-mark { width: 24px; height: 24px; }
  .mode-trigger { max-width: min(140px, calc(100vw - 130px)); }
}

/* Desktop/tablet: hide sheet (popover only) */
@media (min-width: 901px) {
  .mode-sheet { display: none !important; }
  .sidebar-dim { display: none !important; pointer-events: none !important; }
  .sidebar.open { /* no-op on desktop — drawer class ignored */ }
}

/* Touch devices keep nonessential desktop chrome out of the compact shell. */
@media (hover: none) and (pointer: coarse) {
  .composer-hint { display: none !important; }
  .footer {
    display: none !important;
    height: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: hidden !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .mode-indicator { transition: none !important; }
}


/* —— Sing / Play song + settings audio stubs (pro5) —— */
.btn-play-song {
  appearance: none;
  border: 1px solid var(--divider);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
  border-radius: 999px;
  padding: 4px 10px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.btn-play-song:hover { border-color: var(--accent); }
.btn-play-song.playing {
  animation: hal-sing-pulse 1.2s ease-in-out infinite;
}
@keyframes hal-sing-pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 35%, transparent); }
  50% { box-shadow: 0 0 0 6px transparent; }
}
.setting-row-stack {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}
.setting-select,
.setting-input {
  width: 100%;
  border: 1px solid var(--divider);
  background: var(--panel);
  color: inherit;
  border-radius: 10px;
  padding: 8px 10px;
  font: inherit;
}
.setting-inline {
  display: flex;
  gap: 8px;
  align-items: center;
}
.setting-inline .setting-input { flex: 1; min-width: 0; }
.sfx-results {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 160px;
  overflow: auto;
  font-size: 12px;
}
.sfx-results a {
  color: var(--accent);
  text-decoration: none;
  word-break: break-all;
}
.sfx-results a:hover { text-decoration: underline; }
.sfx-note { opacity: 0.7; }

/* SFX search results (audio v2) — keep away from composer/footer layout */
.sfx-item{display:flex;align-items:center;gap:8px;padding:4px 0;flex-wrap:wrap}
.sfx-item .sfx-play{flex:0 0 auto;padding:4px 10px;font-size:12px}
.sfx-note{opacity:.75;font-size:12px;padding:4px 0}


/* hal-sounds Play chips (pro10) */
.hal-sounds-ui {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 8px 0 4px;
  padding: 8px 10px;
  border: 1px solid var(--border, #333);
  border-radius: 10px;
  background: rgba(255,255,255,0.03);
}
.hal-sounds-ui .sfx-note { opacity: 0.7; font-size: 12px; margin-right: 4px; }
.hal-sounds-ui .sound-chip { flex: 0 0 auto; }
.hal-sounds-ui .sound-chip.playing {
  outline: 1px solid var(--accent, #6cf);
  opacity: 1;
}
.sfx-autoplay-note { width: 100%; margin-top: 4px; }
