:root {
  color-scheme: light;
  --ink: #17231d;
  --muted: #6d7a73;
  --line: #e4e9e6;
  --surface: #ffffff;
  --canvas: #f4f7f5;
  --green: #176d4b;
  --green-dark: #0f5137;
  --green-pale: #e8f5ee;
  --orange: #d76a22;
  --red: #bc3a38;
  --shadow: 0 18px 50px rgba(23, 55, 39, 0.09);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--canvas); }
button, input, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell { display: grid; grid-template-columns: 300px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; background: #10271d; color: #fff; }
.brand { display: flex; align-items: center; gap: 12px; padding: 24px 22px 18px; }
.brand-mark { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 14px; background: #e8ff96; color: #173b29; font-weight: 900; }
.brand strong { display: block; font-size: 16px; }
.brand small { display: block; color: #9db1a7; margin-top: 3px; }
.nav-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px 14px 16px; border-bottom: 1px solid rgba(255,255,255,.09); }
.nav-tab { position: relative; border: 0; border-radius: 9px; padding: 9px 5px; color: #afc0b7; background: transparent; font-size: 13px; }
.nav-tab.active { color: #173a28; background: #e7ff9e; font-weight: 700; }
.nav-tab b { position: absolute; top: -4px; right: 3px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: #ff705d; color: white; font-size: 11px; line-height: 18px; }
.conversation-list { flex: 1; overflow: auto; padding: 10px; }
.conversation-item { width: 100%; display: grid; grid-template-columns: 38px 1fr auto; gap: 10px; align-items: center; border: 0; border-radius: 12px; padding: 12px; color: #dce7e1; background: transparent; text-align: left; }
.conversation-item:hover, .conversation-item.active { background: rgba(255,255,255,.09); }
.avatar { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; background: #2e503f; color: #dfff90; font-weight: 800; }
.conversation-copy { min-width: 0; }
.conversation-copy strong, .conversation-copy small { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.conversation-copy strong { font-size: 14px; }
.conversation-copy small { color: #8fa79b; margin-top: 4px; }
.conversation-meta { align-self: stretch; display: flex; flex-direction: column; justify-content: space-between; align-items: flex-end; color: #7f988c; font-size: 11px; }
.unread { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: #ef6e58; color: white; text-align: center; line-height: 18px; }
.sidebar-footer { display: flex; align-items: center; gap: 8px; padding: 15px 20px; color: #8fa79b; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #74d293; box-shadow: 0 0 0 4px rgba(116,210,147,.12); }

.main-panel { min-width: 0; }
.view { display: none; min-height: 100vh; }
.view.active { display: block; }
.empty-state { max-width: 650px; margin: 0 auto; padding: 18vh 30px 60px; text-align: center; }
.empty-icon { width: 68px; height: 68px; display: grid; place-items: center; margin: 0 auto 24px; border-radius: 22px; background: var(--green); color: white; font-size: 32px; box-shadow: var(--shadow); }
.empty-state h1 { margin: 0; font-size: clamp(30px, 4vw, 48px); letter-spacing: -.04em; }
.empty-state p { color: var(--muted); line-height: 1.8; }
.simulate-form { display: grid; grid-template-columns: 1fr auto; gap: 10px; margin-top: 28px; padding: 9px; background: white; border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }

input, textarea { width: 100%; border: 1px solid var(--line); border-radius: 10px; background: white; color: var(--ink); outline: none; transition: .15s ease; }
input { padding: 11px 13px; }
textarea { padding: 12px 13px; resize: vertical; line-height: 1.65; }
input:focus, textarea:focus { border-color: #52a57e; box-shadow: 0 0 0 3px rgba(82,165,126,.12); }
.simulate-form input { border: 0; box-shadow: none; }
button { border: 0; border-radius: 9px; padding: 10px 15px; }
.primary { background: var(--green); color: white; font-weight: 700; }
.primary:hover { background: var(--green-dark); }
.secondary { border: 1px solid #b8c9c0; background: white; color: var(--green-dark); }
.ghost { background: transparent; color: var(--muted); }
.danger-text { color: var(--red); }

.chat-layout { display: grid; grid-template-rows: auto 1fr auto; height: 100vh; }
.chat-header { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 19px 28px; background: rgba(255,255,255,.9); border-bottom: 1px solid var(--line); backdrop-filter: blur(15px); }
.chat-header h2 { margin: 0 0 4px; font-size: 20px; }
.chat-header p { margin: 0; color: var(--muted); font-size: 12px; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.status-chip { padding: 6px 10px; border-radius: 999px; background: var(--green-pale); color: var(--green-dark); font-size: 12px; font-weight: 700; }
.status-chip.pending { background: #fff0e5; color: #a84e16; }
.status-chip.human { background: #e9efff; color: #3a5ba8; }
.status-chip.closed { background: #eef0ef; color: #69716d; }
.messages { overflow: auto; padding: 30px max(24px, calc((100% - 920px) / 2)); }
.message { display: flex; gap: 10px; margin: 16px 0; }
.message.outgoing { justify-content: flex-end; }
.bubble { max-width: min(70%, 680px); padding: 12px 15px; border-radius: 16px 16px 16px 4px; background: white; border: 1px solid var(--line); box-shadow: 0 8px 22px rgba(25,56,41,.05); line-height: 1.65; white-space: pre-wrap; word-break: break-word; }
.outgoing .bubble { border-radius: 16px 16px 4px 16px; background: #dff4e7; border-color: #cae9d7; }
.message.human .bubble { background: #e5edff; border-color: #d5e1fc; }
.message.system { justify-content: center; }
.message.system .bubble { max-width: 80%; padding: 7px 12px; border: 0; border-radius: 99px; background: #e9edeb; color: var(--muted); box-shadow: none; font-size: 12px; }
.message-meta { margin-top: 5px; color: #8b9690; font-size: 10px; }
.composer-wrap { background: white; border-top: 1px solid var(--line); }
.quick-simulate { display: flex; align-items: center; gap: 12px; padding: 7px 24px; background: #f8faf9; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 11px; }
.quick-simulate form { display: flex; gap: 6px; flex: 1; }
.quick-simulate input { padding: 7px 10px; background: transparent; }
.quick-simulate button { padding: 7px 10px; white-space: nowrap; }
.composer { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 12px; max-width: 980px; margin: 0 auto; padding: 14px 24px 20px; }
.composer textarea { min-height: 58px; max-height: 180px; }

.page-header { display: flex; justify-content: space-between; align-items: end; gap: 30px; max-width: 1100px; margin: 0 auto; padding: 58px 34px 28px; }
.page-header h1 { margin: 0; font-size: 38px; letter-spacing: -.04em; }
.page-header p:not(.eyebrow) { max-width: 650px; margin: 10px 0 0; color: var(--muted); line-height: 1.7; }
.eyebrow { margin: 0 0 7px; color: var(--green); font-size: 11px; font-weight: 900; letter-spacing: .13em; }
.knowledge-form, .setup-card { max-width: 1032px; margin: 0 auto 22px; padding: 24px; border: 1px solid var(--line); border-radius: 16px; background: white; box-shadow: 0 8px 30px rgba(28,59,43,.05); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
label { display: grid; gap: 7px; margin-bottom: 15px; color: #3e4a44; font-size: 13px; font-weight: 700; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; }
.knowledge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; max-width: 1100px; margin: 0 auto; padding: 0 34px 60px; }
.knowledge-card { display: flex; flex-direction: column; min-height: 220px; padding: 20px; border: 1px solid var(--line); border-radius: 15px; background: white; box-shadow: 0 7px 22px rgba(28,59,43,.045); }
.knowledge-card header { display: flex; justify-content: space-between; gap: 10px; }
.knowledge-card h3 { margin: 0; font-size: 17px; }
.knowledge-card p { flex: 1; color: var(--muted); line-height: 1.65; white-space: pre-wrap; }
.tags { color: var(--green); font-size: 11px; }
.knowledge-card footer { display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--line); padding-top: 12px; color: #919a95; font-size: 11px; }
.switch-label { display: flex; align-items: center; gap: 6px; margin: 0; font-size: 11px; font-weight: 500; }
.switch-label input { width: auto; }

.status-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; max-width: 1100px; margin: 0 auto 22px; padding: 0 34px; }
.status-card { padding: 22px; border: 1px solid var(--line); border-radius: 15px; background: white; }
.status-card span { display: block; color: var(--muted); font-size: 12px; }
.status-card strong { display: block; margin: 12px 0 4px; font-size: 20px; }
.status-card.ready strong { color: var(--green); }
.status-card.waiting strong { color: var(--orange); }
.setup-card h3 { margin-top: 0; }
.setup-card li, .setup-card p { color: var(--muted); line-height: 1.75; }
.copy-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; background: #f2f5f3; }
.copy-row code { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.warning-card { border-color: #f1d4be; background: #fffaf6; }
code { padding: 2px 5px; border-radius: 5px; background: #eef2f0; font-family: Consolas, monospace; font-size: .9em; }
.toast { position: fixed; right: 24px; bottom: 24px; max-width: 380px; padding: 13px 17px; border-radius: 10px; background: #132b20; color: white; box-shadow: var(--shadow); z-index: 20; }

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .conversation-list { max-height: 220px; }
  .sidebar-footer { display: none; }
  .chat-layout { height: auto; min-height: 75vh; grid-template-rows: auto minmax(380px, 1fr) auto; }
  .page-header { padding-top: 34px; }
  .status-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .chat-header, .page-header { align-items: flex-start; flex-direction: column; }
  .header-actions { flex-wrap: wrap; }
  .simulate-form, .composer, .form-row { grid-template-columns: 1fr; }
  .bubble { max-width: 88%; }
  .knowledge-grid, .status-grid { padding-left: 18px; padding-right: 18px; }
  .page-header { padding-left: 18px; padding-right: 18px; }
}
