/* chat.nitaimaarek.com — self-contained. No web fonts, no third-party CSS:
   the page must paint instantly even when the network is hostile. */

:root {
  --bg: #0c0d10;
  --bg-2: #131519;
  --bg-3: #1a1d23;
  --panel: #15171c;
  --bd: #262a33;
  --bd-2: #333846;
  --fg: #e8eaef;
  --fg-2: #a2a9b8;
  --fg-3: #6b7386;
  --accent: #6ea8fe;
  --accent-2: #3d7ff0;
  --good: #4ec98a;
  --bad: #f0605f;
  --warn: #e5b05a;
  --r: 10px;
  --r-lg: 16px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --side-w: 280px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.015em; }
p { margin: 0; }
button, input, textarea { font: inherit; color: inherit; }
.muted { color: var(--fg-2); }
.err { color: var(--bad); font-size: 14px; }
[hidden] { display: none !important; }

/* ───────────────────────────── top bar ───────────────────────────── */

.bar {
  flex: none;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  border-bottom: 1px solid var(--bd);
  background: var(--bg-2);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--fg);
  text-decoration: none;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.brand svg { width: 20px; height: 20px; fill: var(--accent); }
.bar-left { display: flex; align-items: center; gap: 6px; }
.side-toggle { width: 34px; height: 34px; }
.side-scrim { display: none; }

.chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-3);
  border: 1px solid var(--bd);
  border-radius: 999px;
  padding: 4px 12px 4px 4px;
  cursor: pointer;
  max-width: 220px;
}
.chip:hover { border-color: var(--bd-2); }
.chip span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip img, .chip .av-fallback { width: 26px; height: 26px; }

/* avatars */
img.av, .chip img, .av-fallback {
  border-radius: 50%;
  object-fit: cover;
  flex: none;
  background: var(--bg-3);
}
.av-fallback {
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  color: #0c0d10;
  background: var(--accent);
  text-transform: uppercase;
  border-radius: 50%;
  flex: none;
}

/* ───────────────────────────── buttons ───────────────────────────── */

.btn {
  background: var(--bg-3);
  border: 1px solid var(--bd-2);
  color: var(--fg);
  border-radius: var(--r);
  padding: 9px 16px;
  cursor: pointer;
  font-weight: 550;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: #22262f; }
.btn.primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.btn.primary:hover { background: #4c8bf5; }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--bg-3); }
.btn.danger { color: var(--bad); border-color: #4a2b30; }
.btn.danger:hover { background: #2a1618; }
.btn.big { padding: 12px 22px; font-size: 16px; }
.btn.sm { padding: 6px 12px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.icon-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r);
  cursor: pointer;
  color: var(--fg-2);
  font-size: 12px; font-weight: 700;
  flex: none;
}
.icon-btn:hover { background: var(--bg-3); color: var(--fg); }
.icon-btn svg { width: 19px; height: 19px; fill: currentColor; }
.icon-btn[aria-pressed="true"] { background: var(--accent-2); color: #fff; border-color: var(--accent-2); }
.icon-btn.danger { color: var(--bad); }
.icon-btn.danger:hover { background: #2a1618; }
.icon-btn.send { color: var(--accent); }

.x {
  background: none; border: none; color: var(--fg-3);
  font-size: 20px; line-height: 1; cursor: pointer; padding: 2px 6px;
}
.x:hover { color: var(--fg); }

/* ───────────────────────────── views ───────────────────────────── */

.view { flex: 1; min-height: 0; overflow: hidden; }
#view-home { overflow-y: auto; display: block; }

.hero {
  max-width: 720px;
  margin: 0 auto;
  padding: 72px 20px 40px;
  text-align: center;
}
.hero h1 { font-size: clamp(32px, 6vw, 48px); line-height: 1.1; }
.lede { color: var(--fg-2); margin-top: 14px; font-size: 16px; }

.hero-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 30px;
}
.joinbox { display: flex; gap: 8px; }
.joinbox input {
  background: var(--bg-2);
  border: 1px solid var(--bd-2);
  border-radius: var(--r);
  padding: 12px 16px;
  width: 150px;
  font-family: var(--mono);
  font-size: 17px;
  letter-spacing: .16em;
  text-align: center;
}
.joinbox input:focus { outline: 2px solid var(--accent-2); outline-offset: -1px; }
#home-err { margin-top: 16px; }

.lobby { max-width: 860px; margin: 0 auto; padding: 20px 20px 60px; }
.lobby h2 { font-size: 15px; color: var(--fg-2); margin-bottom: 12px; font-weight: 600; }
.lobby-list { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }

.room-card {
  background: var(--panel);
  border: 1px solid var(--bd);
  border-radius: var(--r);
  padding: 14px;
  cursor: pointer;
  text-align: left;
}
.room-card:hover { border-color: var(--bd-2); background: var(--bg-3); }
.room-card b { display: block; margin-bottom: 3px; }
.room-card .meta { color: var(--fg-3); font-size: 13px; display: flex; gap: 10px; margin-top: 6px; }
.empty { padding: 20px 0; font-size: 14px; }

/* ───────────────────────────── room layout ───────────────────────── */

#view-room { display: flex; }

.side {
  width: var(--side-w);
  flex: none;
  background: var(--bg-2);
  border-right: 1px solid var(--bd);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.side-head { padding: 16px 14px 12px; border-bottom: 1px solid var(--bd); }
.side-head h2 { font-size: 17px; overflow-wrap: anywhere; }
.side-head .muted { font-size: 13px; margin-top: 3px; overflow-wrap: anywhere; }
.codes { display: flex; gap: 8px; align-items: center; margin-top: 12px; flex-wrap: wrap; }

.code {
  font-family: var(--mono);
  font-size: 16px;
  letter-spacing: .16em;
  background: var(--bg-3);
  border: 1px dashed var(--bd-2);
  border-radius: var(--r);
  padding: 7px 12px;
  cursor: pointer;
  color: var(--fg);
}
.code:hover { border-color: var(--accent); color: var(--accent); }

.call-controls { padding: 12px 14px; border-bottom: 1px solid var(--bd); }
.call-join { width: 100%; }
.call-row { display: flex; gap: 4px; margin-top: 8px; justify-content: space-between; }

.members { padding: 12px 14px; flex: 1; }
.members h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--fg-3); }
.count { color: var(--fg-3); }
.members ul { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 2px; }

.member {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px;
  border-radius: 8px;
  font-size: 14px;
}
.member:hover { background: var(--bg-3); }
.member img.av, .member .av-fallback { width: 28px; height: 28px; }
.member .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member .tag { font-size: 10px; color: var(--fg-3); border: 1px solid var(--bd-2); border-radius: 4px; padding: 1px 5px; }
.member .st { display: flex; gap: 3px; color: var(--fg-3); }
.member .st svg { width: 14px; height: 14px; fill: currentColor; }
.member .st .on { color: var(--good); }
.member .kick { opacity: 0; font-size: 11px; }
.member:hover .kick { opacity: 1; }

.side-foot { padding: 10px 14px; border-top: 1px solid var(--bd); display: flex; gap: 8px; }
.side-foot .btn { flex: 1; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }

/* ───────────────────────────── call stage ────────────────────────── */

.stage {
  flex: none;
  max-height: 46vh;
  overflow: auto;
  padding: 12px;
  background: #08090b;
  border-bottom: 1px solid var(--bd);
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  align-content: start;
}
.tile {
  position: relative;
  aspect-ratio: 16 / 10;
  background: var(--bg-3);
  border-radius: var(--r);
  overflow: hidden;
  display: grid;
  place-items: center;
}
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; background: #000; }
.tile.speaking { outline: 2px solid var(--good); outline-offset: -2px; }
.tile .who {
  position: absolute; left: 8px; bottom: 8px;
  background: rgba(0,0,0,.65);
  padding: 3px 9px; border-radius: 6px;
  font-size: 12px; display: flex; align-items: center; gap: 6px;
  max-width: calc(100% - 16px);
}
.tile .who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .who svg { width: 13px; height: 13px; fill: currentColor; flex: none; }
.tile .big-av { width: 68px; height: 68px; font-size: 26px; }

/* ───────────────────────────── messages ─────────────────────────── */

.msgs {
  flex: 1;
  overflow-y: auto;
  padding: 18px 20px 8px;
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
}
/* Pushes a short transcript down to sit above the composer. */
.msgs > *:first-child { margin-top: auto; }
.msgs:focus { outline: none; }

.msg { display: flex; gap: 11px; padding: 3px 0; position: relative; }
.msg.grouped { margin-top: -2px; }
.msg img.av, .msg .av-fallback { width: 36px; height: 36px; margin-top: 2px; }
.msg .spacer { width: 36px; flex: none; }
.msg-body { min-width: 0; flex: 1; }
.msg-head { display: flex; align-items: baseline; gap: 8px; }
.msg-head b { font-size: 14.5px; }
.msg-head time { font-size: 11px; color: var(--fg-3); }
.msg .text { overflow-wrap: anywhere; white-space: pre-wrap; }
.msg a { color: var(--accent); }

.msg.system { justify-content: center; padding: 8px 0; }
.msg.system .text { color: var(--fg-3); font-size: 13px; font-style: italic; }

.quote {
  border-left: 2px solid var(--bd-2);
  padding: 1px 0 1px 9px;
  margin-bottom: 3px;
  font-size: 13px;
  color: var(--fg-2);
  display: flex;
  gap: 6px;
  cursor: pointer;
}
.quote b { color: var(--fg-2); }
.quote span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quote:hover { color: var(--fg); }

.msg.flash { animation: flash 1.2s ease-out; }
@keyframes flash { from { background: rgba(110,168,254,.16); } to { background: transparent; } }

/* attachments */
.att { margin-top: 5px; max-width: 460px; }
.att img, .att video {
  max-width: 100%;
  max-height: 340px;
  border-radius: var(--r);
  display: block;
  background: var(--bg-3);
  cursor: zoom-in;
}
.att video { cursor: default; }
.att audio { width: 100%; max-width: 380px; margin-top: 4px; }

.filecard {
  display: flex; align-items: center; gap: 11px;
  background: var(--panel);
  border: 1px solid var(--bd);
  border-radius: var(--r);
  padding: 11px 13px;
  text-decoration: none;
  color: var(--fg);
  max-width: 340px;
}
.filecard:hover { border-color: var(--bd-2); }
.filecard svg { width: 22px; height: 22px; fill: var(--fg-3); flex: none; }
.filecard .fn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.filecard .fs { font-size: 12px; color: var(--fg-3); }

.voice { display: flex; align-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--bd); border-radius: 999px; padding: 6px 14px 6px 6px; max-width: 320px; }

/* reactions */
.reacts { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 5px; }
.react {
  background: var(--bg-3);
  border: 1px solid var(--bd);
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 13px;
  cursor: pointer;
  display: flex; gap: 5px; align-items: center;
}
.react:hover { border-color: var(--bd-2); }
.react.mine { background: rgba(61,127,240,.18); border-color: var(--accent-2); }
.react .n { font-size: 11px; color: var(--fg-2); }

/* hover actions */
.actions-pop {
  position: absolute; top: -12px; right: 8px;
  display: none; gap: 2px;
  background: var(--bg-3);
  border: 1px solid var(--bd-2);
  border-radius: 8px;
  padding: 2px;
}
.msg:hover .actions-pop, .msg:focus-within .actions-pop { display: flex; }
.actions-pop button {
  background: none; border: none; cursor: pointer;
  padding: 3px 6px; border-radius: 5px; font-size: 15px; line-height: 1;
  color: var(--fg-2);
}
.actions-pop button:hover { background: var(--bg); color: var(--fg); }

.typing { height: 18px; padding: 0 20px; font-size: 12px; color: var(--fg-3); font-style: italic; }

/* ───────────────────────────── composer ─────────────────────────── */

.composer { padding: 0 16px 14px; }
.compose-row {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  background: var(--bg-2);
  border: 1px solid var(--bd-2);
  border-radius: var(--r-lg);
  padding: 5px;
}
.compose-row:focus-within { border-color: var(--accent-2); }
#input {
  flex: 1;
  background: none;
  border: none;
  resize: none;
  padding: 9px 4px;
  max-height: 180px;
  outline: none;
  line-height: 1.5;
}
#input::placeholder { color: var(--fg-3); }

.reply-strip {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-3);
  border: 1px solid var(--bd);
  border-bottom: none;
  border-radius: var(--r) var(--r) 0 0;
  padding: 6px 10px;
  font-size: 13px;
  color: var(--fg-2);
}
.reply-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--fg-3); }

.rec-bar {
  display: flex; align-items: center; gap: 10px;
  margin-top: 8px; padding: 8px 12px;
  background: var(--bg-2); border: 1px solid var(--bd-2); border-radius: var(--r);
  font-family: var(--mono); font-size: 14px;
}
.rec-bar .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--bad); animation: pulse 1.1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.rec-bar .btn { margin-left: auto; }
.rec-bar .btn + .btn { margin-left: 0; }

.drop-hint {
  position: absolute; inset: 0;
  background: rgba(12,13,16,.9);
  border: 2px dashed var(--accent);
  border-radius: var(--r-lg);
  display: grid; place-items: center;
  font-size: 19px; font-weight: 600;
  pointer-events: none;
  z-index: 5;
}

/* ───────────────────────────── modal ────────────────────────────── */

.modal-wrap {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.65);
  display: grid; place-items: center;
  padding: 20px;
  z-index: 50;
}
.modal {
  background: var(--panel);
  border: 1px solid var(--bd-2);
  border-radius: var(--r-lg);
  padding: 22px;
  width: min(460px, 100%);
  max-height: 88vh;
  overflow-y: auto;
  position: relative;
}
.modal.wide { width: min(680px, 100%); }
.modal .close { position: absolute; top: 12px; right: 12px; }
.modal h2 { font-size: 19px; margin-bottom: 4px; }
.modal .sub { color: var(--fg-2); font-size: 14px; margin-bottom: 18px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--fg-2); margin-bottom: 5px; }
.field input[type=text], .field input[type=password], .field input[type=number], .field textarea, .field select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--bd-2);
  border-radius: var(--r);
  padding: 10px 12px;
  outline: none;
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--accent-2); }
.field .hint { font-size: 12px; color: var(--fg-3); margin-top: 5px; }

.toggle { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; padding: 9px 0; }
.toggle input { margin-top: 3px; width: 17px; height: 17px; accent-color: var(--accent-2); flex: none; }
.toggle .t-main { font-size: 14px; }
.toggle .t-sub { font-size: 12.5px; color: var(--fg-3); }

.modal-actions { display: flex; gap: 9px; justify-content: flex-end; margin-top: 20px; }

.av-edit { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.av-edit img.av, .av-edit .av-fallback { width: 62px; height: 62px; font-size: 22px; }

.copyrow { display: flex; gap: 8px; }
.copyrow input {
  flex: 1; font-family: var(--mono); font-size: 12.5px;
  background: var(--bg); border: 1px solid var(--bd-2); border-radius: var(--r); padding: 10px;
}

/* GIF picker */
.gif-search { width: 100%; margin-bottom: 12px; }
.gif-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; max-height: 52vh; overflow-y: auto; }
.gif-grid img { width: 100%; border-radius: 8px; cursor: pointer; display: block; background: var(--bg-3); aspect-ratio: 4/3; object-fit: cover; }
.gif-grid img:hover { outline: 2px solid var(--accent); }

/* lightbox */
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.92);
  display: grid; place-items: center; z-index: 90; padding: 24px;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--bg-3); border: 1px solid var(--bd-2);
  padding: 10px 18px; border-radius: 999px; font-size: 14px;
  z-index: 100; box-shadow: 0 6px 24px rgba(0,0,0,.5);
}

/* ───────────────────────────── mobile ───────────────────────────── */

@media (max-width: 760px) {
  :root { --side-w: min(320px, 86vw); }
  #view-room { position: relative; }
  .side {
    position: absolute; top: 0; bottom: 0; left: 0; z-index: 21;
    transform: translateX(-100%); transition: transform .2s ease;
    border-right: 1px solid var(--bd);
    box-shadow: 0 0 40px rgba(0,0,0,.6);
  }
  #view-room.show-side .side { transform: none; }
  /* Tap-anywhere-else to dismiss the drawer. */
  #view-room.show-side .side-scrim {
    display: block; position: absolute; inset: 0; z-index: 20;
    background: rgba(0,0,0,.5);
  }
  .hero { padding-top: 46px; }
  .msgs { padding: 14px 12px 6px; }
  .composer { padding: 0 10px 10px; }
  .att { max-width: 100%; }
  .gif-grid { grid-template-columns: repeat(2, 1fr); }
}
