:root {
  color-scheme: dark;
  --bg: #0b1020;
  --panel: #121a2d;
  --text: #e8ecf4;
  --muted: #a5b0c2;
  --accent: #7cb3ff;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  width: 100%;
}

@media (min-width: 769px) {
  body {
    margin-left: auto;
    margin-right: auto;
    max-width: none;
  }
}

.app-shell {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  width: 100%;
  position: relative;
}

@media (min-width: 769px) {
  .app-shell {
    max-width: 90vw;
    margin-left: auto;
    margin-right: auto;
    min-height: 100vh;
  }

  /* Let nav/account dropdowns paint over the main column; avoid clipping the account rail. */
  .app-shell-sidebar {
    overflow: visible;
    z-index: 3000;
  }

  .app-shell-main {
    position: relative;
    z-index: 0;
    /* Sidebar is fixed on desktop; offset matches measured chrome height (see ananke-app.js). */
    padding-top: var(--aleph-shell-top-offset, 52px);
  }
}

.app-shell-sidebar {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  z-index: 1250;
  overflow: hidden;
}

.app-shell-chrome-inner {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  min-width: 0;
}

@media (min-width: 769px) {
  .app-shell-sidebar {
    width: 90vw;
    max-width: 100%;
    border-right: none;
    border-bottom: 1px solid #2a3657;
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    box-sizing: border-box;
    overflow: visible;
  }

  .app-shell-chrome-inner {
    flex-direction: row;
    align-items: center;
    gap: 6px;
    padding: 0 10px 0 4px;
    flex: none;
    min-height: 52px;
    overflow: visible;
  }

  .app-shell-brand-row {
    flex-shrink: 0;
    border-bottom: none;
  }

  .app-shell-nav {
    flex: 1;
    min-width: 0;
    min-height: 0;
    overflow: visible;
  }

  .app-shell-user-nav {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    min-width: 0;
    overflow: visible;
  }
}

.app-shell-brand-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  flex-shrink: 0;
  border-bottom: 1px solid #2a3657;
  gap: 0;
}

.app-shell-brand-row #headerRoot {
  flex: 1;
  min-width: 0;
}

.app-shell-nav {
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  background: transparent;
}

.app-shell-user-nav {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  min-width: 0;
  overflow: visible;
}

.app-shell-main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.app-shell-mobile-bar {
  display: none;
  flex-shrink: 0;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top, 8px));
  border-bottom: 1px solid #2a3657;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 1100;
}

.app-shell-burger {
  min-width: 44px;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid #2a3657;
  background: transparent;
  color: var(--text);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  font-family: inherit;
}

.app-shell-burger:hover {
  color: var(--text);
  background: rgba(124, 179, 255, 0.1);
}

.app-shell-mobile-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.app-shell-mobile-header-slot {
  display: none;
}

@media (max-width: 768px) {
  .app-shell-mobile-header-slot {
    display: flex;
    flex: 1;
    min-width: 0;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
  }

  .app-shell-mobile-header-slot:empty {
    display: none;
  }

  .app-shell-mobile-bar:has(#headerMobileSlot:not(:empty)) .app-shell-mobile-title {
    display: none;
  }

  .app-shell-mobile-header-slot .app-header {
    padding: 4px 0;
    width: 100%;
    min-width: 0;
  }

  .app-shell-brand-row:empty {
    display: none;
  }

}

.app-shell-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 1240;
}

.app-shell-backdrop:not([hidden]) {
  display: block;
}

body.app-shell-sidebar-open {
  overflow: hidden;
}

@media (max-width: 768px) {
  .app-shell-mobile-bar {
    display: flex;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 2000 !important;
    box-shadow: 0 1px 0 #2a3657;
    flex-wrap: nowrap;
    align-items: center;
    overflow: visible;
    isolation: isolate;
  }

  .app-shell-burger {
    flex: 0 0 auto;
    order: -1;
    position: relative;
    z-index: 10;
    cursor: pointer;
  }

  .app-shell-mobile-header-slot {
    position: relative;
    z-index: 2100;
    min-width: 0;
    max-width: 100%;
    overflow: visible;
  }

  /* Title already in bar; hide duplicate wordmark inside header when slotted */
  .app-shell-mobile-header-slot .app-header-left {
    display: none !important;
  }

  .app-shell-mobile-header-slot .app-header {
    padding: 2px 0;
    justify-content: flex-end;
    width: 100%;
    min-width: 0;
  }

  .app-shell-main {
    position: relative;
    z-index: 1;
  }

  .app-shell-chrome-inner {
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }

  /* ID + class: win specificity wars with any third-party or stale rules */
  #shellSidebar.app-shell-sidebar {
    --shell-sidebar-width: min(240px, 78vw);
    position: fixed !important;
    left: 0 !important;
    right: auto !important;
    top: var(--aleph-shell-top-offset, 52px) !important;
    bottom: 0 !important;
    height: auto !important;
    width: var(--shell-sidebar-width) !important;
    max-width: 78vw !important;
    margin: 0 !important;
    flex-shrink: 0 !important;
    border-right: 1px solid #2a3657;
    transform: translate3d(-105%, 0, 0) !important;
    transition: transform 0.2s ease;
    box-shadow: 8px 0 24px rgba(0, 0, 0, 0.35);
    z-index: 1250 !important;
  }

  .app-shell:not(.sidebar-open) #shellSidebar.app-shell-sidebar {
    pointer-events: none;
  }

  .app-shell.sidebar-open #shellSidebar.app-shell-sidebar {
    transform: translate3d(0, 0, 0) !important;
    pointer-events: auto;
  }

  /* Nav mobile flyout extends past the drawer; default sidebar overflow would clip it */
  body.nav-flyout-open #shellSidebar.app-shell-sidebar {
    overflow: visible !important;
  }
}

body[data-public-agent] .app-shell-sidebar,
body[data-public-agent] .app-shell-mobile-bar,
body[data-public-agent] .app-shell-backdrop {
  display: none !important;
}

body[data-public-agent] .app-shell-main {
  width: 100%;
}

#headerRoot {
  flex-shrink: 0;
}

#headerRoot:empty {
  display: none;
}

#navRoot {
  position: relative;
  top: auto;
  z-index: auto;
  background: transparent;
  overflow: hidden;
}

#navRoot > * {
  min-width: 0;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

@media (min-width: 769px) {
  #navRoot {
    overflow: visible;
    z-index: 2;
  }

  #navRoot > * {
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    min-height: auto;
    flex: 1;
    overflow: visible;
  }
}

.app-header-entitlements[hidden] {
  display: none !important;
}

.app-header-plan {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent, #7cb3ff);
  border: 1px solid #3d4f7a;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.app-header-usage-meter {
  flex: 1;
  min-width: 72px;
  max-width: 100%;
}

.app-header-usage-label {
  font-size: 0.68rem;
  color: var(--muted, #a5b0c2);
  margin-bottom: 2px;
  white-space: nowrap;
}

.app-header-usage-bar {
  height: 4px;
  background: #2a3657;
  border-radius: 2px;
  overflow: hidden;
}

.app-header-usage-fill {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #5b8cff, #7cb3ff);
  border-radius: 2px;
  transition: width 0.2s ease;
}

.app-header-usage-unlimited {
  font-size: 0.68rem;
  color: var(--muted, #a5b0c2);
  white-space: nowrap;
}

.app-header-usage-warn {
  font-size: 0.68rem;
  color: #f59e0b;
  white-space: nowrap;
}

.app-header-btn {
  border: 1px solid #2a3657;
  background: transparent;
  color: var(--muted, #a5b0c2);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 0.82rem;
  cursor: pointer;
  font-family: inherit;
  text-decoration: none;
}

.app-header-btn:hover {
  color: var(--text, #e8ecf4);
  background: rgba(124, 179, 255, 0.1);
}

.app-header-upgrade {
  color: var(--accent, #7cb3ff) !important;
  border-color: #3d4f7a !important;
}

#footerRoot {
  flex-shrink: 0;
  margin-top: auto;
}

#footerRoot:empty {
  display: none;
}

.app-root {
  flex: 1;
  min-height: 0;
  padding: 14px;
  max-width: 100%;
  overflow: auto;
}

.app-agent-wrap {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: calc(100vh - 70px);
  position: relative;
}

.app-edit-agent-bar {
  flex-shrink: 0;
  width: 100%;
  padding: 0 0 10px;
  margin: 0;
  border: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  row-gap: 6px;
  max-width: 100%;
  box-sizing: border-box;
}

.app-edit-agent-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 0.85rem;
  color: var(--accent);
  text-decoration: none;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
}

.app-edit-agent-btn:hover {
  background: rgba(124, 179, 255, 0.15);
  color: var(--text);
}
.app-edit-agent-bar .app-back-from-test {
  margin-right: 0.75rem;
  font-weight: 500;
}

.app-agent-content {
  flex: 1;
  min-height: 0;
}

/*
 * aleph-chat is position:fixed (desktop) to the viewport, not the flow box.
 * Without this, it starts at --aleph-shell-top-offset and draws over .app-edit-agent-bar.
 */
@media (min-width: 769px) {
  .app-agent-wrap:has(.app-edit-agent-bar) {
    --app-edit-agent-bar-offset: 2.75rem;
  }
  .app-agent-wrap:has(.app-edit-agent-bar) aleph-chat {
    top: calc(var(--aleph-shell-top-offset, 52px) + var(--app-edit-agent-bar-offset, 2.75rem));
  }
}

/* CEL for Buffalo: ensure dark theme when component is mounted */
.app-root.agent-cel-for-buffalo .app-agent-content {
  background: #0a0e17;
}

@media (max-width: 768px) {
  .app-shell {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    max-width: 100%;
  }

  .app-shell-main {
    flex: 1 1 auto;
    min-height: auto;
    overflow: visible;
    width: 100%;
    max-width: 100%;
  }

  .app-root {
    overflow-x: hidden;
    overflow-y: visible;
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding-top: calc(var(--aleph-shell-top-offset, 52px) + 12px);
    padding-right: max(0px, env(safe-area-inset-right, 0px));
    padding-bottom: 12px;
    padding-left: max(0px, env(safe-area-inset-left, 0px));
  }

  .app-agent-wrap {
    height: auto;
    min-height: auto;
  }

  .app-agent-content {
    flex: none;
    min-height: 0;
    overflow: visible;
  }
}

@media (max-width: 480px) {
  .app-root {
    padding-top: calc(var(--aleph-shell-top-offset, 52px) + 10px);
    padding-right: max(0px, env(safe-area-inset-right, 0px));
    padding-bottom: 10px;
    padding-left: max(0px, env(safe-area-inset-left, 0px));
  }
}

/* Component responsive overrides */
@media (max-width: 768px) {
  .gm-grid {
    grid-template-columns: 1fr !important;
  }
  .fd-viewport {
    padding: 12px !important;
  }

  /* CEL path: content 90% of screen on mobile */
  .app-root.agent-cel-for-buffalo .app-agent-content,
  .app-root.agent-cel-functions-hub .app-agent-content,
  .app-root.agent-cel-user-guide .app-agent-content,
  .app-root.agent-business-analysis .app-agent-content,
  .app-root.agent-use-case-cel-questions .app-agent-content,
  .app-root.agent-question-wizard .app-agent-content,
  .app-root.agent-evaluation-wizard .app-agent-content,
  .app-root.agent-cel-business-evaluator .app-agent-content,
  .app-root.agent-evaluation-dashboard .app-agent-content,
  .app-root.agent-cel-dashboard .app-agent-content,
  .app-root.agent-cel-expert-panels .app-agent-content,
  .app-root.agent-cel-intelligence-orchestrator .app-agent-content {
    width: 90vw !important;
    max-width: 90vw !important;
    margin-left: auto !important;
    margin-right: auto !important;
  }

  /* JSON survey: use full viewport width on mobile */
  .app-root.agent-questions-json-survey {
    padding-left: max(0px, env(safe-area-inset-left, 0px));
    padding-right: max(0px, env(safe-area-inset-right, 0px));
  }
  .app-root.agent-questions-json-survey .app-agent-content {
    width: 100% !important;
    max-width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
}

/* CEL path: content 80% of screen on tablet and desktop */
@media (min-width: 769px) {
  .app-root.agent-cel-for-buffalo .app-agent-content,
  .app-root.agent-questions-json-survey .app-agent-content,
  .app-root.agent-cel-functions-hub .app-agent-content,
  .app-root.agent-cel-user-guide .app-agent-content,
  .app-root.agent-business-analysis .app-agent-content,
  .app-root.agent-use-case-cel-questions .app-agent-content,
  .app-root.agent-question-wizard .app-agent-content,
  .app-root.agent-evaluation-wizard .app-agent-content,
  .app-root.agent-cel-business-evaluator .app-agent-content,
  .app-root.agent-evaluation-dashboard .app-agent-content,
  .app-root.agent-cel-dashboard .app-agent-content,
  .app-root.agent-cel-expert-panels .app-agent-content,
  .app-root.agent-cel-intelligence-orchestrator .app-agent-content {
    width: 80vw !important;
    max-width: 80vw !important;
    margin-left: auto !important;
    margin-right: auto !important;
  }
}

@media (max-width: 480px) {
  .gm-btn,
  .fd-card-open,
  button,
  a.btn {
    min-height: 44px;
    padding: 10px 14px;
  }
}

.chess-embed {
  width: 100%;
  max-width: 100%;
}

.app-root.agent-chess-game {
  padding-left: 4px;
  padding-right: 4px;
}

/* Settings split screen */
.app-root.split-active {
  padding: 14px 0;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

.split-container {
  display: grid;
  grid-template-columns: 1fr min(420px, 45%);
  flex: 1;
  min-width: 0;
  min-height: 0;
  width: 100%;
}

.split-left {
  min-width: 0;
  overflow: auto;
  padding: 0 14px;
  position: relative;
  isolation: isolate;
}
/* Chat in split: contain within split-left instead of fixed viewport overlay */
.app-root.split-active .split-left aleph-chat {
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
}

@media (max-width: 768px) {
  .app-root.split-active .split-left aleph-chat .chat-messages {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
  }
}

.split-left.agent-chess-game {
  padding-left: 4px;
  padding-right: 4px;
}

.split-right {
  min-width: 280px;
  overflow: hidden;
  background: var(--panel);
  border-left: 1px solid rgba(255, 255, 255, 0.08);
  padding: 0;
  display: flex;
  flex-direction: column;
  isolation: isolate;
}
.split-right-wrap { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.split-right-header {
  flex-shrink: 0;
  padding: 8px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.2);
}
.split-back-to-edit {
  background: transparent;
  border: 1px solid rgba(124, 92, 252, 0.5);
  color: var(--accent, #7c3aed);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
}
.split-back-to-edit:hover { background: rgba(124, 92, 252, 0.15); }
.split-right-agent { flex: 1; min-height: 0; overflow-y: auto; padding: 14px; }

@media (max-width: 768px) {
  .split-container {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }
  .split-right {
    min-width: 0;
    border-left: none;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
  }
}

.status {
  padding: 10px 12px;
  border: 1px solid #2a3657;
  border-radius: 10px;
  background: #0f172b;
  color: var(--muted);
  max-width: 100%;
  word-wrap: break-word;
}

.status.error {
  border-color: #5f2c39;
  color: #ffb3c2;
}

a {
  color: var(--accent);
}

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--bg);
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.loading-overlay[aria-hidden="true"] {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--panel);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

/* Agent creator: each question with tap buttons */
.agent-creator-questions {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: relative;
  z-index: 1;
  pointer-events: auto;
}

.question-block {
  padding: 12px 14px;
  background: rgba(124, 179, 255, 0.08);
  border: 1px solid rgba(124, 179, 255, 0.25);
  border-radius: 8px;
}

.question-block-label {
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 8px;
  color: var(--text);
}

.question-block-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  position: relative;
  z-index: 1;
}

.question-block-btns button,
.question-block-btns .ui-pref-option,
.question-block-btns .doc-choice-btn {
  pointer-events: auto;
}

.question-block-build {
  margin-top: 12px;
}

.question-block-build .build-btn {
  font-weight: 600;
}

.question-block-build .build-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Agent creator UI preference block (legacy, used inside question-block) */
.ui-preference-block {
  margin-top: 10px;
  padding: 10px 12px;
  background: rgba(124, 179, 255, 0.08);
  border: 1px solid rgba(124, 179, 255, 0.25);
  border-radius: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
}

.ui-pref-option {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0.5rem 1rem;
  cursor: pointer;
  font-size: 0.95rem;
  border: 1px solid var(--accent, #7c5cfc);
  border-radius: 8px;
  color: var(--accent, #7c5cfc);
  background: transparent;
  transition: background 0.15s, color 0.15s;
  touch-action: manipulation;
  position: relative;
}

.ui-pref-option:hover {
  background: var(--accent, #7c5cfc);
  color: #fff;
}

.ui-pref-option.selected {
  background: var(--accent, #7c5cfc);
  color: #fff;
}

.ui-pref-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.ui-pref-info {
  width: 18px;
  height: 18px;
  padding: 0;
  border: none;
  background: var(--muted);
  color: var(--bg);
  border-radius: 50%;
  font-size: 0.7rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.ui-pref-info:hover {
  background: var(--accent);
  color: var(--bg);
}

.ui-pref-popover {
  z-index: 10000;
  max-width: 280px;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid rgba(124, 179, 255, 0.3);
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--text);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Agent creator documents choice block */
.documents-choice-block {
  margin-top: 10px;
  padding: 10px 12px;
  background: rgba(124, 179, 255, 0.08);
  border: 1px solid rgba(124, 179, 255, 0.25);
  border-radius: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.doc-choice-btn {
  min-height: 44px;
  padding: 0.5rem 1rem;
  font-size: 0.95rem;
  background: transparent;
  border: 1px solid var(--accent, #7c5cfc);
  border-radius: 8px;
  color: var(--accent, #7c5cfc);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  touch-action: manipulation;
}

.doc-choice-btn:hover:not(:disabled) {
  background: var(--accent, #7c5cfc);
  color: #fff;
}

.doc-choice-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.doc-choice-btn.selected {
  background: var(--accent, #7c5cfc);
  color: #fff;
}

.doc-choice-btn.selected:disabled {
  opacity: 0.9;
}

/* Agent creator "I'm not sure" button */
.dont-know-block {
  margin-top: 10px;
  padding: 10px 12px;
  background: rgba(124, 179, 255, 0.08);
  border: 1px solid rgba(124, 179, 255, 0.25);
  border-radius: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.animation-choice-block {
  margin-top: 10px;
  padding: 10px 12px;
  background: rgba(124, 179, 255, 0.08);
  border: 1px solid rgba(124, 179, 255, 0.25);
  border-radius: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
