:root {
  color-scheme: light;
  --bg: #ffffff;
  --sidebar: #f9f9f9;
  --surface: #ffffff;
  --surface-soft: #f7f7f8;
  --surface-hover: #ececec;
  --line: #e3e3e3;
  --line-strong: #d5d5d5;
  --text: #0d0d0d;
  --muted: #6b6f76;
  --accent: #10a37f;
  --accent-strong: #0e8f70;
  --danger: #c2414b;
  --focus: rgba(16, 163, 127, 0.18);
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.08);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
}

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

button {
  cursor: pointer;
}

button:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
}

.brand-name,
.panel-title {
  color: var(--text);
  font-weight: 650;
  line-height: 1.2;
}

.brand-subtitle,
.muted {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.35;
}

.ghost-button,
.icon-button,
.danger-button,
.send-button,
.secondary-action,
.new-chat-button,
.model-pill,
.conversation-item,
.suggestions button,
.quick-replies button {
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text);
  background: transparent;
  transition:
    border-color 140ms ease,
    background 140ms ease,
    box-shadow 140ms ease;
}

.ghost-button,
.icon-button,
.danger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  text-decoration: none;
}

.ghost-button:hover,
.icon-button:hover,
.secondary-action:hover,
.new-chat-button:hover,
.model-pill:hover,
.conversation-item:hover,
.suggestions button:hover,
.quick-replies button:hover {
  background: var(--surface-hover);
}

.danger-button {
  border-color: rgba(194, 65, 75, 0.25);
  color: var(--danger);
}

.danger-button:hover:not(:disabled) {
  background: rgba(194, 65, 75, 0.08);
}

textarea {
  width: 100%;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 13px;
  color: var(--text);
  outline: none;
  background: var(--surface);
  line-height: 1.5;
}

textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus);
}

input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--text);
  outline: none;
  background: var(--surface);
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus);
}

.send-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  color: #ffffff;
  background: var(--text);
  font-weight: 650;
}

.send-button:hover:not(:disabled) {
  background: #2f2f2f;
}

.chat-page {
  min-height: 100vh;
  background: var(--bg);
}

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #f4f6f8;
}

.auth-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 24px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-brand {
  justify-content: center;
}

.auth-form {
  display: grid;
  gap: 10px;
}

.auth-form label {
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 650;
}

.auth-error {
  margin: 0;
  color: var(--danger);
  font-size: 0.88rem;
}

.auth-submit {
  min-height: 42px;
  margin-top: 6px;
}

.chat-shell {
  width: 100%;
  height: 100vh;
  min-height: 560px;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  overflow: hidden;
  background: var(--bg);
}

.chat-sidebar {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  border-right: 1px solid var(--line);
  background: var(--sidebar);
}

.sidebar-top {
  padding: 8px;
}

.new-chat-button {
  width: 100%;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  text-align: left;
  font-weight: 520;
}

.conversation-nav {
  display: grid;
  align-content: start;
  gap: 2px;
  padding: 0 8px;
  overflow-y: auto;
}

.conversation-item {
  width: 100%;
  display: grid;
  grid-template-columns: 14px 1fr;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  color: #333333;
  text-align: left;
}

.conversation-item span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-item.active {
  background: var(--surface-hover);
}

.conversation-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: #9b9b9b;
}

.sidebar-footer {
  padding: 8px;
  border-top: 1px solid var(--line);
}

.mini-profile {
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 8px;
  color: #333333;
  font-size: 0.92rem;
}

.mini-avatar {
  width: 26px;
  height: 26px;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  color: #ffffff;
  background: var(--text);
  font-size: 0.78rem;
  font-weight: 700;
}

.chat-main {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto auto;
  background: var(--bg);
}

.chat-header {
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 24px;
  background: var(--bg);
}

.model-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  font-size: 1.06rem;
  font-weight: 650;
}

.chevron {
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
}

.messages,
.admin-messages {
  overflow-y: auto;
  scroll-behavior: smooth;
}

.chat-page .messages {
  padding: 24px 16px 18px;
}

.message-row {
  display: flex;
  margin: 0 0 18px;
}

.chat-page .message-row {
  width: min(100%, 760px);
  margin: 0 auto 26px;
  gap: 14px;
  align-items: flex-start;
}

.chat-page .message-row.assistant::before {
  content: "A";
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #ffffff;
  background: var(--text);
  font-size: 0.78rem;
  font-weight: 700;
}

.message-row.user {
  justify-content: flex-end;
}

.bubble {
  width: fit-content;
  max-width: min(76%, 680px);
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface-soft);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-page .bubble {
  max-width: min(100%, 680px);
  border: 0;
  padding: 0;
  background: transparent;
}

.chat-page .message-row.user .bubble {
  max-width: min(72%, 560px);
  padding: 10px 14px;
  background: var(--surface-soft);
}

.chat-page .message-meta {
  display: none;
}

.bubble.streaming .message-content::after {
  content: "";
  width: 7px;
  height: 1.05em;
  display: inline-block;
  margin-left: 3px;
  border-radius: 2px;
  background: currentColor;
  vertical-align: -0.18em;
  animation: blink 1s steps(2, start) infinite;
}

.bubble.stopped {
  opacity: 0.78;
}

@keyframes blink {
  0%,
  55% {
    opacity: 1;
  }
  56%,
  100% {
    opacity: 0;
  }
}

.admin-page .message-row.assistant .bubble {
  background: var(--surface-soft);
}

.admin-page .message-row.user .bubble {
  background: #eef4ff;
  border-color: #d7e5ff;
}

.message-meta {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.75rem;
}

.typing {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 10px 0;
  color: var(--muted);
}

.typing-label {
  font-size: 0.95rem;
}

.typing-dots {
  display: inline-flex;
  gap: 5px;
}

.typing-dots i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #8e8e8e;
  animation: pulse 1s ease-in-out infinite;
}

.typing-dots i:nth-child(2) {
  animation-delay: 120ms;
}

.typing-dots i:nth-child(3) {
  animation-delay: 240ms;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  50% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

.suggestions,
.quick-replies {
  display: flex;
  gap: 8px;
  overflow-x: auto;
}

.generation-actions {
  width: min(760px, calc(100% - 32px));
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 0 auto;
  padding: 0 0 10px;
}

.secondary-action {
  min-height: 34px;
  padding: 0 12px;
  border-color: var(--line);
  background: var(--surface);
  color: #333333;
  font-size: 0.9rem;
}

.suggestions {
  width: min(760px, calc(100% - 32px));
  margin: 0 auto;
  padding: 0 0 10px;
}

.suggestions button,
.quick-replies button {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 0 11px;
  border-color: var(--line);
  color: #333333;
  background: var(--surface);
  font-size: 0.9rem;
}

.composer {
  width: min(760px, calc(100% - 32px));
  display: grid;
  grid-template-columns: 1fr 34px;
  gap: 8px;
  align-items: end;
  margin: 0 auto 20px;
  padding: 8px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.composer textarea {
  min-height: 38px;
  max-height: 180px;
  padding: 8px 6px;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.composer textarea:focus {
  box-shadow: none;
}

.composer .send-button {
  width: 34px;
  min-height: 34px;
  padding: 0;
  border-radius: 8px;
  font-size: 1.1rem;
  line-height: 1;
}

.admin-page {
  min-height: 100vh;
  padding: 18px;
  background: #f4f6f8;
}

.admin-shell {
  height: calc(100vh - 36px);
  min-height: 640px;
  display: grid;
  grid-template-columns: minmax(290px, 360px) 1fr;
  gap: 16px;
}

.session-sidebar,
.operator-panel {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.session-sidebar {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
}

.admin-topbar,
.session-toolbar,
.operator-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.session-toolbar {
  padding: 14px 16px;
}

.operator-badge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  background: #fbfbfb;
  font-size: 0.82rem;
}

.operator-badge strong {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-list {
  overflow-y: auto;
  padding: 8px;
}

.session-item {
  width: 100%;
  display: grid;
  gap: 7px;
  padding: 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: inherit;
  text-align: left;
  background: transparent;
}

.session-item:hover,
.session-item.active {
  border-color: var(--line);
  background: var(--surface-soft);
}

.session-item[data-waiting="true"] .session-item-title::after {
  content: "";
  width: 7px;
  height: 7px;
  display: inline-block;
  margin-left: 7px;
  border-radius: 999px;
  background: var(--accent);
  vertical-align: 0.08em;
}

.session-item-title,
.session-item-preview {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-item-title {
  font-weight: 650;
}

.session-item-preview {
  color: var(--muted);
  font-size: 0.86rem;
}

.session-item-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.76rem;
}

.operator-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto auto;
}

.admin-messages {
  min-height: 0;
  padding: 20px;
  background: #fbfbfb;
}

.message-row.system {
  justify-content: center;
}

.message-row.system .bubble {
  max-width: min(90%, 720px);
  border-color: rgba(16, 163, 127, 0.2);
  color: #126b55;
  background: rgba(16, 163, 127, 0.08);
  font-size: 0.88rem;
}

.quick-replies {
  padding: 14px 16px 0;
  background: var(--surface);
}

.audit-panel {
  max-height: 154px;
  overflow-y: auto;
  display: grid;
  gap: 7px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.audit-panel:empty {
  display: none;
}

.audit-title {
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 650;
}

.audit-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.audit-item span {
  min-width: 0;
  overflow: hidden;
  color: #333333;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.audit-item time {
  flex: 0 0 auto;
}

.reply-box {
  padding: 16px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.reply-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 12px;
}

.delay-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

select {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface);
  padding: 0 10px;
}

.reply-actions .send-button {
  min-height: 38px;
  padding: 0 16px;
}

.empty-state {
  display: grid;
  place-items: center;
  height: 100%;
  color: var(--muted);
  text-align: center;
  padding: 28px;
  line-height: 1.6;
}

@media (max-width: 860px) {
  .chat-shell {
    grid-template-columns: 1fr;
  }

  .chat-sidebar {
    display: none;
  }

  .chat-header {
    padding: 0 14px;
    border-bottom: 1px solid var(--line);
  }

  .chat-page .messages {
    padding: 18px 14px;
  }

  .chat-page .message-row {
    margin-bottom: 22px;
  }

  .chat-page .message-row.user .bubble {
    max-width: 84%;
  }

  .suggestions,
  .generation-actions,
  .composer {
    width: calc(100% - 24px);
  }
}

@media (max-width: 800px) {
  .admin-page {
    padding: 0;
  }

  .admin-shell {
    width: 100%;
    height: 100vh;
    min-height: 100vh;
    display: grid;
    grid-template-rows: 270px 1fr;
    grid-template-columns: 1fr;
    gap: 0;
  }

  .session-sidebar,
  .operator-panel {
    border-radius: 0;
    box-shadow: none;
  }

  .admin-messages {
    padding: 16px;
  }

  .admin-page .bubble {
    max-width: 88%;
  }

  .reply-actions {
    align-items: stretch;
    flex-wrap: wrap;
  }

  .reply-actions .send-button,
  .reply-actions select {
    flex: 1 1 150px;
  }
}
