/* Dish: charcoal surfaces, one blue accent. */
:root {
  --bg: #0c0d10;
  --panel: #131417;
  --chat: #16171b;
  --raised: #1e2025;
  --hover: #26282e;
  --line: rgba(255, 255, 255, .06);
  --text: #f2f3f5;
  --text-2: #a9adb7;
  --text-3: #6c707b;
  --accent: #5b9dff;
  --accent-ink: #fff;
  --accent-soft: rgba(91, 157, 255, .14);
  --green: #4ade80;
  --danger: #f87171;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  --safe-b: env(safe-area-inset-bottom);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.45 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
h1, h3, p { margin: 0; }
button, input, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; padding: 0; }
a { color: inherit; }
[hidden] { display: none !important; }
.i { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* Buttons */
.btn-primary, .btn-soft {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border-radius: 12px; padding: 10px 14px; font-weight: 600; white-space: nowrap; text-decoration: none;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-soft { background: var(--raised); color: var(--text-2); }
.btn-soft:hover { color: var(--text); background: var(--hover); }
.btn-sm { padding: 7px 11px; font-size: 12.5px; border-radius: 10px; }
.btn-sm .i { width: 14px; height: 14px; }
.btn-lg { padding: 13px 18px; font-size: 15px; width: 100%; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  color: var(--text-2); flex: none; text-decoration: none;
}
.icon-btn:hover { background: var(--raised); color: var(--text); }
.icon-btn.on { background: var(--raised); color: var(--text); }

/* Layout */
.app { display: grid; grid-template-columns: 272px minmax(0, 1fr); height: 100dvh; }
.main { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--chat); }

/* --- Sidebar ------------------------------------------------------------------ */
.side {
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0; position: relative;
}
.brand { padding: 18px 16px 14px; }
.brand-link { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; }
.brand b { font-size: 16px; font-weight: 700; letter-spacing: -.01em; }
.mark {
  width: 28px; height: 28px; border-radius: 9px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; flex: none;
}
.mark .i { width: 16px; height: 16px; stroke-width: 2.6; }
.mark-lg { width: 48px; height: 48px; border-radius: 15px; margin: 0 auto 18px; }
.mark-lg .i { width: 24px; height: 24px; }

.joinbox { margin: 0 12px 10px; padding: 12px; border-radius: 14px; background: var(--raised); }
.joinbox label { font-size: 11.5px; color: var(--text-3); display: block; margin-bottom: 8px; font-weight: 500; }
.join-error { color: var(--danger); font-size: 12.5px; min-height: 0; margin-top: 6px; }
.join-error:empty { display: none; }

/* Four digit boxes driven by one transparent input on top */
.digits { position: relative; display: flex; gap: 6px; }
.digits input {
  position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; border: 0;
  font-size: 16px; /* stops iOS zoom */ caret-color: transparent; cursor: text; z-index: 1;
}
.digits span {
  flex: 1; height: 42px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line);
  display: grid; place-items: center; font: 700 18px var(--mono); color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.digits span.cur { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.digits.error span { border-color: var(--danger); }
.digits-lg { gap: 10px; margin: 24px 0 4px; }
.digits-lg span { height: 68px; border-radius: 14px; font-size: 30px; background: var(--raised); }

.newbtn { margin: 0 12px 4px; }

.side-scroll { flex: 1; overflow-y: auto; min-height: 0; padding-bottom: 8px; }
.label {
  font-size: 11.5px; font-weight: 600; color: var(--text-3);
  padding: 16px 20px 6px; display: flex; justify-content: space-between;
}
.sessions { padding: 0 8px; }
.s {
  display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; align-items: center; gap: 2px 8px;
  padding: 9px 12px; border-radius: 10px; color: var(--text-2); text-decoration: none;
}
.s:hover { background: rgba(255, 255, 255, .03); }
.s.on { background: var(--raised); color: var(--text); }
.s .c { font: 500 11.5px var(--mono); color: var(--text-3); }
.s.on .c { color: var(--accent); }
.s .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.s.unread .nm { color: var(--text); font-weight: 600; }
.s .t { font-size: 11px; color: var(--text-3); }
.s .u { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); justify-self: end; }
.s .pv {
  grid-column: 2 / 4; font-size: 12.5px; color: var(--text-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.s.gone { opacity: .45; }
.empty { color: var(--text-3); font-size: 13px; padding: 6px 20px; }

.me { border-top: 1px solid var(--line); padding: 10px 10px calc(10px + var(--safe-b)) 16px; display: flex; align-items: center; gap: 10px; }
.dev-icon {
  width: 32px; height: 32px; border-radius: 10px; background: var(--raised); color: var(--text-2);
  display: grid; place-items: center; position: relative; flex: none;
}
.dev-icon .i { width: 15px; height: 15px; }
.me .dev-icon::after {
  content: ""; position: absolute; right: -2px; bottom: -2px; width: 9px; height: 9px;
  border-radius: 50%; background: var(--green); border: 2px solid var(--panel);
}
.me-text { flex: 1; min-width: 0; line-height: 1.25; }
.me-text b { font-weight: 600; font-size: 13.5px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-text small { font-size: 11.5px; color: var(--text-3); }

.popover {
  position: absolute; left: 10px; right: 10px; bottom: calc(62px + var(--safe-b)); z-index: 5;
  background: var(--raised); border: 1px solid var(--line); border-radius: 14px; padding: 14px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .5); display: flex; flex-direction: column; gap: 14px;
}
.field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--text-3); font-weight: 500; }
.field input {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px;
  font-size: 14px; color: var(--text); outline: none;
}
.field input:focus { border-color: var(--accent); }

.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 13.5px; cursor: pointer; padding: 4px 0; }
.toggle-row small { display: block; font-size: 11.5px; color: var(--text-3); margin-top: 1px; }
.switch {
  appearance: none; width: 36px; height: 20px; border-radius: 999px; background: var(--hover);
  position: relative; cursor: pointer; flex: none; margin: 0; transition: background .15s;
}
.switch::after {
  content: ""; position: absolute; left: 2px; top: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--text-2); transition: transform .15s, background .15s;
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(16px); background: #fff; }

/* --- Home --------------------------------------------------------------------- */
.home { flex: 1; display: grid; place-items: center; padding: 32px 16px; overflow-y: auto; }
.hero-card { width: 100%; max-width: 400px; text-align: center; }
.hero-card h1 { font-size: 28px; font-weight: 700; letter-spacing: -.02em; }
.hero-card p { color: var(--text-3); margin-top: 6px; }
.or { display: flex; align-items: center; gap: 12px; color: var(--text-3); margin: 20px 0; font-size: 12px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* --- Chat --------------------------------------------------------------------- */
.chat { flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative; }
.chat-head {
  display: flex; align-items: center; gap: 12px; padding: 12px 18px 12px 22px;
  border-bottom: 1px solid var(--line); min-height: 64px;
}
.back { display: none; margin-left: -8px; }
.ch-title { flex: 1; min-width: 0; }
.ch-name {
  font-size: 16px; font-weight: 600; letter-spacing: -.01em; display: block; max-width: 100%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left;
}
.ch-sub { font-size: 12.5px; color: var(--text-3); display: flex; gap: 6px; align-items: center; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px rgba(74, 222, 128, .15); flex: none; }
.dot.off { background: var(--text-3); box-shadow: none; }
#privacy::before { content: "·"; margin-right: 6px; }
.codepill { display: flex; align-items: center; gap: 10px; padding: 4px 4px 4px 14px; border-radius: 12px; background: var(--raised); flex: none; }
.codepill b { font: 700 15px var(--mono); letter-spacing: .2em; }

.msgs { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 18px 28px 10px; display: flex; flex-direction: column; overscroll-behavior: contain; }
.divider {
  align-self: center; font-size: 11.5px; font-weight: 600; color: var(--text-3);
  background: var(--raised); padding: 4px 12px; border-radius: 999px; margin: 12px 0 10px;
}
.chat-empty { margin: auto; text-align: center; color: var(--text-3); max-width: 320px; padding: 20px; }
.chat-empty .bigcode { margin: 0 0 14px; }

/* A run of consecutive messages from one device */
.group { display: flex; gap: 12px; align-items: flex-start; max-width: min(100%, 760px); margin-top: 16px; }
.av {
  width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; flex: none;
  background: var(--raised); color: var(--text-2);
}
.av .i { width: 16px; height: 16px; }
.mine .av { background: var(--accent-soft); color: var(--accent); }
.stack { display: flex; flex-direction: column; gap: 4px; min-width: 0; align-items: flex-start; }
.who { font-size: 12px; color: var(--text-3); margin: 0 2px 1px; display: flex; align-items: center; gap: 6px; line-height: 1.2; min-height: 17px; }
.who b { color: var(--text); font-weight: 600; font-size: 13.5px; }
.you { font-size: 10.5px; font-weight: 600; color: var(--accent); background: var(--accent-soft); padding: 1px 6px; border-radius: 6px; }
.item { position: relative; display: flex; align-items: center; gap: 8px; max-width: 100%; }

.b { background: var(--raised); padding: 9px 14px; border-radius: 16px; overflow-wrap: anywhere; white-space: pre-wrap; min-width: 0; }
.who + .item .b { border-top-left-radius: 6px; }
.mine .b { background: rgba(91, 157, 255, .1); box-shadow: inset 0 0 0 1px rgba(91, 157, 255, .18); }
.b a { color: var(--accent); text-decoration: none; }
.b a:hover { text-decoration: underline; }

/* Side actions (copy, link, save): always visible on text so copying is one tap */
.side-acts { display: flex; gap: 4px; flex: none; }
.chip {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  color: var(--text-3); background: transparent; border: 1px solid var(--line); text-decoration: none;
}
.chip:hover { color: var(--text); background: var(--raised); }
.chip .i { width: 14px; height: 14px; }
.chip.done { color: var(--green); border-color: rgba(74, 222, 128, .35); }
.item:not(.text) .side-acts { opacity: 0; transition: opacity .15s; }
.item:hover .side-acts, .item:focus-within .side-acts { opacity: 1; }

.media {
  display: block; border-radius: 18px; background: var(--raised); max-width: min(100%, 420px);
  max-height: 380px; width: auto; height: auto; object-fit: cover; cursor: zoom-in;
}
video.media { cursor: auto; width: 420px; max-width: 100%; background: #000; }
audio { max-width: 100%; }

/* Image viewer: full-screen over the chat, tap the backdrop or image (or Back) to close */
.viewer {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .92); padding: 64px 16px calc(16px + var(--safe-b)); cursor: zoom-out;
}
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; }
.viewer-bar {
  position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px; cursor: auto;
}
.viewer-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); font-size: 13px; }
.viewer-acts { display: flex; gap: 6px; }
.viewer .chip { width: 38px; height: 38px; color: var(--text); background: rgba(255, 255, 255, .08); border-color: transparent; }
.viewer .chip:hover { background: rgba(255, 255, 255, .16); }
.viewer .chip .i { width: 17px; height: 17px; }

.filecard { background: var(--raised); border-radius: 18px; padding: 12px; width: 300px; max-width: 100%; }
.mine .filecard { border: 1px solid var(--accent-soft); }
.fc-top { display: flex; align-items: center; gap: 12px; }
.fbadge {
  width: 40px; height: 46px; border-radius: 10px; display: grid; place-items: center; flex: none;
  font-size: 10px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase;
  background: var(--accent-soft); color: var(--accent);
}
.fbadge.pdf { background: rgba(239, 68, 68, .15); color: #f87171; }
.fbadge.vid { background: rgba(52, 211, 153, .14); color: #34d399; }
.fbadge.zip { background: rgba(250, 204, 21, .13); color: #facc15; }
.fname { font-weight: 600; overflow-wrap: anywhere; line-height: 1.3; }
.fsub { font-size: 12px; color: var(--text-3); }
.facts { display: flex; gap: 6px; margin-top: 10px; }
.facts > * {
  flex: 1; padding: 7px 8px; border-radius: 10px; background: var(--hover); font-size: 12.5px; font-weight: 600;
  color: var(--text-2); display: flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none;
  white-space: nowrap;
}
.facts > *:hover { color: var(--text); }
.facts .i { width: 14px; height: 14px; }
.facts .done { color: var(--green); }
.text-preview {
  margin: 10px 0 0; padding: 10px 12px; background: var(--bg); border-radius: 10px;
  font: 12px/1.6 var(--mono); color: var(--text-2); max-height: 220px; overflow: auto;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.expired { color: var(--text-3); font-style: italic; font-size: 13px; padding: 9px 14px; border-radius: 18px; border: 1px dashed var(--line); }

/* Composer */
.composer { padding: 8px 22px calc(16px + var(--safe-b)); }
.uploads { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.uploads:empty { display: none; }
.upload {
  display: flex; align-items: center; gap: 10px; background: var(--raised); border-radius: 12px;
  padding: 8px 8px 8px 12px; max-width: 420px; font-size: 12.5px;
}
.upload .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px; }
.upload .bar { flex: 1; height: 4px; border-radius: 4px; background: var(--hover); overflow: hidden; min-width: 60px; }
.upload .bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.upload small { color: var(--text-3); white-space: nowrap; }
.upload.failed small { color: var(--danger); }
.upload .chip { width: 26px; height: 26px; border: 0; }
.bar-in {
  display: flex; align-items: flex-end; gap: 6px; background: var(--raised); border-radius: 16px;
  padding: 6px; border: 1px solid var(--line); transition: border-color .15s;
}
.bar-in:focus-within { border-color: rgba(91, 157, 255, .45); }
.bar-in .icon-btn { width: 38px; height: 38px; }
.bar-in textarea {
  flex: 1; resize: none; border: 0; background: transparent; outline: none; color: var(--text);
  padding: 9px 4px; max-height: 40vh; font-size: 15px; line-height: 1.4;
}
.bar-in textarea::placeholder { color: var(--text-3); }
.send { width: 38px; height: 38px; border-radius: 11px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; flex: none; }
.send:disabled { opacity: .5; }

.drop-overlay {
  position: absolute; inset: 10px; border: 2px dashed var(--accent); border-radius: 20px;
  background: rgba(19, 20, 23, .85); display: none; place-items: center; z-index: 4; pointer-events: none;
}
.drop-overlay div { display: flex; flex-direction: column; align-items: center; gap: 10px; font-size: 18px; font-weight: 600; color: var(--accent); }
.drop-overlay .i { width: 28px; height: 28px; }
.chat.dragging .drop-overlay { display: grid; }

/* --- Details ------------------------------------------------------------------ */
.details { display: none; background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; min-height: 0; }
.details-head { display: none; align-items: center; justify-content: space-between; padding: 12px 12px 4px 22px; }
.d-hero { padding: 24px 22px 22px; text-align: center; border-bottom: 1px solid var(--line); }
.d-hero small, .sec h3 { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .12em; color: var(--text-3); }
.bigcode { display: flex; justify-content: center; gap: 8px; margin: 12px 0 16px; }
.bigcode span {
  width: 48px; height: 60px; border-radius: 12px; background: var(--raised);
  display: grid; place-items: center; font: 700 28px var(--mono); color: var(--text);
}
.d-actions { display: flex; gap: 8px; justify-content: center; }
.qr { margin: 16px auto 0; background: #fff; border-radius: 14px; padding: 12px; width: 184px; }
.qr svg { display: block; width: 100%; height: auto; }
.sec { padding: 18px 22px; border-bottom: 1px solid var(--line); }
.sec:last-child { border-bottom: 0; }
.sec h3 { margin-bottom: 12px; display: flex; justify-content: space-between; }
.sec h3 span { letter-spacing: 0; }
.devrow { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.devrow .dev-icon { width: 34px; height: 34px; }
.devrow div { flex: 1; min-width: 0; line-height: 1.3; }
.devrow b { font-weight: 600; font-size: 13.5px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.devrow b em { font-style: normal; color: var(--text-3); font-weight: 500; }
.devrow small { color: var(--text-3); font-size: 12px; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.grid a { aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--raised); display: block; position: relative; }
.grid img { width: 100%; height: 100%; object-fit: cover; display: block; }
.grid .vid::after { content: "▶"; position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: 14px; background: rgba(0, 0, 0, .3); }
.frow { display: flex; align-items: center; gap: 10px; padding: 6px 0; text-decoration: none; }
.frow .fbadge { width: 34px; height: 38px; font-size: 9px; border-radius: 8px; }
.frow div { min-width: 0; }
.frow b { font-size: 13px; font-weight: 600; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.frow small { font-size: 11.5px; color: var(--text-3); }
.row-btn {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 0; font-size: 13.5px; color: var(--text-2); text-align: left;
}
.row-btn:hover { color: var(--text); }
.row-btn.danger:hover { color: var(--danger); }
.note { font-size: 12px; color: var(--text-3); display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.note .i { width: 14px; height: 14px; }
.scrim { display: none; }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%) translateY(10px);
  background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 10px; z-index: 50;
  font-size: 13.5px; font-weight: 500; opacity: 0; pointer-events: none; transition: .2s;
}
.toast.show { opacity: 1; transform: translateX(-50%); }

/* Wide screens: details panel sits beside the chat */
@media (min-width: 1200px) {
  .app.in-chat.details-open { grid-template-columns: 272px minmax(0, 1fr) 300px; }
  .app.in-chat.details-open .details { display: block; }
}

/* Narrower: details slides over the chat */
@media (max-width: 1199px) {
  .details {
    display: block; position: fixed; top: 0; right: 0; bottom: 0; width: min(340px, 100%); z-index: 20;
    transform: translateX(100%); transition: transform .22s ease; box-shadow: -20px 0 60px rgba(0, 0, 0, .5);
  }
  .details-head { display: flex; }
  .d-hero { padding-top: 8px; }
  .app.in-chat.details-open .details { transform: none; }
  .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 15; opacity: 0; pointer-events: none; transition: opacity .2s; }
  .app.in-chat.details-open .scrim { opacity: 1; pointer-events: auto; }
}

/* Phones: sessions list is home, chat is full screen */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .app:not(.in-chat) .main { display: none; }
  .app.in-chat .side { display: none; }
  .side { border-right: 0; }
  .brand { padding: 16px 20px 12px; }
  .joinbox { margin: 0 16px 10px; padding: 14px; }
  .digits span { height: 56px; font-size: 24px; border-radius: 12px; }
  .newbtn { margin: 0 16px 4px; padding: 12px; }
  .s { padding: 11px 12px; }
  .sessions { padding: 0 8px; }

  .chat-head { padding: 8px 12px; gap: 8px; min-height: 56px; }
  .back { display: grid; }
  .codepill { padding: 3px 3px 3px 10px; gap: 8px; }
  .codepill b { font-size: 14px; letter-spacing: .14em; }
  #share span { display: none; }
  #share { padding: 7px 9px; }
  .ch-sub { font-size: 12px; }
  #privacy { display: none; }
  .msgs { padding: 10px 12px 8px; }
  .group { gap: 10px; }
  .av { width: 30px; height: 30px; border-radius: 10px; }
  .composer { padding: 6px 10px calc(10px + var(--safe-b)); }
  .media, video.media { max-width: 100%; }
  .filecard { width: 260px; }
  /* Touch has no hover, so keep file actions visible */
  .item:not(.text) .side-acts { opacity: 1; }
  .details { width: 100%; }
}
