/* Utseende i stil med Google Messages (Material 3), ljust och mörkt. */
:root {
  --bg: #f8fafd; --surface: #fff; --on: #1f1f1f; --muted: #5f6368; --line: #e1e3e1;
  --in: #e9eef6; --out: #d3e3fd; --on-out: #041e49; --primary: #0b57d0; --on-primary: #fff;
  --chip: #e8eaed; --chip-on: #c2e7ff; --red: #c62828; --field: #eef1f6;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1b1c1e; --surface: #202124; --on: #e3e3e3; --muted: #9aa0a6; --line: #3c4043;
    --in: #303134; --out: #0842a0; --on-out: #d3e3fd; --primary: #a8c7fa; --on-primary: #062e6f;
    --chip: #303134; --chip-on: #004a77; --field: #2a2b2e; --red: #f28b82; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { font: 16px/1.4 Roboto, system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--on); }
button { font: inherit; color: inherit; cursor: pointer; }
.screen { height: 100vh; height: 100dvh; display: flex; flex-direction: column; } /* dvh: inte under Chromes verktygsfält */
.grow { flex: 1; min-width: 0; }

/* inloggning */
.center { align-items: center; justify-content: center; padding: 24px; text-align: center; gap: 8px; }
.logo { width: 112px; height: 112px; border-radius: 28px; box-shadow: 0 4px 16px #0003; }
.center h1 { margin: 12px 0 0; font-weight: 500; }
.center p { margin: 0; color: var(--muted); }
#loginform { display: flex; flex-direction: column; gap: 12px; width: min(320px, 100%); margin-top: 16px; }
#code { font: 500 24px/1 ui-monospace, monospace; letter-spacing: 3px; text-align: center; text-transform: uppercase;
  padding: 14px; border: 2px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--on); }
#code:focus { outline: none; border-color: var(--primary); }
.filled { border: 0; border-radius: 24px; padding: 13px; background: var(--primary); color: var(--on-primary); font-weight: 500; }
.err { color: var(--red) !important; min-height: 1.4em; }
#parents { display: flex; flex-direction: column; gap: 10px; width: min(320px, 100%); margin-top: 16px; }
.person { display: flex; align-items: center; gap: 14px; padding: 12px 16px; border: 0; border-radius: 20px; background: var(--surface);
  font-size: 18px; box-shadow: 0 1px 3px #0002; }

/* toppfält */
.bar { display: flex; align-items: center; gap: 12px; padding: calc(10px + env(safe-area-inset-top)) 8px 10px 16px; background: var(--bg); }
.bar h1 { font-size: 22px; font-weight: 400; margin: 0; }
.bar b { display: block; font-weight: 500; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar small { display: block; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon { border: 0; background: none; width: 44px; height: 44px; border-radius: 50%; font-size: 22px; display: grid; place-items: center; flex: none; }
.icon:active { background: var(--chip); }
#back { margin-left: -8px; }

/* avatarer */
.avatar { width: 36px; height: 36px; border-radius: 50%; flex: none; display: grid; place-items: center; color: #fff;
  font-weight: 500; font-size: 16px; background: #888; }
.avatar.nissen { background: #2e7d32; }
.avatar.nisselina { background: #f06292; }
.avatar.spacer { visibility: hidden; }
.avatar.group { background: none; width: 52px; height: 40px; display: flex; align-items: center; }
.avatar.group .avatar { width: 32px; height: 32px; box-shadow: 0 0 0 2px var(--bg); }
.avatar.group .avatar + .avatar { margin-left: -12px; margin-top: 8px; }

/* konversationslistan */
#convos { list-style: none; margin: 0; padding: 0 0 96px; overflow-y: auto; flex: 1; }
#convos li { display: flex; align-items: center; gap: 14px; padding: 12px 16px; cursor: pointer; }
#convos li:active { background: var(--chip); }
#convos li .avatar { width: 48px; height: 48px; font-size: 20px; }
#convos b { font-weight: 400; display: block; font-size: 17px; }
#convos small { display: block; color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#convos li.unread b, #convos li.unread small, #convos li.unread .side { font-weight: 700; color: var(--on); }
#convos .side { font-size: 12px; color: var(--muted); text-align: right; display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
#convos .empty { color: var(--muted); justify-content: center; cursor: default; padding: 40px 16px; }
.badge { background: var(--chip-on); color: var(--on); border-radius: 10px; padding: 1px 7px; font-weight: 500; }
.fab { position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); border: 0; border-radius: 16px;
  padding: 16px 20px; background: var(--chip-on); color: var(--on); font-weight: 500; box-shadow: 0 3px 8px #0003; }

/* meddelanden */
main { flex: 1; overflow-y: auto; padding: 8px 12px 12px; display: flex; flex-direction: column; }
.day { align-self: center; font-size: 12px; color: var(--muted); margin: 16px 0 8px; font-weight: 500; }
.msg { display: flex; flex-direction: column; max-width: 82%; margin-top: 2px; }
.msg.first { margin-top: 10px; }
.msg.them { align-self: flex-start; }
.msg.me { align-self: flex-end; align-items: flex-end; }
.line { display: flex; align-items: flex-start; gap: 8px; min-width: 0; }
.col { display: flex; flex-direction: column; min-width: 0; align-items: inherit; }
.me .col { align-items: flex-end; }
.them .name { margin-left: 12px; }
.line .avatar { width: 32px; height: 32px; font-size: 14px; }

.name { font-size: 12px; color: var(--muted); margin: 0 12px 2px 52px; }
.me .name { margin: 0 12px 2px; }
.bubble { padding: 10px 14px; border-radius: 20px; white-space: pre-wrap; overflow-wrap: anywhere; min-width: 0; }
.them .bubble { background: var(--in); }
.them:not(.first) .bubble { border-top-left-radius: 6px; }
.them:not(.last) .bubble { border-bottom-left-radius: 6px; }
.me .bubble { background: var(--out); color: var(--on-out); }
.me:not(.first) .bubble { border-top-right-radius: 6px; }
.me:not(.last) .bubble { border-bottom-right-radius: 6px; }
.bubble img, .bubble video { display: block; max-width: 100%; max-height: 60vh; border-radius: 14px; margin: -4px -8px 6px; }
.bubble.media-only { padding: 0; background: none !important; }
.bubble.media-only img, .bubble.media-only video { margin: 0; border-radius: 20px; }
.meta { font-size: 11px; color: var(--muted); margin: 3px 12px 0; }
.them .meta { margin-left: 52px; }
.admin .msg:not(.last):not(.pending):not(.sel) .meta { display: none; }
.meta .del { display: none; border: 0; background: none; color: var(--red); font-size: 12px; font-weight: 500; padding: 0 0 0 10px; }
.sel .meta .del { display: inline; }
.sel .bubble { filter: brightness(.9); }
.pending .bubble { opacity: .7; outline: 2px dashed var(--primary); outline-offset: -2px; }
.pending .meta { color: var(--primary); font-weight: 500; }

/* skrivfält */
#compose { padding: 6px 8px calc(8px + env(safe-area-inset-bottom)); background: var(--bg); }
.row { display: flex; gap: 6px; align-items: flex-end; }
#text { flex: 1; resize: none; font: inherit; padding: 11px 18px; border: 0; border-radius: 24px; max-height: 140px;
  background: var(--field); color: var(--on); }
#text:focus { outline: none; }
.attach { position: relative; font-size: 26px; color: var(--primary); }
.attach input { display: none; }
#send { width: 46px; height: 46px; flex: none; border-radius: 50%; border: 0; background: var(--primary); color: var(--on-primary);
  display: grid; place-items: center; transition: transform .1s; }
#send:active { transform: scale(.92); }
#send:disabled { opacity: .5; }
#send.scheduled { background: #e37400; color: #fff; }
#adminbar { display: flex; gap: 6px; overflow-x: auto; padding: 2px 2px 8px; scrollbar-width: none; }
.chips { display: flex; gap: 6px; }
.chip { display: flex; align-items: center; gap: 6px; white-space: nowrap; border: 1px solid var(--line); background: var(--surface);
  border-radius: 18px; padding: 4px 12px 4px 4px; font-size: 14px; flex: none; }
.chip .avatar { width: 26px; height: 26px; font-size: 14px; }
.chip.on { background: var(--chip-on); border-color: transparent; font-weight: 500; }
#when { padding-left: 12px; margin-left: auto; }
#preview { display: flex; align-items: center; gap: 10px; margin: 0 0 8px 50px; padding: 6px; border-radius: 16px; background: var(--field);
  font-size: 13px; color: var(--muted); }
#previewbody { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; overflow: hidden; }
#preview img, #preview video { width: 56px; height: 56px; object-fit: cover; border-radius: 12px; }
#preview.busy #previewbody::after { content: 'Laddar upp…'; font-weight: 500; color: var(--primary); }
#unattach { border: 0; background: none; font-size: 16px; padding: 8px; }

/* dialoger */
dialog { border: 0; border-radius: 28px; padding: 24px; background: var(--surface); color: var(--on); width: min(360px, calc(100% - 32px)); }
dialog::backdrop { background: #0006; }
dialog h2 { margin: 0 0 12px; font-size: 22px; font-weight: 400; }
dialog p { color: var(--muted); font-size: 14px; margin: 0 0 12px; }
dialog input { width: 100%; font: inherit; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--on); }
.options { display: flex; flex-direction: column; }
.options button { border: 0; background: none; text-align: left; padding: 14px 8px; border-radius: 12px; font-size: 16px; }
.options button:active { background: var(--chip); }
.options button:disabled { color: var(--muted); cursor: default; }
#menudlg { padding: 8px; position: fixed; top: 8px; right: 8px; margin: 0 0 auto auto; width: 240px; border-radius: 12px; }
.custom { display: block; margin-top: 8px; font-size: 14px; color: var(--muted); }
.custom input { margin-top: 4px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.text { border: 0; background: none; color: var(--primary); font-weight: 500; padding: 10px 12px; border-radius: 20px; }
.text.strong { background: var(--primary); color: var(--on-primary); }
.code { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; padding: 10px 0; border-top: 1px solid var(--line); }
.code b { font: 600 20px ui-monospace, monospace; letter-spacing: 2px; flex: 1 1 100%; word-break: break-all; }
.chip:not(.on):not(#when) { padding: 3px; }
.chip:not(.on):not(#when) span:not(.avatar) { display: none; }
.bar .install { padding: 6px 12px; flex: none; }
.center .install { width: min(320px, 100%); margin-top: 24px; }
.admin .bubble { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
#edittext { width: 100%; font: inherit; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--on); resize: vertical; }
.text.danger { color: var(--red); }
#famlist { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
#famlist .person { font-size: 16px; text-align: left; }
#famlist small { display: block; color: var(--muted); font-size: 13px; }
#famform { display: flex; flex-direction: column; gap: 8px; }
.stack { display: flex; flex-direction: column; gap: 10px; width: min(320px, 100%); margin-top: 12px; }
.stack input { font: inherit; padding: 12px 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--on); }
.seg { display: flex; background: var(--chip); border-radius: 20px; padding: 3px; margin-top: 12px; }
.seg button { border: 0; background: none; padding: 8px 16px; border-radius: 18px; }
.seg button.on { background: var(--surface); font-weight: 500; box-shadow: 0 1px 2px #0002; }
.nisserow { display: flex; align-items: center; gap: 10px; }
.nisserow input { flex: 1; }
.chips.wrap { flex-wrap: wrap; justify-content: center; }
#suggest .chip { padding: 5px 12px !important; }
.center { overflow-y: auto; }
