:root {
  --ink: #172421;
  --muted: #5d6b66;
  --line: #ddd4c6;
  --paper: #fffdf8;
  --bg: #efe8dc;
  --rail: #f7f3eb;
  --teal: #0d5c56;
  --teal-dark: #12332f;
  --red: #8d2e2e;
  --amber: #8a5a12;
  --amber-bg: #fff4df;
  --danger: #8d2e2e;
  --shadow: 0 16px 40px rgba(40, 32, 20, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", sans-serif;
  color: var(--ink);
  background: var(--bg);
}
button, input, select, textarea { font: inherit; color: inherit; }
button, .upload-btn {
  border: 0;
  background: var(--teal);
  color: white;
  border-radius: 6px;
  padding: 8px 12px;
  cursor: pointer;
}
button:disabled { opacity: 0.55; cursor: not-allowed; }
button.ghost, .upload-btn { background: transparent; color: var(--teal-dark); border: 1px solid var(--line); }
button.danger { background: transparent; color: var(--danger); border: 1px solid #e4c8c4; }
button.text-btn { background: transparent; color: var(--teal); padding: 0; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: white;
  border-radius: 6px;
  padding: 8px 10px;
}
textarea { resize: vertical; }
h1, h2, p { margin: 0; }
.hidden, [hidden] { display: none !important; }

.auth {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 32px 16px;
  background:
    linear-gradient(180deg, rgba(18, 51, 47, 0.92), rgba(18, 51, 47, 0.78)),
    repeating-linear-gradient(0deg, transparent, transparent 27px, rgba(255,255,255,0.04) 28px);
}
.auth-card {
  width: min(480px, 100%);
  background: var(--paper);
  border-radius: 16px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.eyebrow { color: var(--teal); font-size: 13px; letter-spacing: 0.04em; }
.auth-card h1 { margin: 8px 0; font-size: 32px; }
.lead, .fine { color: var(--muted); line-height: 1.7; }
.fine { font-size: 12px; margin-top: 16px; }
.stack { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }
.form-error { color: var(--danger); min-height: 1.2em; margin-top: 10px; }

.topbar {
  height: 60px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 18px;
  background: var(--teal-dark);
  color: #f4f7f5;
}
.topbar .sub { display: block; color: #c9d7d3; font-size: 12px; font-weight: 400; }
.top-actions, .row { display: flex; gap: 8px; align-items: center; }
.topbar .ghost { color: white; border-color: rgba(255,255,255,0.25); }
.disclaimer {
  margin: 0;
  padding: 8px 18px;
  background: var(--amber-bg);
  color: var(--amber);
  font-size: 13px;
  line-height: 1.6;
}
.workspace {
  height: calc(100vh - 98px);
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) minmax(380px, 460px);
}
.cases, .chat, .record {
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.cases { background: var(--rail); border-right: 1px solid var(--line); padding: 12px; gap: 10px; }
.cases > .row { flex-wrap: nowrap; }
.cases > .row button { white-space: nowrap; flex: none; }
.cases > .row input { flex: 1; width: auto; min-width: 0; }
.case-list { overflow: auto; display: flex; flex-direction: column; gap: 8px; }
.case-item {
  text-align: left;
  background: white;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}
.case-item.active { border-color: var(--teal); box-shadow: inset 3px 0 0 var(--teal); }
.case-item strong { display: block; }
.case-item span { color: var(--muted); font-size: 12px; }

.chat { background: #f6f1e8; }
.pane-head, .record-tools { display: flex; justify-content: space-between; gap: 8px; align-items: center; padding: 12px; flex-wrap: wrap; }
.pane-head h2 { font-size: 18px; }
.pane-head p, .hint { color: var(--muted); font-size: 12px; }
.messages { flex: 1; overflow: auto; padding: 8px 16px 16px; display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: min(680px, 92%); padding: 10px 12px; border-radius: 12px; line-height: 1.7; white-space: pre-wrap; word-break: break-word; }
.bubble.user { align-self: flex-end; background: var(--teal-dark); color: white; }
.bubble.assistant { align-self: flex-start; background: white; border: 1px solid var(--line); }
.bubble.notice { align-self: center; background: transparent; color: var(--muted); font-size: 13px; }
.file-strip { display: flex; gap: 8px; overflow: auto; padding: 0 12px; }
.file-card { display: flex; gap: 8px; align-items: center; background: white; border: 1px solid var(--line); border-radius: 8px; padding: 6px; min-width: 180px; }
.file-card img { width: 42px; height: 42px; object-fit: cover; border-radius: 4px; }
.file-card p { font-size: 12px; }
.file-card .bad { color: var(--danger); }
.composer { padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.upload-btn input { display: none; }
.empty { margin: auto; max-width: 460px; padding: 24px; }
.empty h2 { margin-bottom: 8px; }
.empty li { margin: 6px 0; line-height: 1.6; }

.record { background: #e7efe9; border-left: 1px solid var(--line); }
.record-tools select { max-width: 180px; }
.gaps { margin: 0 12px; background: var(--amber-bg); color: var(--amber); border-radius: 8px; padding: 10px 12px; white-space: pre-wrap; font-size: 13px; line-height: 1.6; }
.paper {
  position: relative;
  margin: 12px;
  background: var(--paper);
  border: 1px solid #e5dccb;
  box-shadow: var(--shadow);
  min-height: 0;
  overflow: auto;
  padding: 22px 22px 28px;
}
.gen-mask {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(255, 253, 248, 0.94);
  text-align: center;
}
.gen-mask p { font-size: 18px; font-weight: 700; }
.gen-mask span { color: var(--muted); font-size: 13px; }
.spinner {
  width: 46px;
  height: 46px;
  border: 4px solid #d5e3df;
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.paper-top { text-align: center; color: var(--red); border-bottom: 3px double var(--red); padding-bottom: 8px; margin-bottom: 12px; }
.paper-top p { line-height: 1.6; }
.sheet, .editor {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: SimSun, "NSimSun", "Songti SC", serif;
  font-size: 16px;
  line-height: 1.9;
  background: transparent;
  border: 0;
  min-height: 420px;
}
.editor { width: 100%; }

.modal { position: fixed; inset: 0; background: rgba(20, 28, 26, 0.45); display: grid; place-items: center; padding: 16px; z-index: 5; }
.dialog { width: min(760px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: white; border-radius: 14px; padding: 18px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }
.grid .wide { grid-column: 1 / -1; }
.row.end { justify-content: flex-end; }
.toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: white;
  padding: 10px 14px;
  border-radius: 8px;
  z-index: 9;
  max-width: min(560px, calc(100% - 24px));
}
.reader {
  position: fixed;
  inset: 0;
  z-index: 7;
  background: #dfe8e2;
  display: flex;
  flex-direction: column;
}
.reader-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 12px 20px;
  background: var(--teal-dark);
  color: #f4f7f5;
}
.reader-bar button { white-space: nowrap; }
.reader-bar .ghost { color: white; border-color: rgba(255, 255, 255, 0.28); }
.reader-meta, #readerMeta { margin-left: 10px; color: #c9d7d3; font-size: 13px; }
.reader-body { flex: 1; overflow: auto; padding: 28px 20px 56px; }
.reader-body .gaps { width: min(860px, 100%); margin: 0 auto 14px; }
.reader-paper {
  width: min(860px, 100%);
  margin: 0 auto;
  overflow: visible;
  padding: 36px 48px 48px;
}
.reader-paper .sheet { font-size: 18px; line-height: 2; min-height: 0; }

@media (max-width: 1100px) {
  .workspace { grid-template-columns: 1fr; height: auto; }
  .cases, .chat, .record { min-height: 70vh; }
  .grid { grid-template-columns: 1fr; }
}
@media print {
  body { background: white; }
  .topbar, .disclaimer, .cases, .chat, .record-tools, .gaps, .toast, .modal, #editor, #toggleEdit, .reader-bar, .gen-mask { display: none !important; }
  .workspace, .record, .paper { display: block; height: auto; margin: 0; border: 0; box-shadow: none; overflow: visible; }
  .sheet { min-height: 0; }
  .reader { display: none !important; }
  body.reading .workspace, body.reading .topbar, body.reading .disclaimer { display: none !important; }
  body.reading .reader { display: block !important; position: static; background: white; }
  body.reading .reader-paper { width: auto; padding: 0; box-shadow: none; border: 0; }
}
