:root {
  --paper: #f4f2ed;
  --surface: #fffdfa;
  --ink: #1e2420;
  --muted: #68706a;
  --line: #d8d8d0;
  --accent: #b44b35;
  --accent-dark: #873423;
  --green: #2f6b4f;
  --amber: #9a6a17;
  --red: #a7352b;
  --shadow: 0 12px 34px rgba(33, 40, 34, .07);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--paper); }
button, input, textarea, select { font: inherit; letter-spacing: 0; }
button { min-height: 40px; border: 1px solid #b9bcb6; background: var(--surface); color: var(--ink); padding: 8px 14px; cursor: pointer; border-radius: 5px; }
button:hover { border-color: #777e77; }
button:disabled { opacity: .45; cursor: wait; }
button.primary { color: #fff; background: var(--accent); border-color: var(--accent); }
button.primary:hover { background: var(--accent-dark); }
button.danger { color: #fff; background: var(--red); border-color: var(--red); }
button.quiet { background: transparent; }
button.full { width: 100%; }
input, textarea, select { width: 100%; border: 1px solid var(--line); border-radius: 4px; background: #fff; color: var(--ink); padding: 10px 11px; }
textarea { resize: vertical; line-height: 1.6; }
label { display: grid; gap: 7px; color: #4e554f; font-size: 13px; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-family: Georgia, "Songti SC", serif; font-size: clamp(23px, 3vw, 34px); letter-spacing: 0; }
h2 { margin-bottom: 0; font-size: 20px; }
h3 { margin-bottom: 0; font-size: 15px; }
.eyebrow { margin-bottom: 5px; color: var(--accent); font: 700 11px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .08em; }
.muted, .summary-line { color: var(--muted); }
.error-text { min-height: 20px; color: var(--red); font-size: 13px; }
.login-gate { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 20px; background: #e9e6df; }
.login-panel { width: min(410px, 100%); padding: 34px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); }
.login-panel h1 { margin-bottom: 12px; }
.login-panel label { margin: 24px 0 14px; }
.app-shell { width: min(1500px, 100%); margin: 0 auto; padding: 24px 28px 60px; }
.topbar { display: flex; align-items: end; justify-content: space-between; gap: 24px; padding-bottom: 20px; border-bottom: 1px solid #bfc2bb; }
.top-actions, .button-row { display: flex; align-items: end; gap: 8px; flex-wrap: wrap; }
.date-field { width: 154px; }
.status-dot { display: inline-flex; align-items: center; min-height: 40px; padding: 0 10px; color: var(--muted); font-size: 13px; }
.status-dot::before { content: ""; width: 8px; height: 8px; margin-right: 7px; background: var(--amber); border-radius: 50%; }
.status-dot.ok::before { background: var(--green); }
.tabs { display: flex; overflow-x: auto; border-bottom: 1px solid var(--line); }
.tab { min-width: 104px; border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: transparent; color: var(--muted); }
.tab.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 700; }
.provider-strip { display: grid; grid-template-columns: 150px minmax(220px, 1.4fr) minmax(150px, .8fr) minmax(220px, 1.2fr); gap: 12px; padding: 18px 0; border-bottom: 1px solid var(--line); }
.tab-panel { display: none; padding-top: 28px; }
.tab-panel.active { display: block; }
.section-heading { display: flex; justify-content: space-between; align-items: end; gap: 20px; }
.section-heading.spaced { margin-top: 34px; }
.candidate-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 14px; }
.data-panel, .output-panel, .context-panel { border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow); }
.data-panel > header, .output-panel > header { display: flex; justify-content: space-between; align-items: center; min-height: 50px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.data-panel > header span { color: var(--muted); font-size: 12px; }
.news-list { height: 370px; overflow: auto; padding: 4px 14px 12px; }
.news-item { padding: 11px 0; border-bottom: 1px solid #ebe9e3; }
.news-item:last-child { border-bottom: 0; }
.news-item a { color: var(--ink); text-decoration: none; line-height: 1.45; }
.news-item a:hover { color: var(--accent); }
.news-meta { display: flex; gap: 8px; margin-top: 5px; color: var(--muted); font-size: 11px; }
.empty { display: grid; place-items: center; color: var(--muted); }
.control-grid { display: grid; grid-template-columns: minmax(200px, .7fr) minmax(320px, 2fr) auto; gap: 14px; margin: 14px 0; align-items: end; }
.align-end { align-self: end; }
.output-panel pre { min-height: 260px; max-height: 520px; margin: 0; padding: 18px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; font: 13px/1.65 ui-monospace, SFMono-Regular, Menlo, monospace; }
.summary-line { padding: 14px 0; border-bottom: 1px solid var(--line); }
.chat-layout { display: grid; grid-template-columns: 300px 1fr; gap: 14px; margin-top: 14px; }
.context-panel { padding: 16px; }
.context-panel fieldset { display: grid; gap: 9px; margin: 18px 0 0; padding: 12px; border: 1px solid var(--line); }
.context-panel fieldset label { display: flex; align-items: center; gap: 8px; }
.context-panel input[type="checkbox"] { width: auto; }
.chat-main { min-width: 0; border: 1px solid var(--line); background: var(--surface); }
.chat-messages { height: 520px; overflow: auto; padding: 18px; }
.message { max-width: 88%; margin-bottom: 14px; padding: 12px 14px; border-left: 3px solid var(--line); background: #f5f3ee; white-space: pre-wrap; line-height: 1.65; }
.message.user { margin-left: auto; border-left-color: var(--accent); background: #f7ece7; }
.message.assistant { border-left-color: var(--green); }
.chat-compose { display: grid; grid-template-columns: 1fr auto; gap: 10px; padding: 12px; border-top: 1px solid var(--line); align-items: end; }
.source-form { display: grid; grid-template-columns: 150px 190px 100px 100px minmax(240px, 1fr) minmax(170px, .7fr) auto; gap: 8px; margin: 14px 0; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); background: var(--surface); }
table { width: 100%; border-collapse: collapse; min-width: 840px; }
th, td { padding: 11px 12px; text-align: left; border-bottom: 1px solid #e5e4de; font-size: 13px; vertical-align: top; }
th { color: var(--muted); background: #f6f4ef; font-size: 11px; }
.health-ok { color: var(--green); }.health-error { color: var(--red); }
.history-list { margin-top: 14px; border-top: 1px solid var(--line); }
.history-item { display: grid; grid-template-columns: 72px 150px 1fr auto; gap: 12px; padding: 13px 4px; border-bottom: 1px solid var(--line); align-items: center; }
.history-item button { min-height: 34px; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 30; max-width: min(420px, calc(100vw - 40px)); padding: 12px 15px; color: #fff; background: #242a25; opacity: 0; pointer-events: none; transform: translateY(10px); transition: .2s; border-radius: 4px; }
.toast.show { opacity: 1; transform: translateY(0); }
@media (max-width: 900px) {
  .app-shell { padding: 18px 16px 48px; }
  .topbar, .section-heading { align-items: flex-start; flex-direction: column; }
  .top-actions { width: 100%; }
  .provider-strip { grid-template-columns: 1fr 1fr; }
  .candidate-grid, .chat-layout { grid-template-columns: 1fr; }
  .control-grid { grid-template-columns: 1fr; }
  .news-list { height: 300px; }
  .source-form { grid-template-columns: 1fr 1fr; }
  .source-form #sourceUrl, .source-form #sourceTopics, .source-form button { grid-column: 1 / -1; }
  .history-item { grid-template-columns: 60px 1fr auto; }
  .history-item .history-model { display: none; }
}
@media (max-width: 560px) {
  .app-shell { padding-inline: 12px; }
  .login-panel { padding: 26px 20px; }
  .provider-strip, .source-form { grid-template-columns: 1fr; }
  .source-form > * { grid-column: 1 !important; }
  .date-field { flex: 1; width: auto; }
  .button-row { width: 100%; }
  .button-row button { flex: 1; }
  .chat-compose { grid-template-columns: 1fr; }
  .chat-messages { height: 420px; }
  .message { max-width: 96%; }
}
