:root {
  --bg: #09070f;
  --panel: rgba(22, 16, 34, 0.88);
  --panel-strong: rgba(27, 19, 42, 0.96);
  --ink: #eee8ff;
  --muted: #b4a8d9;
  --line: rgba(182, 138, 255, 0.18);
  --user: linear-gradient(135deg, #7c3aed 0%, #4f46e5 100%);
  --user-ink: #f9f4ff;
  --assistant: rgba(38, 28, 58, 0.94);
  --slot: rgba(255, 255, 255, 0.04);
  --slot-ink: #dcd2ff;
  --accent: #b68aff;
  --accent-soft: rgba(182, 138, 255, 0.14);
  --card: rgba(255, 255, 255, 0.035);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(124, 58, 237, 0.34), transparent 28%),
    radial-gradient(circle at 80% 10%, rgba(79, 70, 229, 0.24), transparent 24%),
    linear-gradient(180deg, #140f22 0%, var(--bg) 100%);
  background-attachment: fixed;
  background-repeat: no-repeat;
  background-size: cover;
  color: var(--ink);
  font-family: "SF Mono", "IBM Plex Mono", "Menlo", monospace;
}

.app-shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 24px auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  height: calc(100vh - 48px);
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  overflow: hidden;
  box-shadow: 0 28px 80px rgba(5, 3, 12, 0.55);
  backdrop-filter: blur(18px);
}

.sidebar {
  padding: 20px 18px;
  border-right: 1px solid var(--line);
  background: rgba(15, 10, 24, 0.78);
  height: 100%;
  overflow-y: auto;
  border-top-left-radius: 24px;
  border-bottom-left-radius: 24px;
}

.sidebar h1 {
  margin: 0 0 18px;
  font-size: 18px;
  font-weight: 500;
}

.nav-tabs {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.nav-tab {
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  border-radius: 14px;
  padding: 12px 14px;
  text-align: left;
  font: inherit;
  cursor: pointer;
}

.nav-tab.is-active {
  background: var(--accent-soft);
  color: var(--ink);
  border-color: var(--line);
}

.main-panel {
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.view-panel {
  display: none;
  height: 100%;
  min-height: 0;
}

.view-panel.is-active {
  display: grid;
}

#view-chat {
  grid-template-rows: auto 1fr auto;
}

#view-heartbeat {
  grid-template-rows: auto 1fr;
}

.chat-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
}

.heartbeat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 4px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  font-size: 11px;
}

.chat-header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 500;
}

.helper-copy {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.chat-thread,
.heartbeat-thread {
  padding: 24px 20px 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.empty-state {
  color: var(--muted);
  padding: 12px;
}

.bubble {
  max-width: min(78ch, 78%);
  padding: 14px 16px;
  border-radius: 18px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.55;
  font-size: 14px;
}

.bubble.user {
  align-self: flex-end;
  background: var(--user);
  color: var(--user-ink);
  border-bottom-right-radius: 4px;
  box-shadow: 0 16px 40px rgba(94, 58, 168, 0.26);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.screenshot-badge {
  align-self: flex-end;
  font-size: 10px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  padding: 2px 7px;
  white-space: nowrap;
}

.assistant-turn {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.origin-badge {
  align-self: flex-start;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--accent);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.bubble.assistant {
  align-self: flex-start;
  background: var(--assistant);
  color: var(--ink);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
  box-shadow: 0 12px 28px rgba(6, 4, 15, 0.28);
  overflow-x: hidden;
}

.trace-slot {
  align-self: flex-start;
  width: min(92ch, 100%);
  background: var(--slot);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0;
  overflow: hidden;
  backdrop-filter: blur(10px);
}

.trace-slot summary {
  cursor: pointer;
  list-style: none;
  padding: 10px 14px;
  color: var(--accent);
  font-size: 12px;
  user-select: none;
  background: var(--accent-soft);
}

.trace-slot summary::-webkit-details-marker {
  display: none;
}

.trace-content {
  margin: 0;
  padding: 0 14px 14px;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
  font-size: 12px;
  line-height: 1.5;
  color: var(--slot-ink);
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 16px 18px 18px;
  border-top: 1px solid var(--line);
  background: rgba(16, 12, 26, 0.82);
}

.composer-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
}

.screenshot-toggle-btn {
  align-self: stretch;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.78rem;
  padding: 7px 14px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.screenshot-toggle-btn.is-active {
  background: rgba(99, 102, 241, 0.18);
  border-color: #6366f1;
  color: #a5b4fc;
}

.composer textarea {
  width: 100%;
  resize: none;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  padding: 14px 16px;
  font: inherit;
  color: var(--ink);
}

.composer textarea::placeholder {
  color: var(--muted);
}

.composer button,
.secondary-button {
  align-self: end;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, #8b5cf6 0%, #6366f1 100%);
  color: #fff8ff;
  font: inherit;
  padding: 12px 18px;
  cursor: pointer;
  box-shadow: 0 12px 30px rgba(104, 74, 208, 0.28);
}

.secondary-button {
  background: linear-gradient(135deg, #31254e 0%, #4a3a74 100%);
}

.composer button:disabled,
.secondary-button:disabled {
  opacity: 0.55;
  cursor: wait;
}

.heartbeat-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.heartbeat-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.heartbeat-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
}

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

.heartbeat-field {
  display: grid;
  gap: 4px;
}

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

.heartbeat-value {
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

@media (max-width: 860px) {
  .app-shell {
    width: 100vw;
    height: 100vh;
    margin: 0;
    border-radius: 0;
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .sidebar {
    height: auto;
    min-height: 0;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    overflow-y: visible;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }

  .nav-tabs {
    flex-direction: row;
  }

  .bubble,
  .trace-slot {
    max-width: 100%;
    width: 100%;
  }
}
