:root {
  --page: #f5f7fa;
  --panel: #ffffff;
  --ink: #1f2937;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #1e3a5f;
  --brand-soft: #eaf0f7;
  --accent: #b7791f;
  --danger: #b42318;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--page);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

.app {
  display: flex;
  height: 100vh;
  max-width: 1440px;
  margin: 0 auto;
}

.sidebar {
  width: 264px;
  flex: 0 0 264px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.brand { margin-bottom: 18px; }
.brand-name { font-size: 17px; font-weight: 600; color: var(--brand); }
.brand-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.primary-btn, .ghost-btn, .send-btn {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.15s ease;
}

.primary-btn {
  background: var(--brand);
  color: #fff;
  border: 1px solid var(--brand);
  padding: 9px 12px;
  margin-bottom: 20px;
}
.primary-btn:hover { background: #2b507d; }

.ghost-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 6px 12px;
  font-size: 13px;
}
.ghost-btn:hover { background: var(--brand-soft); color: var(--brand); }

.section-title {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.04em;
  margin: 8px 0;
}

.session-list { display: flex; flex-direction: column; gap: 4px; }

.session-item {
  text-align: left;
  font: inherit;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-radius: 6px;
  padding: 8px 10px;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.session-item:hover { background: var(--brand-soft); }
.session-item.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }

.section-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin: 8px 0;
  padding: 4px 2px;
  font: inherit;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}
.section-toggle:hover { color: var(--brand); }
.section-toggle .caret {
  font-size: 10px;
  transition: transform 0.15s ease;
}
.section-toggle[aria-expanded="true"] .caret { transform: rotate(180deg); }

.sources { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.sources[hidden] { display: none; }
.sources a {
  display: flex;
  flex-direction: column;
  gap: 1px;
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  padding: 4px 2px;
}
.source-name { color: var(--muted); }
.source-desc { font-size: 11px; line-height: 1.45; opacity: 0.8; }
.sources a:hover .source-name { color: var(--brand); text-decoration: underline; }

.sidebar-foot {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}
.sidebar-foot a { color: var(--brand); text-decoration: none; }
.sidebar-foot a:hover { text-decoration: underline; }

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 24px 32px 16px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}
.topbar h1 { margin: 0; font-size: 21px; font-weight: 600; color: var(--brand); }
.topbar-sub { margin: 4px 0 0; font-size: 13px; color: var(--muted); }

.notice {
  background: #fff8e8;
  border: 1px solid #f0d9a8;
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  color: #6b4e15;
  margin-bottom: 16px;
}
.notice strong { margin-right: 10px; color: #8a5a06; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 12px 4px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.msg {
  max-width: 820px;
  width: 100%;
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
}
.msg.user {
  align-self: flex-end;
  background: var(--brand-soft);
  border-color: #d3e0ef;
}
.msg.ai { align-self: flex-start; }

.msg-head { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.msg-body { white-space: pre-wrap; word-break: break-word; font-size: 14px; }
.msg-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  font-size: 11px;
  color: var(--muted);
}
.copy {
  font: inherit;
  color: var(--muted);
  background: transparent;
  border: 0;
  cursor: pointer;
  padding: 0;
}
.copy:hover { color: var(--brand); }

.laws-box {
  margin-top: 10px;
  border-top: 1px dashed var(--line);
  padding-top: 8px;
}
.laws-title {
  font-size: 12px;
  color: var(--brand);
  cursor: pointer;
  user-select: none;
}
.laws-title:hover { text-decoration: underline; }
.laws-list { margin-top: 8px; display: flex; flex-direction: column; gap: 8px; }
.laws-item {
  background: var(--brand-soft);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
}
.laws-name { font-weight: 600; color: var(--brand); margin-bottom: 4px; }
.laws-text { color: var(--ink); white-space: pre-wrap; line-height: 1.5; }

.empty {
  margin: auto;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.composer-wrap { border-top: 1px solid var(--line); padding-top: 14px; }
.mode-row { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.mode-toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink); cursor: pointer; }
.mode-toggle input { accent-color: var(--brand); cursor: pointer; }
.mode-note { font-size: 12px; color: var(--muted); }
.composer { display: flex; gap: 12px; align-items: stretch; }
.composer textarea {
  flex: 1;
  resize: none;
  font: inherit;
  color: var(--ink);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}
.composer textarea:focus { outline: 2px solid #c7d8ec; border-color: var(--brand); }
.send-btn {
  background: var(--brand);
  color: #fff;
  border: 1px solid var(--brand);
  padding: 0 26px;
  min-width: 88px;
}
.send-btn:hover { background: #2b507d; }
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.hint { margin: 8px 0 0; font-size: 12px; color: var(--muted); }

@media (max-width: 820px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 12px 16px;
  }
  .session-list, .sources, .section-title, .section-toggle, .sidebar-foot { display: none; }
  .primary-btn { margin-bottom: 0; }
  .main { padding: 16px; }
  .msg { max-width: 100%; }
  .send-btn { padding: 0 18px; min-width: 72px; }
}
