/* SALOM — katta, sodda, aniq. Rang doim bir xil ma'noda:
   yashil = qo'ng'iroq, ko'k = video, oq-chegarali = yozish. */
:root {
  --bg: #f4f4f2;
  --card: #ffffff;
  --text: #111111;
  --muted: #555555;
  --line: #d6d6d2;
  --call: #15803d;
  --call-dark: #116632;
  --video: #1d4ed8;
  --video-dark: #1740b0;
  --danger: #b91c1c;
  --radius: 16px;
  --tap: 60px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
  font-size: 20px;
  line-height: 1.4;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px calc(32px + env(safe-area-inset-bottom));
}

h1 { font-size: 34px; margin: 8px 0 4px; letter-spacing: 1px; }
h2 { font-size: 26px; margin: 0 0 12px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }

/* ---------- Tugmalar ---------- */
button, .btn {
  font: inherit;
  font-weight: 600;
  min-height: var(--tap);
  border-radius: var(--radius);
  border: 2px solid transparent;
  padding: 10px 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  -webkit-tap-highlight-color: transparent;
}
button:focus-visible, input:focus-visible { outline: 4px solid #f59e0b; outline-offset: 2px; }
button:disabled { opacity: .55; cursor: default; }

.btn-primary { background: var(--call); color: #fff; width: 100%; font-size: 22px; }
.btn-primary:active { background: var(--call-dark); }
.btn-plain { background: var(--card); color: var(--text); border-color: var(--line); }
.btn-link { background: none; color: var(--video); min-height: 48px; padding: 6px 4px; text-decoration: underline; }
.btn-danger { background: var(--card); color: var(--danger); border-color: var(--danger); }
.btn-wide { width: 100%; }

/* ---------- Maydonlar ---------- */
label { display: block; font-weight: 600; margin: 14px 0 6px; }
input {
  font: inherit;
  font-size: 24px;
  width: 100%;
  min-height: var(--tap);
  padding: 10px 14px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
}
input.code { letter-spacing: 12px; text-align: center; font-size: 32px; }
.error { color: var(--danger); font-weight: 600; min-height: 28px; margin-top: 8px; }

/* ---------- Kirish ekrani ---------- */
.welcome { text-align: center; padding-top: 24px; }
.logo {
  width: 96px; height: 96px; border-radius: 24px; margin: 0 auto 8px;
  background: var(--call); color: #fff; display: grid; place-items: center;
  font-size: 56px; font-weight: 800;
}
.stack > * + * { margin-top: 12px; }

/* ---------- Bosh ekran ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 12px;
}
.my-number { font-size: 18px; }
.my-number strong { font-size: 24px; letter-spacing: 1px; }
.icon-btn {
  min-width: var(--tap); background: var(--card); border-color: var(--line); font-size: 26px; padding: 0 12px;
}

.add-btn { width: 100%; font-size: 22px; background: var(--card); border: 2px dashed var(--muted); color: var(--text); margin-bottom: 16px; }

.contact {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}
.contact-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: none; border: 0; width: 100%; padding: 0 0 10px; min-height: 48px; text-align: start;
  color: var(--text);
}
.contact-name { font-size: 24px; font-weight: 700; overflow-wrap: anywhere; }
.contact-id { font-size: 17px; color: var(--muted); font-weight: 500; white-space: nowrap; }
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.actions button { flex-direction: column; gap: 2px; font-size: 17px; padding: 8px 4px; min-height: 76px; }
.actions .ico { font-size: 26px; line-height: 1; }
.act-call { background: var(--call); color: #fff; }
.act-call:active { background: var(--call-dark); }
.act-video { background: var(--video); color: #fff; }
.act-video:active { background: var(--video-dark); }
.act-write { background: #fff; color: var(--text); border-color: var(--text); }

.empty { text-align: center; padding: 24px 8px; color: var(--muted); }

/* ---------- Oyna (dialog) ---------- */
dialog {
  border: 0; border-radius: 20px; padding: 20px; width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 32px); overflow: auto; color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dialog-actions { display: grid; gap: 10px; margin-top: 18px; }

.settings-row { padding: 12px 0; border-bottom: 1px solid var(--line); }
.settings-row:last-child { border-bottom: 0; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.segmented button { background: var(--card); border-color: var(--line); color: var(--text); }
.segmented button[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: #fff; }

/* ---------- Xabarcha ---------- */
#toast {
  position: fixed; left: 50%; top: calc(12px + env(safe-area-inset-top)); transform: translateX(-50%);
  box-shadow: 0 6px 24px rgba(0,0,0,.25);
  background: #111; color: #fff; padding: 14px 20px; border-radius: 14px; font-size: 19px;
  max-width: calc(100vw - 32px); text-align: center; z-index: 10;
}

@media (max-width: 360px) {
  body { font-size: 18px; }
  .actions button { font-size: 15px; }
}

/* ---------- Yangi xabar belgisi ---------- */
.unread-line {
  width: 100%; min-height: 48px; margin: 0 0 10px; padding: 6px 12px;
  background: #fef2f2; color: var(--danger); border: 2px solid var(--danger);
  font-size: 19px; justify-content: flex-start;
}
.act-write { position: relative; }
.badge {
  position: absolute; top: 6px; inset-inline-end: 8px; min-width: 28px; height: 28px; padding: 0 7px;
  border-radius: 14px; background: var(--danger); color: #fff; font-size: 16px; line-height: 28px; font-weight: 700;
}

/* ---------- Suhbat ekrani ---------- */
.chat {
  display: flex; flex-direction: column;
  height: calc(100vh - 32px);
  height: calc(100dvh - 32px - env(safe-area-inset-bottom));
}
.chat-top { display: flex; align-items: center; gap: 12px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.back-btn { background: var(--card); border-color: var(--line); color: var(--text); font-size: 20px; flex: none; }
.chat-name { font-size: 24px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.messages { flex: 1; overflow-y: auto; padding: 12px 2px; overscroll-behavior: contain; }
.older { width: 100%; margin-bottom: 10px; }
.day { text-align: center; color: var(--muted); font-size: 16px; margin: 14px 0 8px; }
.msg {
  max-width: 85%; padding: 10px 14px 6px; border-radius: 18px; margin: 6px 0;
  font-size: 21px; overflow-wrap: anywhere; white-space: pre-wrap;
}
.msg.mine { margin-inline-start: auto; background: #dcfce7; border: 1px solid #b7e4c7; border-end-end-radius: 6px; }
.msg.theirs { margin-inline-end: auto; background: var(--card); border: 1px solid var(--line); border-end-start-radius: 6px; }
.msg-text { unicode-bidi: plaintext; }
.msg-time { font-size: 14px; color: var(--muted); text-align: end; margin-top: 2px; }

.composer { display: flex; gap: 8px; align-items: flex-end; padding-top: 10px; border-top: 1px solid var(--line); }
.composer textarea {
  flex: 1; font: inherit; font-size: 21px; min-height: var(--tap); max-height: 180px; resize: none;
  padding: 14px; border: 2px solid var(--line); border-radius: var(--radius); background: #fff; color: var(--text);
}
.composer textarea:focus-visible { outline: 4px solid #f59e0b; outline-offset: 2px; }
.send-btn { background: var(--call); color: #fff; flex: none; font-size: 19px; }
.send-btn:active { background: var(--call-dark); }
.seen { text-align: end; color: var(--call-dark); font-size: 16px; font-weight: 600; margin-block: -2px 6px; margin-inline-end: 4px; }

/* ---------- Tillar ---------- */
.langs { grid-template-columns: repeat(2, 1fr); }
.langs button { font-size: 19px; }
.contact-name, .chat-name { unicode-bidi: plaintext; }
[dir="rtl"] body, [dir="rtl"] input, [dir="rtl"] textarea, [dir="rtl"] button {
  font-family: system-ui, -apple-system, "Segoe UI", Tahoma, "Noto Sans Arabic", Arial, sans-serif;
}

/* ---------- Kirish: raqam tanlash, zaxira kod ---------- */
.choose-box { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px 14px; }
.choose-box label { margin-top: 0; }
.choose-box .btn-plain { margin-top: 10px; }
.id-result { margin-top: 10px; display: grid; gap: 8px; }
.id-result .ok { color: var(--call-dark); font-weight: 700; font-size: 21px; }
.id-result .bad { color: var(--danger); font-weight: 700; font-size: 21px; }
.id-result .star { color: #92400e; font-weight: 700; font-size: 20px; }
.ok { color: var(--call-dark); font-weight: 600; }
.bad { color: var(--danger); font-weight: 600; }
.big-id { font-size: 44px; font-weight: 800; letter-spacing: 3px; margin: 4px 0 16px; }
.recovery-box { background: #fffbeb; border: 2px solid #f59e0b; border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.recovery-code { font-family: ui-monospace, Consolas, monospace; font-size: 28px; font-weight: 700; letter-spacing: 2px; text-align: center; background: #fff; border-radius: 12px; padding: 12px; margin: 8px 0 12px; user-select: all; }
.sep { border: 0; border-top: 1px solid var(--line); margin: 24px 0; }
button[aria-pressed="true"].btn-plain { background: var(--text); color: #fff; border-color: var(--text); }

/* ---------- So'rovlar, ogohlantirish, email eslatmasi ---------- */
.request { background: #fff7ed; border: 2px solid #f59e0b; border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.request-title { font-size: 21px; margin-bottom: 10px; }
.request .actions button { min-height: 56px; flex-direction: row; font-size: 18px; }
.warn { background: #fef2f2; color: #7f1d1d; border-radius: 12px; padding: 10px 12px; font-size: 17px; margin-bottom: 10px; line-height: 1.35; }
.nudge { background: var(--card); border: 1px dashed var(--muted); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; font-size: 18px; }
.nudge-actions { display: flex; gap: 10px; margin-top: 10px; align-items: center; }

/* ---------- Hisob hayoti ---------- */
.warn.big { font-size: 19px; padding: 12px 14px; border: 2px solid var(--danger); background: #fef2f2; margin-bottom: 14px; }
.row-btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.row-btns button { min-height: 52px; font-size: 18px; padding: 8px 14px; }
.extra-check { background: #fffbeb; border: 2px solid #f59e0b; border-radius: var(--radius); padding: 12px 14px; }
.extra-check label { margin-top: 10px; }
.extra-check .btn-plain { margin-top: 8px; }
.cf-turnstile { margin-top: 8px; min-height: 65px; }

/* ---------- Taklif va o'rnatish ---------- */
.invite-btn { width: 100%; font-size: 21px; background: var(--card); border: 2px solid var(--call); color: var(--call-dark); margin: -6px 0 16px; }
.install { background: #eff6ff; border: 2px solid var(--video); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; font-size: 18px; }
.install p { margin: 6px 0 0; }
.hint { font-size: 16px; margin: 8px 0 0; line-height: 1.35; }

/* ---------- Kontakt rasmi ---------- */
.avatar {
  flex: none; width: 56px; height: 56px; border-radius: 50%; display: inline-grid; place-items: center;
  color: #fff; font-size: 26px; font-weight: 700; background-size: cover; background-position: center;
  margin-inline-end: 12px;
}
.avatar.has-photo { color: transparent; }
.contact-head { display: flex; align-items: center; }
.contact-head .contact-name { flex: 1; }
.chat-top .avatar { width: 44px; height: 44px; font-size: 20px; margin-inline-end: 0; }
.edit-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.edit-head .avatar { width: 72px; height: 72px; font-size: 32px; }
.photo-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 10px; }
.file-btn { cursor: pointer; margin: 0; font-weight: 600; }
.file-btn { display: inline-flex; align-items: center; justify-content: center; min-height: 52px; padding: 0 18px; border: 2px solid var(--line, #cfd4d9); border-radius: 14px; background: #fff; font-size: 18px; }

/* ---------- Qo'ng'iroq ekrani ---------- */
#call { position: fixed; inset: 0; z-index: 50; background: #0f172a; color: #fff; }
body.in-call { overflow: hidden; }
.call-screen { position: relative; height: 100%; display: flex; flex-direction: column; justify-content: space-between; align-items: center;
  padding: calc(24px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom)); }
.call-info { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-top: 10vh; text-align: center; }
.call-info .avatar { width: 120px; height: 120px; font-size: 56px; margin: 0 0 8px; }
.call-name { font-size: 32px; font-weight: 700; }
.call-status { font-size: 22px; color: #cbd5e1; min-height: 1.4em; }
.call-buttons { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 14px; width: 100%; max-width: 480px; }
.call-btn { min-height: 96px; border-radius: 22px; border: 0; font-size: 18px; font-weight: 700; color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 8px; }
.call-btn .ico { font-size: 34px; line-height: 1; }
.call-accept { background: var(--call); }
.call-accept:active { background: var(--call-dark); }
.call-end { background: var(--danger); }
.call-end:active { background: #8f1515; }
.call-tool { background: #334155; }
.call-tool.on { background: #f59e0b; color: #111; }
.call-remote { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
audio.call-remote { display: none; }
.call-local { position: absolute; top: calc(16px + env(safe-area-inset-top)); inset-inline-end: 16px; width: 110px; height: 150px; object-fit: cover; border-radius: 14px; border: 2px solid #fff; background: #000; transform: scaleX(-1); }
.call-screen.video .call-info { position: relative; z-index: 1; margin-top: 0; background: rgba(0,0,0,.45); padding: 8px 16px; border-radius: 14px; align-self: flex-start; align-items: flex-start; text-align: start; }
.call-screen.video .call-name { font-size: 22px; }
.call-screen.video .call-status { font-size: 18px; }
.call-screen.video .call-buttons { position: relative; z-index: 1; }
@media (min-width: 700px) { .call-local { width: 180px; height: 240px; } }

.push-nudge { border-color: var(--call); }
