:root {
  --bg: #edf0f5;
  --frame: #f7f8fa;
  --frame-border: #d7dde8;
  --header-bg: #f3f5f8;
  --ink: #0f1728;
  --muted: #94a0b3;
  --line: #dce2ec;
  --bubble: #eef2f8;
  --bubble-border: #d8deea;
  --blue: #2f69e1;
  --blue-soft: #d8e7ff;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Noto Sans", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  line-height: 1.5;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background: radial-gradient(circle at 18% 14%, #f7f9fc 0%, var(--bg) 60%);
  color: var(--ink);
}

body.sidebar-open {
  overflow: hidden;
}

.viewport {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  justify-content: stretch;
  justify-items: stretch;
  padding: 4px;
}

.viewport.with-sidebar {
  grid-template-columns: clamp(240px, 24vw, 300px) minmax(0, 1fr);
  gap: 8px;
  align-items: stretch;
}

.terminal {
  width: 100%;
  max-width: min(1320px, calc(100vw - 8px));
  height: min(1120px, calc(100vh - 8px));
  border-radius: 18px;
  border: 1px solid var(--frame-border);
  background: var(--frame);
  box-shadow: 0 20px 50px rgba(16, 26, 48, 0.1);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  justify-self: center;
}

.viewport.with-sidebar .terminal {
  max-width: none;
  justify-self: stretch;
}

.terminal-body {
  min-height: 0;
  height: 100%;
  padding: 18px 16px 8px;
  background: var(--frame);
  display: flex;
  overflow: hidden;
}

.terminal-sidebar {
  width: min(300px, calc(100vw - 8px));
  height: min(1120px, calc(100vh - 8px));
  min-height: 0;
  border: 1px solid #d8dbe3;
  border-radius: 10px;
  background: #f5f6f8;
  padding: 12px 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.sidebar-account {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px 10px;
}

.sidebar-account-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: #111317;
  color: #ffffff;
  display: grid;
  place-items: center;
  font-size: 0.9rem;
}

.sidebar-account-meta {
  min-width: 0;
  flex: 1;
}

.sidebar-account-name {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 700;
  color: #111827;
}

.sidebar-account-plan {
  margin: 0;
  font-size: 0.84rem;
  color: #4b5563;
}

.sidebar-account-arrow {
  color: #4b5563;
  font-size: 1rem;
}

.sidebar-eyebrow {
  margin: 10px 10px 8px;
  font-size: 0.82rem;
  font-weight: 600;
  color: #6b7280;
}

.sidebar-eyebrow.secondary {
  margin-top: 18px;
}

.sidebar-item {
  width: 100%;
  border: 0;
  border-radius: 10px;
  background: transparent;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px;
  font: inherit;
  color: #111827;
  text-align: left;
  cursor: pointer;
}

.sidebar-item:hover {
  background: #eceff3;
}

.sidebar-item-main {
  margin-bottom: 2px;
}

.sidebar-item-icon {
  width: 18px;
  text-align: center;
  color: #111827;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.sidebar-item-label {
  flex: 1;
  min-width: 0;
  font-size: 0.96rem;
  font-weight: 500;
  line-height: 1.2;
}

.sidebar-item-arrow {
  color: #374151;
  font-size: 1rem;
}

.sidebar-subtree {
  border-left: 1px solid #d8dde6;
  margin: 0 0 8px 16px;
  padding-left: 10px;
  padding-bottom: 4px;
}

.sidebar-hint {
  margin: 6px 8px 8px;
  font-size: 0.82rem;
  line-height: 1.35;
  color: #6b7280;
}

.sidebar-projects {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-item.plain .sidebar-item-label {
  font-size: 0.9rem;
}

.terminal-topbar {
  background: var(--header-bg);
  border-bottom: 1px solid var(--line);
  padding: 18px 26px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.window-dots {
  display: flex;
  gap: 7px;
}

.window-dots span {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #c0cad8;
}

.window-dots span:nth-child(1) {
  background: #22c55e;
}

.window-dots span:nth-child(2) {
  background: #eab308;
}

.window-dots span:nth-child(3) {
  background: #3b82f6;
}

.topbar-divider {
  width: 1px;
  height: 20px;
  background: var(--line);
}

.workspace-title {
  margin: 0;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.8rem;
  color: #8a96ab;
  letter-spacing: 0.08em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.live-badge {
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 0.7rem;
  font-weight: 700;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
}

.chip {
  min-width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 1px solid #ced6e5;
  display: grid;
  place-items: center;
  font-size: 0.66rem;
  font-weight: 800;
  color: #192238;
  background: #fff;
}

.chip.blue {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.icon-btn {
  border: 0;
  background: transparent;
  color: #8793a8;
  width: 28px;
  height: 28px;
  cursor: pointer;
  font-size: 0.95rem;
}

.sidebar-toggle-btn {
  display: none;
  min-height: 32px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid #cfd8e8;
  background: #ffffff;
  color: #0f1d33;
  font: inherit;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  z-index: 120;
  background: rgba(15, 23, 42, 0.38);
}

.terminal-chat {
  min-height: 0;
  flex: 1;
  height: 100%;
  background: var(--frame);
}

.chat-messages {
  height: 100%;
  overflow-y: auto;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #f4f6fa;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bubble {
  width: fit-content;
  max-width: min(85%, 760px);
  border-radius: 14px;
  border: 1px solid var(--bubble-border);
  background: var(--bubble);
  padding: 12px 14px;
  box-shadow: 0 1px 2px rgba(16, 26, 48, 0.03);
}

.bubble.agent {
  align-self: flex-start;
  position: relative;
  margin-left: 54px;
}

.bubble.agent::before {
  content: "⚡";
  position: absolute;
  left: -48px;
  top: 0;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  color: #8ec2ff;
  background: #101a34;
  font-size: 0.8rem;
}

.bubble.customer {
  align-self: flex-end;
  background: linear-gradient(145deg, #3f73e3, var(--blue));
  border-color: #2f5ece;
}

.bubble b {
  display: block;
  margin-bottom: 6px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.bubble.agent b {
  color: #8f9bb0;
}

.bubble.customer b {
  color: rgba(255, 255, 255, 0.78);
}

.bubble-text {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  line-height: 1.5;
  font-size: 0.9rem;
  font-family: "Noto Sans", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  color: #15213a;
}

.bubble.customer .bubble-text {
  color: #fff;
  font-family: "Noto Sans", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-size: 0.9rem;
}

.bubble.is-typing .bubble-text::after {
  content: "|";
  margin-left: 2px;
  color: currentColor;
  animation: caret-blink 0.8s step-end infinite;
}

.bubble.media-bubble {
  width: min(82%, 760px);
}

.bubble-image {
  width: 100%;
  max-height: 460px;
  object-fit: contain;
  border-radius: 10px;
  border: 1px solid #d5dceb;
  background: #fff;
}

.media-zoom-wrap {
  position: relative;
}

.media-zoom-btn {
  display: none;
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 34px;
  height: 34px;
  border: 1px solid #d1d8e6;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

.terminal-keyboard {
  border-top: 1px solid var(--line);
  background: var(--frame);
  padding: 16px 8px 20px;
  display: grid;
  gap: 12px;
  overflow: visible;
}

.terminal-controls {
  display: grid;
  gap: 10px;
}

.doc-actions,
.decision-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  width: 100%;
}

.doc-actions .doc-btn,
.decision-actions .doc-btn {
  width: 100%;
}

.doc-btn,
.btn-link {
  min-width: 0;
  min-height: 54px;
  padding: 10px 14px;
  border-radius: 14px;
  border: 2px solid #d7deea;
  background: #f4f6fa;
  color: #0f1d33;
  font: inherit;
  font-size: 0.84rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 120ms ease, transform 120ms ease, box-shadow 120ms ease;
}

.doc-btn:hover,
.btn-link:hover {
  border-color: #9bb6e9;
  transform: translateY(-1px);
  box-shadow: 0 8px 16px rgba(47, 105, 225, 0.14);
}

.nav-actions .doc-btn:hover,
.step-back-wrap .doc-btn:hover {
  background: linear-gradient(145deg, #eef4ff, #e3edff);
  border-color: #8faeea;
  color: #224a9a;
}

.doc-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.nav-actions,
.step-back-wrap {
  display: none;
  justify-content: flex-end;
  width: 120px;
}

.back-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  width: 100%;
}

.back-actions .doc-btn {
  width: 100%;
}

.topic-actions {
  display: none;
  flex-direction: column;
  flex-wrap: nowrap;
  gap: 2px;
  max-height: 100%;
  overflow-y: auto;
  padding: 2px 0 4px;
}

.topic-group {
  margin: 4px 0;
  padding-left: 2px;
}

.topic-group-title {
  position: relative;
  margin: 0;
  padding: 7px 8px 6px 18px;
  font-size: 0.77rem;
  font-weight: 700;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.topic-group-title::before {
  content: "▾";
  position: absolute;
  left: 2px;
  top: 7px;
  font-size: 0.72rem;
  color: #6b7280;
}

.topic-group-list {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-left: 10px;
  padding: 2px 0 2px 12px;
}

.topic-group-list::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 0;
  bottom: 0;
  width: 1px;
  background: #d8dde6;
}

.topic-btn {
  position: relative;
  width: 100%;
  min-width: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #111827;
  padding: 6px 8px;
  text-align: left;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1.3;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
  cursor: pointer;
  box-shadow: none;
}

.topic-btn.branch-item {
  padding-left: 18px;
}

.topic-btn.branch-item::before {
  content: "";
  position: absolute;
  left: -8px;
  top: 50%;
  width: 12px;
  height: 1px;
  background: #d8dde6;
  transform: translateY(-50%);
}

.topic-btn.branch-item::after {
  content: "";
  position: absolute;
  left: 2px;
  top: 50%;
  width: 5px;
  height: 5px;
  border-radius: 999px;
  background: #c0c8d7;
  transform: translateY(-50%);
}

.topic-btn:hover {
  background: #eceff3;
}

.topic-btn.done {
  color: #0f766e;
}

.topic-btn.current {
  background: #eef2f7;
  color: #111827;
  font-weight: 700;
}

.topic-btn.current.branch-item::after {
  background: #2563eb;
}

.topic-btn.is-locked:not(.current):not(.done) {
  background: transparent;
  color: #9ca3af;
  cursor: not-allowed;
  opacity: 0.95;
}

.topic-btn.current.is-locked {
  opacity: 1;
}

.topic-btn.done.is-locked {
  opacity: 1;
}

.has-tooltip {
  position: relative;
}

.has-tooltip::after {
  content: none;
}

.has-tooltip::before {
  content: none;
}

.floating-tooltip {
  --tt-bg: #0a0a0a;
  --tt-fg: #ffffff;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 9999;
  max-width: min(280px, calc(100vw - 20px));
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--tt-bg);
  color: var(--tt-fg);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  line-height: 1.25;
  box-shadow: 0 10px 20px rgba(10, 10, 10, 0.32);
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity 120ms ease, transform 120ms ease;
}

.floating-tooltip::after {
  content: "";
  position: absolute;
  left: var(--arrow-x, 50%);
  transform: translateX(-50%);
  top: 100%;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 6px solid var(--tt-bg);
}

.floating-tooltip.below::after {
  top: -6px;
  border-top: 0;
  border-bottom: 6px solid var(--tt-bg);
}

.floating-tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}

.floating-tooltip.tt-current {
  --tt-bg: #2563eb;
  --tt-fg: #ffffff;
}

.floating-tooltip.tt-next {
  --tt-bg: #f59e0b;
  --tt-fg: #111827;
}

.floating-tooltip.tt-other {
  --tt-bg: #9ca3af;
  --tt-fg: #111827;
}

.floating-tooltip.tt-done {
  --tt-bg: #22c55e;
  --tt-fg: #052e16;
}

@media (max-width: 900px) {
  .viewport {
    padding: 10px;
  }

  .terminal {
    width: 100%;
    height: calc(100vh - 20px);
    border-radius: 12px;
  }

  .viewport.with-sidebar {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .terminal-topbar {
    padding: 14px 12px;
  }

  .sidebar-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .workspace-title {
    font-size: 0.7rem;
  }

  .terminal-body {
    padding: 12px 10px 8px;
    gap: 10px;
  }

  .chat-messages {
    padding: 10px 8px;
  }

  .terminal-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: min(320px, calc(100vw - 34px));
    height: 100vh;
    max-height: none;
    border-radius: 0 12px 12px 0;
    z-index: 130;
    padding: 10px;
    transform: translateX(-100%);
    transition: transform 180ms ease;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.18);
  }

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

  .bubble,
  .bubble.media-bubble,
  .bubble.agent {
    width: 100%;
    max-width: 100%;
    margin-left: 0;
  }

  .bubble.agent::before {
    display: none;
  }

  .bubble-text {
    font-size: 0.86rem;
  }

  .bubble-image {
    max-height: 70vh;
  }

  .media-zoom-btn {
    display: inline-grid;
    place-items: center;
  }

  .doc-actions,
  .decision-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .terminal-keyboard {
    padding: 12px 8px 14px;
    gap: 10px;
  }

  .topic-actions {
    max-height: 100%;
    gap: 8px;
  }
}

@keyframes caret-blink {
  0%,
  49% {
    opacity: 1;
  }
  50%,
  100% {
    opacity: 0;
  }
}

/* Topic button hover states */
.topic-btn:not(.is-locked):hover {
  background: #eceff3 !important;
  color: #0f172a !important;
  box-shadow: none !important;
}

.topic-btn.done:not(.is-locked):hover {
  background: #eceff3 !important;
  color: #0f766e !important;
}

.topic-btn.current:not(.is-locked):hover {
  background: #eceff3 !important;
  color: #111827 !important;
}
