:root {
  color-scheme: light dark;
  font: 16px/1.5 system-ui, sans-serif;
  --page: light-dark(#f3f5f7, #181c20);
  --surface: light-dark(#fff, #20262b);
  --text: light-dark(#14232d, #edf3f6);
  --muted: light-dark(#526571, #a9bac4);
  --line: light-dark(#ced9e0, #424e55);
  --accent: light-dark(#08665b, #9ae6d5);
  --on-accent: light-dark(#fff, #122621);
  --bubble: light-dark(#e7f4f1, #263d39);
  --error: light-dark(#9b2c29, #ffb4a8);
  color: var(--text);
  background: var(--page);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
button, input, select, textarea { font: inherit; }
h1, h2, p { margin: 0; }
h1 { font-size: 1.35rem; letter-spacing: -.025em; }
h2 { font-size: 1.15rem; letter-spacing: -.015em; }
button, input[type="checkbox"] { cursor: pointer; }
button:disabled { cursor: default; opacity: .55; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.top {
  min-height: 4.25rem;
  padding: .85rem max(1rem, calc((100% - 68rem) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.session-controls { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: .5rem .75rem; }
.top h1 { display: flex; align-items: center; gap: .6rem; }
.top h1 img { flex: none; border-radius: 22%; }
#session-label { color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; }
main { max-width: 70rem; margin: 0 auto; padding: 1.5rem 1rem; }
.loading { color: var(--muted); text-align: center; margin: 3rem auto; }

.login {
  max-width: 26rem;
  margin: 6vh auto 0;
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: .85rem;
}
#login { display: grid; gap: .8rem; margin-top: 1rem; }
#login > label:not(.check), #plain-editor > label { font-weight: 600; }
.check { display: flex; align-items: center; gap: .55rem; }
.check input, .device-option input { accent-color: var(--accent); flex: none; }
input[type="text"], input[type="url"], select, textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: .4rem;
  padding: .58rem .7rem;
  background: var(--surface);
  color: var(--text);
}
#code { font-variant-numeric: tabular-nums; letter-spacing: .15em; }
button {
  border: 1px solid transparent;
  border-radius: .4rem;
  padding: .48rem .85rem;
  min-height: 2.5rem;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 650;
}
button.secondary { background: var(--surface); border-color: var(--line); color: var(--text); }
.error { color: var(--error); }
#login-error { margin-top: .85rem; }
#logout-status, #retry-logout { margin-top: .85rem; }

.workspace {
  display: grid;
  grid-template-columns: minmax(12rem, 16rem) minmax(0, 1fr);
  align-items: stretch;
  gap: 1rem;
}
.device-pane, .message-pane {
  min-width: 0;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: .75rem;
}
.devices { margin: .9rem 0 0; padding: 0; border: 0; min-width: 0; }
.devices legend { font-weight: 600; }
#empty-devices, #empty-history { margin-top: .6rem; color: var(--muted); }
#device-list, #message-list { list-style: none; margin: .6rem 0 0; padding: 0; }
.device-row { display: flex; align-items: center; justify-content: space-between; gap: .25rem; }
.device-option {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .45rem .25rem;
  min-height: 2.55rem;
  cursor: pointer;
  min-width: 0;
  flex: 1;
}
.device-option:hover { background: var(--page); }
.device-name { display: block; font-weight: 650; overflow-wrap: anywhere; }
.device-state { display: block; color: var(--muted); font-size: .83rem; }
.device-state.online { color: var(--accent); }
.device-revoke { font-size: .8rem; min-height: 2rem; padding: .15rem .3rem; }
#enrollment-tools, #auth-tools { border-top: 1px solid var(--line); margin-top: 1rem; padding-top: .8rem; }
#enrollment-tools summary, #auth-tools summary { cursor: pointer; font-weight: 650; }
#enroll, #activate-otp, .pending-device, .pair-scan { display: grid; gap: .45rem; margin-top: .65rem; }
#auth-tools > button, #otp-status { margin-top: .65rem; }
#enrollment-error { margin-top: .55rem; }
.pending-device { border-top: 1px solid var(--line); padding-top: .6rem; overflow-wrap: anywhere; }
#network-status { margin-top: .55rem; }
.history {
  min-height: 12rem;
  height: clamp(15rem, 57vh, 44rem);
  overflow-y: auto;
  padding: .6rem .25rem;
  margin: .6rem 0 .9rem;
  border-block: 1px solid var(--line);
}
#message-list { display: grid; gap: .6rem; }
.message {
  padding: .55rem .7rem;
  background: var(--page);
  border-radius: .55rem;
}
.message.mine { background: var(--bubble); }
.message-meta { color: var(--muted); font-size: .83rem; overflow-wrap: anywhere; }
.message-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.rich-text { display: grid; gap: .4rem; overflow-wrap: anywhere; }
.rich-text p, .rich-text li, .rich-text blockquote, .rich-text pre { white-space: pre-wrap; }
.rich-text a { color: var(--accent); }
.rich-text ul, .rich-text ol { margin: 0; padding-inline-start: 1.35rem; }
.rich-text blockquote, .rich-text pre { margin: 0; padding: .25rem .65rem; }
.rich-text blockquote { border-inline-start: .2rem solid var(--line); }
.rich-text code { background: var(--surface); border-radius: .2rem; padding: .1rem .2rem; }
.rich-text pre { background: var(--surface); border-radius: .35rem; }
.rich-text pre > code { background: none; padding: 0; }
#compose { display: grid; gap: .5rem; }
#draft { resize: vertical; }
.compose-format, .rich-block-options, .rich-marks { display: flex; align-items: center; flex-wrap: wrap; gap: .45rem; }
.compose-format select, .rich-block-options select { width: auto; padding: .35rem .5rem; }
#plain-editor, #rich-editor, #rich-blocks, .rich-block, .rich-runs, .rich-run { display: grid; gap: .45rem; }
.rich-block { margin: 0; min-width: 0; padding: .6rem; border: 1px solid var(--line); border-radius: .4rem; }
.rich-block textarea { resize: vertical; }
.rich-marks { gap: .2rem .65rem; }
.rich-run { padding-block: .2rem; }
.rich-run details { font-size: .92rem; }
.rich-run details > * + * { margin-top: .4rem; }
.rich-run details summary { cursor: pointer; }
.rich-run label[for] { display: block; }
.rich-run button, .rich-block button, #add-block { justify-self: start; }
.compose-controls { display: flex; justify-content: flex-end; align-items: center; gap: .7rem; }
#send-status { margin-right: auto; }
.attachment { display: flex; align-items: center; flex-wrap: wrap; gap: .25rem .65rem; overflow-wrap: anywhere; }
.attachment-name { font-weight: 650; }
.attachment-detail { color: var(--muted); font-size: .85rem; }
.attachment a { color: var(--accent); }
#file-editor { display: grid; gap: .45rem; margin-top: .75rem; padding-top: .75rem; border-top: 1px solid var(--line); }
.file-controls { display: flex; align-items: center; flex-wrap: wrap; gap: .45rem; }
.file-controls input { max-width: 100%; }
#direct-tools { margin-top: .75rem; border-top: 1px solid var(--line); padding-top: .75rem; }
#direct-tools summary { cursor: pointer; font-weight: 650; }
#direct-status, #stop-transfer { margin-top: .5rem; }
#staged-download { display: grid; gap: .4rem; margin-top: .75rem; overflow-wrap: anywhere; }
#receive-checkpoint { display: grid; gap: .4rem; margin-top: .75rem; overflow-wrap: anywhere; }
#discard-checkpoint { justify-self: start; }
#direct-offers { list-style: none; margin: .5rem 0 0; padding: 0; }
.direct-offer { display: grid; gap: .35rem; padding-block: .45rem; overflow-wrap: anywhere; }
.direct-actions { display: flex; flex-wrap: wrap; gap: .4rem; }

@media (max-width: 42rem) {
  .workspace { grid-template-columns: 1fr; }
  main, .device-pane, .message-pane { padding: .75rem; }
  .top { padding-inline: .75rem; }
  .history { height: clamp(14rem, 45vh, 30rem); }
}

.setup-qr {
  display: block;
  width: min(100%, 240px);
  height: auto;
  margin: 0.5rem 0;
  image-rendering: pixelated;
}

.setup-qr[hidden] {
  display: none;
}

.screen-reader { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.conversation-heading, #admin-devices li { display: flex; align-items: center; justify-content: space-between; gap: .6rem; }
.conversation-heading h2 { overflow-wrap: anywhere; }
.conversation-heading button { flex: none; font-size: .85rem; }
.device-option { padding: .5rem; border-radius: .45rem; }
.device-option:has(input:checked) { background: var(--bubble); }
.device-option input { accent-color: var(--accent); }
#management { margin-top: 1rem; padding-top: .75rem; border-top: 1px solid var(--line); }
summary { cursor: pointer; }
#admin-devices { padding: 0; list-style: none; }
#admin-devices li { margin-top: .4rem; font-size: .9rem; overflow-wrap: anywhere; }
#more-recipients { color: var(--muted); font-size: .9rem; }
#copies { display: flex; flex-wrap: wrap; gap: .8rem; }
#json-draft { font-family: ui-monospace, monospace; }
@media (max-width: 42rem) {
  #device-list { display: flex; gap: .5rem; overflow-x: auto; }
  .device-option { width: max-content; }
  .conversation-heading { flex-wrap: wrap; }
}

.device-platform { margin-inline-start: .45em; color: var(--muted); font-size: .75em; font-weight: 400; }
.pair-scan { overflow: hidden; }
#pair-video { width: 100%; }
#pair-fingerprint { color: var(--muted); font: .78rem/1.35 ui-monospace, monospace; overflow-wrap: anywhere; }
