/* 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;
}
