:root {
  color-scheme: light;
  --paper: #fbfaf6;
  --paper-2: #f4f1e8;
  --card: #ffffff;
  --ink: #1f2a37;
  --ink-soft: #5a6472;
  --ink-faint: #8b9099;
  --line: #ded7c7;
  --line-soft: #ebe6d9;
  --seal: #b23a2e;
  --seal-deep: #8e2b22;
  --seal-wash: #f6e7e2;
  --ok-soft: #e4efe2;
  --ok-deep: #2f6b35;
  --cloud-soft: #efe5d8;
  --cloud-deep: #915c14;
  --shadow-sm: 0 1px 2px rgba(31, 42, 55, 0.05);
  --shadow: 0 2px 8px rgba(31, 42, 55, 0.06), 0 18px 40px rgba(31, 42, 55, 0.07);
  --serif: "Songti SC", "STSong", "Noto Serif SC", "SimSun", Georgia, serif;
  --sans: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.paper-grain {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 18% 22%, rgba(178, 58, 46, 0.05), transparent 42%),
    radial-gradient(circle at 82% 78%, rgba(31, 42, 55, 0.05), transparent 46%);
}

.seal {
  --sz: 92px;
  width: var(--sz);
  height: var(--sz);
  border-radius: 18px;
  background: linear-gradient(155deg, #c0473a, var(--seal) 55%, var(--seal-deep));
  color: #fdf3ef;
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-size: calc(var(--sz) * 0.52);
  font-weight: 600;
  box-shadow:
    inset 0 0 0 2px rgba(253, 243, 239, 0.35),
    inset 0 0 0 5px var(--seal),
    0 6px 18px rgba(142, 43, 34, 0.28);
  position: relative;
}

.seal span { transform: translateY(2px); }

.seal.mini {
  --sz: 34px;
  border-radius: 9px;
  box-shadow:
    inset 0 0 0 1.5px rgba(253, 243, 239, 0.4),
    inset 0 0 0 3px var(--seal),
    0 2px 6px rgba(142, 43, 34, 0.25);
}

.login-view {
  position: relative;
  z-index: 1;
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 28px;
  background: linear-gradient(180deg, #fdfcf9, var(--paper) 40%, var(--paper-2));
}

.login-card {
  position: relative;
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border: 1px solid var(--line-soft);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 40px 38px 30px;
  text-align: center;
}

.login-card .seal { margin: 0 auto 22px; }

.eyebrow {
  margin: 0 0 10px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.22em;
  color: var(--seal);
  text-transform: uppercase;
}

.login-title {
  margin: 0;
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--ink);
}

.login-desc,
.login-note {
  color: var(--ink-soft);
  font-size: 14px;
}

.login-desc { margin: 10px 0 10px; }
.login-note { margin: 0 0 24px; line-height: 1.7; }

.field {
  position: relative;
  text-align: left;
  margin-bottom: 14px;
}

.field input {
  width: 100%;
  padding: 16px 15px 8px;
  border: 1px solid var(--line);
  border-radius: 11px;
  font-size: 15px;
  color: var(--ink);
  background: #fdfcfa;
  transition: border-color 0.16s, box-shadow 0.16s;
}

.field label {
  position: absolute;
  left: 15px;
  top: 14px;
  color: var(--ink-faint);
  font-size: 15px;
  pointer-events: none;
  transition: all 0.15s ease;
}

.field input:focus,
.model-switch select:focus,
#input:focus {
  outline: none;
  border-color: var(--seal);
  box-shadow: 0 0 0 3px var(--seal-wash);
}

.field input:focus + label,
.field input:not(:placeholder-shown) + label {
  top: 6px;
  font-size: 11px;
  color: var(--seal);
  letter-spacing: 0.04em;
}

#login-btn {
  width: 100%;
  margin-top: 10px;
  padding: 13px;
  border: none;
  border-radius: 11px;
  background: var(--ink);
  color: #fdfcfa;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.12em;
  transition: transform 0.06s, box-shadow 0.18s, background 0.18s;
  box-shadow: 0 4px 14px rgba(31, 42, 55, 0.18);
}

#login-btn:hover { background: #26323f; box-shadow: 0 6px 18px rgba(31, 42, 55, 0.24); }
#login-btn:active { transform: translateY(1px); }
#login-btn:disabled { opacity: 0.6; cursor: default; }

.login-error {
  color: var(--seal-deep);
  font-size: 13px;
  min-height: 18px;
  margin: 12px 0 0;
}

.login-foot {
  margin: 22px 0 0;
  color: var(--ink-faint);
  font-size: 12px;
}

@keyframes stamp {
  0% { transform: scale(1); }
  45% { transform: scale(0.9); }
  70% { transform: scale(1.04); }
  100% { transform: scale(1); }
}

.login-card.stamping .seal { animation: stamp 0.5s ease; }

.login-card.stamping .seal::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 22px;
  box-shadow: 0 0 0 3px var(--seal-wash);
  opacity: 0;
  animation: ring 0.5s ease;
}

@keyframes ring {
  0% { opacity: 0.9; transform: scale(0.85); }
  100% { opacity: 0; transform: scale(1.25); }
}

.app-view {
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--paper);
}

.conversation-layout {
  min-height: 0;
  flex: 1 1 auto;
  display: flex;
}

.history-panel {
  flex: 0 0 238px;
  min-width: 0;
  padding: 16px 12px;
  background: #f6f3eb;
  border-right: 1px solid var(--line-soft);
  overflow-y: auto;
}

.new-chat-btn {
  width: 100%;
  border: 1px solid var(--seal);
  border-radius: 10px;
  padding: 9px 12px;
  background: var(--seal);
  color: #fff8f5;
  font-weight: 600;
}

.new-chat-btn:hover { background: var(--seal-deep); }

.history-heading {
  margin: 18px 8px 7px;
  color: var(--ink-faint);
  font-size: 12px;
}

.history-list { display: flex; flex-direction: column; gap: 4px; }

.history-item {
  display: flex;
  align-items: center;
  border-radius: 9px;
  overflow: hidden;
}

.history-item:hover,
.history-item.active { background: #fff; }

.history-item.active { box-shadow: inset 3px 0 var(--seal); }

.history-open,
.history-delete {
  border: 0;
  background: transparent;
  color: var(--ink-soft);
}

.history-open {
  flex: 1;
  min-width: 0;
  padding: 9px 8px 9px 12px;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.history-delete {
  flex: 0 0 32px;
  height: 34px;
  opacity: 0;
  color: var(--ink-faint);
}

.history-item:hover .history-delete,
.history-item.active .history-delete { opacity: 1; }
.history-delete:hover { color: var(--seal); }

.chat-main {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 22px;
  background: rgba(251, 250, 246, 0.9);
  backdrop-filter: saturate(1.1) blur(8px);
  border-bottom: 1px solid var(--line-soft);
}

.bar-left,
.bar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.bar-right { flex-wrap: wrap; justify-content: flex-end; }

.bar-title {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.bar-name {
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.bar-sub {
  font-size: 11.5px;
  color: var(--ink-faint);
  letter-spacing: 0.02em;
}

.account-card,
.model-panel {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 7px 10px;
  background: rgba(255, 255, 255, 0.76);
  border: 1px solid var(--line-soft);
  border-radius: 12px;
}

.account-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

.account-role {
  font-size: 11px;
  color: var(--ink-faint);
}

.model-switch {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 220px;
}

.model-switch span {
  font-size: 12px;
  color: var(--ink-faint);
}

.model-switch select {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fffefb;
  color: var(--ink);
  padding: 0 10px;
}

.model-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 22px;
}

.model-badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.model-badge[data-kind="local"] {
  background: var(--ok-soft);
  color: var(--ok-deep);
}

.model-badge[data-kind="remote"],
.model-badge[data-kind="unknown"] {
  background: var(--cloud-soft);
  color: var(--cloud-deep);
}

.model-desc {
  font-size: 11.5px;
  color: var(--ink-faint);
}

.bar-btn {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink-soft);
  border-radius: 9px;
  padding: 7px 14px;
  font-size: 13px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.bar-btn:hover {
  background: var(--seal-wash);
  color: var(--seal-deep);
  border-color: #e3c8c2;
}

.stage {
  flex: 1 1 auto;
  overflow-y: auto;
  position: relative;
  background: linear-gradient(var(--paper), var(--paper));
}

.messages {
  max-width: 860px;
  margin: 0 auto;
  padding: 30px 24px 12px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.empty {
  margin: 8vh auto 0;
  text-align: center;
  max-width: 520px;
  color: var(--ink-soft);
}

.empty .watermark {
  width: 84px;
  height: 84px;
  margin: 0 auto 20px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-size: 46px;
  color: var(--seal);
  border: 2px solid var(--seal);
  opacity: 0.16;
}

.empty h2 {
  margin: 0 0 8px;
  font-family: var(--serif);
  font-size: 22px;
  color: var(--ink);
  letter-spacing: 0.04em;
}

.empty p { margin: 0; font-size: 14px; line-height: 1.8; }

.msg {
  display: flex;
  gap: 12px;
  animation: rise 0.28s ease both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.msg .avatar {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--serif);
}

.msg.user { flex-direction: row-reverse; }
.msg.user .avatar { background: var(--ink); color: #fdfcfa; }

.msg.ai .avatar {
  background: linear-gradient(155deg, #c0473a, var(--seal) 60%, var(--seal-deep));
  color: #fdf3ef;
  box-shadow: inset 0 0 0 1.5px rgba(253, 243, 239, 0.4);
}

.bubble {
  padding: 12px 16px;
  border-radius: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 15px;
  line-height: 1.7;
  max-width: 78%;
}

.msg.user .bubble {
  background: var(--ink);
  color: #f4f6f8;
  border-top-right-radius: 5px;
}

.msg.ai .bubble {
  background: var(--card);
  border: 1px solid var(--line-soft);
  border-top-left-radius: 5px;
  box-shadow: var(--shadow-sm);
}

.source-box {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--line-soft);
  white-space: normal;
  font-size: 13px;
}

.source-title {
  margin-bottom: 6px;
  color: var(--ink-faint);
  font-weight: 600;
}

.source-box ol { margin: 0; padding-left: 21px; }
.source-box li { margin: 4px 0; }
.source-box a { color: var(--seal-deep); text-decoration: none; }
.source-box a:hover { text-decoration: underline; }

.bubble .cursor {
  display: inline-block;
  width: 2px;
  height: 1.05em;
  vertical-align: -2px;
  background: var(--seal);
  margin-left: 1px;
  animation: blink 1s steps(2) infinite;
}

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

.dock {
  flex: 0 0 auto;
  border-top: 1px solid var(--line-soft);
  background: rgba(251, 250, 246, 0.92);
  backdrop-filter: saturate(1.1) blur(8px);
  padding: 12px 24px 14px;
}

.quick {
  max-width: 860px;
  margin: 0 auto 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  transition: all 0.15s;
}

.chip:hover,
.chip.active {
  border-color: var(--seal);
  color: var(--seal-deep);
  background: var(--seal-wash);
}

.composer {
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 8px 8px 8px 16px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.16s, box-shadow 0.16s;
}

.composer:focus-within {
  border-color: var(--seal);
  box-shadow: 0 0 0 3px var(--seal-wash);
}

#input {
  flex: 1;
  resize: none;
  max-height: 200px;
  border: none;
  background: transparent;
  outline: none;
  color: var(--ink);
  padding: 6px 0;
  line-height: 1.6;
}

#attach-btn {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: #fffefb;
  color: var(--ink-soft);
  display: grid;
  place-items: center;
  transition: background 0.15s, color 0.15s, border-color 0.15s, opacity 0.15s;
}

#attach-btn:hover {
  background: var(--seal-wash);
  color: var(--seal-deep);
  border-color: #e3c8c2;
}

#attach-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

#send-btn {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 11px;
  border: none;
  background: var(--seal);
  color: #fdf3ef;
  display: grid;
  place-items: center;
  transition: background 0.15s, transform 0.06s, opacity 0.15s;
  box-shadow: 0 3px 10px rgba(142, 43, 34, 0.28);
}

#send-btn:hover { background: var(--seal-deep); }
#send-btn:active { transform: translateY(1px); }
#send-btn:disabled { opacity: 0.45; cursor: default; box-shadow: none; }

.attachments {
  max-width: 860px;
  margin: 8px auto 0;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.attachment-chip {
  max-width: 100%;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 8px 5px 10px;
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  background: #fffefb;
  color: var(--ink-soft);
  font-size: 12px;
}

.attachment-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-chip button {
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 50%;
  background: var(--seal-wash);
  color: var(--seal-deep);
  line-height: 1;
  display: grid;
  place-items: center;
  padding: 0;
}

.verify-hint {
  max-width: 860px;
  margin: 8px auto 0;
  text-align: center;
  font-size: 11.5px;
  color: var(--ink-faint);
}

@media (max-width: 880px) {
  .bar {
    align-items: flex-start;
    flex-direction: column;
  }

  .bar-right {
    width: 100%;
    justify-content: flex-start;
  }

  .model-panel {
    width: 100%;
  }

  .model-switch {
    min-width: 0;
  }
}

@media (max-width: 640px) {
  .bar { padding: 10px 15px; }
  .bar-sub { display: none; }
  .messages { padding: 22px 15px 10px; }
  .bubble { max-width: 86%; }
  .dock { padding: 10px 14px 12px; }
  .quick { gap: 6px; }
  .login-card { padding: 34px 24px 26px; }
  .login-title { font-size: 26px; }
  .bar-right { gap: 8px; }
  .account-card, .model-panel { width: 100%; }
  .conversation-layout { flex-direction: column; }
  .history-panel {
    flex: 0 0 auto;
    width: 100%;
    max-height: 132px;
    padding: 10px 14px;
    border-right: 0;
    border-bottom: 1px solid var(--line-soft);
  }
  .new-chat-btn { padding: 7px 10px; }
  .history-heading { display: none; }
  .history-list {
    margin-top: 7px;
    flex-direction: row;
    overflow-x: auto;
  }
  .history-item { flex: 0 0 auto; max-width: 190px; background: rgba(255,255,255,.72); }
  .history-open { max-width: 150px; padding: 6px 8px 6px 10px; }
  .history-delete { opacity: 1; height: 30px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
