/* EncChat - permanent dark theme, single configurable accent. */

:root {
  --accent: #00e5a0;
  --accent-dim: color-mix(in srgb, var(--accent) 22%, transparent);
  --accent-soft: color-mix(in srgb, var(--accent) 12%, transparent);

  --bg: #000000;
  --surface: #0a0b0d;
  --surface-2: #121317;
  --surface-3: #1a1c22;
  --line: #23262e;
  --text: #e9ebee;
  --muted: #868c96;
  --danger: #ff4d5e;

  --kb-h: 0px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);

  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans",
        "Vazirmatn", "IRANSans", Tahoma, sans-serif;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

body { touch-action: manipulation; }

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

.hidden { display: none !important; }

/* ------------------------------------------------------------------ screens */

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  padding-top: var(--safe-t);
}

/* Screens that host editable surfaces shrink to make room for the keyboard. */
#chat, #admin { padding-bottom: var(--kb-h); transition: padding-bottom .16s ease; }

/* -------------------------------------------------------------- desktop gate */

#gate {
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px;
  z-index: 100;
}
#gate .glyph { font-size: 54px; margin-bottom: 18px; }
#gate h1 { font-size: 20px; margin: 0 0 10px; letter-spacing: .3px; }
#gate p { color: var(--muted); margin: 0; max-width: 320px; font-size: 14px; }

/* ---------------------------------------------------------------- lock screen */

#lock { align-items: center; justify-content: center; padding: 24px 20px calc(24px + var(--safe-b)); }

.brand { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 26px; }
.brand .mark {
  width: 62px; height: 62px; border-radius: 18px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  display: grid; place-items: center;
  color: var(--accent);
  box-shadow: 0 0 0 6px var(--accent-soft);
}
.brand .mark svg { width: 30px; height: 30px; }
.brand h1 { margin: 0; font-size: 19px; font-weight: 600; letter-spacing: 2px; }
.brand .sub { color: var(--muted); font-size: 12px; letter-spacing: .6px; }

.pin-dots { display: flex; gap: 12px; height: 14px; margin-bottom: 6px; }
.pin-dots i {
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--surface-3); border: 1px solid var(--line);
  transition: transform .12s ease, background .12s ease;
}
.pin-dots i.on { background: var(--accent); border-color: var(--accent); transform: scale(1.12); }

.pin-msg { min-height: 20px; font-size: 13px; color: var(--muted); margin: 10px 0 18px; text-align: center; }
.pin-msg.err { color: var(--danger); }

.keypad { display: grid; grid-template-columns: repeat(3, 76px); gap: 14px; }
.keypad button {
  height: 76px; border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 26px; font-weight: 400;
  display: grid; place-items: center;
  transition: background .09s ease, transform .09s ease;
}
.keypad button:active { background: var(--surface-3); transform: scale(.94); }
.keypad button.fn { font-size: 15px; color: var(--muted); background: transparent; border-color: transparent; }
.keypad button.go { color: var(--accent); border-color: var(--accent-dim); background: var(--accent-soft); }
.keypad button[disabled] { opacity: .35; }

/* -------------------------------------------------------------------- topbar */

.topbar {
  display: flex; align-items: center; gap: 10px;
  height: 54px; padding: 0 12px; flex: 0 0 auto;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.topbar .title { flex: 1; min-width: 0; }
.topbar .title b { display: block; font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .title span { display: block; font-size: 11px; color: var(--muted); }
.iconbtn {
  width: 38px; height: 38px; border-radius: 11px;
  display: grid; place-items: center; color: var(--muted);
  background: transparent;
}
.iconbtn:active { background: var(--surface-2); }
.iconbtn.accent { color: var(--accent); }
.iconbtn svg { width: 20px; height: 20px; }

/* --------------------------------------------------------------- contact list */

.list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

.row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
}
.row:active { background: var(--surface-2); }
.avatar {
  width: 44px; height: 44px; border-radius: 14px; flex: 0 0 auto;
  display: grid; place-items: center; font-weight: 600; font-size: 16px;
  background: var(--surface-2); color: var(--accent); border: 1px solid var(--line);
}
.row .meta { flex: 1; min-width: 0; }
.row .meta b { display: block; font-size: 15px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta span { display: block; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .side { text-align: right; flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }
.row .side .time { font-size: 11px; color: var(--muted); }
.badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--accent); color: #000; font-size: 11px; font-weight: 700;
  display: grid; place-items: center;
}

.empty { padding: 48px 30px; text-align: center; color: var(--muted); font-size: 13px; }
.empty .glyph { font-size: 40px; margin-bottom: 12px; opacity: .5; }

/* ------------------------------------------------------------------- messages */

.thread {
  flex: 1; overflow-y: auto; padding: 14px 12px 8px;
  display: flex; flex-direction: column; gap: 8px;
  -webkit-overflow-scrolling: touch;
}

.bubble {
  max-width: 78%; padding: 8px 11px 6px; border-radius: 16px;
  background: var(--surface-2); border: 1px solid var(--line);
  word-break: break-word; overflow-wrap: anywhere;
  user-select: none;
}
.bubble.me { align-self: flex-end; background: var(--accent-soft); border-color: var(--accent-dim); }
.bubble.them { align-self: flex-start; border-bottom-left-radius: 6px; }
.bubble.me { border-bottom-right-radius: 6px; }
.bubble .txt { white-space: pre-wrap; font-size: 14.5px; }
.bubble .txt a { color: var(--accent); text-decoration: underline; }
.bubble img { display: block; max-width: 100%; border-radius: 10px; margin-bottom: 4px; }
.bubble .foot { display: flex; gap: 5px; align-items: center; justify-content: flex-end; margin-top: 2px; }
.bubble .foot .t { font-size: 10.5px; color: var(--muted); }
.bubble .foot .tick { font-size: 11px; color: var(--muted); }
.bubble .foot .tick.seen { color: var(--accent); }
.bubble.pending { opacity: .55; }
.bubble.failed { border-color: var(--danger); }
.bubble.sel { outline: 2px solid var(--accent); }

.daysep { align-self: center; font-size: 11px; color: var(--muted); padding: 3px 10px; background: var(--surface-2); border-radius: 9px; margin: 6px 0; }

/* ------------------------------------------------------------------- composer */

.composer {
  flex: 0 0 auto; display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 10px; border-top: 1px solid var(--line); background: var(--surface);
}
.composer .iconbtn { flex: 0 0 auto; }

.vk-input {
  flex: 1; min-height: 40px; max-height: 120px; overflow-y: auto;
  padding: 9px 12px; border-radius: 18px;
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: 15px; line-height: 1.4; white-space: pre-wrap;
  word-break: break-word; overflow-wrap: anywhere; cursor: text;
}
.vk-input.focused { border-color: var(--accent-dim); }
.vk-input .ph { color: var(--muted); }
.vk-input.rtl { direction: rtl; text-align: right; }

.vk-caret {
  display: inline-block; width: 1.5px; height: 1.05em; vertical-align: text-bottom;
  background: var(--accent); margin: 0 -0.75px;
}
.vk-input.focused .vk-caret { animation: blink 1.05s step-end infinite; }
@keyframes blink { 50% { opacity: 0; } }

.send {
  width: 40px; height: 40px; border-radius: 50%; flex: 0 0 auto;
  background: var(--accent); color: #000; display: grid; place-items: center;
}
.send:active { transform: scale(.92); }
.send[disabled] { background: var(--surface-3); color: var(--muted); }
.send svg { width: 19px; height: 19px; }

/* ----------------------------------------------------------- virtual keyboard */

#vk {
  /* Above .sheet-wrap (80): the sheet backdrop spans the whole viewport, so a
     lower keyboard would swallow every key tap as an outside-tap and close. */
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 90;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + var(--safe-b));
  transform: translateY(110%);
  transition: transform .16s ease;
  user-select: none;
}
#vk.open { transform: translateY(0); }

.vk-row { display: flex; gap: 5px; margin-bottom: 6px; justify-content: center; }
.vk-row:last-child { margin-bottom: 0; }

.vk-key {
  flex: 1 1 0; min-width: 0; height: 44px; border-radius: 7px;
  background: var(--surface-3); border: 1px solid transparent;
  display: grid; place-items: center; font-size: 17px;
  transition: background .06s ease;
}
.vk-key:active, .vk-key.down { background: var(--accent); color: #000; }
.vk-key.mod { background: var(--surface-2); font-size: 12.5px; color: var(--muted); flex-grow: 1.5; }
.vk-key.mod.on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-dim); }
.vk-key.wide { flex-grow: 4.5; }
.vk-key.act { background: var(--accent-soft); color: var(--accent); }
.vk-key svg { width: 18px; height: 18px; }

/* ---------------------------------------------------------------- sheet/modal */

.sheet-wrap {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(0,0,0,.72);
  display: flex; align-items: flex-end;
  padding-bottom: var(--kb-h);
  transition: padding-bottom .16s ease;
}
.sheet {
  width: 100%; max-height: 88vh; overflow-y: auto;
  background: var(--surface); border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  padding: 8px 16px calc(20px + var(--safe-b));
  animation: rise .18s ease;
}
@keyframes rise { from { transform: translateY(18px); opacity: 0; } }
.sheet .grip { width: 38px; height: 4px; border-radius: 2px; background: var(--line); margin: 6px auto 14px; }
.sheet h2 { font-size: 16px; margin: 0 0 14px; font-weight: 600; }
.sheet h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); margin: 20px 0 8px; font-weight: 600; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.field .vk-input { min-height: 42px; border-radius: 11px; }
.field .hint { font-size: 11px; color: var(--muted); margin-top: 5px; }

.btn {
  width: 100%; height: 46px; border-radius: 12px; font-size: 15px; font-weight: 600;
  background: var(--accent); color: #000; display: grid; place-items: center; margin-top: 6px;
}
.btn:active { opacity: .8; }
.btn.ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn[disabled] { opacity: .5; }

.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatches button {
  width: 38px; height: 38px; border-radius: 50%; border: 2px solid transparent;
}
.swatches button.on { border-color: var(--text); }

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.kv span { color: var(--muted); }
.kv b { font-weight: 500; text-align: right; word-break: break-all; }

.code-out {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 22px; letter-spacing: 4px; color: var(--accent);
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 11px; padding: 13px; text-align: center; user-select: text;
}

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%);
  background: var(--surface-3); border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 11px; font-size: 13px; z-index: 200;
  max-width: 86vw; text-align: center; animation: rise .16s ease;
}
.toast.err { border-color: var(--danger); color: var(--danger); }

.tabs { display: flex; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--surface); flex: 0 0 auto; }
.tabs button { flex: 1; height: 34px; border-radius: 9px; font-size: 13px; color: var(--muted); background: var(--surface-2); }
.tabs button.on { background: var(--accent-soft); color: var(--accent); }

.pane { flex: 1; overflow-y: auto; padding: 12px 14px calc(20px + var(--safe-b)); }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 13px; padding: 12px 14px; margin-bottom: 10px;
}
.card .head { display: flex; align-items: center; gap: 10px; }
.card .head b { flex: 1; font-size: 14.5px; font-weight: 600; }
.card .sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.card .acts { display: flex; gap: 8px; margin-top: 11px; }
.card .acts button {
  flex: 1; height: 34px; border-radius: 9px; font-size: 12.5px;
  background: var(--surface-2); border: 1px solid var(--line);
}
.card .acts button.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: 0 0 auto; }
.dot.on { background: var(--accent); }

.log { font-family: ui-monospace, monospace; font-size: 11px; color: var(--muted); line-height: 1.7; word-break: break-all; }

.viewer {
  position: fixed; inset: 0; z-index: 150; background: #000;
  display: grid; place-items: center;
}
.viewer img { max-width: 100%; max-height: 100%; }
.viewer .close { position: absolute; top: calc(12px + var(--safe-t)); right: 12px; }

.spin {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.center-spin { flex: 1; display: grid; place-items: center; }
