:root {
  font-family: Inter, "Microsoft YaHei UI", "PingFang SC", "Noto Sans CJK SC", system-ui, sans-serif;
  color: #202640;
  background: #f4f5fa;
  color-scheme: light;
  --surface: #fff;
  --ink: #202640;
  --muted: #616983;
  --line: #e2e5ef;
  --accent: #5340c4;
  --accent-hover: #4130a5;
  --soft-accent: #f1eeff;
  --error: #a02843;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font-size: 1rem; line-height: 1.5; }
h1, h2, p { margin: 0; }
button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: var(--accent); text-underline-offset: 0.2em; }
:focus-visible { outline: 3px solid #7664e7; outline-offset: 3px; }
.muted { color: var(--muted); }
.error { color: var(--error); font-size: 0.875rem; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.brand-mark {
  position: relative;
  display: inline-block;
  flex: none;
  width: 2.125rem;
  height: 2.125rem;
  border-radius: 0.68rem;
  background: linear-gradient(145deg, #705ce5, #4b39b4);
  box-shadow: inset 0 1px 1px #fff4;
}

.brand-mark::before, .brand-mark::after {
  position: absolute;
  width: 43%;
  height: 34%;
  border: 1.5px solid #fff;
  border-radius: 0.2rem;
  content: "";
}

.brand-mark::before { top: 25%; left: 23%; opacity: 0.7; }
.brand-mark::after { right: 22%; bottom: 25%; background: #6955d7; }
.brand-mark-large { width: 3rem; height: 3rem; border-radius: 0.9rem; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 2.75rem;
  padding: 0.5rem 0.875rem;
  border: 1px solid transparent;
  border-radius: 0.625rem;
  background: transparent;
  color: var(--ink);
  font-size: 0.875rem;
  font-weight: 650;
  line-height: 1.35;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.button-primary { background: var(--accent); color: white; }
.button-primary:hover:not(:disabled) { background: var(--accent-hover); }
.button-primary:disabled { background: #e9e6f5; color: #656079; cursor: default; }
.button-secondary { background: #f3f1fc; color: #4634a5; }
.button-secondary:hover:not(:disabled) { background: #eae5fd; }
.button-quiet { color: var(--muted); }
.button-quiet:hover:not(:disabled) { background: #f3f4f9; color: var(--ink); }
.button:disabled { cursor: default; }
.button-pill {
  border-color: var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--accent);
  box-shadow: 0 3px 12px #26244518;
}
.button-pill:hover { background: var(--soft-accent); }

.login-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 1.25rem;
  background: radial-gradient(ellipse at 50% 0, #eae6ff, transparent 62%), #f4f5fa;
}

.login-card {
  width: min(100%, 26rem);
  padding: clamp(1.5rem, 6vw, 2.5rem);
  border: 1px solid var(--line);
  border-radius: 1.25rem;
  background: var(--surface);
  box-shadow: 0 20px 56px #342a6014;
}
.login-card h1 { margin-top: 0.9rem; font-size: 1.875rem; letter-spacing: -0.04em; }
.login-card > p { margin-top: 0.5rem; }
.login-form { display: grid; gap: 0.625rem; margin-top: 1.75rem; }
.login-form label { font-weight: 650; font-size: 0.875rem; }
.login-form input[type="password"] {
  width: 100%;
  min-height: 3rem;
  padding: 0.7rem;
  border: 1px solid #cbd0df;
  border-radius: 0.625rem;
  background: #fcfcff;
  color: var(--ink);
}
.login-form .button { margin-top: 0.5rem; min-height: 3rem; }

.workspace-page {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  background: linear-gradient(150deg, #f0eefb 0, #f4f5fa 45%, #f4f5fa 100%);
}

.app-header { border-bottom: 1px solid var(--line); background: #ffffffed; }
.app-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(100%, 65rem);
  min-height: 4rem;
  margin: auto;
  padding: 0 1.25rem;
}
.brand { display: flex; align-items: center; gap: 0.625rem; font-weight: 750; }
.logout-form { margin: 0; }

.workspace {
  width: min(100%, 59rem);
  min-height: 0;
  margin: 0 auto;
  padding: clamp(1rem, 3vw, 2rem);
}

.chat {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100%;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 1.125rem;
  background: var(--surface);
  box-shadow: 0 16px 52px #342a6010, 0 2px 8px #342a600a;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1.125rem 1.5rem;
  border-bottom: 1px solid var(--line);
}
.chat-header h1 { font-size: 1.375rem; letter-spacing: -0.025em; }
.chat-header p { margin-top: 0.125rem; font-size: 0.875rem; }
.sync { display: grid; justify-items: end; gap: 0.25rem; font-size: 0.875rem; }
.sync-status { display: inline-flex; align-items: center; gap: 0.4rem; color: var(--muted); }
.sync-status::before { width: 0.45rem; height: 0.45rem; border-radius: 50%; background: #8f96af; content: ""; }
.sync-status[data-state="ready"]::before { background: #279468; }
.sync-status[data-state="offline"]::before,
.sync-status[data-state="error"]::before { background: #bd702a; }

.timeline-area { position: relative; min-height: 0; background: #fafaff; }
.timeline {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: auto;
  overflow-anchor: none;
  overscroll-behavior: contain;
  padding: 1.3rem 1.5rem;
  scrollbar-color: #c6c8db transparent;
}
.timeline:focus-visible { outline-offset: -3px; }
.history { text-align: center; margin-bottom: 0.5rem; }
.history .error { margin-top: 0.25rem; }

.empty {
  display: grid;
  justify-items: center;
  gap: 0.375rem;
  margin: auto;
  padding: 1.125rem 0.5rem;
  text-align: center;
}
.empty-icon {
  display: grid;
  place-items: center;
  width: 4rem;
  height: 4rem;
  margin-bottom: 0.625rem;
  border: 1px solid #e4dfff;
  border-radius: 1.25rem;
  background: var(--soft-accent);
  color: #6753cc;
}
.empty-icon span {
  position: relative;
  display: block;
  width: 1.625rem;
  height: 1.25rem;
  border: 1.5px solid currentColor;
  border-radius: 0.375rem;
}
.empty-icon span::before {
  position: absolute;
  top: 0.35rem;
  left: 0.3rem;
  width: 0.825rem;
  height: 1px;
  background: currentColor;
  box-shadow: 0 0.3rem currentColor;
  content: "";
}
.empty-title { font-weight: 700; font-size: 1.125rem; }
.empty .muted { font-size: 0.9375rem; }

.message-list { display: grid; gap: 0.875rem; margin: 0; padding: 0; list-style: none; }
.day-label {
  margin: 0.35rem auto 0.75rem;
  color: var(--muted);
  font-size: 0.8125rem;
  text-align: center;
}
.message-card {
  width: fit-content;
  max-width: min(100%, 38rem);
  padding: 0.8rem 0.875rem 0.375rem;
  border: 1px solid #e2e3f4;
  border-radius: 0.35rem 0.9rem 0.9rem 0.9rem;
  background: #fff;
}
.message-text { overflow-wrap: anywhere; white-space: pre-wrap; user-select: text; }
.message-image { margin-top: 0.625rem; }
.message-card > .message-image:first-child { margin-top: 0; }
.image-preview {
  display: block;
  max-width: 100%;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 0.5rem;
  background: #eeedf5;
  cursor: zoom-in;
}
.image-preview img { display: block; max-width: 100%; max-height: 16rem; object-fit: contain; }
.image-fallback { padding: 0.5rem 0; font-size: 0.875rem; overflow-wrap: anywhere; }
.message-footer { display: flex; flex-wrap: wrap; align-items: center; gap: 0.375rem; }
.message-footer time { margin-right: 0.125rem; color: var(--muted); font-size: 0.8125rem; }
.message-footer .button { min-height: 2.25rem; padding: 0.325rem 0.5rem; color: var(--accent); }
#latest { position: absolute; right: 1.25rem; bottom: 0.75rem; }

.composer { display: grid; gap: 0.625rem; padding: 1rem 1.5rem; border-top: 1px solid var(--line); }
.composer textarea {
  display: block;
  width: 100%;
  min-height: 4.375rem;
  max-height: 11rem;
  padding: 0.68rem 0.8rem;
  resize: vertical;
  border: 1px solid #dce0ee;
  border-radius: 0.7rem;
  background: #fafaff;
  color: var(--ink);
}
.composer textarea::placeholder { color: #686f89; opacity: 1; }
.composer-error { margin: 0 0.125rem; }
.composer-actions { display: flex; align-items: center; gap: 0.75rem; }
.keyboard-hint { margin-left: auto; font-size: 0.8125rem; white-space: nowrap; }
.send-button { min-width: 5.375rem; margin-left: auto; }
.keyboard-hint + .send-button { margin-left: 0; }
.picture-icon {
  position: relative;
  display: inline-block;
  flex: none;
  width: 1rem;
  height: 0.8rem;
  overflow: hidden;
  border: 1.4px solid currentColor;
  border-radius: 0.2rem;
}
.picture-icon::before {
  position: absolute;
  top: 0.12rem;
  left: 0.15rem;
  width: 0.18rem;
  height: 0.18rem;
  border-radius: 50%;
  background: currentColor;
  content: "";
}
.picture-icon::after {
  position: absolute;
  right: 0.02rem;
  bottom: -0.2rem;
  width: 0.62rem;
  height: 0.62rem;
  transform: rotate(45deg);
  border: 1.4px solid currentColor;
  content: "";
}
.draft-attachment {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  justify-self: start;
  max-width: 100%;
  min-width: 0;
  padding: 0.25rem 0.25rem 0.25rem 0.375rem;
  border: 1px solid var(--line);
  border-radius: 0.625rem;
  background: #fafaff;
}
.draft-thumbnail {
  position: relative;
  display: grid;
  flex: none;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  overflow: hidden;
  border-radius: 0.4rem;
  background: var(--soft-accent);
  color: var(--accent);
}
.draft-thumbnail img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.draft-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.875rem; }
.draft-attachment .button { min-height: 2.25rem; padding: 0.25rem 0.5rem; }

.viewer {
  width: min(calc(100% - 2rem), 54rem);
  max-height: calc(100dvh - 2rem);
  padding: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: var(--surface);
  color: var(--ink);
}
.viewer::backdrop { background: #161832bc; }
.viewer-header, .viewer-actions { display: flex; align-items: center; padding: 0.625rem 0.875rem; }
.viewer-header { justify-content: space-between; gap: 0.5rem; border-bottom: 1px solid var(--line); }
.viewer-header h2 { font-size: 1rem; overflow-wrap: anywhere; }
.viewer-content { display: grid; place-items: center; min-height: 10rem; padding: 0.875rem; background: #f4f5fa; }
.viewer-content img { display: block; max-width: 100%; max-height: 65dvh; object-fit: contain; }
.viewer-actions { justify-content: flex-end; border-top: 1px solid var(--line); }

@media (max-width: 40rem) {
  .workspace { padding: 0; }
  .app-header-inner { min-height: 3.5rem; padding: 0 0.875rem; }
  .chat { border: 0; border-radius: 0; box-shadow: none; }
  .chat-header { padding: 0.65rem 0.875rem; }
  .chat-header h1 { font-size: 1.125rem; }
  .timeline { padding: 0.875rem; }
  .composer { padding: 0.625rem 0.875rem max(0.625rem, env(safe-area-inset-bottom)); }
  .composer textarea { min-height: 3.5rem; }
  .keyboard-hint { display: none; }
  .keyboard-hint + .send-button { margin-left: auto; }
}
