:root {
  --ink: #22262b;
  --muted: #8d949c;
  --line: #e8eaed;
  --canvas: #f8f9fa;
  --paper: #ffffff;
  --brand: #f2d600;
  --danger: #e44949;
  --focus: #356ae6;
  --shadow: 0 18px 36px rgba(25, 31, 38, 0.09);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body { min-width: 320px; background: var(--canvas); }
button { font: inherit; }
button:focus-visible { outline: 3px solid rgba(53, 106, 230, .28); outline-offset: 2px; }
svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.7; }

.app { min-height: 100vh; background: var(--canvas); }
.topbar { position: relative; z-index: 5; display: flex; align-items: center; height: 58px; padding: 0 28px 0 32px; background: var(--paper); border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; align-items: center; gap: 10px; flex: 0 0 auto; min-width: 158px; }
.brand-mark { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--brand); color: #3b3600; font-size: 15px; font-weight: 800; }
.brand strong { font-size: 15px; letter-spacing: -.02em; }
.primary-nav { display: flex; align-items: stretch; gap: 2px; min-width: 0; height: 100%; overflow-x: auto; scrollbar-width: none; }
.primary-nav::-webkit-scrollbar { display: none; }
.nav-link { position: relative; flex: 0 0 auto; height: 100%; padding: 0 13px; border: 0; background: transparent; color: #7b838b; cursor: pointer; font-size: 13px; white-space: nowrap; }
.nav-link:hover, .nav-link.is-active { color: var(--ink); }
.nav-link.is-active { font-weight: 700; }
.nav-link.is-active::after { position: absolute; right: 13px; bottom: 0; left: 13px; height: 2px; background: var(--brand); content: ""; }
.top-actions { display: flex; align-items: center; gap: 9px; margin-left: auto; padding-left: 18px; background: var(--paper); }
.icon-button, .avatar-button, .small-pill { display: grid; place-items: center; border: 0; cursor: pointer; }
.icon-button { position: relative; width: 30px; height: 30px; color: #9299a1; background: transparent; }
.notification-dot { position: absolute; top: 5px; right: 5px; width: 5px; height: 5px; border-radius: 50%; background: var(--danger); }
.small-pill { width: 32px; height: 32px; border-radius: 50%; color: #69717a; background: #f1f3f5; font-size: 12px; font-weight: 700; }
.avatar-button { width: 32px; height: 32px; border-radius: 50%; color: #69717a; background: #f1f3f5; font-size: 12px; font-weight: 700; }
.avatar-button.is-authenticated { color: #4e4200; background: var(--brand); }
.login-button { border: 1px solid #d7dbe0; border-radius: 9px; padding: 7px 12px; color: var(--ink); background: var(--paper); cursor: pointer; font-size: 12px; white-space: nowrap; }
.login-button:hover { border-color: #babfc5; background: #fbfbfc; }

.workspace { display: flex; min-height: calc(100vh - 58px); }
.side-rail { width: 232px; flex: 0 0 232px; padding: 28px 18px 24px; background: var(--canvas); border-right: 1px solid var(--line); }
.side-title { display: flex; align-items: center; gap: 9px; padding: 0 12px 18px; color: #7d858e; font-size: 13px; font-weight: 700; }
.side-icon { display: grid; place-items: center; color: #aab0b6; }
.side-items { display: grid; gap: 3px; }
.side-item { display: flex; align-items: center; min-height: 38px; width: 100%; padding: 0 12px; border: 0; border-radius: 9px; color: #858c94; background: transparent; cursor: pointer; text-align: left; font-size: 13px; }
.side-item:hover { color: var(--ink); background: rgba(255, 255, 255, .72); }
.side-item.is-selected { color: var(--ink); background: var(--paper); box-shadow: 0 1px 4px rgba(24, 32, 40, .04); }
.content-area { display: flex; flex: 1; min-width: 0; flex-direction: column; background: var(--paper); }
.content-toolbar { display: flex; align-items: center; justify-content: space-between; min-height: 80px; padding: 20px 36px 16px; border-bottom: 1px solid var(--line); }
.content-heading { display: flex; align-items: baseline; gap: 16px; min-width: 0; }
.content-heading h1 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -.03em; }
.status-copy { max-width: 380px; overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.status-copy.has-error { color: var(--danger); }
.new-button { display: inline-flex; align-items: center; gap: 6px; border: 0; border-radius: 8px; padding: 7px 12px; color: #9a3131; background: #fff0f0; cursor: pointer; font-size: 12px; }
.new-button:hover { background: #ffe5e5; }
.content-canvas { position: relative; display: grid; flex: 1; place-items: center; min-height: 420px; padding: 36px; background: var(--paper); }
.content-canvas.has-chat { display: block; min-height: 0; padding: 0; }
.empty-state { display: grid; justify-items: center; max-width: 370px; color: var(--muted); text-align: center; }
.empty-icon { display: grid; place-items: center; width: 48px; height: 48px; margin-bottom: 17px; color: #aeb4ba; border: 1px solid var(--line); border-radius: 14px; background: #fcfcfd; }
.empty-icon svg { width: 21px; height: 21px; }
.empty-state p { margin: 0; color: #6f7780; font-size: 14px; }
.empty-state small { margin-top: 8px; color: #a2a8ae; font-size: 12px; line-height: 1.7; }
.empty-login { display: inline-flex; align-items: center; gap: 7px; margin-top: 20px; border: 1px solid #dedfe2; border-radius: 9px; padding: 9px 13px; color: #4e555c; background: #fff; cursor: pointer; font-size: 12px; }
.empty-login:hover { border-color: #b9bec3; }
.empty-login svg { width: 14px; height: 14px; color: #716500; }

.profile-menu { position: absolute; top: 58px; right: 28px; width: 232px; padding: 12px 0 10px; border: 1px solid var(--line); border-radius: 15px; background: var(--paper); box-shadow: var(--shadow); }
.profile-menu-header { display: flex; align-items: center; gap: 10px; padding: 2px 16px 12px; }
.profile-avatar { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; color: #4e4200; background: var(--brand); font-size: 12px; font-weight: 700; }
.profile-menu-header strong, .profile-menu-header small { display: block; }
.profile-menu-header strong { font-size: 13px; }
.profile-menu-header small { margin-top: 3px; color: var(--muted); font-size: 11px; }
.menu-divider { height: 1px; margin: 0 12px 5px; background: var(--line); }
.profile-menu-item { display: block; width: 100%; padding: 9px 16px; border: 0; background: transparent; cursor: pointer; text-align: left; }
.profile-menu-item:hover { background: #fafafa; }
.profile-menu-item span, .profile-menu-item small { display: block; }
.profile-menu-item span { color: #42484e; font-size: 13px; }
.profile-menu-item small { margin-top: 3px; color: #a2a7ad; font-size: 11px; }
.profile-menu-login, .profile-menu-logout { width: calc(100% - 28px); margin: 6px 14px 0; border: 1px solid #dedfe2; border-radius: 8px; padding: 8px 10px; color: #4e555c; background: #fff; cursor: pointer; font-size: 12px; }
.profile-menu-login:hover, .profile-menu-logout:hover { background: #fafafa; }

.login-toast { position: fixed; right: 18px; bottom: 17px; z-index: 6; display: flex; align-items: center; gap: 9px; min-width: 126px; padding: 11px 13px; border: 1px solid #ffd3d3; border-radius: 12px; color: var(--danger); background: #fffafa; box-shadow: 0 12px 30px rgba(210, 51, 51, .09); font-size: 13px; }
.toast-symbol { display: grid; place-items: center; width: 17px; height: 17px; border: 1px solid currentColor; border-radius: 50%; font-size: 13px; line-height: 1; }
.login-toast button { margin-left: auto; border: 0; padding: 0; color: #9a3131; background: transparent; cursor: pointer; font-size: 12px; }

.chat-workspace { display: grid; grid-template-columns: 220px minmax(0, 1fr); height: 100%; min-height: 560px; background: var(--paper); }
.chat-sidebar { min-width: 0; border-right: 1px solid var(--line); background: #fbfbfc; }
.chat-sidebar-header, .chat-panel-header { display: flex; align-items: center; justify-content: space-between; min-height: 58px; padding: 0 18px; border-bottom: 1px solid var(--line); }
.chat-sidebar-header strong, .chat-panel-header strong { font-size: 13px; }
.chat-new-button { border: 1px solid #dfe2e5; border-radius: 7px; padding: 6px 9px; color: #535a61; background: var(--paper); cursor: pointer; font-size: 11px; }
.chat-new-button:hover { border-color: #b9bec3; }
.chat-list { display: grid; gap: 3px; padding: 10px; }
.chat-list-item { display: block; width: 100%; padding: 10px 9px; border: 0; border-radius: 8px; color: var(--ink); background: transparent; cursor: pointer; text-align: left; }
.chat-list-item:hover, .chat-list-item.is-selected { background: var(--paper); box-shadow: 0 1px 4px rgba(24, 32, 40, .05); }
.chat-list-item strong, .chat-list-item small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-list-item strong { font-size: 12px; font-weight: 600; }
.chat-list-item small { margin-top: 4px; color: var(--muted); font-size: 10px; }
.chat-list-note { padding: 20px 9px; color: var(--muted); font-size: 12px; line-height: 1.6; }
.chat-panel { display: grid; min-width: 0; grid-template-rows: auto minmax(0, 1fr) auto auto; }
.chat-panel-header { padding: 0 24px; }
.chat-panel-header small { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }
.chat-connection { color: var(--muted); font-size: 11px; }
.chat-connection.is-ready { color: #3f8b61; }
.chat-messages { overflow-y: auto; min-height: 0; padding: 24px 30px; }
.chat-empty { display: grid; justify-items: center; max-width: 360px; margin: 10vh auto 0; color: var(--muted); text-align: center; }
.chat-empty p { margin: 0; color: #6f7780; font-size: 14px; }
.chat-empty small { margin-top: 8px; font-size: 12px; }
.chat-message { display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 10px; max-width: 760px; margin: 0 auto 18px; }
.chat-message-role { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 8px; color: #555d65; background: #f0f2f4; font-size: 10px; font-weight: 700; }
.chat-message.is-assistant .chat-message-role { color: #4e4200; background: var(--brand); }
.chat-message-body { padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; color: #373d43; background: #fcfcfd; font-size: 13px; line-height: 1.7; overflow-wrap: anywhere; }
.chat-message.is-user .chat-message-body { background: #fffdf0; border-color: #f0e8a8; }
.chat-message-error { grid-column: 2; color: var(--danger); font-size: 11px; }
.chat-progress { max-width: 760px; margin: 0 auto 12px; color: var(--muted); font-size: 12px; }
.chat-notice { margin: 0 24px 10px; padding: 8px 10px; border: 1px solid #ffd3d3; border-radius: 7px; color: var(--danger); background: #fffafa; font-size: 12px; }
.chat-composer { margin: 0 24px 22px; border: 1px solid #dfe2e5; border-radius: 12px; background: var(--paper); box-shadow: 0 6px 18px rgba(25, 31, 38, .05); }
.chat-composer textarea { display: block; width: 100%; resize: vertical; min-height: 76px; padding: 13px 14px; border: 0; outline: 0; border-radius: 12px 12px 0 0; color: var(--ink); background: transparent; font: inherit; font-size: 13px; line-height: 1.6; }
.chat-composer-footer { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px 9px 14px; border-top: 1px solid #f0f1f2; color: var(--muted); font-size: 11px; }
.chat-send-button { border: 0; border-radius: 7px; padding: 7px 14px; color: #4e4200; background: var(--brand); cursor: pointer; font-size: 12px; font-weight: 700; }
.chat-send-button:disabled { color: #a7a7a0; background: #f0f1e8; cursor: not-allowed; }

@media (max-width: 1060px) {
  .topbar { padding-left: 18px; }
  .brand { min-width: 142px; }
  .nav-link { padding: 0 9px; }
  .nav-link.is-active::after { right: 9px; left: 9px; }
  .side-rail { width: 200px; flex-basis: 200px; }
}

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; height: auto; min-height: 58px; padding: 10px 14px 0; }
  .brand { min-width: 0; }
  .top-actions { padding-left: 10px; }
  .primary-nav { order: 3; width: 100%; height: 42px; margin-top: 6px; }
  .nav-link { height: 42px; padding: 0 11px; }
  .workspace { min-height: calc(100vh - 110px); }
  .side-rail { width: 150px; flex-basis: 150px; padding: 20px 10px; }
  .side-title { padding-right: 8px; padding-left: 8px; }
  .side-item { padding-right: 8px; padding-left: 8px; font-size: 12px; }
  .content-toolbar { padding: 18px 18px 14px; }
  .content-heading { display: block; }
  .status-copy { display: block; margin-top: 6px; }
  .content-canvas { min-height: 500px; padding: 24px 18px; }
  .content-canvas.has-chat { min-height: 620px; padding: 0; }
  .chat-workspace { grid-template-columns: 168px minmax(0, 1fr); }
  .chat-panel-header { padding: 0 16px; }
  .chat-messages { padding: 20px 16px; }
  .chat-composer { margin: 0 16px 16px; }
  .profile-menu { top: 58px; right: 12px; }
}

@media (max-width: 470px) {
  .brand strong { font-size: 14px; }
  .small-pill, .icon-button { display: none; }
  .login-button { padding: 7px 9px; }
  .side-rail { width: 132px; flex-basis: 132px; }
  .content-heading h1 { font-size: 18px; }
  .new-button { padding: 7px 9px; }
  .login-toast { right: 12px; bottom: 12px; }
  .chat-workspace { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .chat-sidebar { max-height: 124px; border-right: 0; border-bottom: 1px solid var(--line); overflow-y: auto; }
  .chat-sidebar-header { min-height: 46px; }
  .chat-list { display: flex; overflow-x: auto; padding: 7px 10px; }
  .chat-list-item { min-width: 150px; }
}
