@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=JetBrains+Mono:wght@400;500&family=Noto+Sans+SC:wght@400;500;600;700&display=swap');

:root {
  --bg: #ffffff;
  --sidebar: #f7f8fa;
  --ink: #1f2329;
  --muted: #8b8f97;
  --line: #eceef2;
  --hover: #eef0f4;
  --active: #e8ecff;
  --blue: #4d6bfe;
  --blue-2: #3b57e6;
  --blue-soft: #eef2ff;
  --user-bubble: #e8f1ff;
  --danger: #e24c4c;
  --ok: #2f9e62;
  --shadow: 0 8px 28px rgba(31, 35, 41, 0.08);
  --sans: "DM Sans", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --radius: 16px;
  --sidebar-w: 268px;
  --rail-w: 338px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
}
button, input, textarea { font-family: inherit; }
a { color: inherit; }
.hidden { display: none !important; }

.icon-btn {
  width: 34px;
  height: 34px;
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 10px;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.icon-btn:hover { background: var(--hover); color: var(--ink); }

/* Login */
.gate-body {
  position: relative;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(900px 420px at 50% -10%, #e8eeff 0%, transparent 60%),
    var(--bg);
}
.gate-bits {
  position: fixed;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.gate-top,
.gate-main,
.gate-foot {
  position: relative;
  z-index: 1;
}
.gate-top, .gate-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 22px 32px;
  color: var(--muted);
  font-size: 13px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ink);
  font-weight: 700;
  font-size: 20px;
  letter-spacing: -0.03em;
}
.brand img { width: 32px; height: 32px; object-fit: contain; }
.gate-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.card {
  width: 100%;
  max-width: 400px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 28px 28px 24px;
  box-shadow: var(--shadow);
}
.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--sidebar);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 20px;
}
.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  height: 36px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
}
.tab.on {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(31, 35, 41, 0.08);
}
.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 14px;
}
.auth-form input {
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 12px;
  font-size: 15px;
  outline: none;
  color: var(--ink);
  background: #fff;
}
.auth-form input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(77, 107, 254, 0.12); }
.wax, .send-login {
  width: 100%;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: var(--blue);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 6px;
}
.wax:hover, .send-login:hover { background: var(--blue-2); }
.wax:disabled { opacity: 0.55; cursor: wait; }
.auth-msg { min-height: 1.3em; color: var(--danger); font-size: 13px; margin: 10px 0 0; }

.consent-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 2px 0 12px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.55;
}
.consent-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 3px 0 0;
  flex-shrink: 0;
  accent-color: var(--blue);
  cursor: pointer;
}
.consent-link {
  border: 0;
  padding: 0;
  background: none;
  color: var(--blue);
  font: inherit;
  cursor: pointer;
}
.consent-link:hover { text-decoration: underline; }
.consent-mask {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(20, 24, 32, 0.42);
}
.consent-dialog {
  width: min(460px, 100%);
  max-height: min(72vh, 640px);
  overflow: auto;
  background: #fff;
  border-radius: 18px;
  padding: 24px 24px 20px;
  box-shadow: 0 18px 50px rgba(20, 24, 32, 0.18);
}
.consent-dialog h2 {
  margin: 0 0 12px;
  font-size: 18px;
  letter-spacing: -0.03em;
}
.consent-dialog p,
.consent-dialog li {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
}
.consent-dialog ol {
  margin: 0 0 12px;
  padding-left: 1.2em;
}
.consent-dialog .wax { margin-top: 8px; }

/* Workspace */
.os-body {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr var(--rail-w);
  height: 100vh;
  overflow: hidden;
}
.os-body > * { min-height: 0; min-width: 0; }
.os-body.collapsed { grid-template-columns: 0 1fr var(--rail-w); }
.os-body.collapsed .sidebar { transform: translateX(-100%); }
.os-body.rail-off { grid-template-columns: var(--sidebar-w) 1fr 0; }
.os-body.collapsed.rail-off { grid-template-columns: 0 1fr 0; }
.os-body.rail-off .data-rail { transform: translateX(100%); }

.col-resizer {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 8px;
  z-index: 40;
  cursor: col-resize;
  touch-action: none;
}
.col-resizer::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 3px;
  width: 2px;
  background: transparent;
}
.col-resizer:hover::after,
.col-resizer.active::after,
body.resizing .col-resizer.active::after {
  background: var(--blue);
}
#resize-sidebar { right: 0; }
#resize-rail { left: 0; }
.os-body.collapsed #resize-sidebar,
.os-body.rail-off #resize-rail { display: none; }
body.resizing { cursor: col-resize; user-select: none; }
body.resizing .sidebar,
body.resizing .data-rail { transition: none; }

.sidebar {
  position: relative;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  transition: transform 0.2s ease;
  z-index: 20;
}
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 12px 8px;
}
.new-chat {
  margin: 6px 12px 10px;
  height: 40px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
}
.new-chat:hover { border-color: var(--blue); color: var(--blue); }
.search-wrap {
  margin: 0 12px 10px;
  position: relative;
}
.search-wrap svg {
  position: absolute;
  left: 10px;
  top: 10px;
  color: var(--muted);
}
.search-wrap input {
  width: 100%;
  height: 36px;
  border: 0;
  background: #fff;
  border-radius: 10px;
  padding: 0 10px 0 32px;
  outline: none;
  font-size: 13px;
  color: var(--ink);
}
.session-pane {
  flex: 1;
  overflow: auto;
  padding: 0 8px 12px;
}
.session-label {
  font-size: 12px;
  color: var(--muted);
  padding: 6px 8px 8px;
}
#session-list { list-style: none; margin: 0; padding: 0; }
#session-list li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 8px;
  border-radius: 10px;
  cursor: pointer;
  color: var(--ink);
  font-size: 13.5px;
  line-height: 1.35;
}
#session-list li:hover { background: var(--hover); }
#session-list li.on { background: var(--active); color: var(--blue); }
.session-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.session-del {
  opacity: 0;
  width: 26px;
  height: 26px;
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
#session-list li:hover .session-del,
#session-list li.on .session-del { opacity: 1; }
.session-del:hover { background: #ffe8e8; color: var(--danger); }
.sidebar-foot {
  padding: 10px 12px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-top: 1px solid var(--line);
}
.who-chip {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}
.who-chip #who {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}
#logout {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  padding: 6px 8px;
  border-radius: 8px;
}
#logout:hover { background: var(--hover); color: var(--ink); }

.stage {
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  position: relative;
}
.stage-bar {
  height: 56px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px;
  flex-shrink: 0;
}
.run-meter {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  margin-right: auto;
}
.run-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #c5c9d2;
}
.run-meter.live .run-dot { background: var(--blue); animation: pulse 1.2s ease-in-out infinite; }
.run-meter.done .run-dot { background: var(--ok); }
.run-meter.err .run-dot { background: var(--danger); }
@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.35); opacity: 0.5; }
}
.upload-chip {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
  color: var(--ink);
  background: #fff;
}
.upload-chip:hover { border-color: var(--blue); color: var(--blue); }
.upload-chip input, .attach-btn input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.chat-scroll {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  position: relative;
}
.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  pointer-events: none;
  overflow: auto;
  padding: 24px 16px 96px;
}
.empty-state img { width: 56px; height: 56px; object-fit: contain; }
.empty-state h1 {
  margin: 8px 0 0;
  font-size: 32px;
  letter-spacing: -0.04em;
  font-weight: 700;
}
.empty-state p { margin: 0; color: var(--muted); font-size: 15px; }
.hello-guide {
  width: min(520px, 100%);
  margin-top: 22px;
}
.empty-state .hello-howto {
  margin: 0;
  padding: 16px 18px;
  text-align: left;
  color: var(--ink);
  font-size: 14.5px;
  line-height: 1.85;
  background: var(--blue-soft);
  border: 1px solid #e4e9ff;
  border-radius: 14px;
}
.hello-action {
  display: inline;
  font-weight: 600;
  color: var(--blue);
  white-space: nowrap;
}
.os-body.chatting .empty-state { display: none; }

.stream {
  width: min(780px, calc(100% - 40px));
  margin: 0 auto;
  padding: 12px 0 28px;
}
.bubble {
  display: flex;
  margin: 18px 0;
}
.bubble.user { justify-content: flex-end; }
.bubble.user .body {
  max-width: 78%;
  background: var(--user-bubble);
  padding: 10px 14px;
  border-radius: 14px 14px 4px 14px;
  line-height: 1.65;
  font-size: 15px;
}
.bubble.assistant { justify-content: flex-start; }
.bubble.assistant .body {
  width: 100%;
  line-height: 1.75;
  font-size: 15.5px;
}

.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4 {
  font-weight: 650;
  line-height: 1.3;
  margin: 1.05em 0 0.4em;
}
.md h1 { font-size: 1.4em; }
.md h2 { font-size: 1.22em; }
.md h3 { font-size: 1.08em; }
.md p { margin: 0.6em 0; }
.md ul, .md ol { margin: 0.4em 0 0.7em; padding-left: 1.35em; }
.md li { margin: 0.18em 0; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1em 0; }
.md blockquote {
  margin: 0.7em 0;
  padding: 0.15em 0 0.15em 12px;
  border-left: 3px solid var(--blue);
  color: var(--muted);
}
.md code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--sidebar);
  padding: 0.12em 0.35em;
  border-radius: 5px;
}
.md pre {
  margin: 0.7em 0;
  padding: 12px 14px;
  background: #f4f6fb;
  border: 1px solid var(--line);
  overflow: auto;
  border-radius: 12px;
}
.md pre code { background: none; padding: 0; font-size: 12px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.md a { color: var(--blue); text-decoration: none; }
.md a:hover { text-decoration: underline; }
.md img { max-width: 100%; border-radius: 12px; border: 1px solid var(--line); cursor: zoom-in; }
.md table { border-collapse: collapse; width: 100%; margin: 0.8em 0; font-size: 13px; }
.md { overflow-x: auto; }
.md th, .md td {
  border: 1px solid var(--line);
  padding: 7px 10px;
  text-align: left;
  vertical-align: top;
}
.md th { background: var(--sidebar); font-weight: 600; }
.md tr:nth-child(even) td { background: #fafbfe; }
.md del { color: var(--muted); }

.step-mark {
  width: min(780px, 100%);
  margin: 14px auto 4px;
  font-size: 12px;
  color: var(--blue);
}
.think-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0;
  color: var(--muted);
  font-size: 13px;
}
.think-row .run-dot { animation: pulse 1.2s ease-in-out infinite; background: var(--blue); }

.skill-card {
  margin: 12px 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  overflow: hidden;
}
.skill-card.running {
  border-color: #cfd8ff;
  box-shadow: 0 0 0 3px var(--blue-soft);
}
.skill-card.err { border-color: #ffd4d4; }
.skill-head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: 0;
  background: #f5f7fb;
  color: inherit;
  padding: 9px 12px;
  cursor: pointer;
  text-align: left;
}
.skill-card.running .skill-head { background: var(--blue-soft); }
.skill-card.err .skill-head { background: #fff5f5; }
.skill-chevron {
  width: 7px;
  height: 7px;
  border-right: 1.6px solid var(--muted);
  border-bottom: 1.6px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 0.16s ease;
  flex-shrink: 0;
  margin: 0 4px 3px 2px;
}
.skill-card.open .skill-chevron {
  transform: rotate(45deg);
  margin-bottom: 0;
}
.skill-lang {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 2px 6px;
  border-radius: 4px;
  background: #5b6475;
  color: #fff;
  flex-shrink: 0;
}
.skill-lang.r { background: #276dc2; }
.skill-lang.py { background: #c47b16; }
.skill-lang.skill { background: #4d6bfe; }
.skill-lang.web { background: #0f766e; }
.skill-title {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.skill-file {
  min-width: 0;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.skill-state {
  margin-left: auto;
  font-size: 11px;
  color: var(--blue);
  flex-shrink: 0;
}
.skill-card.ok .skill-state { color: var(--ok); }
.skill-card.err .skill-state { color: var(--danger); }
.skill-body { display: none; border-top: 1px solid var(--line); }
.skill-card.open .skill-body { display: block; }
.skill-md {
  padding: 12px 14px;
  font-size: 13.5px;
  line-height: 1.65;
  background: #fbfcfe;
}
.skill-md > *:first-child { margin-top: 0; }
.skill-md > *:last-child { margin-bottom: 0; }
.skill-code, .skill-out {
  margin: 0;
  padding: 12px 14px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 320px;
  overflow: auto;
}
.skill-code {
  background: #111827;
  color: #e5edf7;
}
.skill-out {
  background: #0b1220;
  color: #b7c4d4;
  border-top: 1px solid #1f2937;
}
.skill-plots {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 12px;
  background: #fff;
}
.skill-plots:empty { display: none; }
.skill-plots img {
  max-width: 100%;
  max-height: 280px;
  border-radius: 8px;
  border: 1px solid var(--line);
  cursor: zoom-in;
}

.img-lightbox {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(16, 18, 24, 0.72);
  align-items: center;
  justify-content: center;
  padding: 56px 28px 28px;
}
.img-lightbox.on { display: flex; }
.img-lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.35);
}
.img-lightbox-close {
  position: absolute;
  top: 12px;
  right: 12px;
  height: 40px;
  padding: 0 14px 0 12px;
  border: 0;
  border-radius: 20px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.22);
}
.img-lightbox-close:hover {
  background: var(--blue);
  color: #fff;
}

.trace {
  font-size: 13px;
  border: 1px solid var(--line);
  background: #fbfcfe;
  padding: 11px 12px;
  margin: 10px 0;
  border-radius: 12px;
}
.trace.running { background: var(--blue-soft); }
.trace.err { background: #fff5f5; border-color: #ffd4d4; }
.trace-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 12px; }
.trace-head b { font-size: 13px; font-weight: 600; }
.trace-head code { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.trace-state { margin-left: auto; font-size: 11px; color: var(--blue); }
.trace.err .trace-state { color: var(--danger); }
.trace-brief { margin: 6px 0 0; color: var(--muted); line-height: 1.5; }
.trace details { margin-top: 6px; color: var(--muted); }
.trace summary { cursor: pointer; font-size: 12px; }
.trace pre {
  margin: 8px 0 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.45;
  max-height: 240px;
  overflow: auto;
  background: #fff;
  padding: 8px;
  border-radius: 8px;
}

.composer-dock {
  width: min(780px, calc(100% - 32px));
  margin: 0 auto 18px;
  flex-shrink: 0;
}
.artifact-list {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin-bottom: 8px;
}
.artifact-list:empty { display: none; }
.artifact-list a { color: var(--blue); font-size: 12px; }
.artifact-list img { height: 64px; border-radius: 8px; border: 1px solid var(--line); cursor: zoom-in; }
.composer {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 12px 12px 10px;
}
.composer textarea {
  width: 100%;
  border: 0;
  outline: none;
  resize: none;
  min-height: 44px;
  max-height: 180px;
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: transparent;
  padding: 4px 6px;
}
.composer-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}
.attach-btn {
  position: relative;
  overflow: hidden;
  width: 34px;
  height: 34px;
  margin-right: auto;
  border-radius: 10px;
  color: var(--muted);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.attach-btn:hover { background: var(--hover); color: var(--ink); }
.send-btn {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.send-btn:hover { background: var(--blue-2); }
.send-btn:disabled { background: #d7dbe6; cursor: default; }
.stop-btn {
  height: 34px;
  padding: 0 12px;
  border: 1px solid #ffd4d4;
  background: #fff5f5;
  color: var(--danger);
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
}
.stop-btn:hover { background: #ffe8e8; }
.abort-note {
  margin: 12px 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: #fff5f5;
  color: var(--ink);
  font-size: 14px;
}

.data-rail {
  position: relative;
  background: #f4f6fa;
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  z-index: 12;
  transition: transform 0.2s ease;
}
.rail-head {
  height: 56px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px 0 12px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.rail-quota {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px 10px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.rail-quota-track {
  flex: 1;
  height: 6px;
  border-radius: 99px;
  background: #e8ebf2;
  overflow: hidden;
  min-width: 0;
}
.rail-quota-fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 99px;
  background: var(--blue);
}
.rail-quota.warn .rail-quota-fill { background: #d89b2c; }
.rail-quota.full .rail-quota-fill { background: var(--danger); }
.rail-quota-label {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}
.rail-tabs {
  display: flex;
  gap: 2px;
  background: #e8ebf2;
  border-radius: 9px;
  padding: 3px;
  flex: 1;
}
.rail-tabs button {
  flex: 1;
  height: 28px;
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 7px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}
.rail-tabs button.on {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(31, 35, 41, 0.08);
}
.rail-files, .rail-plots {
  flex: 0 1 36%;
  min-height: 72px;
  overflow: auto;
  padding: 8px;
  border-bottom: 1px solid var(--line);
}
.rail-file {
  width: 100%;
  display: grid;
  grid-template-columns: 28px 1fr auto auto;
  gap: 8px;
  align-items: center;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 8px;
  border-radius: 10px;
  cursor: pointer;
  color: inherit;
}
.rail-file > span:nth-child(2) { min-width: 0; }
.rail-file.on { background: #fff; box-shadow: 0 1px 4px rgba(31, 35, 41, 0.06); }
.rail-ext {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: #dfe4f0;
  color: #44506a;
}
.rail-ext.csv, .rail-ext.txt { background: #dce8ff; color: #2f4fc0; }
.rail-ext.xlsx, .rail-ext.xls { background: #d9f0e3; color: #1f7a4c; }
.rail-file-name {
  font-size: 12.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rail-file-meta {
  font-size: 11px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rail-file-size {
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.rail-del {
  width: 24px;
  height: 24px;
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 7px;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  opacity: 0.7;
}
.rail-del:hover, .rail-remove:hover { background: #ffe8e8; color: var(--danger); }
.rail-preview {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.55), transparent 48px),
    #fbfcfe;
}
.rail-preview-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 12px 8px;
  flex-shrink: 0;
}
.rail-preview-bar b {
  font-size: 12.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1 1 120px;
}
.rail-preview-bar span {
  font-size: 11px;
  color: var(--muted);
  flex: 1 1 100%;
  order: 3;
}
.rail-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.rail-insert, .rail-remove {
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 7px;
  cursor: pointer;
  font-size: 12px;
  color: var(--ink);
  white-space: nowrap;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.rail-insert:hover { border-color: var(--blue); color: var(--blue); }
.rail-remove { color: var(--danger); }
.rail-table-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0 0 12px;
}
.rail-table {
  border-collapse: collapse;
  font-size: 11px;
  min-width: 100%;
}
.rail-table th, .rail-table td {
  border-bottom: 1px solid #e7eaf1;
  padding: 5px 10px;
  text-align: left;
  white-space: nowrap;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}
.rail-table th {
  position: sticky;
  top: 0;
  background: #f4f6fa;
  font-weight: 650;
  color: #5b6478;
  z-index: 1;
}
.rail-table tr:nth-child(even) td { background: rgba(255,255,255,0.65); }
.rail-empty, .rail-note {
  margin: 28px 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
  text-align: center;
}
.rail-plot-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.rail-plot {
  position: relative;
}
.rail-plot img {
  display: block;
  width: 100%;
  height: 88px;
  object-fit: cover;
  cursor: zoom-in;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
}
.rail-plot .rail-del {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(255,255,255,0.94);
  box-shadow: 0 1px 4px rgba(31, 35, 41, 0.12);
  opacity: 1;
  z-index: 1;
}
.rail-preview img.rail-hero {
  width: calc(100% - 24px);
  margin: 0 12px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  cursor: zoom-in;
}

.sidebar-mask {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(20, 24, 32, 0.28);
  z-index: 15;
}
.mobile-only { display: none; }
.os-body.collapsed #open-sidebar { display: grid; }

.chat-scroll,
.session-pane,
.rail-files,
.rail-plots,
.rail-table-wrap {
  scrollbar-width: thin;
  scrollbar-color: #b7becc transparent;
}
.chat-scroll::-webkit-scrollbar,
.session-pane::-webkit-scrollbar,
.rail-files::-webkit-scrollbar,
.rail-plots::-webkit-scrollbar,
.rail-table-wrap::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
.chat-scroll::-webkit-scrollbar-thumb,
.session-pane::-webkit-scrollbar-thumb,
.rail-files::-webkit-scrollbar-thumb,
.rail-plots::-webkit-scrollbar-thumb,
.rail-table-wrap::-webkit-scrollbar-thumb {
  background: #c5cad6;
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.chat-scroll::-webkit-scrollbar-thumb:hover,
.session-pane::-webkit-scrollbar-thumb:hover,
.rail-files::-webkit-scrollbar-thumb:hover,
.rail-plots::-webkit-scrollbar-thumb:hover,
.rail-table-wrap::-webkit-scrollbar-thumb:hover {
  background: #9aa3b5;
  background-clip: padding-box;
}

@media (max-width: 1100px) {
  .os-body, .os-body.collapsed, .os-body.rail-off, .os-body.collapsed.rail-off {
    grid-template-columns: var(--sidebar-w) 1fr;
  }
  .os-body.collapsed { grid-template-columns: 0 1fr; }
  .data-rail {
    position: fixed;
    inset: 0 0 0 auto;
    width: min(360px, 92vw);
    transform: translateX(100%);
    box-shadow: -12px 0 32px rgba(20, 24, 32, 0.12);
  }
  .os-body.rail-on .data-rail { transform: none; }
  #resize-rail { display: none; }
}

@media (max-width: 860px) {
  .os-body, .os-body.collapsed, .os-body.rail-off, .os-body.collapsed.rail-off {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    transform: translateX(-100%);
  }
  .os-body.drawer .sidebar { transform: none; }
  .os-body.drawer .sidebar-mask { display: block; }
  .mobile-only { display: grid; }
  #resize-sidebar, #resize-rail { display: none; }
  .empty-state h1 { font-size: 26px; }
  .stream, .composer-dock { width: calc(100% - 20px); }
}
