:root {
  --bg: #0b0e14;
  --panel: #111621;
  --elev: #171e2d;
  --elev-2: #1e273a;
  --border: #232d42;
  --text: #e6edf7;
  --muted: #8b9bb4;
  --accent: #3b82f6;
  --accent-soft: rgba(59, 130, 246, 0.16);
  --green: #10b981;
  --amber: #f59e0b;
  --red: #ef4444;
  --radius: 12px;
  --mono: "Cascadia Code", "JetBrains Mono", Consolas, ui-monospace, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.tiny { font-size: 11.5px; }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); }
.row { display: flex; align-items: center; }
.between { justify-content: space-between; }
.center { align-items: center; }
.gap-4 { gap: 4px; }
.gap-8 { gap: 8px; }

/* Buttons & Inputs */
.btn {
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text);
  background: var(--elev-2);
  transition: all 0.15s ease;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.12); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-danger { background: var(--red); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--muted); }
.btn-ghost:hover { color: var(--text); border-color: #364666; }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 7px; }
.btn-full { width: 100%; }

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--elev);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--elev-2); }
.icon-btn.recording { border-color: var(--red); color: var(--red); animation: pulse 1.2s infinite; }

.pill-btn {
  padding: 5px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--elev);
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.pill-btn.active {
  border-color: rgba(16, 185, 129, 0.5);
  background: rgba(16, 185, 129, 0.12);
  color: #34d399;
}

.text-input, .ctrl-select {
  background: var(--elev);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
}
.text-input:focus, .ctrl-select:focus { border-color: var(--accent); }
.text-input.sm { padding: 7px 9px; font-size: 12.5px; width: 100%; }
.ctrl-select { padding: 5px 8px; font-size: 12px; max-width: 170px; }

/* App 3-Column Desktop Layout */
.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 350px;
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
}

/* Left Rail */
.left-rail {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.rail-header {
  padding: 14px 14px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.brand-row { display: flex; align-items: center; gap: 10px; }
.brand-badge {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #60a5fa);
  color: #fff; font-weight: 700; font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.brand-badge.sm { width: 30px; height: 30px; font-size: 15px; border-radius: 8px; }
.brand-title { font-weight: 600; font-size: 14px; }
.status-line { display: flex; align-items: center; gap: 6px; margin-top: 1px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--amber); display: inline-block; }
.dot.ok { background: var(--green); }
.dot.err { background: var(--red); }

.rail-actions { padding: 12px; }
.rail-section-title {
  padding: 6px 14px 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.session-item {
  padding: 9px 10px;
  border-radius: 9px;
  cursor: pointer;
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.session-item:hover { background: var(--elev); }
.session-item.active { background: var(--accent-soft); border-color: rgba(59, 130, 246, 0.35); }
.session-item-main { min-width: 0; flex: 1; }
.session-item-title { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-item-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.session-del {
  background: transparent; border: none; color: var(--muted);
  cursor: pointer; padding: 3px 6px; border-radius: 6px; opacity: 0.6;
}
.session-del:hover { color: var(--red); background: rgba(239, 68, 68, 0.12); opacity: 1; }

.rail-footer {
  border-top: 1px solid var(--border);
  padding: 10px 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.steward-btn {
  text-align: left;
  background: var(--elev);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
}
.steward-btn:hover { border-color: var(--accent); background: var(--elev-2); }

/* Center Stage */
.center-stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}
.top-bar {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(17, 22, 33, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.top-left { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.session-title-wrap { min-width: 0; flex: 1; }
.session-title-input {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  width: 100%;
  max-width: 340px;
  padding: 2px 6px;
  border-radius: 6px;
  outline: none;
}
.session-title-input:focus { border-color: var(--border); background: var(--elev); }
.top-controls { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.chat-feed {
  flex: 1;
  overflow-y: auto;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.empty-hero {
  margin: auto;
  max-width: 560px;
  text-align: center;
  padding: 24px 16px;
}
.hero-icon { font-size: 38px; margin-bottom: 10px; }
.empty-hero h2 { font-size: 19px; margin-bottom: 8px; }
.hero-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 18px; }
.chip-btn {
  background: var(--elev);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  cursor: pointer;
}
.chip-btn:hover { border-color: var(--accent); background: var(--elev-2); }

/* Messages */
.msg {
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.msg-user { align-items: flex-end; }
.msg-bubble {
  padding: 12px 15px;
  border-radius: 14px;
  word-break: break-word;
  max-width: 100%;
}
.msg-user .msg-bubble {
  background: #1d365d;
  border: 1px solid #2b4c7e;
  max-width: 85%;
  white-space: pre-wrap;
}
.msg-assistant .msg-bubble {
  background: var(--panel);
  border: 1px solid var(--border);
  width: 100%;
}
.msg-meta { font-size: 11px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; }

/* Steps / Tool Calls Accordion */
.steps-card {
  background: #0f141e;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 10px;
  overflow: hidden;
}
.steps-card summary {
  padding: 7px 11px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.steps-list {
  border-top: 1px solid var(--border);
  padding: 8px 11px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.step-row {
  font-size: 12px;
  font-family: var(--mono);
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.step-badge {
  font-size: 10.5px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--elev-2);
  color: var(--muted);
}
.step-badge.ACTIVE { background: rgba(245, 158, 11, 0.18); color: #fbbf24; }
.step-badge.DONE { background: rgba(16, 185, 129, 0.16); color: #34d399; }

/* Markdown Rendering inside Assistant Bubble */
.md-body p { margin: 0 0 8px; }
.md-body p:last-child { margin-bottom: 0; }
.md-body h1, .md-body h2, .md-body h3 { margin: 12px 0 6px; font-size: 1.08em; }
.md-body ul, .md-body ol { padding-left: 20px; margin: 6px 0 10px; }
.md-body code {
  font-family: var(--mono);
  font-size: 12.5px;
  background: var(--elev-2);
  padding: 1px 5px;
  border-radius: 4px;
}
.code-block-wrap {
  position: relative;
  margin: 10px 0;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: #0a0d13;
  overflow: hidden;
}
.code-block-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 10px;
  background: #131926;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  color: var(--muted);
  font-family: var(--mono);
}
.code-copy-btn {
  background: transparent; border: none; color: var(--muted);
  cursor: pointer; font-size: 11px;
}
.code-copy-btn:hover { color: var(--text); }
.code-block-wrap pre {
  padding: 10px 12px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.5;
}
.code-block-wrap pre code { background: none; padding: 0; }

/* Composer */
.composer-wrap {
  padding: 10px 16px 14px;
  border-top: 1px solid var(--border);
  background: var(--panel);
}
.attached-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}
.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-soft);
  border: 1px solid rgba(59, 130, 246, 0.35);
  color: #93c5fd;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
}
.attach-chip button {
  background: none; border: none; color: inherit; cursor: pointer; font-size: 12px;
}
.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 10px;
}
.composer-box:focus-within { border-color: var(--accent); }
#promptInput {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  resize: none;
  max-height: 160px;
  outline: none;
  line-height: 1.5;
  padding: 4px 2px;
}
.composer-actions { display: flex; align-items: center; gap: 6px; }

/* Right Rail (Dropzone + Clips + Workspace) */
.right-rail {
  background: var(--panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.right-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--border);
  padding: 8px 8px 0;
  gap: 4px;
}
.rtab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 8px 4px 10px;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
}
.rtab.active { color: var(--text); border-bottom-color: var(--accent); }

.right-pane {
  display: none;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  padding: 12px;
  gap: 10px;
}
.right-pane.active-rtab { display: flex; }

.pane-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.pane-title { font-weight: 600; font-size: 13.5px; }

.drop-zone {
  border: 1.5px dashed #334569;
  border-radius: 12px;
  padding: 16px 12px;
  text-align: center;
  background: rgba(59, 130, 246, 0.05);
  cursor: pointer;
  transition: all 0.15s ease;
}
.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.14);
}
.drop-icon { font-size: 22px; margin-bottom: 4px; }
.drop-text { font-size: 13px; margin-bottom: 3px; }
.upload-progress { margin-top: 8px; font-size: 12px; color: #93c5fd; }

.clip-composer {
  display: flex;
  flex-direction: column;
  gap: 7px;
  background: var(--elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
}
.check-label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }

.item-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.file-card, .clip-card, .ws-row {
  background: var(--elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
}
.file-name { font-size: 13px; font-weight: 500; word-break: break-all; }
.file-meta { font-size: 11px; color: var(--muted); margin-top: 3px; }
.card-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.clip-preview {
  font-size: 12.5px;
  color: #cbd5e1;
  margin-top: 6px;
  white-space: pre-wrap;
  max-height: 96px;
  overflow: hidden;
  word-break: break-word;
}
.ws-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
  padding: 9px 11px;
}
.ws-row:hover { border-color: var(--accent); background: var(--elev-2); }

/* Modals & Toast */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(4, 7, 13, 0.78);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  z-index: 100;
}
.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.preview-card { max-width: 780px; max-height: 84dvh; }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.preview-body {
  background: #090c12;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 12.5px;
  white-space: pre-wrap;
  word-break: break-word;
  flex: 1;
}
.field-label { font-size: 12.5px; color: var(--muted); }
.error-text { color: #f87171; font-size: 12.5px; }

.toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  border: 1px solid #3b82f6;
  color: #f8fafc;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 12.5px;
  z-index: 200;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 40;
}
.mobile-only { display: none; }
.hide-desktop { display: none; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Tablet Breakpoint (768px - 1079px) */
@media (max-width: 1079px) {
  .app-shell { grid-template-columns: minmax(0, 1fr) 320px; }
  .hide-desktop { display: inline-flex; }
  .left-rail {
    position: fixed; left: 0; top: 0; bottom: 0; width: 280px;
    z-index: 50; transform: translateX(-105%); transition: transform 0.2s ease;
  }
  .left-rail.open { transform: translateX(0); }
}

/* Android Phone Breakpoint (<768px) */
@media (max-width: 767px) {
  .mobile-only { display: flex; }
  .hide-mobile { display: none !important; }
  .app-shell {
    display: block;
    height: calc(100dvh - 58px - env(safe-area-inset-bottom));
    position: relative;
  }
  .center-stage, .right-rail {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: none;
    display: none;
  }
  .center-stage.active-mobile-pane { display: flex; }
  .right-rail.active-mobile-pane { display: flex; }

  .top-bar { padding: 8px 10px; gap: 6px; }
  .top-controls { width: 100%; justify-content: flex-start; }
  .ctrl-select { flex: 1; min-width: 0; max-width: none; font-size: 11.5px; padding: 5px 6px; }
  .chat-feed { padding: 12px 10px; }
  .msg-user .msg-bubble { max-width: 92%; }
  .composer-wrap { padding: 8px 10px 10px; }

  .mobile-nav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    height: calc(58px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--panel);
    border-top: 1px solid var(--border);
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    z-index: 30;
  }
  .mnav-btn {
    background: none; border: none; color: var(--muted);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; font-size: 18px; cursor: pointer;
  }
  .mnav-btn small { font-size: 11px; }
  .mnav-btn.active { color: #60a5fa; }
}
