:root {
  --bg: #f5f8fc;
  --panel: #ffffff;
  --ink: #14213d;
  --muted: #66758f;
  --line: #dce5f1;
  --blue: #2475e8;
  --blue-dark: #1559b8;
  --blue-soft: #eef5ff;
  --blue-mid: #d7e7ff;
  --warn: #c2410c;
  --warn-soft: #fff7ed;
  --danger: #b91c1c;
  --shadow: 0 1px 2px rgba(23, 32, 29, 0.04), 0 12px 32px rgba(23, 32, 29, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;
  --radius: 12px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
}

.layout {
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  height: 100%;
  max-width: 1600px;
  margin: 0 auto;
}

.sidebar {
  border-right: 1px solid var(--line);
  padding: 22px 16px 16px;
  background: #f7faff;
  overflow: auto;
}

.brand-block {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
}
.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: #2475e8;
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.02em;
}
.brand { font-weight: 700; font-size: 1.05rem; color: var(--ink); }
.hint { margin: 2px 0 0; color: var(--muted); font-size: 0.78rem; }

.case-label {
  margin: 18px 0 8px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.case-list { display: flex; flex-direction: column; gap: 8px; }
.sidebar-foot {
  position: sticky;
  top: calc(100% - 32px);
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 16px 4px 0;
  color: var(--muted);
  font-size: 0.73rem;
}
.sidebar-foot .dot { width: 7px; height: 7px; border-radius: 50%; background: #4a90f2; }
.mobile-history-btn,
.mobile-close,
.mobile-overlay { display: none; }
.case-empty {
  color: var(--muted);
  font-size: 0.82rem;
  padding: 8px 4px;
}
.case-item {
  display: flex;
  align-items: stretch;
  gap: 2px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 10px;
  overflow: hidden;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.case-item:hover { border-color: #93c5fd; background: var(--blue-soft); }
.case-item.active {
  border-color: var(--blue);
  background: var(--blue-soft);
  box-shadow: inset 3px 0 0 var(--blue);
}
.case-item-main {
  flex: 1;
  min-width: 0;
  text-align: left;
  border: none;
  background: transparent;
  padding: 10px 8px 10px 12px;
  cursor: pointer;
  font: inherit;
  font-size: 0.9rem;
  color: inherit;
}
.case-item-title {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.case-item small { display: block; color: var(--muted); margin-top: 4px; font-size: 0.75rem; }
.case-del {
  flex-shrink: 0;
  width: 32px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  opacity: 0.55;
}
.case-del:hover {
  color: var(--danger);
  background: #fef2f2;
  opacity: 1;
}

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.top {
  min-height: 74px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  background: rgba(255, 255, 255, 0.94);
}
.top h1 { margin: 0; font-size: 1.18rem; font-weight: 680; letter-spacing: -0.01em; }
.title-row { display: flex; align-items: center; gap: 7px; }
.icon-btn { border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 3px 6px; border-radius: 6px; }
.icon-btn:hover { color: var(--blue-dark); background: var(--blue-soft); }
.status { margin-top: 5px; font-size: 0.76rem; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #9ca3af; }
.status.ok { color: var(--blue); }
.status.bad { color: var(--danger); }
.status.ok .status-dot { background: #2475e8; box-shadow: 0 0 0 3px #e4efff; }
.status.bad .status-dot { background: var(--danger); }

.stages {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
  align-items: center;
}

.panel, .work {
  padding: 20px 24px;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: auto;
}

/* 新建案子：整页不滚动，内容压进一屏 */
.create-panel {
  overflow: hidden;
  align-items: stretch;
  justify-content: flex-start;
  padding: 16px 20px;
}
.create-panel .create-card {
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 18px 20px;
  overflow: hidden;
}

.create-card {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 20px 22px;
}

.create-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  flex-shrink: 0;
}
.create-sub {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
  flex: 1;
  min-width: 0;
}
.create-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 0.86rem;
  color: var(--muted);
  font-weight: 500;
}
.field > span { color: #334155; }
.field-compact { margin-bottom: 10px; flex-shrink: 0; }
.field-materials {
  flex: 1;
  min-height: 0;
  margin-bottom: 0;
}

.materials-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 12px;
  align-items: stretch;
}
.materials-upload {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}
.field-materials > .materials-grid {
  height: 100%;
}
.field-materials {
  display: flex;
  flex-direction: column;
}

input, textarea {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  color: var(--ink);
  background: #fff;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, textarea:focus {
  border-color: #72aaf4;
  box-shadow: 0 0 0 3px rgba(36, 117, 232, 0.12);
}
#newRaw {
  height: 100%;
  min-height: 0;
  resize: none;
  overflow: auto;
}

.dropzone {
  position: relative;
  border: 1.5px dashed #94bdf4;
  border-radius: 12px;
  background: var(--blue-soft);
  flex: 1;
  min-height: 120px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.dropzone:hover, .dropzone.dragover {
  background: var(--blue-mid);
  border-color: var(--blue);
}
.dropzone input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}
.dropzone-inner {
  pointer-events: none;
  height: 100%;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--blue-dark);
  text-align: center;
  padding: 12px;
}
.dropzone-inner strong { font-size: 0.9rem; }
.dropzone-inner span { font-size: 0.75rem; color: var(--muted); font-weight: 400; line-height: 1.35; }

.file-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 72px;
  overflow: auto;
  flex-shrink: 0;
}
.file-list:empty { display: none; }
.file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
  font-size: 0.8rem;
  color: var(--ink);
}
.file-item button {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.8rem;
}
.file-item button:hover { color: var(--danger); }

.btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 9px 14px;
  cursor: pointer;
  font: inherit;
  font-weight: 550;
  color: var(--ink);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn:hover { background: var(--blue-soft); border-color: #94bdf4; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}
.btn.primary:hover { background: var(--blue-dark); border-color: var(--blue-dark); }
.btn.warn {
  background: var(--warn);
  color: #fff;
  border-color: var(--warn);
}
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }

.work {
  overflow: hidden;
  padding: 12px 16px 14px;
}

.step-page {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 12px 14px;
}

.step-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  flex-shrink: 0;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.step-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  min-width: 0;
  flex: 1;
}
.step-desc {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.4;
}
.step-rounds {
  flex-shrink: 0;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--blue-dark);
  background: var(--blue-soft);
  border: 1px solid var(--blue-mid);
  border-radius: 999px;
  padding: 3px 9px;
}
.step-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  flex-shrink: 0;
}

.step-error {
  flex-shrink: 0;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--danger);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.88rem;
}

.doc-shell {
  position: relative;
  flex: 1;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fafbf9;
  overflow: hidden;
}
.doc-empty {
  height: 100%;
  min-height: 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--muted);
  text-align: center;
  padding: 24px;
}
.doc-empty strong {
  color: #334155;
  font-size: 1rem;
}
.doc-empty span { font-size: 0.86rem; }
.doc-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.72);
  color: var(--blue-dark);
  font-weight: 600;
  font-size: 0.95rem;
  z-index: 2;
}

.timeline {
  height: 100%;
  overflow: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.turn {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 12px 14px;
}
.turn.is-latest {
  border-color: #94bdf4;
  box-shadow: 0 0 0 1px rgba(36, 117, 232, 0.08);
}
.turn.is-streaming {
  border-style: dashed;
  border-color: var(--blue);
}
.turn-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}
.turn-idx {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--blue-dark);
}
.turn-head time {
  font-size: 0.75rem;
  color: var(--muted);
}
.turn-user, .turn-assistant {
  margin-top: 8px;
}
.turn-user strong, .turn-assistant strong {
  display: block;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}
.turn-user p {
  margin: 0;
  font-size: 0.9rem;
  color: #334155;
  white-space: pre-wrap;
  background: var(--blue-soft);
  border-radius: 8px;
  padding: 8px 10px;
}
.turn-assistant .md {
  font-size: 0.92rem;
  line-height: 1.6;
  color: #1e293b;
  overflow-wrap: anywhere;
}
.turn-assistant .md > :first-child { margin-top: 0; }
.turn-assistant .md > :last-child { margin-bottom: 0; }
.turn-assistant .md blockquote { margin: 0.8em 0; padding: 0.1em 0 0.1em 14px; border-left: 3px solid var(--blue); color: #53615b; }
.turn-assistant .md code { background: #eef2f0; border-radius: 5px; padding: 0.12em 0.35em; font-size: 0.88em; }
.turn-assistant .md table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.85rem;
  margin: 0.6em 0;
}
.turn-assistant .md th, .turn-assistant .md td {
  border: 1px solid var(--line);
  padding: 6px 8px;
  vertical-align: top;
}
.turn-assistant .md th { background: var(--blue-soft); }
.turn-assistant .md h1, .turn-assistant .md h2, .turn-assistant .md h3 {
  margin: 1em 0 0.4em;
  line-height: 1.3;
}
.turn-assistant .md h2 {
  font-size: 1.05rem;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.3em;
}

.step-foot {
  flex-shrink: 0;
  padding-top: 2px;
}
.note-form {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
}
.note-form textarea {
  min-height: 52px;
  max-height: 120px;
  resize: vertical;
}
.send-actions { display: flex; align-items: center; gap: 10px; }
.send-hint { color: var(--muted); font-size: 0.7rem; white-space: nowrap; }
.attach-btn {
  position: relative;
  align-self: stretch;
  min-width: 58px;
  border: 1px solid #cfdced;
  border-radius: 12px;
  background: #fff;
  color: var(--blue-dark);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  cursor: pointer;
}
.attach-btn:hover { background: var(--blue-soft); border-color: #94bdf4; }
.attach-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.attach-btn > span:first-of-type { font-size: 1.1rem; line-height: 1; }
.attach-label { font-size: 0.68rem; }
.composer-file-list {
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.composer-file-list:empty { display: none; }
.composer-file-list .file-item { width: auto; background: var(--blue-soft); border-color: var(--blue-mid); }

.stage-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 0.78rem;
  color: var(--muted);
  background: #fff;
  cursor: pointer;
  font: inherit;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.stage-pill:hover:not(:disabled) {
  border-color: #94bdf4;
  background: var(--blue-soft);
  color: var(--blue-dark);
}
.stage-pill.current {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
  font-weight: 600;
}
.stage-pill.current:hover:not(:disabled) {
  background: var(--blue-dark);
  color: #fff;
}
.stage-pill.done {
  background: var(--blue-soft);
  color: var(--blue-dark);
  border-color: var(--blue-mid);
}
.stage-pill.locked,
.stage-pill:disabled.locked {
  opacity: 0.45;
  cursor: not-allowed;
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--line);
    max-height: 28vh;
  }
  .top { flex-direction: column; align-items: stretch; }
  .stages { justify-content: flex-start; }
  .step-toolbar { flex-direction: column; align-items: stretch; }
  .step-actions { justify-content: flex-start; }
  .note-form { grid-template-columns: auto minmax(0, 1fr); }
  .send-actions { justify-content: space-between; }
  .send-actions { grid-column: 1 / -1; }
  .materials-grid { grid-template-columns: 1fr; }
  .dropzone, .dropzone-inner { min-height: 72px; }
  .create-panel { overflow: auto; }
}

@media (max-width: 560px) {
  html, body { height: 100%; overflow: hidden; }
  .layout { display: block; height: 100dvh; }
  .main { height: 100dvh; }
  .sidebar {
    position: fixed;
    z-index: 30;
    inset: 0 auto 0 0;
    width: min(86vw, 330px);
    max-height: none;
    padding: 18px 14px;
    border: 0;
    box-shadow: 18px 0 50px rgba(20, 46, 84, 0.18);
    transform: translateX(-105%);
    transition: transform 0.22s ease;
  }
  .mobile-history-open .sidebar { transform: translateX(0); }
  .mobile-overlay {
    position: fixed;
    z-index: 20;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    background: rgba(18, 37, 68, 0.34);
  }
  .mobile-history-open .mobile-overlay { display: block; }
  .mobile-close {
    display: grid;
    place-items: center;
    margin-left: auto;
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 10px;
    background: #eef5ff;
    color: #426189;
    font-size: 1.25rem;
  }
  .mobile-history-btn {
    display: grid;
    place-items: center;
    flex: 0 0 36px;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    color: var(--blue-dark);
    font-size: 1rem;
  }
  .brand-block { margin-bottom: 14px; }
  .top { min-height: 62px; padding: 10px 12px; flex-direction: row; align-items: center; gap: 10px; }
  .top-left { min-width: 0; }
  .top h1 { font-size: 1.02rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .status { margin-top: 2px; font-size: 0.68rem; }
  .work { padding: 0; min-height: 0; }
  .step-page { padding: 0; border: 0; border-radius: 0; box-shadow: none; gap: 0; }
  .doc-shell { border: 0; border-radius: 0; }
  .step-foot { padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); background: #fff; }
  .turn { padding: 10px; }
  .turn-assistant .md table { display: block; overflow-x: auto; white-space: nowrap; }
  .stage-pill { padding: 5px 9px; }
  .note-form { grid-template-columns: 44px minmax(0, 1fr) auto; gap: 6px; }
  .note-form textarea { min-height: 46px; max-height: 94px; padding: 11px; resize: none; }
  .attach-btn { min-width: 44px; border-radius: 12px; }
  .attach-label, .send-hint { display: none; }
  .send-actions { grid-column: auto; align-self: stretch; }
  .send-actions .btn { height: 100%; padding: 0 14px; border-radius: 12px; }
}

/* 对话模式：一轮历史 = 用户消息 + 智能体回复 */
.create-panel,
.stages,
.step-actions,
.step-toolbar,
.icon-btn { display: none !important; }
.top { justify-content: flex-start; }
.timeline {
  padding: 20px clamp(12px, 3vw, 34px);
  gap: 22px;
  background: #f8fbff;
}
.turn,
.turn.is-latest,
.turn.is-streaming {
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0 0 22px;
  box-shadow: none;
  border-bottom: 1px solid #e6edf7;
}
.turn:last-child { border-bottom: 0; padding-bottom: 4px; }
.turn-head { margin: 0 42px 12px; }
.turn-idx { color: #71809a; font-weight: 600; }
.message-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 12px 0;
}
.user-row { justify-content: flex-end; padding-left: min(18%, 180px); }
.assistant-row { justify-content: flex-start; padding-right: min(10%, 100px); }
.avatar {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 700;
}
.user-avatar { background: #dceaff; color: #1559b8; }
.assistant-avatar { background: #2475e8; color: #fff; box-shadow: 0 4px 12px rgba(36, 117, 232, 0.2); }
.message-content { min-width: 0; max-width: 100%; }
.turn-user { background: #2475e8; color: #fff; border-radius: 16px 5px 16px 16px; padding: 10px 14px; }
.turn-user p { margin: 0; padding: 0; background: transparent; color: #fff; line-height: 1.55; }
.turn-assistant { background: #fff; border: 1px solid #dce5f1; border-radius: 5px 16px 16px 16px; padding: 14px 16px; box-shadow: 0 4px 18px rgba(32, 83, 146, 0.06); }
.turn-assistant .md { color: #27364f; }
.turn-assistant .md th { background: #eef5ff; color: #214e88; }
.turn-assistant .md blockquote { border-left-color: #2475e8; }
.step-foot { border-top: 1px solid var(--line); padding-top: 10px; }
.note-form textarea { background: #f9fbfe; border-color: #cfdced; }
.btn.primary { box-shadow: 0 4px 12px rgba(36, 117, 232, 0.16); }

@media (max-width: 560px) {
  .timeline { padding: 14px 10px; }
  .turn-head { margin: 0 4px 10px; }
  .user-row { padding-left: 34px; }
  .assistant-row { padding-right: 0; }
  .avatar { width: 28px; height: 28px; flex-basis: 28px; border-radius: 8px; }
  .turn-assistant { padding: 12px; }
  .timeline { padding-bottom: 16px; }
}
