:root {
  color-scheme: light dark;
  --bg: #f5f6fb;
  --surface: #ffffff;
  --surface-soft: #f0f2f9;
  --border: #dde1ee;
  --text: #1d2333;
  --muted: #667089;
  --accent: #4f5bd5;
  --accent-strong: #3f49b8;
  --accent-soft: #eaecfb;
  --danger: #b3261e;
  --danger-soft: #fdecea;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(24, 30, 55, 0.06), 0 8px 24px rgba(24, 30, 55, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161d;
    --surface: #1c1f28;
    --surface-soft: #232733;
    --border: #2f3442;
    --text: #eef0f7;
    --muted: #a0a8bd;
    --accent: #8f9bff;
    --accent-strong: #aab3ff;
    --accent-soft: #262b3c;
    --danger: #ffb4ab;
    --danger-soft: #3a1f1e;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.28);
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

.app { min-height: 100%; display: flex; flex-direction: column; }

.boot {
  margin: auto;
  padding: 40px 24px;
  max-width: 420px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.boot-mark {
  width: 56px; height: 56px;
  border-radius: 18px;
  background: var(--accent);
  color: #fff;
  display: grid; place-items: center;
  font-size: 24px; font-weight: 600;
  animation: pulse 1.6s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(0.94); opacity: 0.75; }
}

.boot-title { margin: 4px 0 0; font-size: 20px; }
.boot-text { margin: 0; color: var(--muted); }
.boot-hint {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
  text-align: left;
  white-space: pre-line;
}

.workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
  gap: 12px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

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

.avatar {
  width: 40px; height: 40px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  display: grid; place-items: center;
  font-weight: 600;
  flex: none;
}

.identity-text { min-width: 0; }
.app-title { margin: 0; font-size: 17px; line-height: 1.3; }
.identity-line {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badges { display: flex; gap: 6px; flex-wrap: wrap; }

.badge {
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
}

.badge-accent { background: var(--accent-soft); border-color: transparent; color: var(--accent-strong); }

.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface-soft);
  border-radius: 12px;
  border: 1px solid var(--border);
}

.tab {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 500;
  padding: 8px 10px;
  border-radius: 9px;
  cursor: pointer;
  min-height: 40px;
}

.tab.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.tab:focus-visible, .btn:focus-visible, .input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.panels { flex: 1; display: flex; min-height: 0; }

.panel { flex: 1; display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.panel-collect { overflow-y: auto; padding-bottom: 8px; }

.panel-chat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
  min-height: 360px;
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 2px 8px;
  min-height: 200px;
  max-height: calc(100vh - 320px);
}

.bubble {
  max-width: 86%;
  padding: 9px 12px;
  border-radius: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14px;
}

.bubble-assistant {
  align-self: flex-start;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.bubble-user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.bubble-error { background: var(--danger-soft); color: var(--danger); border-color: transparent; }

.bubble-meta { display: block; margin-top: 4px; font-size: 11px; opacity: 0.7; }

.empty {
  margin: auto;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 24px 12px;
}

.composer { display: flex; gap: 8px; align-items: flex-end; }

.input {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 11px;
  resize: vertical;
  min-height: 42px;
}

.composer-input { flex: 1; }
.composer-send { flex: none; min-width: 72px; min-height: 42px; }

.btn {
  font: inherit;
  font-weight: 500;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 9px 14px;
  min-height: 42px;
  cursor: pointer;
}

.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--accent-strong); }
.btn-small { min-height: 34px; padding: 6px 10px; font-size: 13px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card-title { margin: 0; font-size: 15px; }
.card-text { margin: 0; color: var(--muted); font-size: 13px; }
.card-text.is-bound { color: var(--accent-strong); }

.field { display: flex; flex-direction: column; gap: 5px; }
.field-label { font-size: 12px; color: var(--muted); }

.record-form { display: flex; flex-direction: column; gap: 10px; }

.records { display: flex; flex-direction: column; gap: 8px; }
.records-head { display: flex; align-items: center; justify-content: space-between; }
.record-list { display: flex; flex-direction: column; gap: 10px; }

.record {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.record.is-focused { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.record-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.record-title { margin: 0; font-size: 14px; font-weight: 600; }
.record-meta { font-size: 11px; color: var(--muted); white-space: nowrap; }
.record-summary { margin: 0; font-size: 13px; white-space: pre-wrap; color: var(--text); }
.record-note { margin: 0; font-size: 12px; color: var(--muted); }
.record-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 9px 14px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: var(--shadow);
  max-width: min(90vw, 460px);
  text-align: center;
  z-index: 20;
}

.toast.is-error { background: var(--danger); color: #fff; }

.hint { margin: 0; font-size: 12px; color: var(--muted); }

.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
  vertical-align: -2px;
  margin-right: 6px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.typing { color: var(--muted); font-size: 13px; display: flex; align-items: center; }

@media (max-width: 480px) {
  .workspace { padding: 10px; gap: 10px; }
  .panel-chat { min-height: 320px; border-radius: 12px; padding: 10px; }
  .chat-list { max-height: calc(100vh - 300px); }
  .bubble { max-width: 92%; }
  .composer { flex-direction: column; align-items: stretch; }
  .composer-send { width: 100%; }
  .topbar { align-items: flex-start; }
}

@media (min-width: 768px) {
  .workspace { padding: 24px; gap: 14px; }
  .chat-list { max-height: calc(100vh - 360px); }
  .record-form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .record-form .field:nth-child(3) { grid-column: 1 / -1; }
  .record-form button { grid-column: 1 / -1; justify-self: start; }
}

@media (min-width: 1200px) {
  .workspace { max-width: 1080px; }
  .panel-collect { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; align-items: start; }
  .panel-collect .records { grid-column: 1 / -1; }
}
