:root {
  --bg: #0b1220;
  --panel: #111a2c;
  --panel-2: #18233a;
  --line: #24314d;
  --text: #edf2fb;
  --muted: #93a1bb;
  --accent: #12b886;
  --accent-ink: #04221a;
  --mine: #0e5c4a;
  --theirs: #1c2841;
  --danger: #f0556b;
  --radius: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body, #root { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
[hidden] { display: none !important; }

/* Buttons and fields */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 16px; min-height: 44px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  color: var(--text); text-decoration: none; font-weight: 600;
}
.btn:hover { border-color: #3a4c74; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn {
  width: 42px; height: 42px; flex: none; display: grid; place-items: center;
  background: transparent; border: 0; border-radius: 50%; color: var(--text);
}
.icon-btn:hover { background: var(--panel-2); }
.icon-btn svg { width: 22px; height: 22px; }
.field { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.input {
  width: 100%; min-height: 44px; padding: 10px 12px; font-size: 16px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; color: var(--text);
}
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.error { color: var(--danger); font-size: 14px; min-height: 20px; }

/* Sign in */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 380px; display: grid; gap: 14px; }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.brand img { width: 48px; height: 48px; }
.brand h1 { font-size: 24px; letter-spacing: .3px; }
.link { background: none; border: 0; padding: 8px 0; color: var(--accent); font-weight: 600; }

/* Layout */
.shell { height: 100%; display: grid; grid-template-columns: 360px 1fr; }
.sidebar { display: flex; flex-direction: column; min-height: 0; background: var(--panel); border-right: 1px solid var(--line); }
.pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--bg); }
.topbar {
  display: flex; align-items: center; gap: 8px; min-height: 60px; padding: 8px 10px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.topbar .title { flex: 1; min-width: 0; }
.topbar .title b, .topbar .title span { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.topbar .title span { font-size: 12.5px; color: var(--muted); }
.tappable { background: none; border: 0; padding: 0; text-align: left; }
.search { padding: 10px; border-bottom: 1px solid var(--line); }
.list { flex: 1; overflow-y: auto; min-height: 0; }
.empty { display: grid; place-items: center; flex: 1; padding: 24px; text-align: center; color: var(--muted); }
.conv {
  display: flex; gap: 12px; align-items: center; width: 100%; padding: 11px 12px;
  background: transparent; border: 0; border-bottom: 1px solid rgba(36, 49, 77, .55); text-align: left;
}
.conv:hover { background: var(--panel-2); }
.conv.active { background: var(--panel-2); }
.conv-main { flex: 1; min-width: 0; }
.conv-row { display: flex; align-items: baseline; gap: 8px; }
.conv-name { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.conv-time { font-size: 12px; color: var(--muted); flex: none; }
.conv-preview { flex: 1; min-width: 0; color: var(--muted); font-size: 14px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.badge { flex: none; min-width: 20px; padding: 1px 6px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 700; text-align: center; }
.tag { padding: 1px 7px; border-radius: 8px; background: rgba(18, 184, 134, .16); color: var(--accent); font-size: 11px; font-weight: 700; }
.avatar {
  position: relative; flex: none; width: 46px; height: 46px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; color: #fff;
}
.avatar.sm { width: 38px; height: 38px; font-size: 14px; }
.avatar.online::after {
  content: ""; position: absolute; right: 0; bottom: 0; width: 12px; height: 12px;
  background: var(--accent); border: 2px solid var(--panel); border-radius: 50%;
}

/* Chat */
.messages { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 12px; display: flex; flex-direction: column; gap: 4px; }
.day { align-self: center; margin: 10px 0; padding: 3px 12px; border-radius: 10px; background: var(--panel-2); color: var(--muted); font-size: 12px; }
.system { align-self: center; max-width: 90%; margin: 6px 0; padding: 4px 12px; border-radius: 10px; background: var(--panel); color: var(--muted); font-size: 13px; text-align: center; }
.bubble { max-width: min(78%, 560px); padding: 7px 10px; border-radius: 12px; background: var(--theirs); overflow-wrap: anywhere; }
.bubble.mine { align-self: flex-end; background: var(--mine); }
.bubble .who { font-size: 12.5px; font-weight: 700; color: var(--accent); }
.bubble .text { white-space: pre-wrap; }
.bubble .meta { display: flex; justify-content: flex-end; gap: 4px; margin-top: 2px; font-size: 11px; color: rgba(237, 242, 251, .65); }
.bubble .ticks.read { color: #54d7ff; }
.bubble img { display: block; max-width: 100%; max-height: 320px; min-width: 120px; min-height: 80px; border-radius: 8px; background: var(--panel); }
.file-link { display: flex; align-items: center; gap: 10px; padding: 6px 2px; background: none; border: 0; text-align: left; }
.file-link svg { width: 26px; height: 26px; flex: none; }
.call-line { display: flex; align-items: center; gap: 8px; }
.call-line svg { width: 18px; height: 18px; }
.typing { min-height: 20px; padding: 0 14px; font-size: 12.5px; color: var(--accent); }
.composer {
  display: flex; align-items: flex-end; gap: 6px; padding: 8px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: var(--panel); border-top: 1px solid var(--line);
}
.composer textarea {
  flex: 1; min-width: 0; min-height: 42px; max-height: 130px; padding: 9px 13px; resize: none; font-size: 16px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 21px;
}
.composer textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.send { background: var(--accent); color: var(--accent-ink); }
.send:hover { background: var(--accent); }
.offline { padding: 5px 12px; background: #5c3b12; color: #ffdca8; font-size: 13px; text-align: center; }

/* Dialogs */
.modal-back { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px; background: rgba(3, 7, 15, .72); }
.modal { width: 100%; max-width: 440px; max-height: 88vh; overflow-y: auto; display: grid; gap: 14px; padding: 18px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.modal h2 { font-size: 18px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > .input { flex: 1; min-width: 0; }
.row.end { justify-content: flex-end; flex-wrap: wrap; }
.person { display: flex; gap: 10px; align-items: center; padding: 6px 0; }
.person .grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.code { padding: 8px 12px; border-radius: 8px; background: var(--bg); font: 16px ui-monospace, Consolas, monospace; letter-spacing: 1px; user-select: all; }
.toast { position: fixed; left: 50%; bottom: 84px; z-index: 40; max-width: calc(100% - 32px); padding: 10px 16px; transform: translateX(-50%); background: #26344f; border-radius: 10px; }
.viewer { position: fixed; inset: 0; z-index: 25; display: grid; place-items: center; background: #000; }
.viewer img { max-width: 100%; max-height: 100%; }
.viewer .icon-btn { position: absolute; top: max(10px, env(safe-area-inset-top)); right: 10px; background: rgba(0, 0, 0, .5); }

/* Admin */
.admin { flex: 1; min-height: 0; overflow-y: auto; padding: 16px; display: grid; gap: 18px; align-content: start; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.stat { padding: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.stat b { display: block; font-size: 26px; font-variant-numeric: tabular-nums; }
.section { display: grid; gap: 10px; }
.section h3 { font-size: 16px; }
.admin-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 11px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.admin-row .grow { flex: 1; min-width: 170px; overflow-wrap: anywhere; }
.admin-row .btn { min-height: 38px; padding: 7px 11px; font-size: 13px; }

/* Calls */
.call { position: fixed; inset: 0; z-index: 30; display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 48px 16px 40px; background: #060b14; }
.call video.remote { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
.call video.local { position: absolute; top: 16px; right: 16px; width: 110px; height: 150px; object-fit: cover; border-radius: 12px; border: 1px solid var(--line); background: #111; transform: scaleX(-1); z-index: 2; }
.call-info { position: relative; z-index: 2; text-align: center; display: grid; gap: 8px; justify-items: center; text-shadow: 0 1px 6px #000; }
.call-info h2 { font-size: 24px; }
.call-info .avatar { width: 96px; height: 96px; font-size: 34px; }
.call-actions { position: relative; z-index: 2; display: flex; gap: 22px; }
.round { width: 62px; height: 62px; display: grid; place-items: center; border: 0; border-radius: 50%; background: var(--panel-2); color: #fff; }
.round svg { width: 26px; height: 26px; }
.round.on { background: #e9eefb; color: #111a2c; }
.round.accept { background: var(--accent); color: var(--accent-ink); }
.round.end { background: var(--danger); }

/* Download page */
.download-page { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.download-card { width: 100%; max-width: 380px; display: grid; gap: 12px; text-align: center; justify-items: center; }
.download-card .btn { width: 100%; }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .shell.in-pane .sidebar { display: none; }
  .shell:not(.in-pane) .pane { display: none; }
}
@media (min-width: 761px) {
  .back-btn { display: none; }
}
