:root {
  --bg: #0a0e14;
  --surface: #131a24;
  --surface-2: #1a2433;
  --surface-3: #243044;
  --text: #e8eef7;
  --muted: #8494ad;
  --accent: #4f8cff;
  --accent-glow: rgba(79, 140, 255, 0.35);
  --accent-hover: #3b7aed;
  --success: #34d399;
  --success-glow: rgba(52, 211, 153, 0.3);
  --warning: #fbbf24;
  --error: #f87171;
  --border: #2a364a;
  --assistant-bg: #182333;
  --user-bg: #1a3555;
  --log-info: #7dd3fc;
  --log-chunk: #a78bfa;
  --log-success: #34d399;
  --log-error: #f87171;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  overflow-x: hidden;
  max-width: 100%;
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100dvh;
  height: 100dvh;
  overflow: hidden;
  overflow-x: hidden;
  max-width: 100%;
  display: flex;
  flex-direction: column;
}

.header {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  padding: 0.875rem 1.25rem;
  flex-shrink: 0;
}

.header-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo {
  font-size: 1.5rem;
}

.brand h1 {
  font-size: 1.1rem;
  font-weight: 700;
}

.brand p {
  font-size: 0.78rem;
  color: var(--muted);
}

.header-stats {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.mini-stat {
  text-align: center;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent);
}

.mini-stat small {
  display: block;
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.status {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.status.ok .status-dot {
  background: var(--success);
  box-shadow: 0 0 8px var(--success-glow);
}

.status.error .status-dot {
  background: var(--error);
}

.workspace {
  display: grid;
  grid-template-columns: 320px 1fr 280px;
  flex: 1;
  min-height: 0;
  min-width: 0;
  gap: 0;
  max-width: 100%;
}

.workspace > * {
  min-height: 0;
}

.panel {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--surface);
  min-height: 0;
}

.progress-panel {
  border-right: none;
  border-left: 1px solid var(--border);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: 48px;
  height: 48px;
  padding: 0 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  flex-shrink: 0;
}

.panel-header h2 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
  line-height: 1;
}

.panel-header-spacer {
  width: 52px;
  height: 24px;
  flex-shrink: 0;
}

.panel-header-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.logs-close-btn {
  display: none;
}

.logs-drawer-backdrop {
  display: none;
}

.logs-drawer-handle {
  display: none;
}

.logs-edge-swipe {
  display: none;
}

.progress-edge-swipe {
  display: none;
}

.progress-drawer-handle {
  display: none;
}

.progress-close-btn {
  display: none;
}

.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.72rem;
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
  cursor: pointer;
}

.ghost-btn:hover {
  color: var(--text);
  border-color: var(--muted);
}

/* Logs */
.logs {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
  font-family: "JetBrains Mono", "Fira Code", ui-monospace, monospace;
  font-size: 0.72rem;
}

.log-line {
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 0.5rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid rgba(42, 54, 74, 0.5);
  animation: logIn 0.35s ease-out;
}

@keyframes logIn {
  from {
    opacity: 0;
    transform: translateX(-6px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.log-time {
  color: var(--muted);
  flex-shrink: 0;
}

.log-msg {
  word-break: break-word;
}

.log-info .log-msg { color: var(--log-info); }
.log-chunk .log-msg { color: var(--log-chunk); }
.log-success .log-msg { color: var(--log-success); }
.log-error .log-msg { color: var(--log-error); }

.log-chunk-spoiler {
  margin-top: 0.15rem;
}

.log-chunk-spoiler summary {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  list-style: none;
  user-select: none;
  color: var(--log-chunk);
}

.log-chunk-spoiler summary::-webkit-details-marker {
  display: none;
}

.chunk-arrow {
  display: inline-block;
  font-size: 0.6rem;
  color: var(--muted);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.log-chunk-spoiler[open] .chunk-arrow {
  transform: rotate(90deg);
}

.chunk-summary-text {
  font-weight: 500;
}

.log-chunk-spoiler summary:hover .chunk-summary-text {
  color: #c4b5fd;
}

.log-chunk-card {
  margin-top: 0.4rem;
  margin-left: 1rem;
  padding: 0.5rem;
  background: var(--surface-3);
  border-radius: 6px;
  border-left: 2px solid var(--log-chunk);
}

.log-chunk-card .chunk-title {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.15rem;
}

.log-chunk-card .chunk-meta {
  color: var(--muted);
  font-size: 0.68rem;
  margin-bottom: 0.25rem;
}

.log-chunk-card .chunk-snippet {
  color: #b8c5d9;
  font-size: 0.68rem;
  line-height: 1.45;
}

/* Chat */
.chat-panel {
  background: var(--bg);
  border-right: none;
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.chat-body {
  --chat-form-offset: 6.5rem;
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  min-height: 0;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  isolation: isolate;
}

.chat-body::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 7rem;
  background: linear-gradient(to top, var(--bg) 55%, rgba(10, 14, 20, 0));
  pointer-events: none;
  z-index: 2;
}

.chat-log {
  position: relative;
  flex: 1 1 0;
  height: 0;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1.25rem;
  padding-bottom: var(--chat-form-offset);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
  max-width: 100%;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

.message {
  padding: 0.875rem 1rem;
  border-radius: 12px;
  max-width: 88%;
  min-width: 0;
  flex-shrink: 0;
  overflow: hidden;
  animation: msgIn 0.4s cubic-bezier(0.22, 1, 0.36, 1);
  line-height: 1.5;
}

@keyframes msgIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.message.user {
  align-self: flex-end;
  display: flex;
  align-items: center;
  background: linear-gradient(135deg, var(--user-bg), #1f4068);
  border: 1px solid rgba(79, 140, 255, 0.2);
}

.message.assistant {
  align-self: flex-start;
  background: var(--assistant-bg);
  border: 1px solid var(--border);
  max-width: 96%;
  width: 96%;
  min-width: 0;
}

.message p {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.5;
}

.message.loading p {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin: 0;
  min-height: 1.5em;
  color: var(--muted);
}

/* Markdown in assistant messages */
.markdown-body {
  font-size: 0.95rem;
  line-height: 1.65;
  color: var(--text);
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.markdown-body > *:first-child {
  margin-top: 0;
}

.markdown-body > *:last-child {
  margin-bottom: 0;
}

.markdown-body p {
  margin: 0.75rem 0;
  white-space: normal;
  word-break: break-word;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  margin: 1.25rem 0 0.5rem;
  line-height: 1.3;
  font-weight: 700;
}

.markdown-body h1 { font-size: 1.35rem; }
.markdown-body h2 { font-size: 1.15rem; }
.markdown-body h3 { font-size: 1rem; }

.markdown-body ul,
.markdown-body ol {
  margin: 0.5rem 0 0.75rem;
  padding-left: 1.35rem;
}

.markdown-body li {
  margin: 0.35rem 0;
}

.markdown-body li::marker {
  color: var(--accent);
}

.markdown-body strong {
  color: #fff;
  font-weight: 600;
}

.markdown-body em {
  color: #c8d4e8;
}

.markdown-body a {
  color: var(--accent);
  text-decoration: none;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.markdown-body a:hover {
  text-decoration: underline;
}

.markdown-body blockquote {
  margin: 0.75rem 0;
  padding: 0.5rem 0.85rem;
  border-left: 3px solid var(--accent);
  background: rgba(79, 140, 255, 0.08);
  border-radius: 0 8px 8px 0;
  color: var(--muted);
}

.markdown-body :not(pre) > code {
  font-family: "JetBrains Mono", "Fira Code", ui-monospace, monospace;
  font-size: 0.85em;
  background: var(--surface-3);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  color: #fbbf24;
}

.code-block {
  margin: 1rem 0;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #0d1117;
  max-width: 100%;
  min-width: 0;
}

.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 0.75rem;
  background: #161b22;
  border-bottom: 1px solid var(--border);
}

.code-lang {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-family: ui-monospace, monospace;
}

.copy-code-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.68rem;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  cursor: pointer;
}

.copy-code-btn:hover {
  color: var(--text);
  border-color: var(--muted);
}

.code-block pre {
  margin: 0;
  padding: 1rem;
  overflow-x: auto;
  max-width: 100%;
  background: #0d1117;
  white-space: pre;
  -webkit-overflow-scrolling: touch;
}

.code-block pre code {
  display: block;
  font-family: "JetBrains Mono", "Fira Code", ui-monospace, monospace;
  font-size: 0.8rem;
  line-height: 1.55;
  background: transparent !important;
  padding: 0 !important;
  color: #e6edf3;
  white-space: pre;
  word-break: normal;
  overflow-wrap: normal;
}

.code-block pre code.hljs {
  background: transparent !important;
}

.markdown-body table {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  margin: 0.75rem 0;
  font-size: 0.85rem;
  -webkit-overflow-scrolling: touch;
}

.markdown-body img {
  max-width: 100%;
  height: auto;
}

.markdown-body th,
.markdown-body td {
  border: 1px solid var(--border);
  padding: 0.45rem 0.65rem;
  text-align: left;
}

.markdown-body th {
  background: var(--surface-3);
}

.message.error {
  align-self: flex-start;
  background: #2a1515;
  border: 1px solid #5c2020;
  color: #fca5a5;
}

.typing-dots {
  display: inline-flex;
  gap: 4px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: bounce 1.2s infinite ease-in-out;
}

.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

.citations {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.citations h4 {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.5rem;
  letter-spacing: 0.05em;
}

.citations ul {
  list-style: none;
}

.citations li {
  margin-bottom: 0.35rem;
  font-size: 0.85rem;
}

.cite-ref {
  margin: 0 0.1em;
  font-size: 0.65em;
  font-weight: 600;
  vertical-align: super;
  line-height: 0;
}

.cite-ref a {
  color: var(--muted);
  text-decoration: none;
  padding: 0.05rem 0.3rem;
  border-radius: 4px;
  background: rgba(132, 148, 173, 0.15);
}

.cite-ref a:hover {
  color: var(--accent);
  background: rgba(79, 140, 255, 0.15);
}

.cite-badge {
  display: none;
}

.citations a {
  color: var(--accent);
  text-decoration: none;
}

.citations a:hover {
  text-decoration: underline;
}

.chat-form {
  position: absolute;
  left: 1rem;
  right: 1rem;
  bottom: 1rem;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  flex-shrink: 0;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}

.chat-form input {
  flex: 1;
  min-width: 0;
  height: 48px;
  padding: 0 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.25;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-form input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.chat-form button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 48px;
  padding: 0 1.35rem;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  color: white;
  border: none;
  border-radius: 10px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  min-width: 80px;
  transition: transform 0.15s, opacity 0.15s;
}

.chat-form button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.chat-form button:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.btn-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.btn-spinner.hidden,
.hidden {
  display: none !important;
}

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

/* Progress panel */
.progress-badge {
  font-size: 0.68rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.progress-badge.idle {
  background: var(--surface-3);
  color: var(--muted);
}

.progress-badge.running {
  background: rgba(79, 140, 255, 0.15);
  color: var(--accent);
  animation: pulseBadge 1.5s ease-in-out infinite;
}

.progress-badge.done {
  background: rgba(52, 211, 153, 0.15);
  color: var(--success);
}

.progress-badge.error {
  background: rgba(248, 113, 113, 0.15);
  color: var(--error);
}

@keyframes pulseBadge {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.65; }
}

.progress-steps {
  list-style: none;
  padding: 1rem;
  flex: 1;
  overflow-y: auto;
}

.step {
  display: flex;
  gap: 0.75rem;
  padding: 0.65rem 0;
  position: relative;
  opacity: 0.45;
  transition: opacity 0.3s;
}

.step:not(:last-child)::after {
  content: "";
  position: absolute;
  left: 11px;
  top: 32px;
  width: 2px;
  height: calc(100% - 8px);
  background: var(--border);
  transition: background 0.4s;
}

.step.active {
  opacity: 1;
}

.step.done {
  opacity: 1;
}

.step.done:not(:last-child)::after {
  background: var(--success);
}

.step-icon {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

.step-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border);
  transition: all 0.3s;
}

.step.active .step-dot {
  width: 14px;
  height: 14px;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
  animation: stepPulse 1.2s ease-in-out infinite;
}

.step.done .step-dot {
  width: 12px;
  height: 12px;
  background: var(--success);
  box-shadow: 0 0 10px var(--success-glow);
}

@keyframes stepPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

.step-body {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.step-title {
  font-size: 0.82rem;
  font-weight: 600;
}

.step-desc {
  font-size: 0.72rem;
  color: var(--muted);
}

.step.active .step-title {
  color: var(--accent);
}

.step.done .step-title {
  color: var(--success);
}

.progress-bar-wrap {
  padding: 0 1rem 1rem;
  flex-shrink: 0;
}

.progress-bar {
  height: 4px;
  background: var(--surface-3);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}

.progress-bar::after {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: var(--progress, 0%);
  background: linear-gradient(90deg, var(--accent), #818cf8, var(--success));
  border-radius: 999px;
  transition: width 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}

.progress-bar.indeterminate::after {
  width: 40% !important;
  animation: indeterminate 1.4s ease-in-out infinite;
}

@keyframes indeterminate {
  0% { left: -40%; }
  100% { left: 100%; }
}

@media (max-width: 1100px) {
  body {
    overflow: hidden;
  }

  body.logs-drawer-open {
    overflow: hidden;
  }

  .header {
    padding: 0.5rem 0.75rem;
  }

  .header-inner {
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.5rem;
  }

  .brand {
    gap: 0.5rem;
    min-width: 0;
  }

  .brand h1 {
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .logo {
    font-size: 1.15rem;
  }

  .brand p {
    display: none;
  }

  .header-stats {
    gap: 0.5rem;
    flex-shrink: 0;
  }

  .mini-stat {
    font-size: 0.8rem;
  }

  .mini-stat small {
    font-size: 0.58rem;
  }

  .status {
    font-size: 0.72rem;
  }

  .workspace {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
  }

  .chat-panel .panel-header {
    display: none;
  }

  .chat-panel {
    order: 1;
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
    border-right: none;
    border-bottom: none;
    display: flex;
    flex-direction: column;
  }

  .chat-body {
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
    height: 0;
    overflow: hidden;
  }

  .chat-body::before {
    display: none;
  }

  .chat-log {
    position: relative;
    flex: 1 1 0;
    height: 0;
    min-height: 0;
    padding: 0.75rem;
    overflow-y: scroll;
    overflow-x: hidden;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
  }

  .chat-log .message {
    flex-shrink: 0;
  }

  .chat-form {
    position: static;
    left: auto;
    right: auto;
    bottom: auto;
    margin: 0 0.75rem calc(0.75rem + 44px);
    z-index: 1;
    flex-shrink: 0;
  }

  .logs-edge-swipe {
    display: block;
    position: fixed;
    left: 0;
    top: var(--app-header-height, 60px);
    bottom: 0;
    width: 72px;
    z-index: 104;
    touch-action: none;
  }

  body.logs-drawer-open .logs-edge-swipe {
    display: none;
  }

  .progress-edge-swipe {
    display: block;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 80px;
    z-index: 104;
    touch-action: none;
  }

  body.progress-drawer-open .progress-edge-swipe {
    display: none;
  }

  .progress-drawer-handle {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    position: fixed;
    left: 50%;
    bottom: 0;
    transform: translateX(-50%);
    z-index: 105;
    min-width: 128px;
    height: 40px;
    padding: 0.45rem 1rem 0.55rem;
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: 14px 14px 0 0;
    background: linear-gradient(180deg, var(--surface), var(--surface-2));
    color: var(--muted);
    cursor: grab;
    touch-action: none;
    box-shadow: 0 -4px 18px rgba(0, 0, 0, 0.35);
    animation: progressHint 2.4s ease-in-out infinite;
  }

  .progress-drawer-handle.is-dragging {
    animation: none;
    cursor: grabbing;
  }

  .progress-drawer-handle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }

  body.progress-drawer-open .progress-drawer-handle {
    opacity: 0;
    pointer-events: none;
    transform: translateX(-50%) translateY(120%);
  }

  .progress-drawer-handle-grip {
    width: 34px;
    height: 4px;
    border-radius: 999px;
    background: linear-gradient(
      90deg,
      transparent 0%,
      var(--accent) 20%,
      var(--accent) 80%,
      transparent 100%
    );
    box-shadow: 0 0 10px var(--accent-glow);
  }

  .progress-drawer-handle-label {
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--accent);
    line-height: 1;
  }

  @keyframes progressHint {
    0%, 100% {
      transform: translateX(-50%) translateY(0);
      box-shadow: 0 -4px 18px rgba(0, 0, 0, 0.35);
    }
    50% {
      transform: translateX(-50%) translateY(-3px);
      box-shadow: 0 -8px 22px rgba(79, 140, 255, 0.25);
    }
  }

  .logs-panel {
    position: fixed;
    left: 0;
    top: var(--app-header-height, 60px);
    bottom: 0;
    width: min(88vw, 320px);
    max-height: none;
    z-index: 120;
    transform: translateX(calc(-100% + var(--logs-drag-offset, 0px)));
    transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
    border-right: 1px solid var(--border);
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.45);
    order: unset;
    border-bottom: none;
    touch-action: pan-y;
  }

  .logs-panel.is-open {
    transform: translateX(0);
  }

  .logs-panel.is-dragging {
    transition: none;
  }

  .logs-close-btn {
    display: inline-flex;
  }

  .logs-drawer-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    top: var(--app-header-height, 60px);
    background: rgba(4, 8, 14, 0.55);
    z-index: 110;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
  }

  .logs-drawer-backdrop.is-visible {
    opacity: 1;
    pointer-events: auto;
  }

  .logs-drawer-handle {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.55rem;
    position: fixed;
    left: 0;
    top: calc(var(--app-header-height, 60px) + 18dvh);
    z-index: 105;
    width: 40px;
    min-height: 104px;
    padding: 0.75rem 0.45rem;
    border: 1px solid var(--border);
    border-left: none;
    border-radius: 0 14px 14px 0;
    background: linear-gradient(180deg, var(--surface-2), var(--surface));
    color: var(--muted);
    cursor: grab;
    touch-action: none;
    box-shadow: 4px 0 18px rgba(0, 0, 0, 0.35);
    animation: drawerHint 2.4s ease-in-out infinite;
  }

  .logs-drawer-handle.is-dragging {
    animation: none;
    cursor: grabbing;
  }

  .logs-drawer-handle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }

  body.logs-drawer-open .logs-drawer-handle {
    opacity: 0;
    pointer-events: none;
    transform: translateX(-120%);
  }

  .logs-drawer-handle-grip {
    width: 4px;
    height: 34px;
    border-radius: 999px;
    background: linear-gradient(
      180deg,
      transparent 0%,
      var(--accent) 20%,
      var(--accent) 80%,
      transparent 100%
    );
    box-shadow: 0 0 10px var(--accent-glow);
  }

  .logs-drawer-handle-label {
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--accent);
  }

  @keyframes drawerHint {
    0%, 100% {
      transform: translateX(0);
      box-shadow: 4px 0 18px rgba(0, 0, 0, 0.35);
    }
    50% {
      transform: translateX(3px);
      box-shadow: 8px 0 22px rgba(79, 140, 255, 0.25);
    }
  }

  .progress-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: min(52dvh, 360px);
    max-height: none;
    z-index: 120;
    transform: translateY(calc(100% - var(--progress-drag-offset, 0px)));
    transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
    border-top: 1px solid var(--border);
    border-left: none;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.45);
    order: unset;
    flex-shrink: unset;
    touch-action: pan-y;
  }

  .progress-panel.is-open {
    transform: translateY(0);
  }

  .progress-panel.is-dragging {
    transition: none;
  }

  .progress-close-btn {
    display: inline-flex;
  }

  .progress-steps {
    padding: 0.75rem 1rem;
  }

  .message {
    max-width: 100%;
    width: 100%;
  }

  .message.user {
    max-width: 92%;
    width: auto;
    align-self: flex-end;
  }

  .message.assistant {
    width: 100%;
    max-width: 100%;
  }

  .chat-form button {
    min-width: 64px;
    padding: 0.75rem 1rem;
  }
}

@media (max-width: 480px) {
  .header {
    padding: 0.4rem 0.65rem;
  }

  .brand h1 {
    font-size: 0.88rem;
  }

  .header-stats .mini-stat:last-of-type {
    display: none;
  }

  .status-text {
    display: none;
  }

  .chat-form {
    flex-direction: column;
    align-items: stretch;
    margin: 0 0.5rem calc(0.5rem + 44px);
  }

  .chat-form input {
    line-height: 1.4;
    height: auto;
    min-height: 48px;
    padding: 0.75rem 1rem;
  }

  .chat-form button {
    width: 100%;
    height: 48px;
  }
}

/* Intro splash */
.intro {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  pointer-events: auto;
}

.intro.hidden {
  display: none;
}

body.intro-active {
  overflow: hidden;
}

.intro-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 8, 14, 0.88);
  backdrop-filter: blur(8px);
  animation: introBackdropIn 0.9s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.intro-aurora {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.intro-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0;
  animation: introOrbIn 1.4s ease forwards;
}

.intro-orb--1 {
  width: min(420px, 70vw);
  height: min(420px, 70vw);
  top: 18%;
  left: 12%;
  background: rgba(79, 140, 255, 0.35);
  animation-delay: 0.1s;
}

.intro-orb--2 {
  width: min(360px, 60vw);
  height: min(360px, 60vw);
  right: 8%;
  bottom: 16%;
  background: rgba(99, 102, 241, 0.28);
  animation-delay: 0.25s;
}

.intro-orb--3 {
  width: min(280px, 50vw);
  height: min(280px, 50vw);
  left: 38%;
  bottom: 8%;
  background: rgba(52, 211, 153, 0.18);
  animation-delay: 0.4s;
}

.intro-panel {
  position: relative;
  z-index: 2;
  width: min(640px, 100%);
  text-align: center;
  padding: clamp(1.5rem, 4vw, 2.75rem) clamp(1.25rem, 4vw, 2.5rem);
  border-radius: 24px;
  border: 1px solid rgba(79, 140, 255, 0.22);
  background: linear-gradient(
    165deg,
    rgba(26, 36, 51, 0.92) 0%,
    rgba(19, 26, 36, 0.88) 55%,
    rgba(10, 14, 20, 0.9) 100%
  );
  box-shadow:
    0 24px 80px rgba(0, 0, 0, 0.55),
    0 0 0 1px rgba(255, 255, 255, 0.04) inset,
    0 0 48px rgba(79, 140, 255, 0.12);
  animation: introPanelIn 0.85s cubic-bezier(0.22, 1, 0.36, 1) 0.15s both;
}

.intro-eyebrow {
  font-size: clamp(0.68rem, 2vw, 0.78rem);
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 1.25rem;
  opacity: 0;
  animation: introFadeUp 0.7s cubic-bezier(0.22, 1, 0.36, 1) 0.35s both;
}

.intro-name {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 1rem;
  line-height: 1.1;
}

.intro-name-line {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.02em;
  max-width: 100%;
}

.intro-letter {
  display: inline-block;
  font-size: clamp(2rem, 8.5vw, 3.6rem);
  font-weight: 800;
  letter-spacing: 0.05em;
  background: linear-gradient(135deg, #e8eef7 0%, #4f8cff 45%, #818cf8 75%, #34d399 100%);
  background-size: 200% auto;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  opacity: 0;
  transform: translateY(1.1em) rotateX(55deg) scale(0.85);
  filter: blur(6px);
  animation:
    introLetterIn 0.75s cubic-bezier(0.22, 1, 0.36, 1) both,
    introNameShine 4s ease-in-out infinite;
  animation-delay: calc(0.45s + var(--i) * 0.055s), calc(1.8s + var(--i) * 0.04s);
}

.intro-tagline {
  font-size: clamp(0.88rem, 2.8vw, 1.05rem);
  font-weight: 600;
  color: #c8d4e8;
  margin-bottom: 0.65rem;
  opacity: 0;
  animation: introFadeUp 0.7s cubic-bezier(0.22, 1, 0.36, 1) 1.15s both;
}

.intro-desc {
  font-size: clamp(0.82rem, 2.5vw, 0.95rem);
  line-height: 1.55;
  color: var(--muted);
  max-width: 34ch;
  margin: 0 auto 1.6rem;
  opacity: 0;
  animation: introFadeUp 0.7s cubic-bezier(0.22, 1, 0.36, 1) 1.35s both;
}

.intro-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 168px;
  padding: 0.8rem 1.6rem;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 10px 32px rgba(79, 140, 255, 0.35);
  opacity: 0;
  animation: introFadeUp 0.7s cubic-bezier(0.22, 1, 0.36, 1) 1.55s both;
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.intro-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 36px rgba(79, 140, 255, 0.45);
}

.intro-btn:active {
  transform: translateY(0);
}

.intro--closing .intro-backdrop {
  animation: introBackdropOut 0.65s ease forwards;
}

.intro--closing .intro-panel {
  animation: introPanelOut 0.65s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.intro--closing .intro-orb {
  animation: introOrbOut 0.5s ease forwards;
}

@keyframes introBackdropIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes introBackdropOut {
  to { opacity: 0; }
}

@keyframes introPanelIn {
  from {
    opacity: 0;
    transform: translateY(28px) scale(0.94);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes introPanelOut {
  to {
    opacity: 0;
    transform: translateY(-16px) scale(0.96);
    filter: blur(4px);
  }
}

@keyframes introOrbIn {
  from {
    opacity: 0;
    transform: scale(0.6);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes introOrbOut {
  to {
    opacity: 0;
    transform: scale(1.2);
  }
}

@keyframes introLetterIn {
  0% {
    opacity: 0;
    transform: translateY(1.1em) rotateX(55deg) scale(0.85);
    filter: blur(6px);
  }
  60% {
    opacity: 1;
    filter: blur(0);
  }
  100% {
    opacity: 1;
    transform: translateY(0) rotateX(0deg) scale(1);
    filter: blur(0);
  }
}

@keyframes introFadeUp {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes introNameShine {
  0%, 100% { background-position: 0% center; }
  50% { background-position: 100% center; }
}

@media (max-width: 480px) {
  .intro {
    padding: 1rem;
    align-items: flex-end;
    padding-bottom: max(1.25rem, env(safe-area-inset-bottom));
  }

  .intro-panel {
    border-radius: 20px;
    padding: 1.35rem 1.1rem 1.5rem;
  }

  .intro-eyebrow {
    letter-spacing: 0.14em;
    margin-bottom: 1rem;
  }

  .intro-desc {
    margin-bottom: 1.25rem;
  }

  .intro-btn {
    width: 100%;
    min-width: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .intro-backdrop,
  .intro-panel,
  .intro-orb,
  .intro-eyebrow,
  .intro-letter,
  .intro-tagline,
  .intro-desc,
  .intro-btn {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
    filter: none !important;
  }

  .intro-letter {
    color: var(--accent);
    background: none;
    -webkit-background-clip: unset;
    background-clip: unset;
  }
}

/* Onboarding tour */
.onboarding {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: visible;
}

.onboarding:not(.hidden) {
  pointer-events: none;
}

.onboarding.hidden {
  display: none;
}

body.onboarding-active {
  overflow: hidden;
}

.onboarding-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(4, 8, 14, 0.72);
  backdrop-filter: blur(1px);
  animation: onboardingFadeIn 0.35s ease;
  pointer-events: auto;
}

.onboarding-target {
  z-index: 203;
  outline: 2px solid rgba(79, 140, 255, 0.95);
  outline-offset: 3px;
  border-radius: inherit;
  animation: onboardingTargetPulse 2s ease-in-out infinite;
}

.header-stats.onboarding-target {
  position: relative;
}

#chat-log.onboarding-target {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
}

.chat-panel.onboarding-target {
  position: relative;
  z-index: 203;
  outline: none;
  overflow: visible;
}

.chat-panel.onboarding-elevated {
  position: relative;
  z-index: 203;
  overflow: visible;
}

.header.onboarding-elevated {
  position: relative;
  z-index: 203;
}

.panel.onboarding-elevated {
  position: relative;
  z-index: 203;
}

.chat-panel.onboarding-target::after {
  content: "";
  position: absolute;
  inset: 3px;
  border: 2px solid rgba(79, 140, 255, 0.95);
  border-radius: 12px;
  pointer-events: none;
  z-index: 6;
  animation: onboardingTargetRing 2s ease-in-out infinite;
}

#chat-form.onboarding-target {
  position: absolute;
  left: 1rem;
  right: 1rem;
  bottom: 1rem;
  z-index: 4;
  overflow: visible;
  outline-offset: 4px;
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.45),
    0 0 0 2px rgba(79, 140, 255, 0.95);
}

#logs-panel.onboarding-target,
#progress-panel.onboarding-target {
  position: relative;
  z-index: 203;
}

#logs-drawer-handle.onboarding-target,
#progress-drawer-handle.onboarding-target {
  z-index: 203;
}

.onboarding-card {
  position: fixed;
  z-index: 210;
  max-width: min(360px, calc(100vw - 24px));
  padding: 1rem 1.1rem 1rem;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
  pointer-events: auto;
}

.onboarding-card--center {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(360px, calc(100vw - 24px));
  animation: onboardingCardIn 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}

.onboarding-card--center-static {
  animation: none;
}

.onboarding-card--in-target {
  position: absolute;
  left: 12px;
  right: 12px;
  width: auto;
  max-width: none;
  z-index: 204;
  max-height: min(42vh, 240px);
  overflow-y: auto;
  animation: onboardingCardPop 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

.onboarding-card--in-target-top {
  top: 10px;
}

@media (min-width: 1101px) {
  .onboarding-card {
    max-width: 300px;
  }

  .onboarding-card--center {
    width: min(300px, calc(100vw - 24px));
  }

  .onboarding-card--in-target {
    left: 12px;
    right: auto;
    width: min(300px, calc(100% - 24px));
    max-width: 300px;
  }

  .chat-panel > .onboarding-card--in-target-top {
    top: 56px;
  }
}

.onboarding-card--top,
.onboarding-card--bottom {
  transform: none;
}

.onboarding-step {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.45rem;
}

.onboarding-title {
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 0.55rem;
}

.onboarding-text {
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--muted);
  margin-bottom: 1rem;
}

.onboarding-actions {
  display: flex;
  justify-content: space-between;
  gap: 0.65rem;
}

.onboarding-btn {
  border-radius: 10px;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.65rem 0.95rem;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.onboarding-btn:active {
  transform: scale(0.98);
}

.onboarding-btn--ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--muted);
}

.onboarding-btn--ghost:hover {
  color: var(--text);
  border-color: var(--muted);
}

.onboarding-btn--primary {
  flex: 1;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  color: #fff;
}

.onboarding-btn--primary:hover {
  opacity: 0.92;
}

@keyframes onboardingFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes onboardingCardIn {
  from {
    opacity: 0;
    transform: translate(-50%, calc(-50% + 12px)) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

.onboarding-card--top,
.onboarding-card--bottom {
  animation: onboardingCardPop 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes onboardingCardPop {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes onboardingTargetPulse {
  0%, 100% {
    outline-color: rgba(79, 140, 255, 0.85);
    box-shadow: 0 0 0 0 rgba(79, 140, 255, 0.2);
  }
  50% {
    outline-color: rgba(79, 140, 255, 1);
    box-shadow: 0 0 16px rgba(79, 140, 255, 0.55);
  }
}

@keyframes onboardingTargetRing {
  0%, 100% {
    border-color: rgba(79, 140, 255, 0.85);
    box-shadow: 0 0 0 0 rgba(79, 140, 255, 0.15);
  }
  50% {
    border-color: rgba(79, 140, 255, 1);
    box-shadow: 0 0 22px rgba(79, 140, 255, 0.55);
  }
}

@media (max-width: 1100px) {
  .chat-panel.onboarding-target {
    z-index: 203;
  }

  .chat-panel.onboarding-target::after {
    inset: 2px;
    border-radius: 10px;
  }

  .onboarding-card--in-target {
    left: 10px;
    right: 10px;
    max-height: min(38vh, 220px);
  }

  .onboarding-card--in-target-top {
    top: 10px;
  }

  #chat-log.onboarding-target {
    position: relative;
    inset: auto;
    flex: 1 1 0;
    height: 0;
    min-height: 0;
  }

  #chat-form.onboarding-target {
    position: relative;
    left: auto;
    right: auto;
    bottom: auto;
    z-index: 5;
    overflow: visible;
    box-shadow:
      0 8px 32px rgba(0, 0, 0, 0.45),
      0 0 0 2px rgba(79, 140, 255, 0.95),
      0 0 20px rgba(79, 140, 255, 0.35);
  }

  .chat-panel.onboarding-target,
  .chat-panel.onboarding-elevated {
    z-index: 203;
  }

  .onboarding-card {
    max-width: calc(100vw - 20px);
    padding: 0.95rem 1rem;
  }

  .onboarding-card--center {
    width: calc(100vw - 20px);
  }

  .onboarding-card--mobile-dock {
    max-height: min(38vh, 220px);
    overflow-y: auto;
    animation: onboardingCardPop 0.35s cubic-bezier(0.22, 1, 0.36, 1);
  }

  .onboarding-title {
    font-size: 1rem;
  }

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

  .onboarding-actions {
    flex-direction: column-reverse;
  }

  .onboarding-btn--primary {
    width: 100%;
  }
}
