:root {
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #111111;
  background: #ffffff;
  font-synthesis: none;
  --base: #ffffff;
  --raised: #ffffff;
  --soft: #f4f4f4;
  --hover: #ebebeb;
  --border: #e7e7e7;
  --focus-border: #bdbdbd;
  --muted: #707070;
  --faint: #999999;
  --contrast: #0a0a0a;
  --on-contrast: #ffffff;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { min-height: 100%; }
body { margin: 0; min-height: 100vh; overflow-x: hidden; background: var(--base); }
button, textarea, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible { outline: 2px solid #777; outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 10;
  width: 257px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 14px 12px 12px;
  background: var(--base);
  border-right: 1px solid var(--border);
}
.sidebar-brand { height: 42px; display: flex; align-items: center; gap: 11px; padding: 0 8px; }
.sidebar-brand strong { font-size: 18px; letter-spacing: -.03em; }
.brand-mark, .welcome-mark { display: block; object-fit: cover; }
.brand-mark { width: 32px; height: 32px; border-radius: 10px; }
.sidebar-nav { display: grid; gap: 4px; margin-top: 16px; }
.sidebar-item { width: 100%; min-height: 40px; display: flex; align-items: center; gap: 11px; padding: 0 11px; color: inherit; background: transparent; border: 0; border-radius: 10px; font-size: 14px; font-weight: 550; text-align: left; }
.sidebar-item.is-active, .sidebar-item:hover { background: var(--soft); }
.sidebar-item svg { width: 19px; height: 19px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sidebar-server { display: flex; align-items: center; gap: 10px; padding: 9px 8px; }
.sidebar-server img { width: 30px; height: 30px; border-radius: 50%; }
.sidebar-server div, .sidebar-server strong, .sidebar-server span { min-width: 0; display: block; }
.sidebar-server strong { overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.connection { display: inline-flex; align-items: center; gap: 6px; margin-top: 2px; color: var(--muted); font-size: 11px; }
.connection::before { width: 6px; height: 6px; content: ""; border-radius: 50%; background: currentColor; }
.secondary {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 13px;
  color: inherit;
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  backdrop-filter: blur(18px);
}
.secondary:hover { background: var(--soft); }

.access { min-height: 100vh; display: grid; place-items: center; padding: 88px 20px 56px; }
.access-card { width: min(390px, 100%); display: grid; gap: 15px; }
.access-brand { display: flex; align-items: center; justify-content: center; gap: 13px; margin-bottom: 16px; }
.access-card .welcome-mark { width: 52px; height: 52px; margin: 0; border-radius: 16px; }
.access-card h1 { margin: 0; font-size: 34px; letter-spacing: -.045em; }
.access-card h2 { margin: 0; text-align: center; font-size: 24px; letter-spacing: -.035em; }
.access-card > p { margin: -5px 0 10px; color: var(--muted); text-align: center; line-height: 1.45; }
.access-card label { display: grid; gap: 7px; font-size: 13px; font-weight: 600; }
.access-card input, .access-settings input {
  width: 100%;
  min-height: 48px;
  padding: 0 16px;
  color: inherit;
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: 24px;
  outline: none;
}
.access-card input:focus, .access-settings input:focus { border-color: var(--faint); }
.access-card small { color: var(--faint); text-align: center; line-height: 1.4; }
.primary { min-height: 48px; padding: 0 18px; color: var(--on-contrast); background: var(--contrast); border: 0; border-radius: 24px; cursor: pointer; font-weight: 650; }
.primary:hover { opacity: .86; }
.form-error { min-height: 18px; margin: -5px 0 !important; color: #c52c20 !important; font-size: 13px; }

.conversation { width: calc(100% - 257px); min-height: 100vh; margin-left: 257px; padding: 80px 24px 150px; }
/* The top leaves room for the empty-timeline guide above the centered
   composer, so the brand does not move when the guide appears. */
.welcome { position: fixed; inset: calc(50% - 265px) 0 auto 257px; display: grid; justify-items: center; pointer-events: none; }
.welcome-guide { display: grid; justify-items: center; gap: 14px; margin-top: 14px; padding: 0 20px; text-align: center; }
.welcome-guide p { margin: 0; color: var(--muted); font-size: 15px; line-height: 1.45; }
.welcome-connect { pointer-events: auto; }
.welcome-brand { display: flex; align-items: center; gap: 13px; }
.welcome-mark { width: 64px; height: 64px; border-radius: 20px; }
.welcome h1 { margin: 0; font-size: 42px; font-weight: 650; letter-spacing: -.05em; }
.messages { width: min(704px, 100%); margin: 0 auto; display: flex; flex-direction: column; gap: 30px; }
.message { display: flex; flex-direction: column; align-items: flex-start; }
.message.is-current-device { align-items: flex-end; }
.message-body { max-width: 90%; padding: 8px 16px; background: var(--soft); border: 1px solid var(--border); border-radius: 24px 24px 24px 8px; }
.message.is-current-device .message-body { border-radius: 24px 24px 8px; }
.device-icon { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.message-head { display: flex; align-items: center; gap: 5px; margin: 0 9px 6px; color: var(--faint); font-size: 11px; line-height: 1.2; }
.message-source-icon { display: inline-flex; }
.message-source-icon .device-icon { width: 13px; height: 13px; stroke-width: 1.7; }
.sender { font-weight: 500; }
.time { color: inherit; }
.time::before { margin-right: 5px; content: "·"; }
.copy-message { padding: 0; color: inherit; background: none; border: 0; font: inherit; cursor: pointer; }
.copy-message::before { margin-right: 5px; content: "·"; }
.copy-message:hover, .copy-message:focus-visible { color: var(--muted); outline: none; }
.message-text { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; font-size: 15px; line-height: 1.5; }
.message-body.has-image { padding: 4px; }
.message-image { width: fit-content; max-width: 100%; margin: 0; overflow: hidden; border-radius: 20px; }
/* Until the bytes arrive the <img> has no src, and the browser draws its
   broken-image icon and alt text: a loading image looked like a failed one. */
.message-image.is-loading { min-width: 176px; min-height: 118px; display: grid; place-items: center; background: var(--hover); }
.message-image.is-loading img { display: none; }
.message-image.is-loading::after { width: 22px; height: 22px; content: ""; border: 2px solid var(--border); border-top-color: var(--muted); border-radius: 50%; animation: image-spin .8s linear infinite; }
@keyframes image-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .message-image.is-loading::after { animation-duration: 2.4s; } }
/* A percentage inside min() is indefinite while the browser is measuring
   intrinsic width, so the constraint was dropped and the bubble sized itself
   from max-height times the aspect ratio instead -- leaving a tall image with
   empty bubble beside it. The figure already caps at 100% of the bubble. */
.message-image img { display: block; width: auto; height: auto; max-width: 320px; max-height: 360px; object-fit: contain; cursor: zoom-in; }
.viewer { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 24px; background: rgba(0, 0, 0, .82); cursor: zoom-out; }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; }
.viewer-save { position: absolute; top: 20px; right: 20px; padding: 8px 16px; color: #fff; text-decoration: none; background: rgba(255, 255, 255, .18); border-radius: 999px; font-size: 13px; font-weight: 500; cursor: pointer; }
.viewer-save:hover, .viewer-save:focus-visible { background: rgba(255, 255, 255, .3); }

.file-card { width: min(330px, 100%); display: flex; align-items: center; gap: 11px; padding: 2px 0; color: inherit; text-align: left; background: transparent; cursor: pointer; border: 0; border-radius: 12px; }
.file-card:hover .file-title { text-decoration: underline; }
.file-icon { width: 38px; height: 42px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 10px; color: #fff; background: #2e6da8; font-size: 10px; font-weight: 750; }
.file-copy { min-width: 0; }
.file-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; font-weight: 600; }
.file-meta { margin-top: 3px; color: var(--muted); font-size: 12px; }

.composer-shell {
  position: fixed;
  inset: auto 0 0 257px;
  z-index: 8;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--base) 64%, transparent);
  transition: top 180ms ease, bottom 180ms ease;
}
.composer { width: min(752px, 100%); min-height: 60px; margin: 0 auto; padding: 9px; background: var(--raised); border: 1px solid var(--border); border-radius: 999px; box-shadow: 0 8px 30px rgba(0, 0, 0, .06); }
.composer.has-attachment { border-radius: 32px; }
.composer:focus-within { border-color: var(--focus-border); }
.composer-row { display: flex; align-items: center; gap: 8px; }
.attachment-picker { position: relative; flex: 0 0 auto; }
.attach, .send { width: 40px; height: 40px; display: grid; place-items: center; flex: 0 0 auto; padding: 0; border: 0; border-radius: 50%; cursor: pointer; }
.attach { background: var(--soft); }
.attach:hover { background: var(--hover); }
.attach[aria-expanded="true"] { transform: rotate(45deg); }
.attach svg, .send svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.send { color: var(--on-contrast); background: var(--contrast); }
.send:disabled { color: var(--faint); background: var(--soft); cursor: default; }
textarea { min-height: 40px; max-height: 180px; width: 100%; resize: none; padding: 9px 2px 7px; color: inherit; background: transparent; border: 0; outline: 0; font-size: 15px; line-height: 1.5; }
textarea:focus-visible { outline: none; }
textarea::placeholder { color: var(--faint); }
textarea:disabled { color: var(--faint); }
.file-chip { position: relative; width: fit-content; max-width: calc(100% - 8px); height: 40px; margin: 3px 4px 8px; padding: 0 6px 0 10px; display: flex; align-items: center; gap: 8px; color: inherit; background: var(--soft); border: 1px solid var(--border); border-radius: 12px; font-size: 13px; }
.file-kind-icon { width: 20px; height: 24px; display: grid; place-items: center; flex: 0 0 auto; color: var(--muted); }
.file-kind-icon svg, .file-chip button svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.file-chip #file-name { max-width: min(250px, calc(100vw - 190px)); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip button { width: 24px; height: 24px; padding: 4px; display: grid; place-items: center; flex: 0 0 auto; color: var(--muted); background: transparent; border: 0; border-radius: 50%; cursor: pointer; }
.file-chip button:hover, .file-chip button:focus-visible { color: inherit; background: var(--hover); outline: none; }
.file-preview { display: none; width: auto; height: auto; max-width: 220px; max-height: 96px; object-fit: contain; border-radius: 10px; }
.file-chip.is-image { width: fit-content; height: auto; min-height: 40px; padding: 3px; gap: 0; }
.file-chip.is-image .file-kind-icon, .file-chip.is-image #file-name { display: none; }
.file-chip.is-image .file-preview { display: block; }
.file-chip.is-image button { position: absolute; top: -7px; right: -7px; color: inherit; background: var(--raised); border: 1px solid var(--border); opacity: 1; transform: scale(.8); transition: transform .12s ease; }
.file-chip.is-image:hover button, .file-chip.is-image:focus-within button { transform: scale(1); }
.footnote { min-height: 15px; margin: 7px auto 0; color: var(--faint); text-align: center; font-size: 11px; }
.footnote.error { color: #c52c20; }

.attachment-menu { position: absolute; z-index: 20; bottom: calc(100% + 12px); left: 0; width: 248px; padding: 7px; color: inherit; background: var(--raised); background: color-mix(in srgb, var(--raised) 92%, transparent); border: 1px solid var(--border); border-radius: 18px; box-shadow: 0 16px 48px rgba(0, 0, 0, .15); backdrop-filter: blur(22px); }
.attachment-menu > button { width: 100%; display: flex; align-items: center; gap: 11px; padding: 10px; color: inherit; text-align: left; background: transparent; border: 0; border-radius: 12px; cursor: pointer; }
.attachment-menu > button:hover, .attachment-menu > button:focus-visible { background: var(--soft); outline: none; }
.attachment-menu-icon { width: 36px; height: 36px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 11px; color: inherit; background: var(--soft); }
.attachment-menu-icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.attachment-menu strong, .attachment-menu small { display: block; }
.attachment-menu strong { font-size: 14px; }
.attachment-menu small { margin-top: 2px; color: var(--muted); font-size: 11px; }

.devices-page { width: calc(100% - 257px); min-height: 100vh; margin-left: 257px; padding: 72px 24px 96px; }
.devices-content { width: min(760px, 100%); margin: 0 auto; }
.devices-head { margin-bottom: 36px; }
.devices-head h1, .devices-head p, .devices-section h2 { margin: 0; }
.devices-head > p:first-child { margin-bottom: 8px; color: var(--faint); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; }
.devices-head h1 { font-size: 34px; letter-spacing: -.045em; }
.devices-head #current-device { margin-top: 8px; color: var(--muted); font-size: 13px; }
.devices-section h2, .access-settings h2 { margin: 0; font-size: 17px; letter-spacing: -.02em; }
.connect-device { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 24px; margin-bottom: 36px; padding: 22px; background: var(--soft); border: 1px solid var(--border); border-radius: 22px; }
.connect-copy { min-width: 0; display: grid; gap: 12px; }
.connect-copy h2, .connect-copy p { margin: 0; }
.connect-copy h2 { font-size: 17px; letter-spacing: -.02em; }
.connect-copy p { color: var(--muted); font-size: 13px; line-height: 1.45; }
.connect-address { min-width: 0; display: flex; gap: 8px; }
.connect-address input { min-width: 0; min-height: 40px; flex: 1 1 auto; padding: 0 14px; color: inherit; background: var(--raised); border: 1px solid var(--border); border-radius: 20px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; }
.connect-note:empty { display: none; }
.connect-copy .connect-note.error { color: #c52c20; }
/* The code keeps its own white ground and quiet zone in dark mode; scanners
   expect dark modules on a light background. */
.connect-qr { width: 168px; overflow: hidden; background: #ffffff; border: 1px solid var(--border); border-radius: 14px; }
.connect-qr svg { display: block; width: 100%; height: auto; }
.device-list { display: grid; margin-top: 12px; border-top: 1px solid var(--border); }
.device-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 68px; padding: 10px 4px; border-bottom: 1px solid var(--border); }
.device-row:hover { background: var(--soft); }
.device-identity { min-width: 0; display: flex; align-items: center; gap: 10px; }
.device-list-icon { width: 36px; height: 36px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 11px; color: inherit; background: var(--soft); }
.device-name { font-weight: 600; }
.device-meta { margin-top: 2px; color: var(--muted); font-size: 12px; }
.revoke { padding: 7px 10px; color: #c52c20; background: transparent; border: 1px solid #dcaaa6; border-color: color-mix(in srgb, #c52c20 35%, var(--border)); border-radius: 999px; cursor: pointer; }
.access-settings { display: grid; gap: 14px; margin-top: 36px; padding: 22px; background: var(--soft); border: 1px solid var(--border); border-radius: 22px; }
.access-settings h2, .access-settings p { margin: 0; }
.access-settings p, .access-settings output { color: var(--muted); font-size: 13px; line-height: 1.4; }
.access-settings p { margin-top: 5px; }
.access-settings label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; }
.access-settings .secondary { justify-self: start; }
.access-settings output { min-height: 18px; }

@media (min-width: 641px) {
  .welcome:not([hidden]) ~ .composer-shell { inset: calc(50% - 101px) 0 auto 257px; background: transparent; }
  .welcome:not([hidden]) ~ .composer-shell .footnote { width: min(736px, 100%); min-height: 66px; display: grid; place-items: center; margin-top: 32px; color: var(--muted); background: var(--base); border: 1px solid var(--border); border-radius: 16px; font-size: 13px; }
}

@media (prefers-color-scheme: dark) {
  :root {
    color: #f2f2f2;
    background: #050505;
    --base: #050505;
    --raised: #141414;
    --soft: #141414;
    --hover: #202020;
    --border: #292929;
    --focus-border: #4a4a4a;
    --muted: #a3a3a3;
    --faint: #777777;
    --contrast: #f3f3f3;
    --on-contrast: #080808;
  }
  .composer { box-shadow: 0 8px 32px rgba(0, 0, 0, .35); }
  .form-error, .footnote.error, .connect-copy .connect-note.error { color: #ff7167 !important; }
}

@media (max-width: 640px) {
  .sidebar { width: 56px; padding: 10px 7px; }
  .sidebar-brand { padding: 0 5px; }
  .sidebar-brand strong, .sidebar-item span, .sidebar-server div { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
  .sidebar-item { justify-content: center; padding: 0; }
  .sidebar-server { justify-content: center; padding: 8px 0; }
  .conversation { width: calc(100% - 56px); margin-left: 56px; padding: 72px 12px 132px; }
  .devices-page { width: calc(100% - 56px); margin-left: 56px; padding: 40px 16px 64px; }
  .devices-head { margin-bottom: 28px; }
  .devices-head h1 { font-size: 30px; }
  .access-settings { margin-top: 28px; padding: 18px; }
  .connect-device { grid-template-columns: minmax(0, 1fr); margin-bottom: 28px; padding: 18px; }
  .connect-qr { justify-self: center; width: min(220px, 100%); }
  .access-settings .secondary { justify-self: stretch; }
  .welcome { inset: calc(50% - 170px) 0 auto 56px; }
  .welcome-mark { width: 44px; height: 44px; border-radius: 14px; }
  .welcome h1 { font-size: 32px; }
  .messages { gap: 24px; }
  .message-body { max-width: 94%; }
  .composer-shell { left: 56px; padding: 9px 8px calc(9px + env(safe-area-inset-bottom)); }
  .composer { padding: 8px; }
  .attach, .send { width: 42px; height: 42px; }
  textarea { min-height: 42px; padding-top: 10px; }
  .footnote { margin-top: 5px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
