:root {
  color: #1b211e;
  background: #eef0eb;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-synthesis: none;
  --ink: #1b211e;
  --muted: #68716c;
  --line: #d9ddd6;
  --surface: #ffffff;
  --soft: #f5f6f3;
  --green: #087f5b;
  --green-dark: #076548;
  --orange: #c45732;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body { margin: 0; overflow: hidden; }

button, textarea, input, select { font: inherit; }

button { letter-spacing: 0; }

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-rows: 68px minmax(0, 1fr);
  background: var(--surface);
}

.topbar {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.brand-block { display: flex; align-items: center; gap: 11px; min-width: 0; }

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  color: #fff;
  background: var(--ink);
  border-radius: 7px;
}

.brand-mark svg { width: 21px; height: 21px; }

.brand-block h1 { margin: 0; font-size: 17px; line-height: 1.25; letter-spacing: 0; }
.brand-block p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.user-name { max-width: 130px; overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions a { text-decoration: none; }

.status-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #98a19c; }
.status-pill.ready .status-dot { background: var(--green); }
.status-pill.error .status-dot { background: var(--orange); }

.icon-button, .send-button {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  cursor: pointer;
}

.icon-button { border: 1px solid var(--line); color: var(--muted); background: #fff; }
.icon-button:hover { color: var(--ink); background: var(--soft); }
.icon-button svg, .send-button svg { width: 18px; height: 18px; }

.workspace { min-height: 0; display: grid; grid-template-columns: 250px minmax(0, 1fr); }

.sidebar {
  min-height: 0;
  padding: 22px 16px;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: var(--soft);
}

.sidebar section + section { margin-top: 28px; }

.section-heading { display: flex; align-items: center; justify-content: space-between; margin: 0 4px 10px; }
.section-heading h2 { margin: 0; font-size: 12px; font-weight: 650; color: #515a55; letter-spacing: 0; }
.section-heading svg { width: 15px; height: 15px; color: #8b948f; }

.quick-actions { display: grid; gap: 7px; }

.quick-actions button {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #e0e3dd;
  border-radius: 6px;
  background: #fff;
  color: #343b37;
  text-align: left;
  cursor: pointer;
}

.quick-actions button:hover { border-color: #aeb7b1; background: #fbfcfa; }
.quick-actions button:disabled { opacity: .5; cursor: not-allowed; }
.quick-actions svg { width: 17px; height: 17px; flex: 0 0 auto; color: var(--green); }
.quick-actions span { min-width: 0; overflow-wrap: anywhere; font-size: 13px; }

.data-panel dl { margin: 0; padding: 0 4px; }
.data-panel dl div { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid #e2e5df; }
.data-panel dt, .data-panel dd { margin: 0; font-size: 11px; }
.data-panel dt { color: #7a837e; }
.data-panel dd { color: #343b37; text-align: right; overflow-wrap: anywhere; }

.chat-panel { min-width: 0; min-height: 0; display: grid; grid-template-rows: minmax(0, 1fr) auto; background: #fff; }

.messages {
  min-height: 0;
  overflow-y: auto;
  padding: 30px max(24px, calc((100% - 850px) / 2));
  scroll-behavior: smooth;
}

.empty-state { height: 100%; min-height: 320px; display: grid; place-content: center; justify-items: center; text-align: center; }
.empty-icon { width: 52px; height: 52px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 8px; color: var(--green); background: var(--soft); }
.empty-icon svg { width: 25px; height: 25px; }
.empty-state h2 { margin: 17px 0 7px; font-size: 21px; letter-spacing: 0; }
.empty-state p { margin: 0; color: var(--muted); font-size: 14px; }

.message { display: grid; grid-template-columns: 32px minmax(0, 1fr); gap: 11px; margin: 0 0 26px; }
.message.user { grid-template-columns: minmax(0, 1fr); justify-items: end; }
.message-avatar { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 6px; background: #edf5f1; color: var(--green); }
.message-avatar svg { width: 17px; height: 17px; }
.message-content { min-width: 0; max-width: 760px; color: #29302c; font-size: 14px; line-height: 1.75; overflow-wrap: anywhere; }
.message-body { min-width: 0; }
.message.user .message-content { padding: 9px 13px; border-radius: 8px 8px 2px 8px; background: #edf0eb; color: #252b28; line-height: 1.6; white-space: pre-wrap; }
.message.assistant .message-content { padding-top: 4px; }
.message-content p { margin: 0 0 12px; }
.message-content p:last-child, .message-content ul:last-child, .message-content ol:last-child, .message-content pre:last-child, .message-content .markdown-table-wrap:last-child { margin-bottom: 0; }
.message-content h3, .message-content h4, .message-content h5 { margin: 18px 0 8px; color: #1d2823; line-height: 1.35; }
.message-content h3:first-child, .message-content h4:first-child, .message-content h5:first-child { margin-top: 0; }
.message-content h3 { font-size: 18px; }
.message-content h4 { font-size: 16px; }
.message-content h5 { font-size: 14px; }
.message-content ul, .message-content ol { margin: 0 0 13px; padding-left: 20px; }
.message-content li { margin: 4px 0; }
.message-content code { padding: 1px 5px; border-radius: 4px; background: #edf0eb; color: #24302a; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace; font-size: .92em; }
.message-content pre { margin: 0 0 14px; padding: 12px; overflow-x: auto; border: 1px solid #dfe4df; border-radius: 7px; background: #f8faf7; }
.message-content pre code { padding: 0; background: transparent; white-space: pre; }
.message-content blockquote { margin: 0 0 14px; padding: 8px 12px; border-left: 3px solid #9db9ae; color: #4e5a54; background: #f4f8f5; }
.message-content a { color: var(--green-dark); text-decoration-thickness: 1px; text-underline-offset: 2px; }
.markdown-table-wrap { max-width: 100%; margin: 4px 0 15px; overflow-x: auto; border: 1px solid #dfe4df; border-radius: 8px; background: #fff; }
.message-content table { min-width: 100%; border-collapse: collapse; font-size: 13px; line-height: 1.45; }
.message-content th, .message-content td { padding: 9px 11px; border-bottom: 1px solid #e7ebe6; vertical-align: top; white-space: normal; overflow-wrap: break-word; }
.message-content th { color: #4d5953; font-weight: 650; background: #f6f8f5; }
.message-content tr:last-child td { border-bottom: 0; }
.message.error .message-content { color: #a64224; }
.thinking-status { display: inline-flex; align-items: center; gap: 9px; min-height: 30px; padding: 6px 10px; border: 1px solid #dfe7e1; border-radius: 7px; color: #5c6861; background: #f6faf7; font-size: 13px; line-height: 1.35; }
.thinking-dots { display: inline-flex; gap: 3px; align-items: center; }
.thinking-dots span { width: 5px; height: 5px; border-radius: 50%; background: var(--green); opacity: .35; animation: thinkingPulse 1.15s ease-in-out infinite; }
.thinking-dots span:nth-child(2) { animation-delay: .16s; }
.thinking-dots span:nth-child(3) { animation-delay: .32s; }
@keyframes thinkingPulse { 0%, 80%, 100% { opacity: .28; transform: translateY(0); } 40% { opacity: .9; transform: translateY(-2px); } }
.feedback-controls { display: flex; gap: 4px; min-height: 28px; margin-top: 6px; }
.feedback-controls button { width: 28px; height: 28px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 5px; color: #8b948f; background: transparent; cursor: pointer; }
.feedback-controls button:hover, .feedback-controls button.selected { color: var(--green); background: #edf5f1; }
.feedback-controls svg { width: 15px; height: 15px; }
.typing-cursor::after { content: ""; display: inline-block; width: 7px; height: 15px; margin-left: 3px; background: var(--green); vertical-align: -2px; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.composer-wrap { padding: 10px max(24px, calc((100% - 850px) / 2)) 16px; background: #fff; }
.composer { min-height: 54px; display: grid; grid-template-columns: minmax(0, 1fr) 38px; align-items: end; gap: 10px; padding: 8px 8px 8px 15px; border: 1px solid #cbd1cc; border-radius: 8px; background: #fff; box-shadow: 0 5px 20px rgba(30, 38, 33, .07); }
.composer:focus-within { border-color: #7cae9b; box-shadow: 0 0 0 3px rgba(8, 127, 91, .08); }
.composer textarea { width: 100%; max-height: 150px; min-height: 36px; padding: 8px 0 5px; resize: none; border: 0; outline: 0; background: transparent; color: var(--ink); line-height: 1.5; }
.composer textarea::placeholder { color: #99a19c; }
.composer textarea:disabled { cursor: not-allowed; }
.send-button { align-self: end; border: 0; background: var(--green); color: #fff; }
.send-button:hover { background: var(--green-dark); }
.send-button:disabled { background: #b8c0bb; cursor: not-allowed; }
.send-button.stop { background: var(--orange); }
.composer-note { margin: 7px 2px 0; color: #8a938e; font-size: 11px; text-align: center; }
.composer-note.error { color: #a64224; }

.tool-activity { display: flex; align-items: center; gap: 8px; min-height: 30px; margin-bottom: 6px; color: #5f6963; font-size: 12px; }
.tool-activity[hidden] { display: none; }
.tool-activity::before { content: ""; width: 13px; height: 13px; border: 2px solid #c8d0cb; border-top-color: var(--green); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.auth-view { min-height: 100vh; display: grid; place-content: center; gap: 28px; padding: 24px; background: var(--soft); }
.auth-view[hidden] { display: none; }
.auth-brand { display: flex; align-items: center; gap: 12px; }
.auth-brand h1 { margin: 0; font-size: 20px; }
.auth-brand p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.auth-form, .password-dialog form { width: min(360px, calc(100vw - 48px)); display: grid; gap: 16px; }
.auth-form { padding: 24px; border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: 0 10px 28px rgba(30, 38, 33, .07); }
.auth-form div, .password-dialog form > div:not(.dialog-heading), .admin-form div { display: grid; gap: 6px; }
label { color: #4e5752; font-size: 12px; font-weight: 650; }
input, select { min-height: 40px; width: 100%; padding: 8px 10px; border: 1px solid #cbd1cc; border-radius: 6px; outline: none; color: var(--ink); background: #fff; }
input:focus, select:focus { border-color: #7cae9b; box-shadow: 0 0 0 3px rgba(8, 127, 91, .08); }
.primary-button { min-height: 40px; padding: 8px 14px; border: 0; border-radius: 6px; color: #fff; background: var(--green); cursor: pointer; }
.primary-button:hover { background: var(--green-dark); }
.form-error { margin: 0; color: #a64224; font-size: 12px; }
.password-dialog { padding: 0; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); box-shadow: 0 20px 60px rgba(20, 28, 24, .22); }
.password-dialog::backdrop { background: rgba(24, 30, 27, .46); }
.password-dialog form { padding: 24px; }
.dialog-heading h2 { margin: 0; font-size: 18px; }
.dialog-heading p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.password-dialog small { color: var(--muted); font-size: 11px; }

.admin-shell { min-height: 100vh; background: var(--soft); }
.admin-topbar { height: 68px; display: flex; align-items: center; justify-content: space-between; padding: 0 24px; border-bottom: 1px solid var(--line); background: #fff; }
.admin-topbar h1 { margin: 0; font-size: 17px; }
.admin-content { width: min(1180px, calc(100% - 32px)); margin: 0 auto; padding: 28px 0 48px; }
.admin-heading { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.admin-heading h2 { margin: 0; font-size: 20px; }
.admin-heading p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.metric { min-width: 0; padding: 16px; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric span { display: block; color: var(--muted); font-size: 11px; }
.metric strong { display: block; margin-top: 5px; font-size: 20px; font-weight: 650; overflow-wrap: anywhere; }
.admin-section { margin-top: 28px; }
.admin-section-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.admin-section-title h2 { margin: 0; font-size: 15px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { padding: 11px 12px; border-bottom: 1px solid #e5e8e3; text-align: left; white-space: nowrap; }
th { color: var(--muted); font-weight: 600; background: #fafbf9; }
tr:last-child td { border-bottom: 0; }
.text-button { padding: 6px 9px; border: 1px solid var(--line); border-radius: 5px; color: var(--ink); background: #fff; cursor: pointer; }
.text-button.danger { color: #a64224; }
.admin-form { display: grid; grid-template-columns: 1fr 1fr 1fr 120px auto; align-items: end; gap: 10px; margin-bottom: 12px; }
.admin-message { min-height: 18px; margin: 6px 0; color: var(--muted); font-size: 12px; }

@media (max-width: 760px) {
  .app-shell { grid-template-rows: 62px minmax(0, 1fr); }
  .topbar { padding: 0 14px; }
  .brand-block p { display: none; }
  .status-pill { width: 32px; min-height: 32px; justify-content: center; padding: 0; overflow: hidden; }
  .status-pill span:last-child { display: none; }
  .user-name { display: none; }
  .workspace { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .sidebar { padding: 10px 12px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar .section-heading, .data-panel { display: none; }
  .sidebar section + section { margin-top: 0; }
  .quick-actions { display: flex; width: max-content; gap: 7px; }
  .quick-actions button { width: auto; min-height: 36px; padding: 7px 10px; white-space: nowrap; }
  .messages { padding: 22px 16px; }
  .composer-wrap { padding: 8px 12px 12px; }
  .empty-state { min-height: 260px; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .admin-form { grid-template-columns: 1fr; }
}
