:root {
  color-scheme: light;
  --ink: #192f29;
  --muted: #53685f;
  --line: #dbe4df;
  --surface: #ffffff;
  --rail: #f3f7f5;
  --green: #166044;
  --green-hover: #104b35;
  --selected: #e1efe7;
  --amber-bg: #fff5df;
  --amber-ink: #775014;
  --red: #a02e2e;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--surface); color: var(--ink); font: 14px/1.55 "Segoe UI", "Microsoft YaHei", system-ui, sans-serif; }
button, input, select, textarea { font: inherit; }
button { min-height: 38px; padding: 7px 13px; color: var(--ink); background: white; border: 1px solid #b6c8bf; border-radius: 7px; cursor: pointer; transition: background-color 160ms ease-out; }
button:hover:not(:disabled) { background: var(--selected); }
button:disabled { cursor: not-allowed; background: #edf0ee; color: #53685f; border-color: #d6dfda; }
button.primary { color: white; background: var(--green); border-color: var(--green); }
button.primary:hover:not(:disabled) { background: var(--green-hover); }
button.primary:disabled { color: #52655a; background: #dfe8e2; border-color: #dfe8e2; }
input, select, textarea { color: var(--ink); background: white; border: 1px solid #b6c8bf; border-radius: 7px; padding: 9px 11px; caret-color: var(--green); }
input::placeholder, textarea::placeholder { color: #61736a; }
input:focus-visible, textarea:focus-visible, select:focus-visible, button:focus-visible, [tabindex]:focus-visible { outline: 3px solid #5c9c7c; outline-offset: 3px; }
textarea:disabled { background: #f6f8f7; }
::selection { background: #c4e6d4; color: #122e21; }
* { scrollbar-width: thin; scrollbar-color: #b6c8bf transparent; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 17px; font-weight: 600; }
h2 { font-size: 17px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }
.wordmark { font-size: 22px; font-weight: 750; letter-spacing: -.03em; color: var(--green); }
.app-bar { height: 68px; padding: 0 26px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); gap: 20px; }
.brand, .app-tools { display: flex; align-items: center; gap: 16px; }
.brand-divider { height: 21px; width: 1px; background: var(--line); }
#connection { color: var(--muted); font-size: 12px; }
.stage-banner { min-height: 44px; padding: 10px 26px; display: flex; gap: 16px; align-items: center; background: var(--amber-bg); color: var(--amber-ink); border-bottom: 1px solid #eddfc0; font-size: 13px; }
.stage-banner strong { flex-shrink: 0; }
.desk-layout { display: grid; grid-template-columns: 280px minmax(0,1fr) 260px; height: calc(100dvh - 112px); min-height: 420px; }
.inbox { display: flex; flex-direction: column; min-height: 0; padding: 22px 16px 0; background: var(--rail); border-right: 1px solid var(--line); }
.inbox-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
#session-count { color: var(--muted); font-variant-numeric: tabular-nums; }
.search-label { font-size: 12px; margin-bottom: 7px; color: var(--muted); }
.list-filters { display: flex; gap: 9px; align-items: center; margin: 12px 0 18px; font-size: 12px; color: var(--muted); }
.list-filters select { flex: 1; padding: 6px 9px; }
.session-list { overflow-y: auto; flex: 1; padding: 3px; margin: -3px; }
.session-item { width: 100%; text-align: left; background: transparent; border: 1px solid transparent; padding: 14px 12px; margin-bottom: 6px; border-radius: 8px; }
.session-item[aria-current="true"] { background: var(--selected); border-color: #accdbb; }
.session-row { display: flex; justify-content: space-between; gap: 7px; align-items: center; }
.session-item strong { font-size: 14px; overflow-wrap: anywhere; }
.session-item small { color: var(--muted); display: block; margin-top: 4px; overflow-wrap: anywhere; }
.mini-state { font-size: 11px; color: var(--green); white-space: nowrap; }
.inbox-footer { padding: 17px 0; margin-top: 16px; border-top: 1px solid var(--line); font-size: 11px; color: var(--muted); }
.load-more { margin-top: 14px; }
.conversation { min-width: 0; min-height: 0; background: white; }
.thread { height: 100%; display: flex; flex-direction: column; }
.thread-header { min-height: 91px; display: flex; align-items: center; gap: 14px; padding: 18px 24px; border-bottom: 1px solid var(--line); }
.thread-identity { min-width: 0; flex: 1; }
.thread-identity h2 { overflow-wrap: anywhere; }
.thread-identity p { font-size: 12px; color: var(--muted); margin-top: 3px; }
.thread-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.badge { display: inline-block; font-size: 12px; padding: 3px 8px; border-radius: 5px; color: var(--green); background: var(--selected); white-space: nowrap; }
.review-note { color: var(--amber-ink); background: var(--amber-bg); padding: 10px 24px; font-size: 12px; }
.messages { flex: 1; min-height: 0; padding: 25px 28px 16px; overflow: auto; }
.message { max-width: 85%; margin: 0 0 23px; }
.message.outbound { margin-left: auto; }
.message-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 7px; color: var(--muted); font-size: 11px; flex-wrap: wrap; }
.message.outbound .message-meta { justify-content: flex-end; }
.message-body { white-space: pre-wrap; overflow-wrap: anywhere; padding: 14px 17px; border-radius: 12px; background: #f1f4f2; line-height: 1.65; max-width: 70ch; }
.message.outbound .message-body { background: #eaf3ee; }
.delivery-note { color: var(--amber-ink); }
.history-note { text-align: center; color: var(--muted); font-size: 11px; margin-bottom: 25px; }
.composer { padding: 17px 24px 19px; border-top: 1px solid var(--line); }
.composer-label { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 9px; }
.composer-label label { font-weight: 600; }
#draft-status { font-size: 12px; color: var(--muted); }
textarea { width: 100%; resize: vertical; min-height: 82px; max-height: 200px; }
.composer-footer { display: flex; align-items: center; gap: 9px; margin-top: 11px; flex-wrap: wrap; }
.composer-footer p { font-size: 11px; color: var(--muted); flex: 1; min-width: 160px; }
.details { padding: 24px 20px; border-left: 1px solid var(--line); background: #fcfdfc; overflow: auto; }
.details-intro { font-size: 12px; color: var(--muted); margin-top: 6px; }
dl { margin: 25px 0 28px; }
dt { font-size: 11px; color: var(--muted); margin-top: 19px; }
dd { margin: 4px 0 0; overflow-wrap: anywhere; font-size: 13px; font-variant-numeric: tabular-nums; }
.record-note { border-top: 1px solid var(--line); padding-top: 19px; margin-top: 23px; }
.record-note p { color: var(--muted); font-size: 12px; line-height: 1.8; margin-top: 8px; }
.empty-state { padding: 75px 36px; text-align: center; color: var(--muted); max-width: 540px; margin: auto; }
.empty-state h2 { color: var(--ink); margin-bottom: 16px; }
.empty-state p + p { margin-top: 12px; font-size: 12px; }
.empty-list { padding: 24px 8px; color: var(--muted); font-size: 13px; }
.app-error { padding: 12px 26px; color: var(--red); background: #fff0ee; border-bottom: 1px solid #efd2cc; }
body.has-error .desk-layout { height: calc(100dvh - 159px); }
.login-panel { width: min(410px,calc(100% - 40px)); margin: 12vh auto; }
.login-panel h1 { font-size: 24px; margin: 24px 0 9px; }
.login-panel p { color: var(--muted); }
.login-panel form { display: grid; gap: 10px; margin-top: 30px; }
.login-panel form button { margin-top: 8px; }
.login-panel .fine-print { font-size: 12px; margin-top: 25px; }
.login-panel .error-text { margin-top: 15px; color: var(--red); }
.loading-state { padding: 15vh 24px; text-align: center; color: var(--muted); }
.mobile-only, #details-toggle, #details-back { display: none; }
@media (max-width: 1190px) {
  .desk-layout { grid-template-columns: 240px minmax(0,1fr) 225px; }
  .thread-header { align-items: flex-start; flex-wrap: wrap; padding: 16px 20px; }
  .messages { padding: 22px 20px; }
}
@media (max-width: 1000px) {
  .desk-layout { grid-template-columns: 245px minmax(0,1fr); }
  .details { display: none; }
  #details-toggle { display: inline-block; }
  .desk-layout.details-open { grid-template-columns: 245px minmax(0,1fr); }
  .details-open .conversation { display: none; }
  .details-open .details { display: block; border-left: 0; }
  #details-back { display: inline-block; margin-bottom: 20px; }
}
@media (max-width: 680px) {
  .app-bar { height: 62px; padding: 0 15px; gap: 8px; }
  .brand { gap: 9px; }
  .wordmark { font-size: 19px; }
  h1 { font-size: 14px; }
  .app-tools { gap: 5px; }
  .app-tools button { padding: 6px 9px; }
  #connection { display: none; }
  .stage-banner { padding: 10px 15px; display: block; }
  .stage-banner span { display: block; font-size: 11px; margin-top: 3px; }
  .desk-layout, .desk-layout.details-open { display: block; height: calc(100dvh - 130px); min-height: 350px; }
  body.has-error .desk-layout { height: calc(100dvh - 198px); }
  .inbox { height: 100%; border-right: 0; }
  .conversation { display: none; height: 100%; }
  body.thread-open .inbox { display: none; }
  body.thread-open .conversation { display: block; }
  .thread-header { gap: 10px; padding: 12px 15px; }
  .thread-actions { width: 100%; justify-content: flex-start; }
  .mobile-only { display: inline-block; }
  .messages { padding: 20px 15px; }
  .message { max-width: 94%; }
  .composer { padding: 13px 15px; }
  .composer-footer p { flex-basis: 100%; }
  .details-open .conversation { display: none !important; }
  .details-open .details { height: 100%; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
