/* SafetyBuddy AI — MUX tri-split layout (mu.html + ai.html) */
:root {
  --mux-teal: #2dd4a8;
  --mux-teal-dim: #1f7a66;
  --mux-conv-w: 220px;
  --mux-setup-w: 380px;
  --mux-chat-bg: #212121;
  --mux-chat-surface: #2f2f2f;
  --mux-chat-border: #424242;
  --mux-chat-text: #ececec;
  --mux-chat-muted: #9ca3af;
  --mux-conv-bg: #171717;
  --mux-conv-hover: #2a2a2a;
  --mux-conv-active: #343434;
  --mux-side-bg: #1a2420;
  --mux-side-border: #2a4038;
  --mux-side-text: #e8f0ec;
  --mux-side-muted: #8fa89c;
}

body.ai-mux-page .hero.ai-hero-fill { min-height: calc(100dvh - 80px); }
body.ai-mux-page .hero.ai-hero-fill > .container { max-width: 1440px; padding: 0 8px 12px; }
body.ai-mux-page .ai-wrap { max-width: none; }
body.ai-mux-page .ai-panel.mux-host {
  background: transparent; border: none; box-shadow: none; padding: 0;
}

.mux-app {
  min-height: calc(100dvh - 140px);
  display: flex; flex-direction: column;
  border: 1px solid var(--mux-chat-border); border-radius: 10px; overflow: hidden;
  position: relative;
}
.mux-topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; background: var(--mux-chat-surface);
  border-bottom: 1px solid var(--mux-chat-border);
}
.mux-topbar h1 { margin: 0; font-size: 1.05rem; font-weight: 800; color: var(--mux-chat-text); }
.mux-topbar-actions { display: flex; gap: 5px; flex-wrap: wrap; }
.mux-topbar-actions button, .mux-topbar-actions a {
  padding: 5px 10px; border-radius: 6px; border: 1px solid var(--mux-chat-border);
  background: #383838; color: var(--mux-chat-text); font-size: 0.72rem; cursor: pointer; text-decoration: none;
}

.mux-tri,
.tri-split {
  flex: 1; display: grid;
  grid-template-columns: var(--mux-conv-w) 1fr var(--mux-setup-w);
  min-height: 0; position: relative;
}
body.mux-left-collapsed .mux-tri,
body.mux-left-collapsed .tri-split { grid-template-columns: 0 1fr var(--mux-setup-w); }
body.mux-right-collapsed .mux-tri,
body.mux-right-collapsed .tri-split { grid-template-columns: var(--mux-conv-w) 1fr 0; }
body.mux-left-collapsed.mux-right-collapsed .mux-tri,
body.mux-left-collapsed.mux-right-collapsed .tri-split { grid-template-columns: 0 1fr 0; }

/* Left conversation rail */
.mux-conv-rail,
.conv-rail {
  background: var(--mux-conv-bg); border-right: 1px solid var(--mux-chat-border);
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
  transition: opacity 0.2s ease;
}
body.mux-left-collapsed .mux-conv-rail,
body.mux-left-collapsed .conv-rail { opacity: 0; pointer-events: none; overflow: hidden; }
.mux-conv-head { padding: 10px; border-bottom: 1px solid var(--mux-chat-border); display: flex; gap: 6px; align-items: center; }
.mux-conv-collapse {
  width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--mux-chat-border);
  background: transparent; color: var(--mux-chat-muted); cursor: pointer; flex-shrink: 0;
}
.mux-conv-new {
  flex: 1; padding: 10px; border: 1px solid var(--mux-chat-border); border-radius: 8px;
  background: transparent; color: var(--mux-chat-text); font-size: 0.85rem; cursor: pointer; text-align: left;
}
.mux-conv-list { flex: 1; overflow-y: auto; padding: 6px; min-height: 0; }
.mux-conv-item {
  display: block; width: 100%; text-align: left; padding: 10px; margin-bottom: 2px;
  border: none; border-radius: 8px; background: transparent; color: var(--mux-chat-muted);
  font-size: 0.82rem; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.mux-conv-item:hover { background: var(--mux-conv-hover); color: var(--mux-chat-text); }
.mux-conv-item.active { background: var(--mux-conv-active); color: var(--mux-chat-text); }
.mux-conv-foot { padding: 8px; border-top: 1px solid var(--mux-chat-border); font-size: 0.65rem; color: #666; }

/* Edge tabs unused — CHATS/SETUP live in center chat-view-bar */
.mux-edge-tab { display: none !important; }

/* Center chat */
.mux-chat-col { display: flex; flex-direction: column; background: var(--mux-chat-bg); min-height: 0; }
.mux-thread { flex: 1; overflow-y: auto; padding: 20px 16px 12px; }
.mux-empty { text-align: center; margin-top: 10vh; padding: 0 20px; }
.mux-empty h2 {
  font-size: clamp(1.2rem, 3.5vw, 1.65rem); font-weight: 600;
  color: var(--mux-chat-text); margin: 0 0 10px; line-height: 1.35;
}
.mux-empty .mux-tagline { font-size: 0.78rem; color: var(--mux-chat-muted); }

.mux-bubble { max-width: 680px; margin: 0 auto 14px; line-height: 1.55; font-size: 0.94rem; color: var(--mux-chat-text); }
.mux-bubble.user { background: var(--mux-chat-surface); border-radius: 16px; padding: 12px 16px; }
.mux-bubble .meta { font-size: 0.65rem; color: var(--mux-chat-muted); margin-bottom: 4px; text-transform: uppercase; }

.mux-composer-wrap { padding: 10px 14px 16px; }
.mux-composer {
  max-width: 680px; margin: 0 auto; display: flex; align-items: flex-end; gap: 6px;
  background: var(--mux-chat-surface); border: 1px solid var(--mux-chat-border);
  border-radius: 24px; padding: 8px 8px 8px 14px;
}
.mux-composer textarea, .mux-composer input {
  flex: 1; border: none; outline: none; background: transparent;
  color: var(--mux-chat-text); font-size: 0.95rem; font-family: inherit; resize: none;
}
.mux-composer .mux-send {
  background: var(--mux-teal-dim); color: #fff; border: none; border-radius: 18px;
  padding: 8px 16px; font-weight: 700; cursor: pointer; white-space: nowrap;
}
.mux-composer.disabled .mux-send { opacity: 0.45; pointer-events: none; }
.mux-composer.disabled textarea,
.mux-composer.disabled input { pointer-events: auto; opacity: 1; }

/* Right setup column */
.mux-setup-col,
.setup-col {
  background: var(--mux-side-bg); border-left: 2px solid var(--mux-teal-dim);
  overflow-y: auto; padding: 10px 8px; display: flex; flex-direction: column; gap: 10px;
  color: var(--mux-side-text); min-height: 0;
  transition: opacity 0.2s ease;
}
body.mux-right-collapsed .mux-setup-col,
body.mux-right-collapsed .setup-col { opacity: 0; pointer-events: none; overflow: hidden; }
.mux-setup-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: -4px; }
.mux-setup-collapse {
  width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--mux-side-border);
  background: #243029; color: var(--mux-side-muted); cursor: pointer;
}

.mux-panel {
  border: 2px solid var(--mux-teal-dim); border-radius: 8px; padding: 12px 14px;
  background: #1e2a24; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}
.mux-sec-q { font-size: 0.8rem; font-weight: 700; color: var(--mux-side-text); margin: 0 0 8px; line-height: 1.3; }
.mux-sec-sub { font-size: 0.68rem; color: var(--mux-side-muted); margin: -2px 0 6px; }

.mux-btn-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.mux-chip {
  padding: 8px 4px; border: 1px solid var(--mux-side-border); border-radius: 6px;
  background: #243029; color: var(--mux-side-text); font-size: 0.72rem; font-weight: 700;
  cursor: pointer; text-align: center;
}
.mux-chip.active { border-color: var(--mux-teal); background: #1a3d32; color: var(--mux-teal); }
.mux-chip.hidden { display: none; }

.mux-prov-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 4px;
}
.mux-prov-row .mux-chip {
  flex: none;
  min-width: 0;
  width: 100%;
  padding: 10px 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.mux-prov-row .mux-chip[data-prov="claude"] { order: 1; }
.mux-prov-row .mux-chip[data-prov="cursor"] { order: 2; }
.mux-prov-row a.mux-prov-request { order: 3; border-style: dashed; opacity: 0.9; }
.mux-prov-row .mux-chip[data-prov="gemini"] { order: 4; }
.mux-prov-row .mux-chip[data-prov="chatgpt"] { order: 5; }
.mux-prov-row .mux-chip[data-prov="groq"] { order: 6; }
body.mux-help-team .mux-prov-row .mux-chip.active:not(.c5-baton-current),
body.skill-expert .mux-prov-row .mux-chip.active:not(.c5-baton-current) { box-shadow: 0 0 0 2px var(--mux-teal); }
.mux-prov-note { font-size: 0.7rem; color: var(--mux-teal); margin: 4px 0 0; font-weight: 600; }

.mux-step-rail { display: flex; gap: 4px; }
.mux-step-badge {
  flex: 1; text-align: center; padding: 5px 2px; border-radius: 6px;
  font-size: 0.6rem; font-weight: 700; border: 1px solid var(--mux-side-border);
  background: #243029; color: var(--mux-side-muted); line-height: 1.15;
}
.mux-step-badge.active { border-color: var(--mux-teal); color: var(--mux-teal); background: #1a3d32; }
.mux-step-badge.done { opacity: 0.65; }

.mux-field-block { margin-bottom: 6px; }
.mux-field-block.accepted textarea { opacity: 0.75; border-color: #3a5a48; }
.mux-field-block.accepted .mux-btn-accept { background: #2a5040; color: var(--mux-teal); }
.mux-field-block .lbl { font-size: 0.68rem; font-weight: 800; color: var(--mux-teal); display: block; margin-bottom: 3px; }
.mux-field-block textarea {
  width: 100%; border: 1px solid var(--mux-side-border); border-radius: 8px; padding: 8px;
  font-size: 0.8rem; min-height: 44px; background: #1e2a24; color: var(--mux-side-text);
  font-family: inherit; resize: vertical; box-sizing: border-box;
}
.mux-field-block.active textarea { border-color: var(--mux-teal); }
.mux-btn-accept {
  width: 100%; margin-top: 4px; padding: 6px; border: none; border-radius: 6px;
  background: var(--mux-teal-dim); color: #fff; font-weight: 700; font-size: 0.75rem; cursor: pointer;
}
.mux-main-prompt-lbl { font-size: 0.65rem; font-weight: 700; color: var(--mux-side-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.mux-main-prompt {
  margin-top: 4px; padding: 8px; min-height: 56px; max-height: 100px; overflow-y: auto;
  border: 1px dashed var(--mux-teal-dim); border-radius: 8px; background: #142018;
  font-size: 0.75rem; line-height: 1.45; color: #b8d4c8; white-space: pre-wrap;
}
.mux-main-prompt.empty { color: var(--mux-side-muted); font-style: italic; }
.mux-btn-continue {
  width: 100%; padding: 12px; background: var(--mux-teal-dim); color: #fff; border: none;
  border-radius: 8px; font-weight: 700; font-size: 0.9rem; cursor: pointer;
}
.mux-btn-continue:disabled { opacity: 0.4; cursor: not-allowed; }

/* Library gate dialog */
.mux-library-dlg {
  border: none; border-radius: 12px; max-width: 520px; width: calc(100% - 24px);
  background: #fffdf8; color: #1c2a24; padding: 0;
  max-height: min(92dvh, 720px);
}
.mux-library-dlg--mobile {
  width: 100%; max-width: none; height: 100dvh; max-height: 100dvh;
  margin: 0; border-radius: 0;
}
.mux-library-dlg::backdrop { background: rgba(0,0,0,0.55); }
.mux-library-inner {
  display: flex; flex-direction: column; max-height: inherit; height: 100%;
}
.mux-library-header {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 18px 18px 0; flex-shrink: 0;
}
.mux-library-header h2 { margin: 0; flex: 1; }
.mux-library-close {
  flex-shrink: 0; width: 36px; height: 36px; border: none; border-radius: 8px;
  background: #e8e8e8; color: #333; font-size: 1.1rem; line-height: 1; cursor: pointer;
}
.mux-library-body {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 12px 18px 8px;
}
.mux-library-body p { margin: 0 0 10px; line-height: 1.55; font-size: 0.92rem; }
.mux-library-actions {
  flex-shrink: 0; display: flex; gap: 8px; flex-wrap: wrap; flex-direction: column;
  padding: 12px 18px 18px; border-top: 1px solid #e0e0e0; background: #fffdf8;
}
.mux-library-actions button { width: 100%; }
.mux-ios-steps-wrap { margin-top: 10px; font-size: 0.85rem; color: #333; }
.mux-ios-steps-wrap summary { cursor: pointer; font-weight: 600; color: #145a4c; }
.mux-ios-steps { margin: 8px 0 0; padding-left: 1.2rem; line-height: 1.45; }
.mux-ios-tip { font-size: 0.8rem; color: #666; margin: 8px 0 0; }
.mux-library-inner h2 { font-size: 1.2rem; color: var(--mux-teal-deep, #145a4c); }
.mux-library-highlight {
  background: #e8f5f0; border-left: 4px solid var(--mux-teal-dim);
  padding: 12px 14px; border-radius: 6px; margin: 12px 0; font-size: 0.88rem;
}
.mux-library-folder-hint {
  font-family: ui-monospace, monospace; font-size: 0.85rem;
  background: #f0f0f0; padding: 8px 10px; border-radius: 6px; margin: 8px 0 14px;
}
.mux-library-actions button {
  flex: 1; min-width: 140px; padding: 10px 14px; border-radius: 8px; font-weight: 700; cursor: pointer; border: none;
}
.mux-library-actions .primary { background: var(--mux-teal-dim); color: #fff; }
.mux-library-actions .secondary { background: #e8e8e8; color: #333; }
/* FIX 2026-09-22 (Bill: mobile "Sync from Cloud" looked like a line of tiny
   text instead of a button): .mux-library-actions button had no :disabled
   styling here (unlike the sidebar's .cloud-hs-btn:disabled), so a disabled
   Save-to-Cloud/Sync-from-Cloud button could render with little to no visual
   weight depending on the browser. Now explicitly dimmed but still clearly a
   button, same idea as the sidebar version. */
.mux-library-actions button:disabled { opacity: 0.5; cursor: not-allowed; }
.mux-restore-list { display: flex; flex-direction: column; gap: 6px; margin: 4px 0 10px; }
.mux-restore-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid #ddd; border-radius: 8px; background: #fff; }
.mux-restore-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.mux-restore-info strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.92rem; }
.mux-restore-info span { font-size: 0.78rem; color: #666; }
.mux-restore-btn { flex-shrink: 0; padding: 8px 14px; border: none; border-radius: 8px; font-weight: 700; cursor: pointer; background: var(--mux-teal-dim, #2a6b5a); color: #fff; }
.mux-restore-btn:disabled { opacity: 0.5; cursor: default; }

.mux-drawer-done { display: none; }
.mux-drawer-backdrop { display: none; }

/* Hide legacy ai.html chrome as soon as ai-mux-page loads (before JS mount) */
body.ai-mux-page .ai-brand,
body.ai-mux-page .ai-top-help,
body.ai-mux-page .mode-section,
body.ai-mux-page .skill-section,
body.ai-mux-page .learning-center-section,
body.ai-mux-page .provider-section,
body.ai-mux-page .agentic-provider-section {
  display: none !important;
}
body.ai-mux-page .hero.ai-hero-fill {
  background: #0f0f0f !important;
}
body.ai-mux-page .ai-panel {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
}

/* Hide legacy ai.html chrome when mux mounted (detail panels) */
body.ai-mux-page.mux-mounted .conversation-bar,
body.ai-mux-page.mux-mounted #panelEntry > .ai-step-label,
body.ai-mux-page.mux-mounted #panelEntry > .entry-title,
body.ai-mux-page.mux-mounted #panelEntry > .entry-hint,
body.ai-mux-page.mux-mounted #noviceSetupFields,
body.ai-mux-page.mux-mounted #panelEntry > .btn-row,
body.ai-mux-page.mux-mounted #panelEntry > #continueBtn,
body.ai-mux-page.mux-mounted #panelEntry > #startOverBtn,
body.ai-mux-page.mux-mounted #panelEntry > #stopBtn {
  display: none !important;
}
body.ai-mux-page.mux-mounted #workArea { display: block !important; }
body.ai-mux-page.mux-mounted #workArea > p:first-child { display: none; }

@media (max-width: 1100px) {
  .mux-tri { grid-template-columns: 0 1fr var(--mux-setup-w); }
  body:not(.mux-left-collapsed) .mux-tri { grid-template-columns: var(--mux-conv-w) 1fr var(--mux-setup-w); }
  .tri-split { grid-template-columns: 0 1fr var(--mux-setup-w); }
  body:not(.mux-left-collapsed) .tri-split { grid-template-columns: var(--mux-conv-w) 1fr var(--mux-setup-w); }
}
@media (max-width: 768px) {
  .mux-tri,
  body.mux-left-collapsed .mux-tri,
  body.mux-right-collapsed .mux-tri,
  body.mux-left-collapsed.mux-right-collapsed .mux-tri,
  .tri-split,
  body.mux-left-collapsed .tri-split,
  body.mux-right-collapsed .tri-split,
  body.mux-left-collapsed.mux-right-collapsed .tri-split {
    grid-template-columns: 1fr !important;
  }
  body.mux-left-collapsed .mux-edge-tab--left,
  body.mux-right-collapsed .mux-edge-tab--right {
    display: none !important;
  }
  .mux-drawer-done { display: inline-block; }
  .mux-drawer-backdrop:not([hidden]) { display: block; }
}
@media (max-width: 768px) {
  .mux-drawer-done { display: inline-block; }
  .mux-drawer-backdrop:not([hidden]) { display: block; }
}

/* FIX 2026-09-23 (K-v2.94, Bill): SYNC INSTRUCTIONS — replaces the old
   #muxConvFoot "Library: SafetyBuddy-AI" status text/link (fully redundant
   with the Library button in .cloud-lib-actions above it). Skinny, full-
   width button, same green family as .cloud-lib-btn / .cloud-hs-btn. */
.sync-instr-btn {
  width: 100%;
  padding: 5px 8px;
  border-radius: 6px;
  border: 1px solid var(--teal-dim);
  background: #243029;
  color: var(--teal);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  font-family: inherit;
  text-align: center;
}
.sync-instr-btn:hover { background: #2c3a32; }
