/* Colours follow WhatsApp's palette: teal-green bar, green accents, beige chat
   background, light-green sent bubbles; dark mode uses its night colours. */
:root {
  --bg: #f0f2f5;
  --chat-bg: #efeae2;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --topbar: #008069;
  --topbar-ink: #ffffff;
  --ink: #111b21;
  --muted: #667781;
  --line: #e9edef;
  --accent: #00a884;
  --accent-strong: #008069;
  --accent-ink: #ffffff;
  --accent-soft: #d9fdd3;
  --bubble-in: #ffffff;
  --bubble-out: #d9fdd3;
  --bubble-out-ink: #111b21;
  --bubble-shadow: 0 1px .5px rgb(11 20 26 / 13%);
  --sys-bg: #ffffff;
  --badge: #25d366;
  --badge-ink: #ffffff;
  --danger: #ea0038;
  --warn-bg: #ffeecd;
  --warn-ink: #54656f;
  --alert-bg: #fde3e7;
  --alert-ink: #8c0021;
  --ok: #008069;
  --online: #25d366;
  --radius: 8px;
  --shadow: 0 1px 3px rgb(11 20 26 / 12%), 0 6px 20px rgb(11 20 26 / 8%);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111b21;
    --chat-bg: #0b141a;
    --panel: #111b21;
    --panel-2: #202c33;
    --topbar: #202c33;
    --topbar-ink: #e9edef;
    --ink: #e9edef;
    --muted: #8696a0;
    --line: #222d34;
    --accent: #00a884;
    --accent-strong: #06cf9c;
    --accent-ink: #111b21;
    --accent-soft: #103529;
    --bubble-in: #202c33;
    --bubble-out: #005c4b;
    --bubble-out-ink: #e9edef;
    --bubble-shadow: 0 1px .5px rgb(0 0 0 / 30%);
    --sys-bg: #182229;
    --badge: #00a884;
    --badge-ink: #111b21;
    --danger: #f15c6d;
    --warn-bg: #182229;
    --warn-ink: #ffd279;
    --alert-bg: #3b1d24;
    --alert-ink: #ffb3bd;
    --ok: #06cf9c;
    --online: #25d366;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.45; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.8rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: .95rem; margin-top: 1rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; margin: .5rem 0 0; }
.fineprint { font-size: .8rem; margin-top: 1rem; }

button, input, select, textarea { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line); background: var(--panel); border-radius: 10px;
  padding: .45rem .8rem; cursor: pointer;
}
button:hover { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
button.ghost { background: transparent; }
button.danger { color: var(--danger); }
button.danger:not(.ghost) { background: var(--danger); color: #fff; border-color: var(--danger); }
button.icon { padding: .3rem .55rem; font-size: 1.05rem; line-height: 1; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input, textarea, select {
  width: 100%; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: .55rem .7rem;
}
textarea { resize: none; }
label { display: block; font-weight: 600; margin-top: .9rem; }
small { display: block; margin-top: .25rem; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; margin-top: 1rem; }

/* ---------------------------------------------------------- screens */
.screen { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.card {
  width: min(440px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 28px; box-shadow: var(--shadow);
}
.card form button.primary { width: 100%; margin-top: 1.2rem; padding: .7rem; }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; }
.brand.big { gap: .75rem; margin-bottom: .5rem; }
.brand.big h1 { margin: 0; }
.lead { font-size: 1.05rem; }
.points { padding-left: 1.1rem; color: var(--muted); margin: 0 0 1rem; }
.points li { margin: .2rem 0; }
.overlay { position: fixed; inset: 0; background: rgb(0 0 0 / 45%); z-index: 20; }

/* ---------------------------------------------------------- app shell */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 1rem; padding: .6rem 16px;
  background: var(--topbar); color: var(--topbar-ink);
}
.topbar .me { display: flex; align-items: center; gap: .4rem; opacity: .9; margin-right: auto; }
.topbar button { border-color: transparent; color: var(--topbar-ink); background: transparent; }
.topbar button:hover { border-color: currentColor; }
.switch { display: flex; align-items: center; gap: .4rem; margin: 0; font-weight: 500; font-size: .9rem; cursor: pointer; }
.switch input { width: auto; accent-color: var(--badge); }

.layout { flex: 1; display: grid; grid-template-columns: 300px 1fr; min-height: 0; }
.sidebar { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); border-bottom: 1px solid var(--line); }
.tabs button { border: 0; border-radius: 0; padding: .75rem .1rem; background: transparent; border-bottom: 2px solid transparent; font-size: .9rem; }
.tabs button[aria-selected="true"] { border-bottom-color: var(--accent); color: var(--accent-strong); font-weight: 600; }
.badge {
  display: inline-block; min-width: 1.3em; padding: 0 .35em; border-radius: 999px; background: var(--badge);
  color: var(--badge-ink); font-weight: 600; font-size: .75rem; line-height: 1.3em; text-align: center;
}
.count { color: var(--online); font-size: .8rem; font-weight: 600; }

.list { list-style: none; margin: 0; padding: .4rem; overflow-y: auto; flex: 1; }
.list li { display: flex; align-items: center; gap: .6rem; padding: .55rem .6rem; border-radius: 10px; }
.list li.clickable { cursor: pointer; }
.list li.clickable:hover, .list li.current { background: var(--panel-2); }
.list .name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.list .sub { display: block; font-weight: 400; font-size: .8rem; color: var(--muted); }
.list .section { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: .8rem .6rem .3rem; }
.list button { padding: .3rem .6rem; font-size: .85rem; }
.empty { padding: 1rem; }
.list li.actions-row { gap: .4rem; padding: .3rem .2rem .6rem; }
.list li.actions-row button { flex: 1; padding: .45rem .5rem; }
.list li.note-row { color: var(--muted); font-size: .88rem; }
.room-mark {
  width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 700; font-size: .8rem; flex: none;
}
.note { background: var(--accent-soft); border-radius: 10px; padding: .6rem .8rem; margin: 0 0 .5rem; }
.small { font-size: .8rem; }
.copy-row { display: flex; gap: .4rem; align-items: center; }
.copy-row input { flex: 1; min-width: 0; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .8rem; }
.empty.center { height: 100%; display: grid; place-items: center; text-align: center; max-width: 360px; margin: auto; }

.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); opacity: .45; flex: none; }
.dot.on { background: var(--online); opacity: 1; }
.dot.wait { opacity: 1; }
.dot.wait { background: #d9a21b; }

/* ---------------------------------------------------------- chat */
.chat { min-height: 0; display: flex; flex-direction: column; background: var(--chat-bg); }
.chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-head {
  display: flex; align-items: center; gap: .6rem; padding: .55rem 16px; border-bottom: 1px solid var(--line);
  background: var(--panel-2); flex-wrap: wrap;
}
.chat-head .peer { display: flex; align-items: center; gap: .45rem; margin-right: auto; min-width: 0; }
.chat-head .actions { display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; }
.chat-head .back { display: none; }
.timer { display: flex; align-items: center; gap: .25rem; margin: 0; font-weight: 400; }
.timer select { width: auto; padding: .3rem .4rem; }
.pill { font-size: .75rem; padding: .1rem .5rem; border-radius: 999px; }
.pill.ok { background: var(--accent-soft); color: var(--ok); }

.banner { padding: .75rem 16px; border-bottom: 1px solid var(--line); background: var(--warn-bg); color: var(--warn-ink); }
.banner.alert { background: var(--alert-bg); color: var(--alert-ink); }
.banner.info { background: var(--accent-soft); color: var(--ink); }
.banner button { padding: .3rem .7rem; font-size: .88rem; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 30; max-width: calc(100% - 32px);
  background: var(--ink); color: var(--bg); padding: .6rem 1rem; border-radius: 10px; box-shadow: var(--shadow);
}
.banner p { margin: 0 0 .5rem; }
.banner p:last-child { margin: 0; }

.messages { list-style: none; margin: 0; padding: 16px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: .35rem; }
.messages li { max-width: min(75%, 560px); display: flex; flex-direction: column; }
.messages .bubble { padding: .4rem .65rem; border-radius: var(--radius); white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: var(--bubble-shadow); }
.messages .in { align-self: flex-start; }
.messages .in .bubble { background: var(--bubble-in); color: var(--ink); border-top-left-radius: 0; }
.messages .out { align-self: flex-end; align-items: flex-end; }
.messages .out .bubble { background: var(--bubble-out); color: var(--bubble-out-ink); border-top-right-radius: 0; }
.messages .sys {
  align-self: center; max-width: 90%; font-size: .78rem; color: var(--muted); text-align: center;
  background: var(--sys-bg); padding: .3rem .7rem; border-radius: 7px; box-shadow: var(--bubble-shadow); margin: .2rem 0;
}
.messages .from { font-size: .75rem; font-weight: 600; color: var(--accent-strong); margin: .2rem 0 .1rem .3rem; }
.messages .meta { font-size: .72rem; color: var(--muted); margin-top: .15rem; padding: 0 .2rem; }
.messages .failed .meta { color: var(--danger); }
.messages .meta button { padding: 0 .4rem; font-size: .72rem; margin-left: .3rem; }

.composer { display: flex; gap: .5rem; padding: .6rem 16px; background: var(--panel-2); }
.composer textarea { max-height: 9rem; overflow-y: hidden; border: 0; border-radius: 8px; }
.composer button.primary { border-radius: 999px; padding: .45rem 1.1rem; }

/* ---------------------------------------------------------- media, replies, menus */
.messages li { position: relative; }
.messages .bubble { position: relative; }
.bubble .menu-btn {
  position: absolute; top: 2px; right: 2px; padding: 0 .35rem; font-size: .8rem; line-height: 1.4; border: 0;
  background: var(--bubble-in); color: var(--muted); border-radius: 6px; opacity: 0;
}
.out .bubble .menu-btn { background: var(--bubble-out); }
.messages li:hover .menu-btn, .menu-btn:focus-visible { opacity: 1; }
@media (hover: none) { .bubble .menu-btn { opacity: .8; } }
.bubble.has-media { padding: 4px; }
.bubble .media-box { position: relative; border-radius: 6px; overflow: hidden; cursor: pointer; background: #00000022; }
.bubble .media-box img, .bubble .media-box video { display: block; max-width: min(320px, 60vw); max-height: 360px; width: 100%; object-fit: cover; }
.bubble .media-box .blur { filter: blur(6px); transform: scale(1.05); }
.media-badge {
  position: absolute; inset: auto auto 8px 8px; background: rgb(11 20 26 / 65%); color: #fff;
  padding: .15rem .5rem; border-radius: 999px; font-size: .75rem;
}
.media-play { position: absolute; inset: 0; display: grid; place-items: center; font-size: 2.2rem; color: #fff; text-shadow: 0 1px 6px #000; }
.bubble .caption { padding: .3rem .4rem .1rem; }
.once-pill { display: flex; align-items: center; gap: .5rem; cursor: pointer; padding: .25rem .2rem; }
.once-pill .once-icon {
  width: 28px; height: 28px; border-radius: 50%; border: 2px dashed var(--accent); color: var(--accent);
  display: grid; place-items: center; font-weight: 700; font-size: .8rem; flex: none;
}
.once-pill.used .once-icon { border-style: solid; border-color: var(--muted); color: var(--muted); }
.bubble .deleted { font-style: italic; color: var(--muted); }
.quote {
  display: flex; flex-direction: column; border-left: 4px solid var(--accent); background: rgb(0 0 0 / 5%);
  border-radius: 6px; padding: .25rem .5rem; margin-bottom: .25rem; font-size: .82rem; cursor: pointer; min-width: 0;
}
.quote strong { color: var(--accent-strong); font-size: .78rem; }
.quote span { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.messages li.flash .bubble { outline: 2px solid var(--accent); }
.compose-bar { display: flex; align-items: center; gap: .5rem; padding: .4rem 16px 0; background: var(--panel-2); }
.compose-bar .quote { flex: 1; margin: 0; cursor: default; background: var(--panel); }
.composer .attach { font-size: 1.15rem; }
.msg-menu {
  position: fixed; z-index: 40; min-width: 190px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; box-shadow: var(--shadow); padding: .3rem 0;
}
.msg-menu button { display: block; width: 100%; text-align: left; border: 0; border-radius: 0; background: transparent; padding: .5rem 1rem; }
.msg-menu button:hover { background: var(--panel-2); }
.msg-menu button.danger { color: var(--danger); }
.media-preview { display: grid; place-items: center; background: var(--panel-2); border-radius: 8px; min-height: 120px; margin-bottom: .6rem; overflow: hidden; }
.media-preview img, .media-preview video { max-width: 100%; max-height: 50vh; display: block; }
.once-toggle { display: flex; gap: .6rem; align-items: flex-start; font-weight: 400; cursor: pointer; }
.once-toggle input { width: auto; margin-top: .3rem; accent-color: var(--accent); }
dialog.viewer {
  width: 100vw; height: 100vh; max-width: 100vw; max-height: 100vh; padding: 0; border: 0; border-radius: 0;
  background: #0b141a; color: #e9edef;
}
dialog.viewer::backdrop { background: #0b141a; }
.viewer-bar { display: flex; align-items: center; gap: .5rem; padding: .6rem 16px; }
.viewer-bar button { color: #e9edef; border-color: #2a3942; }
.viewer-bar .spacer { flex: 1; }
.viewer-body { height: calc(100vh - 110px); display: grid; place-items: center; padding: 0 16px; }
.viewer-body img, .viewer-body video { max-width: 100%; max-height: 100%; display: block; }
.viewer-caption { text-align: center; padding: 0 16px; margin: .4rem 0 0; }

/* ---------------------------------------------------------- dialogs */
dialog {
  border: 1px solid var(--line); border-radius: 12px; padding: 24px; width: min(480px, calc(100% - 32px));
  background: var(--panel); color: var(--ink); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgb(0 0 0 / 45%); }
.digits {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: .4rem .9rem; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 1.15rem; letter-spacing: .05em; background: var(--panel-2); padding: 1rem; border-radius: 12px; text-align: center;
}
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { display: flex; justify-content: space-between; align-items: center; padding: .3rem 0; }
ul.plain .dot { display: inline-block; vertical-align: middle; margin-right: .2rem; }

/* ---------------------------------------------------------- phones */
@media (max-width: 720px) {
  .topbar { gap: .6rem; }
  .switch span { display: none; }
  .switch::after { content: "Online"; font-size: .85rem; }
  .layout { grid-template-columns: 1fr; }
  .layout.chat-open .sidebar { display: none; }
  .layout:not(.chat-open) .chat { display: none; }
  .chat-head .back { display: inline-block; }
  .chat-head { gap: .4rem; padding: .45rem 12px; }
  .chat-head .actions { width: 100%; flex-wrap: nowrap; }
  .chat-head .actions button, .timer select { font-size: .8rem; padding: .25rem .5rem; }
  .timer { flex: 1; min-width: 0; }
  .timer select { width: 100%; }
  .messages li { max-width: 88%; }
  .digits { grid-template-columns: repeat(3, 1fr); font-size: 1rem; }
}
