:root {
  --bg: #f4f7fb;
  --surface: #fff;
  --surface-2: #f8fafc;
  --text: #17243a;
  --muted: #6b798e;
  --border: #e3e9f2;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #e9f1ff;
  --accent: #0ea5a4;
  --accent-soft: #e6f7f5;
  --danger: #e11d48;
  --danger-soft: #fff0f4;
  --warning: #f59e0b;
  --warning-soft: #fff6e6;
  --success: #10b981;
  --success-soft: #e8f9f3;
  --shadow: 0 14px 36px rgba(18, 38, 72, .07);
  --radius: 18px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: var(--primary); text-decoration: none; }

.topbar {
  height: 66px; background: #fff; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px; padding: 0 28px;
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 780; font-size: 17px; letter-spacing: -.3px; }
.brand span { color: var(--primary); }
.topbar-spacer { flex: 1; }
.topbar a, .topbar button { font-size: 13px; }
.user-chip { font-size: 12px; color: var(--muted); background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 5px 11px; }

.btn {
  border: 1px solid var(--border); background: #fff; color: var(--text);
  border-radius: 10px; padding: 8px 14px; font-size: 13px; font-weight: 620;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:hover { border-color: #c4d3ea; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-danger { color: var(--danger); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.app-shell { max-width: 1560px; margin: 0 auto; padding: 16px 22px 22px; }
.danger-banner { background: var(--danger-soft); border: 1px solid #f3bdcc; color: #a11344; border-radius: 13px; padding: 11px 14px; font-size: 13px; margin-bottom: 14px; }
.danger-banner strong { display: block; margin-bottom: 3px; }
.right-panel .danger-banner { margin: 0; border-radius: 0; border-width: 0 0 1px; }

.grid { display: grid; grid-template-columns: 260px minmax(0, 1fr) 330px; gap: 16px; align-items: stretch; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.panel-head { padding: 15px 17px 12px; border-bottom: 1px solid var(--border); }
.panel-head h2 { margin: 0; font-size: 14px; }
.panel-head p { margin: 3px 0 0; font-size: 11px; color: var(--muted); }
.panel-body { padding: 16px 17px; }

.field { margin-bottom: 13px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; font-weight: 620; }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 10px; padding: 9px 11px;
  background: #fff; color: var(--text); outline: 0; font-size: 13px;
}
.field textarea { min-height: 90px; resize: vertical; line-height: 1.6; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: #b7ccff; box-shadow: 0 0 0 3px rgba(37,99,235,.08); }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.step-rail { display: flex; gap: 5px; margin: 12px 0 16px; }
.step-dot { flex: 1; height: 6px; border-radius: 999px; background: #e8edf5; }
.step-dot.done { background: var(--primary); }
.step-dot.current { background: var(--accent); }
.info-block { border-left: 2px solid var(--border); padding-left: 12px; margin-left: 3px; margin-bottom: 14px; }
.info-block h4 { margin: 0 0 4px; font-size: 12px; color: var(--primary-dark); }
.info-block p, .info-block li { font-size: 12px; color: #44536a; margin: 3px 0; }
.info-block ul { margin: 0; padding-left: 16px; }

.sessions-panel, .center-column, .right-panel { height: calc(100vh - 38px); min-height: 620px; }
.sessions-panel, .right-panel { position: sticky; top: 16px; }
.sessions-panel { display: flex; flex-direction: column; }
.session-list { flex: 1; overflow-y: auto; padding: 8px; }
.session-item { width: 100%; text-align: left; border: 1px solid transparent; background: transparent; border-radius: 10px; padding: 10px 11px; margin-bottom: 4px; display: block; }
.session-item:hover { background: var(--surface-2); }
.session-item.active { background: var(--primary-soft); border-color: #cddcff; }
.session-title { display: block; font-size: 13px; font-weight: 650; color: var(--text); }
.session-preview { display: block; font-size: 11px; color: var(--muted); margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-meta { display: block; font-size: 10px; color: #9aa7b8; margin-top: 3px; }
.session-item.pinned { background: var(--accent-soft); border-color: #b8e6e2; }
.session-pin { color: var(--accent); font-size: 10px; margin-right: 4px; }
.session-menu { position: fixed; z-index: 50; background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); padding: 5px; min-width: 132px; }
.session-menu button { display: block; width: 100%; text-align: left; border: 0; background: transparent; border-radius: 7px; padding: 7px 9px; font-size: 12px; color: var(--text); }
.session-menu button:hover { background: var(--surface-2); }
.session-menu button[data-action="delete"] { color: var(--danger); }
.sidebar-footer { margin-top: auto; border-top: 1px solid var(--border); padding: 12px 13px; background: var(--surface-2); }
.brand-sidebar { font-size: 14px; line-height: 1.4; padding: 0 2px 8px; }
.sidebar-user-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sidebar-user-row a, .sidebar-user-row button { font-size: 12px; }
.sidebar-user-row .user-chip { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.center-column { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.case-panel { flex: 0 0 auto; }
.case-head { cursor: pointer; position: relative; }
.case-head .fold-icon { position: absolute; right: 16px; top: 50%; transform: translateY(-50%); font-size: 12px; color: var(--muted); transition: transform .15s; }
.case-panel.collapsed { display: none; }
.case-body { padding: 11px 16px; }
.case-row { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.case-row .field { margin-bottom: 0; flex: 1 1 150px; }
.case-select-field { flex: 2 1 240px; }
.case-mode-field { flex: 1 1 130px; }
.case-check { font-size: 12px; color: var(--muted); white-space: nowrap; padding-bottom: 9px; }
.case-row .btn { margin-bottom: 0; }
.case-body > .field { margin-top: 10px; }
.case-body .field textarea { min-height: 56px; }
.center-panel { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.step-content { flex: 1; overflow-y: auto; padding: 18px; }
.right-panel { display: flex; flex-direction: column; }
.right-panel .panel-body { flex: 1; overflow-y: auto; }
.step-card { border: 1px solid var(--border); border-radius: 13px; margin-bottom: 9px; background: var(--surface-2); overflow: hidden; }
.step-card[open] { padding-bottom: 12px; }
.step-card summary { cursor: pointer; padding: 10px 13px; font-size: 13px; font-weight: 650; list-style: none; display: flex; align-items: center; }
.step-card summary::-webkit-details-marker { display: none; }
.step-card summary::before { content: '▸'; margin-right: 7px; color: var(--muted); font-size: 11px; transition: transform .15s; }
.step-card[open] summary::before { transform: rotate(90deg); }
.step-card .rich-body { padding: 0 13px; font-size: 12px; color: #3f4d62; }
.step-card.current { border-color: #cddcff; background: #f5f9ff; }
.step-index { color: var(--primary); font-weight: 750; margin-right: 5px; }
.reliability { font-size: 10px; margin-left: auto; border-radius: 999px; padding: 2px 8px; background: var(--warning-soft); color: #8a5a10; }
.chat-log { flex: 1; overflow-y: auto; padding: 18px; }
.msg { margin-bottom: 14px; }
.msg-user { background: var(--primary); color: #fff; border-radius: 13px 13px 4px 13px; padding: 10px 13px; margin-left: 18%; font-size: 13px; }
.msg-assistant { background: var(--surface-2); border: 1px solid var(--border); border-radius: 13px 13px 13px 4px; padding: 10px 13px; margin-right: 12%; font-size: 13px; }
.typing { display: flex; align-items: center; gap: 5px; color: var(--muted); }
.typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--primary); animation: typing-blink 1.1s infinite; }
.typing span:nth-child(2) { animation-delay: .18s; }
.typing span:nth-child(3) { animation-delay: .36s; }
.typing em { font-style: normal; margin-left: 6px; font-size: 12px; }
@keyframes typing-blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }
.stream-msg { white-space: normal; }
.stream-msg em { font-style: normal; color: var(--muted); font-size: 12px; display: block; margin-bottom: 8px; }
.rich-body { font-size: 13px; color: #3f4d62; line-height: 1.7; }
.md-p { margin: 0 0 8px; }
.md-list { margin: 6px 0 10px; padding-left: 20px; }
.md-list li { margin: 3px 0; }
.md-heading { font-weight: 700; color: var(--primary-dark); margin: 12px 0 6px; font-size: 13px; }
.kv-inline { margin: 3px 0; }
code { background: #eef2f7; padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.wait-progress { height: 4px; background: #e8edf5; border-radius: 999px; overflow: hidden; margin-bottom: 9px; }
.wait-progress span { display: block; width: 35%; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--primary), var(--accent)); animation: wait-slide 1.4s ease-in-out infinite; }
@keyframes wait-slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(320%); } }
.stream-cursor { display: inline-block; width: 7px; height: 15px; margin-left: 2px; vertical-align: -2px; background: var(--primary); animation: cursor-blink .9s steps(1) infinite; }
@keyframes cursor-blink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }
.reasoning-box { border-left: 3px solid #a78bfa; background: #f8f6ff; border-radius: 10px; padding: 8px 11px; margin-bottom: 10px; font-size: 12px; color: #5b4b8a; }
.reasoning-box summary { cursor: pointer; font-weight: 650; font-size: 12px; color: #6d5bb5; outline: none; }
.reasoning-box summary::marker { color: #a78bfa; }
.reasoning-text { white-space: pre-wrap; margin-top: 6px; max-height: 260px; overflow-y: auto; line-height: 1.55; }
.msg .reasoning-box { margin-top: 9px; }
.followup-box { border: 1px solid #dbe7ff; background: #f5f9ff; border-radius: 12px; padding: 12px 14px; margin-top: 14px; }
.followup-title { font-size: 12px; font-weight: 700; color: var(--primary-dark); margin-bottom: 6px; }
.followup-box ul { margin: 0; padding-left: 18px; }
.followup-box li { font-size: 12px; color: #44536a; margin: 3px 0; }
.followup-none { font-size: 12px; color: var(--muted); margin: 0; }
.followup-box .btn { margin-top: 10px; }
.composer { border-top: 1px solid var(--border); padding: 13px 16px; }
.composer textarea { width: 100%; min-height: 64px; max-height: 150px; border: 1px solid var(--border); border-radius: 11px; padding: 9px 11px; resize: vertical; outline: 0; font-size: 13px; }
.composer-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.composer-actions { display: flex; gap: 8px; }
.composer-caption { text-align: center; font-size: 10px; color: #9aa7b8; margin-top: 7px; }
.attachment-bar { display: flex; align-items: center; gap: 8px; margin-top: 7px; flex-wrap: wrap; }
.attach-btn { font-size: 11px; color: var(--primary); border: 1px dashed #b7ccff; border-radius: 8px; padding: 4px 9px; cursor: pointer; }
.attach-btn:hover { background: var(--primary-soft); }
.attachment-list { display: flex; gap: 6px; flex-wrap: wrap; }
.attachment-chip { font-size: 10px; background: var(--accent-soft); color: #0b7d76; border-radius: 999px; padding: 3px 8px; display: inline-flex; align-items: center; gap: 5px; max-width: 220px; }
.attachment-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-chip button { border: 0; background: transparent; color: inherit; cursor: pointer; font-size: 12px; line-height: 1; padding: 0; }
.modal-overlay { position: fixed; inset: 0; z-index: 90; background: rgba(15,23,42,.45); display: flex; align-items: center; justify-content: center; }
.modal-box { width: 360px; max-width: 90vw; background: #fff; border-radius: 14px; box-shadow: var(--shadow); padding: 20px 22px; }
.modal-box h3 { margin: 0 0 10px; font-size: 15px; }
.modal-box p { margin: 0 0 14px; font-size: 13px; color: var(--muted); }
.modal-box input { width: 100%; margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.upload-progress { position: fixed; right: 24px; bottom: 24px; z-index: 80; width: 300px; background: #fff; border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 14px 16px; }
.upload-progress-title { font-size: 13px; font-weight: 650; color: var(--text); margin-bottom: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-progress-track { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.upload-progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--primary), var(--accent)); border-radius: 999px; transition: width .15s ease; }
.upload-progress-fill.indeterminate { width: 35%; animation: progress-slide 1.1s ease-in-out infinite; }
@keyframes progress-slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(300%); } }
.upload-progress-detail { font-size: 11px; color: var(--muted); margin-top: 7px; }
.attachment-chip .apply-text { font-size: 10px; color: var(--primary); border-left: 1px solid #d7e3ff; padding-left: 6px; margin-left: 2px; }
.attach-note { font-size: 10px; color: var(--muted); }
.upload-chip { color: var(--primary-dark); background: var(--primary-soft); }
.msg-attachments { display: block; font-size: 10px; color: #0b7d76; background: var(--accent-soft); border-radius: 999px; padding: 2px 8px; margin-top: 6px; }
.msg-user .msg-attachments { color: #dbeafe; background: rgba(255,255,255,.18); }
.hint { font-size: 10px; color: #9aa7b8; }

.tabs { display: flex; gap: 5px; padding: 10px 12px 0; flex-wrap: wrap; }
.tab { border: 1px solid var(--border); background: var(--surface-2); border-radius: 9px; padding: 5px 9px; font-size: 11px; color: var(--muted); }
.tab.active { background: var(--primary-soft); border-color: #cddcff; color: var(--primary-dark); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }
.kv-card { border: 1px solid var(--border); border-radius: 12px; padding: 12px 13px; margin-bottom: 10px; background: var(--surface-2); }
.kv-card h3 { margin: 0 0 5px; font-size: 13px; }
.kv-card p { margin: 3px 0; font-size: 12px; color: #44536a; }
.kv-card b { color: var(--text); }
.risk-tag { display: inline-block; font-size: 10px; border-radius: 999px; padding: 2px 8px; margin: 2px 4px 2px 0; background: var(--danger-soft); color: var(--danger); }
.ok-tag { background: var(--success-soft); color: #0b8a63; }
.warn-tag { background: var(--warning-soft); color: #8a5a10; }

.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: 100%; max-width: 420px; background: #fff; border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow); padding: 28px; }
.auth-card h1 { margin: 0 0 6px; font-size: 22px; }
.auth-card p { margin: 0 0 22px; color: var(--muted); font-size: 13px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { font-size: 11px; color: var(--muted); font-weight: 700; }
.error-text { color: var(--danger); font-size: 12px; min-height: 18px; }
.empty { text-align: center; color: var(--muted); padding: 34px; font-size: 13px; }

@media (max-width: 1180px) {
  .grid { grid-template-columns: 230px minmax(0, 1fr); }
  .right-panel { grid-column: 1 / -1; height: auto; min-height: 0; }
  .right-panel .panel-body { max-height: 520px; }
}
@media (max-width: 820px) {
  .topbar { padding: 0 14px; }
  .user-chip { display: none; }
  .app-shell { padding: 14px 12px 28px; }
  .grid { grid-template-columns: 1fr; }
  .sessions-panel { height: auto; min-height: 0; max-height: 260px; }
  .center-column { height: auto; min-height: 0; }
  .case-fields { grid-template-columns: 1fr; }
  .center-panel { height: 72vh; min-height: 520px; }
}
