:root {
  --bg: #f6f5f3;
  --surface: #ffffff;
  --text: #1a1a18;
  --muted: #75756f;
  --border: #e3e2dd;
  --accent: #1f4e45;
  --accent-ink: #ffffff;
  --danger: #a33a2b;
  --ok: #2f6b4f;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.hidden { display: none !important; }

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--accent);
  color: var(--accent-ink);
  padding: 8px 14px;
  border-radius: var(--radius);
}
button:hover { filter: brightness(0.96); }
button.ghost { background: transparent; color: var(--text); }
button.danger { background: transparent; color: var(--danger); border-color: transparent; }

input {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-card h1 { margin: 0; font-size: 18px; font-weight: 600; }
.login-hint { margin: 0 0 8px; color: var(--muted); }
.login-error { margin: 0; color: var(--danger); }
.login-card button { margin-top: 8px; }

/* app layout */
.app { min-height: 100vh; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
}
.topbar-title { font-weight: 600; }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 0; }

.employees-panel { padding: 20px; }
.panel-head { display: flex; align-items: baseline; gap: 10px; }
.panel-head h2 { margin: 0; font-size: 16px; }
.muted { color: var(--muted); }

.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-top: 12px; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.table th { font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.02em; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #fafaf8; }
.emp-name { color: var(--accent); background: none; border: none; padding: 0; font-weight: 600; }
.emp-name:hover { text-decoration: underline; }
.badge { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--border); }
.badge.active { color: var(--ok); border-color: var(--ok); }
.badge.revoked { color: var(--muted); }
.budget-value { display: inline-flex; align-items: center; gap: 6px; }
.budget-value button { padding: 2px 8px; font-size: 12px; }
.budget-input { width: 96px; }

/* detail */
.detail { padding: 20px; border-left: 1px solid var(--border); background: var(--surface); min-height: 100vh; }
#detail-head h2 { margin: 0 0 6px; font-size: 16px; }
.detail-meta { color: var(--muted); display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.detail-section { margin-top: 20px; }
.detail-section h3 { margin: 0 0 8px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.02em; }

.sessions { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.session-item { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; cursor: pointer; }
.session-item:hover { border-color: var(--accent); }
.session-item.selected { border-color: var(--accent); background: #f2f5f3; }
.session-item .s-top { display: flex; justify-content: space-between; font-size: 13px; }
.session-item .s-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

.conversation { margin-top: 20px; border-top: 1px solid var(--border); padding-top: 16px; }
.conversation h3 { margin: 0 0 12px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.02em; }
.exchanges { display: flex; flex-direction: column; gap: 12px; max-height: 60vh; overflow-y: auto; }
.turn { max-width: 90%; border-radius: var(--radius); padding: 10px 12px; white-space: pre-wrap; word-break: break-word; }
.turn.user { align-self: flex-end; background: #e9efe9; }
.turn.assistant { align-self: flex-start; background: #f2f2f0; }
.turn .label { font-size: 11px; color: var(--muted); margin-bottom: 4px; }

.empty { color: var(--muted); padding: 20px; text-align: center; }

/* key cell */
.key-cell code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  background: #f2f2f0;
  padding: 2px 6px;
  border-radius: 4px;
  word-break: break-all;
}

/* session page */
.session { min-height: 100vh; }
.session-main { max-width: 900px; margin: 0 auto; padding: 24px 20px 64px; }
.session-head { margin-bottom: 20px; }
.session-head h2 { margin: 0 0 8px; font-size: 18px; }
.session-main .exchanges { max-height: none; overflow-y: visible; }
.exchange { display: flex; flex-direction: column; gap: 8px; }
.exchange-meta { color: var(--muted); font-size: 12px; text-align: center; }

/* raw traffic panel */
.raw-toggle {
  margin-left: 8px;
  font-size: 12px;
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--border);
  padding: 1px 8px;
  border-radius: 4px;
}
.sys-prompt { margin-top: 12px; }
.sys-prompt .sys-toggle { margin-left: 0; }
.sys-prompt .raw-panel { margin-top: 6px; }
.raw-panel {
  margin-top: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fafaf8;
  padding: 10px 12px;
  font-size: 12px;
  text-align: left;
}
.raw-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin-bottom: 10px;
  color: var(--muted);
}
.rmeta b { font-weight: 600; color: var(--text); }
.raw-block { margin-bottom: 12px; }
.raw-block:last-child { margin-bottom: 0; }
.raw-block h4 {
  margin: 0 0 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}
.raw-block pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  max-height: 360px;
  overflow: auto;
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .detail { border-left: none; border-top: 1px solid var(--border); min-height: 0; }
}

/* topbar actions */
.topbar-actions { display: flex; align-items: center; gap: 8px; }

/* 状态徽章补充 */
.badge.deleted { color: var(--muted); }
.badge.revoked { color: #b26a1f; border-color: #b26a1f; }

/* 操作列 */
.actions { white-space: nowrap; }
.actions button { margin-right: 4px; padding: 3px 8px; font-size: 12px; }
.actions button.danger { background: transparent; color: var(--danger); border-color: var(--danger); }

/* 绑定页 */
.qr { margin: 8px 0; text-align: center; }
.qr svg, .qr img { image-rendering: pixelated; }
.secret {
  display: block; margin: 8px 0; padding: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px; word-break: break-all; background: #f2f2f0; border-radius: 4px;
}

/* modal */
.modal-root {
  position: fixed; inset: 0; background: rgba(0,0,0,0.35);
  display: flex; align-items: center; justify-content: center; z-index: 30;
}
.modal-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 20px; width: min(420px, 90vw); display: flex; flex-direction: column; gap: 10px;
}
.modal-card h2 { margin: 0; font-size: 16px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.key-copy {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px; padding: 8px; min-height: 64px; resize: vertical; word-break: break-all;
  border: 1px solid var(--border); border-radius: var(--radius);
}