:root {
  --bg: #f8f8f8;
  --panel: #ffffff;
  --text: #151515;
  --muted: #737373;
  --line: #dedede;
  --blue: #1d1d1d;
  --green: #0f8f64;
  --red: #c93535;
  --shadow: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 256px minmax(0, 1fr);
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

a { color: inherit; text-decoration: none; }

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 14px 10px;
  background: #fafafa;
  color: #171717;
  border-right: 1px solid #e3e3e3;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.app-sidebar .chat-brand { display: flex; align-items: center; min-width: 0; padding: 5px 8px 12px; gap: 10px; }
.app-sidebar .chat-brand .mark {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid #1c1c1c;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  background: #fff;
  color: #171717;
  font-size: 12px;
  font-weight: 800;
}
.app-sidebar .chat-brand strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.app-sidebar .new-chat { width: 100%; padding: 10px 12px; border: 0; background: #eeeeee; color: #171717; text-align: left; }

.side-footer {
  margin-top: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  padding: 0 8px;
  color: #666;
  font-size: 12px;
}
.side-footer a { color: #444; }

.main { padding: 0 32px 40px; min-width: 0; background: #fff; }

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  min-height: 72px;
  margin: 0 -32px 28px;
  padding: 0 32px;
  border-bottom: 1px solid var(--line);
}
.page-head h1 { margin: 0; font-size: 26px; letter-spacing: 0; }
.eyebrow {
  margin: 0 0 6px;
  color: #666;
  font-weight: 700;
  font-size: 13px;
}

.user-chip, .button, button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 10px 14px;
  color: var(--text);
}

button, .button { cursor: pointer; font-weight: 700; }
button.primary, .primary {
  background: #171717;
  border-color: #171717;
  color: #fff;
}
button.danger { border-color: #f0c4c4; color: var(--red); }
button.small { padding: 6px 10px; font-size: 12px; }

.flash {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}
.flash div {
  padding: 12px 14px;
  border-radius: 8px;
  background: #fff7d6;
  border: 1px solid #f2d775;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: none;
  padding: 20px;
  margin-bottom: 18px;
}
.panel-title {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}
.panel-title h2 { margin: 0; font-size: 18px; }
.panel-title p { margin: 6px 0 0; color: var(--muted); }

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}
.metrics div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  box-shadow: none;
}
.metrics strong { display: block; font-size: 32px; }
.metrics span { color: var(--muted); }

.grid.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.split { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 18px; align-items: start; }
.narrow { position: sticky; top: 24px; }

.stack { display: grid; gap: 14px; }
.stack.compact { gap: 10px; }
label { display: grid; gap: 7px; font-weight: 700; color: #344054; }
input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  font: inherit;
  background: #fff;
  color: var(--text);
}
textarea { resize: vertical; }

.inline-form {
  display: grid;
  grid-template-columns: 1fr 1.5fr 140px 150px 120px auto;
  gap: 10px;
  align-items: center;
}
.panel > .inline-form:first-child { grid-template-columns: 1fr 2fr auto; }

.list { display: grid; gap: 10px; }
.list a, .list div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcff;
}
.list a.active { border-color: var(--blue); background: #eef5ff; }
.list strong { display: block; }
.list span { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }
.empty { color: var(--muted); }
.center { text-align: center; padding: 80px 20px; }

.editor { display: grid; gap: 14px; }
.doc-title { font-size: 24px; font-weight: 800; }
.editor-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.editor-grid textarea {
  min-height: 520px;
  line-height: 1.6;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.preview {
  min-height: 520px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  overflow: auto;
  line-height: 1.7;
  background: #fff;
}
.preview h1, .preview h2, .preview h3 { margin-top: 0.8em; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }

.kanban {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 16px;
}
.lane {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f8fafc;
  min-height: 180px;
}
.lane h3 { margin: 0 0 12px; }
.task {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
  display: grid;
  gap: 8px;
}
.task p { margin: 0; color: var(--muted); }
.task span { color: var(--muted); font-size: 12px; }

table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}
th { color: var(--muted); font-size: 13px; }

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
}
.auth-panel {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: none;
  padding: 28px;
  transform: translateY(clamp(24px, 6vh, 80px));
}
.auth-panel h1 { margin: 0 0 8px; }
.auth-panel p { margin: 0 0 20px; color: var(--muted); }
.muted-link {
  display: inline-block;
  margin-top: 16px;
  color: var(--blue);
  font-weight: 700;
}

.settings {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 24px;
}

.chat-layout {
  min-height: calc(100vh - 72px);
  display: block;
}
.chat-panel { min-height: calc(100vh - 72px); display: grid; grid-template-rows: minmax(0, 1fr) auto; }
.chat-messages { min-height: 440px; max-height: calc(100vh - 208px); overflow: auto; padding: 64px max(32px, calc((100% - 820px) / 2)); display: grid; align-content: start; gap: 28px; }
.chat-message { max-width: 800px; display: grid; gap: 8px; }
.chat-message span { color: #777; font-size: 12px; font-weight: 700; }
.chat-message div { white-space: pre-wrap; line-height: 1.75; font-size: 16px; }
.chat-message.user { justify-self: end; }
.chat-message.user div { background: #f5f5f5; border: 1px solid #e3e3e3; padding: 13px 15px; border-radius: 18px 18px 4px 18px; }
.chat-message.user span { text-align: right; }
.chat-image { display: block; width: min(360px, 100%); max-height: 360px; object-fit: contain; border: 1px solid #e3e3e3; border-radius: 8px; background: #f5f5f5; }
.thinking-status { color: #777; font-size: 14px !important; line-height: 1.4 !important; }
.chat-message.pending .thinking-status { color: #454545; }
.chat-empty { color: #777; text-align: center; align-self: center; padding: 16px; }
.chat-empty h2 { color: #191919; margin: 18px 0 8px; font-size: 32px; }
.chat-empty p { margin: 0; }
.chat-empty-mark { width: 58px; height: 58px; display: grid; place-items: center; margin: 0 auto; border: 1px solid #202020; border-radius: 50%; color: #202020; font-size: 22px; font-weight: 800; }
.chat-compose { width: min(940px, calc(100% - 48px)); justify-self: center; margin: 0 24px 28px; border: 1px solid #d7d7d7; border-radius: 26px; padding: 10px 10px 10px 20px; display: grid; grid-template-columns: minmax(0, 1fr) minmax(140px, 220px) auto; gap: 12px; align-items: end; background: #fff; }
.chat-compose:focus-within { border-color: #555; }
.compose-body { min-width: 0; display: grid; gap: 7px; }
.chat-compose textarea { min-height: 56px; border: 0; padding: 7px 0; outline: 0; resize: none; }
.chat-compose button { min-width: 76px; }
.chat-toolbar { display: flex; align-items: center; min-height: 30px; gap: 5px; }
.toolbar-button { width: 30px; min-width: 30px !important; height: 30px; display: grid; place-items: center; padding: 0 !important; border: 0; border-radius: 6px; background: transparent; color: #555; font-size: 20px; line-height: 1; cursor: pointer; }
.toolbar-button:hover, .toolbar-button.selected { background: #ececec; color: #171717; }
.toolbar-button input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.image-name { min-width: 0; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #666; font-size: 12px; }
.chat-context-panel { max-height: 180px; overflow: auto; border-top: 1px solid #e4e4e4; padding-top: 8px; }
.chat-context-panel strong { display: block; margin-bottom: 6px; font-size: 12px; }
.knowledge-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 10px; }
.knowledge-options label { display: flex; min-width: 0; align-items: center; gap: 6px; color: #444; font-size: 12px; font-weight: 500; }
.knowledge-options input { width: auto; padding: 0; }
.knowledge-options span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-info { min-width: 0; align-self: center; border-left: 1px solid #e0e0e0; padding-left: 12px; display: grid; gap: 2px; }
.model-info span { color: #777; font-size: 11px; }
.model-info strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; font-weight: 700; }

.chat-screen {
  --bg: #f8f8f8;
  --panel: #ffffff;
  --text: #151515;
  --muted: #737373;
  --line: #dedede;
  --blue: #1d1d1d;
  --shadow: none;
  grid-template-columns: 256px minmax(0, 1fr);
  background: var(--bg);
}
.chat-screen .sidebar { background: #fafafa; color: #171717; padding: 14px 10px; gap: 12px; border-right: 1px solid #e3e3e3; }
.chat-brand { display: flex; align-items: center; min-width: 0; padding: 5px 8px 12px; gap: 10px; }
.chat-brand .mark { width: 30px; height: 30px; border-radius: 50%; border: 1px solid #1c1c1c; display: grid; place-items: center; flex: 0 0 auto; font-size: 12px; font-weight: 800; }
.chat-brand strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.chat-screen .new-chat { width: 100%; padding: 10px 12px; border: 0; background: #eeeeee; color: #171717; text-align: left; }
.chat-search { display: flex; align-items: center; gap: 8px; border: 1px solid #e0e0e0; border-radius: 7px; background: #fff; padding: 0 9px; color: #606060; }
.chat-search input { border: 0; padding: 9px 0; outline: 0; font-size: 13px; }
.chat-nav { display: grid; gap: 2px; }
.chat-nav a { padding: 9px 10px; border-radius: 6px; color: #242424; font-size: 14px; font-weight: 650; }
.chat-nav a:hover, .chat-nav a.active { background: #ededed; color: #171717; }
.chat-history { display: grid; min-height: 0; gap: 8px; margin-top: 4px; }
.chat-history > span { padding: 0 9px; color: #555; font-size: 12px; font-weight: 700; }
.chat-session-list { display: grid; align-content: start; gap: 2px; overflow: auto; }
.chat-session-list a { padding: 8px 10px; border-radius: 6px; color: #303030; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 600; }
.chat-session-list a:hover, .chat-session-list a.active { background: #e9e9e9; color: #111; }
.chat-account { margin-top: auto; display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; align-items: center; gap: 8px; padding: 9px 7px; border-top: 1px solid #e4e4e4; font-size: 13px; }
.chat-account span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-account a { color: #666; font-size: 12px; }
.account-mark { width: 28px; height: 28px; display: grid; place-items: center; background: #171717; color: #fff; border-radius: 50%; font-size: 12px; }
.chat-screen .main { padding: 0; background: #fff; }
.chat-screen .page-head { height: 72px; margin: 0; padding: 0 32px; border-bottom: 1px solid var(--line); justify-content: flex-end; }
.chat-screen .page-head h1 { display: none; }
.chat-screen .page-head .eyebrow { display: none; }
.chat-screen button.primary, .chat-screen .primary { background: #171717; border-color: #171717; }
.chat-screen .flash { position: fixed; right: 20px; top: 20px; z-index: 10; width: min(360px, calc(100% - 40px)); }
.hint {
  border-left: 4px solid var(--green);
  padding-left: 16px;
  color: var(--muted);
}
code {
  background: #eef2f7;
  padding: 2px 5px;
  border-radius: 5px;
}

@media (max-width: 980px) {
  body { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .main { padding: 20px; }
  .page-head { margin: 0 -20px 20px; padding: 0 20px; }
  .auth-panel { transform: none; }
  .metrics, .grid.two, .split, .editor-grid, .kanban, .settings, .chat-layout { grid-template-columns: 1fr; }
  .chat-layout { min-height: auto; }
  .chat-screen { grid-template-columns: 1fr; }
  .chat-screen .sidebar { position: static; height: auto; }
  .chat-history { max-height: 200px; }
  .chat-messages { max-height: none; min-height: 360px; }
  .chat-compose { grid-template-columns: 1fr; }
  .knowledge-options { grid-template-columns: 1fr; }
  .model-info { border-left: 0; border-top: 1px solid #e0e0e0; padding: 8px 0 0; }
  .narrow { position: static; }
  .inline-form, .panel > .inline-form:first-child { grid-template-columns: 1fr; }
}
