:root {
  color-scheme: light;
  font-family: system-ui, "Microsoft YaHei", sans-serif;
  color: #102a34;
  background: #edf2f0;
  font-synthesis: none;
  --navy: #0a2330;
  --green: #315d4d;
  --lime: #c5f04b;
  --line: #d6e2de;
  --muted: #4d6469;
  --panel: #fff;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .65; cursor: wait; }
a { color: #285947; text-underline-offset: .2em; }
:focus-visible { outline: 3px solid #337b62; outline-offset: 3px; }

.topbar { background: var(--navy); color: #f6fbf8; }
.topbar-inner {
  width: min(100% - 3rem, 1270px);
  margin: auto;
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand, .topbar-controls { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 45px;
  height: 45px;
  flex: 0 0 45px;
  display: grid;
  place-items: center;
  background: var(--lime);
  color: var(--navy);
  border-radius: 10px;
  font-size: 17px;
  font-style: italic;
  font-weight: 900;
}
.brand strong { display: block; font-size: .86rem; letter-spacing: .1em; }
.brand div span { color: #b7cec8; font-size: .83rem; }
.presence, .logout {
  min-height: 40px;
  padding: .5rem .75rem;
  border: 1px solid #46636c;
  border-radius: 8px;
  color: #f6fbf8;
  background: transparent;
  font-size: .86rem;
  font-weight: 650;
}
.presence { display: flex; align-items: center; gap: 8px; }
.presence-light { width: 8px; height: 8px; border-radius: 50%; background: #a6bab8; }
.presence[aria-pressed="true"] .presence-light { background: var(--lime); }
.presence:hover, .logout:hover { background: #1f404c; }
.topbar :focus-visible { outline-color: var(--lime); }

.loading { padding: 1rem; text-align: center; color: var(--muted); }
.login-card {
  width: min(100% - 2rem, 430px);
  margin: clamp(2rem, 9vh, 6rem) auto;
  padding: clamp(1.4rem, 5vw, 2.35rem);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 16px 70px #0a233012;
}
h1, h2, p { margin: 0; }
.login-card h1, .workspace h1 { font-size: clamp(1.5rem, 4vw, 2rem); letter-spacing: -.035em; }
.login-card > p { margin-top: .65rem; color: var(--muted); line-height: 1.65; }
.login-card form { display: grid; gap: .65rem; margin-top: 1.5rem; }
label { font-weight: 700; font-size: .94rem; }
input, textarea {
  width: 100%;
  border: 1px solid #a7bab5;
  border-radius: 8px;
  background: #fff;
  color: var(--navy);
  padding: .7rem .8rem;
  font-size: 1rem;
}
textarea { min-height: 75px; max-height: 200px; resize: vertical; }
.button-primary {
  min-height: 44px;
  padding: .55rem 1rem;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--lime);
  color: #14260b;
  font-weight: 750;
}
.button-primary:hover { background: #d0f66c; }
.login-card .button-primary { margin-top: .4rem; }
.form-error, .sync-error { color: #98392d; font-size: .875rem; line-height: 1.45; }

.workspace { width: min(100% - 3rem, 1270px); margin: 1.95rem auto 2rem; }
.workspace-heading { display: flex; align-items: end; justify-content: space-between; gap: .9rem; margin-bottom: 1.1rem; }
.workspace-heading p:not(.sync-error) { margin-top: .4rem; line-height: 1.6; color: var(--muted); font-size: .94rem; }
.inbox {
  min-height: 490px;
  height: calc(100dvh - 208px);
  max-height: 1000px;
  display: grid;
  grid-template-columns: minmax(235px, 30%) minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--panel);
  box-shadow: 0 10px 36px #0a23300b;
}
.thread-sidebar, .chat-area, .chat-conversation { min-height: 0; min-width: 0; }
.thread-sidebar { display: flex; flex-direction: column; border-right: 1px solid var(--line); }
.sidebar-heading { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 1rem 1.15rem; border-bottom: 1px solid var(--line); }
.sidebar-heading h2, .conversation-header h2 { font-weight: 800; font-size: 1.12rem; }
.button-text { border: 0; background: transparent; color: #285947; padding: .45rem .2rem; font-weight: 700; font-size: .9rem; }
.button-text:hover { text-decoration: underline; }
.list-empty, .thread-notice { padding: 1.1rem 1.15rem; color: var(--muted); font-size: .93rem; }
.thread-list, .message-list { list-style: none; margin: 0; padding: 0; overflow: auto; overscroll-behavior: contain; }
.thread-row {
  display: block;
  width: 100%;
  padding: .83rem 1.15rem;
  border: 0;
  border-bottom: 1px solid #e8efed;
  border-left: 3px solid transparent;
  background: var(--panel);
  color: var(--navy);
  text-align: left;
}
.thread-row:focus-visible { outline-offset: -4px; }
.thread-row:hover { background: #f5f9f6; }
.thread-row[aria-current="true"] { background: #e8f2e7; border-left-color: #4f8665; }
.thread-row-title, .thread-row-message { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.thread-row-title { font-weight: 750; }
.thread-row-message { margin: .3rem 0; font-size: .89rem; color: var(--muted); }
.thread-row time { color: var(--muted); font-size: .79rem; }

.chat-empty { display: grid; height: 100%; place-items: center; padding: 1rem; color: var(--muted); text-align: center; background: #f7faf8; }
.chat-conversation { display: flex; flex-direction: column; height: 100%; }
.conversation-header { padding: .9rem 1.2rem; border-bottom: 1px solid var(--line); }
.visitor-details { display: flex; flex-wrap: wrap; column-gap: 1rem; row-gap: .3rem; margin: .45rem 0 0; font-size: .86rem; }
.visitor-details div { display: flex; min-width: 0; gap: .4rem; }
.visitor-details dt { color: var(--muted); flex: none; }
.visitor-details dd { margin: 0; overflow-wrap: anywhere; }
.thread-notice { background: #f5f9f7; }
.message-list { flex: 1; padding: 1rem 1.2rem; background: #f7faf8; }
.message { width: fit-content; max-width: min(84%, 620px); margin: 0 auto .75rem 0; }
.message.staff { margin-right: 0; margin-left: auto; }
.message.staff .message-meta { text-align: right; }
.message-meta { margin-bottom: .25rem; color: var(--muted); font-size: .79rem; }
.message-body { padding: .65rem .85rem; border: 1px solid #d9e4df; border-radius: 2px 11px 11px 11px; background: #fff; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.message.staff .message-body { border-color: #d9e7ca; border-radius: 11px 2px 11px 11px; background: #e9f3dd; }
.reply-form { display: grid; gap: .45rem; padding: .7rem 1.2rem 1rem; border-top: 1px solid var(--line); }
.reply-controls { display: flex; align-items: center; justify-content: space-between; gap: .7rem; }
.reply-controls .button-primary { margin-left: auto; flex: none; }
.mobile-back { display: none; }

@media (max-width: 685px) {
  .topbar-inner { width: calc(100% - 1.4rem); min-height: 64px; gap: .55rem; }
  .brand { gap: .45rem; }
  .brand-mark { width: 31px; height: 31px; flex-basis: 31px; font-size: .74rem; }
  .brand strong { font-size: .65rem; letter-spacing: .04em; }
  .brand div span { font-size: .72rem; }
  .topbar-controls { gap: .32rem; }
  .presence, .logout { min-height: 38px; font-size: .72rem; padding: .35rem .43rem; white-space: nowrap; }
  .presence { gap: .3rem; }
  .workspace { width: calc(100% - 1.4rem); margin-top: 1.1rem; }
  .workspace-heading { display: block; margin-bottom: .8rem; }
  .sync-error { margin-top: .35rem; }
  .inbox { grid-template-columns: 1fr; height: calc(100dvh - 186px); min-height: 490px; }
  .thread-sidebar { border-right: 0; }
  .chat-area, .inbox[data-chat-open="true"] .thread-sidebar { display: none; }
  .inbox[data-chat-open="true"] .chat-area { display: block; }
  .mobile-back { display: inline-block; padding-top: 0; }
  .conversation-header, .reply-form, .message-list { padding-inline: .75rem; }
  .message { max-width: 90%; }
}
