@font-face {
  font-family: 'Vazirmatn';
  src: url('/fonts/Vazirmatn.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --bg: #f1f5f4;
  --panel: #ffffff;
  --panel-2: #f7faf9;
  --text: #1c2b29;
  --muted: #6b7c79;
  --border: #dfe7e5;
  --primary: #0f766e;
  --primary-2: #0d9488;
  --primary-text: #ffffff;
  --mine: #d7f3ee;
  --other: #ffffff;
  --danger: #dc2626;
  --warn: #b45309;
  --success: #15803d;
  --mention: #fff7d6;
  --shadow: 0 6px 24px rgba(0, 0, 0, .08);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1513; --panel: #14201e; --panel-2: #192826; --text: #e3ece9; --muted: #8fa29e; --border: #23332f;
    --primary: #14b8a6; --primary-2: #2dd4bf; --primary-text: #04201c; --mine: #0f3a35; --other: #1b2a28;
    --mention: #3a3214; --shadow: 0 6px 24px rgba(0, 0, 0, .4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1513; --panel: #14201e; --panel-2: #192826; --text: #e3ece9; --muted: #8fa29e; --border: #23332f;
  --primary: #14b8a6; --primary-2: #2dd4bf; --primary-text: #04201c; --mine: #0f3a35; --other: #1b2a28;
  --mention: #3a3214; --shadow: 0 6px 24px rgba(0, 0, 0, .4); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'Vazirmatn', Tahoma, 'Segoe UI', 'Noto Sans Arabic', system-ui, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--primary); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; }
.grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- buttons & forms */
.btn {
  border: 1px solid var(--border); background: var(--panel-2); border-radius: 10px; padding: 8px 16px;
  cursor: pointer; transition: background .15s, transform .05s; white-space: nowrap;
}
.btn:hover { background: var(--border); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-2); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .6; cursor: default; }
.icon-btn {
  border: 0; background: transparent; cursor: pointer; font-size: 19px; width: 38px; height: 38px;
  border-radius: 50%; display: inline-grid; place-items: center; position: relative; text-decoration: none; flex: none;
}
.icon-btn:hover { background: var(--panel-2); }
.link { background: none; border: 0; color: var(--primary); cursor: pointer; padding: 0; }
.link.small { font-size: 12px; }
.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
.form label.check, label.check { flex-direction: row; align-items: center; gap: 8px; }
input, textarea, select {
  border: 1px solid var(--border); background: var(--panel); border-radius: 10px; padding: 9px 12px; outline: none; width: 100%;
}
input[type="checkbox"] { width: auto; }
input:focus, textarea:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent); }
.captcha { display: flex; align-items: center; gap: 10px; background: var(--panel-2); border-radius: 12px; padding: 10px 12px; flex-wrap: wrap; }
.form .captcha label { flex: 1; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 6px; color: var(--text); }
.captcha .captcha-q { font-size: 18px; padding: 0 4px; unicode-bidi: isolate; }
.captcha input { width: 80px; text-align: center; font-size: 17px; }
.hint { font-size: 13px; color: var(--muted); margin: 0; }
.alert { padding: 10px 14px; border-radius: 10px; font-size: 14px; background: var(--panel-2); border: 1px solid var(--border); }
.alert.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); background: color-mix(in srgb, var(--danger) 8%, var(--panel)); }
.alert.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent); background: color-mix(in srgb, var(--warn) 8%, var(--panel)); }
.alert.success { color: var(--success); border-color: color-mix(in srgb, var(--success) 35%, transparent); background: color-mix(in srgb, var(--success) 8%, var(--panel)); }

/* ---------- auth */
#auth, #nick-screen, #pin-screen { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 420px; background: var(--panel); border-radius: 20px; padding: 28px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 16px; }
.auth-card h2 { margin: 0; font-size: 20px; }
.brand { display: flex; align-items: center; gap: 12px; justify-content: center; }
.brand img { width: 48px; height: 48px; }
.brand h1 { margin: 0; font-size: 22px; }
.tabs { display: flex; background: var(--panel-2); border-radius: 12px; padding: 4px; }
.tab { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 9px; cursor: pointer; }
.tab.active { background: var(--panel); box-shadow: 0 1px 4px rgba(0, 0, 0, .1); font-weight: bold; }

/* ---------- layout */
#app { height: 100dvh; display: grid; grid-template-columns: 290px 1fr 240px; }
.panel { background: var(--panel); display: flex; flex-direction: column; min-height: 0; overflow-y: auto; }
#sidebar { border-left: 1px solid var(--border); }
#online { border-right: 1px solid var(--border); }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--border); min-height: 58px; position: sticky; top: 0; background: var(--panel); z-index: 1; }
.head-actions { display: flex; align-items: center; gap: 2px; }
.me-box { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.me-box div { display: flex; flex-direction: column; line-height: 1.4; }
#conn-state.ok { color: var(--success); }
.section-title { font-size: 13px; color: var(--muted); margin: 14px 14px 6px; font-weight: normal; display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.section-title small { font-size: 11px; }
.search-box { padding: 0 10px 6px; }
.search-box input { padding: 6px 10px; font-size: 14px; }
.list { list-style: none; margin: 0; padding: 0 6px; }
.item { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 10px; cursor: pointer; }
.item:hover { background: var(--panel-2); }
.item.active { background: color-mix(in srgb, var(--primary) 14%, transparent); }
.item.empty { cursor: default; font-size: 13px; }
.room-icon { width: 30px; height: 30px; border-radius: 9px; background: var(--panel-2); display: grid; place-items: center; color: var(--muted); font-weight: bold; }
.badge { background: var(--primary); color: var(--primary-text); border-radius: 999px; font-size: 11px; padding: 0 7px; min-width: 20px; text-align: center; line-height: 20px; }
.icon-btn .badge { position: absolute; top: -2px; left: -4px; font-size: 10px; line-height: 16px; min-width: 16px; padding: 0 4px; }
.icon-btn .badge:empty { display: none; }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: inline-grid; place-items: center; color: #fff; font-weight: bold; flex: none; background: var(--primary); user-select: none; }
.avatar.sm { width: 30px; height: 30px; font-size: 13px; }
.avatar.big { width: 96px; height: 96px; font-size: 40px; }
.avatar-wrap { position: relative; display: inline-flex; }
.dot { position: absolute; bottom: 0; left: 0; width: 10px; height: 10px; border-radius: 50%; background: #22c55e; border: 2px solid var(--panel); }
.role { font-size: 10px; padding: 0 6px; border-radius: 6px; margin-inline-start: 6px; font-weight: normal; vertical-align: middle; }
.role.admin { background: #fee2e2; color: #b91c1c; }
.role.mod { background: #dbeafe; color: #1d4ed8; }

/* ---------- chat */
#chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.chat-head { display: flex; align-items: center; gap: 8px; padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--border); min-height: 58px; }
.chat-title { flex: 1; display: flex; flex-direction: column; line-height: 1.4; min-width: 0; }
.chat-title b, .chat-title small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.announcement { background: color-mix(in srgb, var(--primary) 12%, var(--panel)); padding: 8px 16px; font-size: 14px; border-bottom: 1px solid var(--border); white-space: pre-wrap; }
.messages { flex: 1; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 2px; overscroll-behavior: contain; }
.messages .loading, .messages .empty { margin: auto; }
.load-more { align-self: center; background: var(--panel); border: 1px solid var(--border); border-radius: 999px; padding: 4px 14px; cursor: pointer; font-size: 13px; margin-bottom: 8px; }
.e2e-note { align-self: center; text-align: center; font-size: 12px; color: var(--muted); background: var(--panel); border-radius: 10px; padding: 6px 12px; margin: 4px 0 10px; max-width: 520px; }
.day-sep { text-align: center; margin: 12px 0 6px; }
.day-sep span { background: var(--panel); color: var(--muted); font-size: 12px; padding: 2px 12px; border-radius: 999px; }
.msg { display: flex; gap: 8px; align-items: flex-end; margin-top: 8px; max-width: 100%; }
.msg.grouped { margin-top: 2px; padding-inline-start: 38px; }
.msg.mine { flex-direction: row-reverse; padding-inline-start: 0; }
.msg-avatar { cursor: pointer; }
.bubble { position: relative; background: var(--other); border-radius: var(--radius); padding: 6px 12px 4px; max-width: min(620px, 78%); box-shadow: 0 1px 2px rgba(0, 0, 0, .06); overflow-wrap: anywhere; }
.msg.mine .bubble { background: var(--mine); }
.msg.mention .bubble { background: var(--mention); }
.msg.flash .bubble { outline: 2px solid var(--primary); }
.msg-author { font-size: 13px; font-weight: bold; color: var(--primary); cursor: pointer; }
.text { white-space: pre-wrap; }
.text mark { background: color-mix(in srgb, var(--primary) 25%, transparent); color: inherit; border-radius: 4px; padding: 0 2px; }
.meta { font-size: 11px; color: var(--muted); text-align: left; direction: rtl; margin-top: 1px; }
.tick.read { color: #0ea5e9; }
.quote { border-inline-start: 3px solid var(--primary); background: color-mix(in srgb, var(--primary) 8%, transparent); padding: 2px 8px; border-radius: 6px; margin: 2px 0 4px; font-size: 13px; cursor: pointer; display: flex; flex-direction: column; }
.quote span { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-menu-btn { position: absolute; top: 2px; left: 4px; border: 0; background: var(--panel); border-radius: 8px; cursor: pointer; opacity: 0; transition: opacity .15s; line-height: 1; padding: 2px 6px; }
.msg.mine .msg-menu-btn { left: auto; right: 4px; }
.bubble:hover .msg-menu-btn, .msg-menu-btn:focus { opacity: 1; }
@media (hover: none) { .msg-menu-btn { opacity: .6; } }
.file img, .file video { max-width: 100%; max-height: 320px; border-radius: 10px; display: block; margin: 4px 0; cursor: zoom-in; }
.file audio { width: 260px; max-width: 100%; margin: 4px 0; display: block; }
.file-row { display: flex; align-items: center; gap: 10px; border: 1px solid var(--border); background: var(--panel); border-radius: 10px; padding: 8px 10px; cursor: pointer; width: 280px; max-width: 100%; text-align: right; margin: 4px 0; }
.file-row b, .file-row small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-icon { font-size: 24px; }
.typing { min-height: 22px; font-size: 12px; color: var(--muted); padding: 0 18px; }
#mute-banner { margin: 0 12px 6px; }
.reply-bar, .upload-bar { display: flex; align-items: center; gap: 10px; margin: 0 12px; padding: 6px 12px; background: var(--panel); border-radius: 12px 12px 0 0; border-inline-start: 3px solid var(--primary); }
.reply-bar div { flex: 1; min-width: 0; }
.reply-bar p { margin: 0; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-bar progress { flex: 1; }
.composer { position: relative; display: flex; align-items: flex-end; gap: 4px; padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--border); }
.composer textarea { resize: none; max-height: 160px; min-height: 40px; line-height: 1.6; border-radius: 20px; padding: 8px 14px; }
.composer .send { border-radius: 20px; height: 40px; }
.emoji-panel { position: absolute; bottom: 100%; right: 10px; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 8px; display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; width: min(340px, calc(100vw - 20px)); z-index: 5; }
.emoji-panel button { border: 0; background: none; font-size: 22px; cursor: pointer; border-radius: 8px; padding: 4px; }
.emoji-panel button:hover { background: var(--panel-2); }
.recording-bar { display: flex; align-items: center; gap: 10px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--border); }
.recording-bar #rec-time { flex: 1; font-variant-numeric: tabular-nums; }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

/* ---------- menus, modal, toast */
.menu { position: fixed; z-index: 50; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; display: flex; flex-direction: column; min-width: 200px; }
.menu button { border: 0; background: none; text-align: right; padding: 8px 12px; border-radius: 8px; cursor: pointer; }
.menu button:hover { background: var(--panel-2); }
.menu button.danger { color: var(--danger); }
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 60; display: grid; place-items: center; padding: 16px; }
.modal-card { background: var(--panel); border-radius: 18px; width: 100%; max-width: 460px; max-height: 90dvh; overflow-y: auto; box-shadow: var(--shadow); }
.modal-card header { display: flex; align-items: center; justify-content: space-between; padding: 12px 18px; border-bottom: 1px solid var(--border); }
.modal-card header h3 { margin: 0; font-size: 17px; }
#modal-body { padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; }
.settings-info p { margin: 2px 0; }
.notice-text { white-space: pre-wrap; font-size: 16px; }
.safety-code { font-family: ui-monospace, monospace; font-size: 22px; letter-spacing: 2px; text-align: center; background: var(--panel-2); border-radius: 12px; padding: 14px; word-spacing: 8px; }
.toasts { position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%); z-index: 70; display: flex; flex-direction: column; gap: 8px; align-items: center; width: min(480px, calc(100vw - 32px)); pointer-events: none; }
.toast { background: #1f2937; color: #fff; padding: 10px 16px; border-radius: 12px; box-shadow: var(--shadow); font-size: 14px; animation: rise .2s; pointer-events: auto; }
.toast.danger { background: #b91c1c; }
.toast.warn { background: #92400e; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
.lightbox { position: fixed; inset: 0; background: rgba(0, 0, 0, .9); z-index: 80; display: grid; place-items: center; cursor: zoom-out; }
.lightbox img { max-width: 95vw; max-height: 95dvh; }
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 20; }

/* ---------- call */
.call { position: fixed; inset: 0; z-index: 90; background: linear-gradient(160deg, #0f2f2b, #071513); color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 40px 16px calc(30px + env(safe-area-inset-bottom)); }
.call-info { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; z-index: 2; }
.call-info h2 { margin: 8px 0 0; }
.call-info p { margin: 0; font-variant-numeric: tabular-nums; }
.call-info .muted { color: #9fb8b3; font-size: 12px; }
#remote-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; display: none; }
#local-video { position: absolute; top: 16px; left: 16px; width: 28vw; max-width: 200px; border-radius: 14px; z-index: 3; display: none; transform: scaleX(-1); background: #000; }
.call.video #remote-video, .call.video #local-video { display: block; }
.call.video .call-info { background: rgba(0, 0, 0, .35); padding: 8px 16px; border-radius: 14px; }
.call.video .call-info .avatar { display: none; }
.call-controls { display: flex; gap: 18px; z-index: 2; }
.round { width: 62px; height: 62px; border-radius: 50%; border: 0; font-size: 24px; cursor: pointer; background: rgba(255, 255, 255, .15); color: #fff; }
.round.off { background: rgba(255, 255, 255, .5); text-decoration: line-through; }
.round.accept { background: #16a34a; animation: pulse 1.2s infinite; }
.round.hangup { background: #dc2626; transform: rotate(135deg); }

/* ---------- responsive */
.mobile-only { display: none; }
@media (max-width: 1100px) {
  #app { grid-template-columns: 270px 1fr; }
  #online { position: fixed; top: 0; bottom: 0; left: 0; width: 280px; z-index: 30; transform: translateX(-105%); transition: transform .2s; box-shadow: var(--shadow); }
  #online.open { transform: none; }
  #open-online { display: inline-grid; }
  #online .mobile-only { display: inline-grid; }
}
@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; }
  #sidebar { position: fixed; top: 0; bottom: 0; right: 0; width: min(320px, 86vw); z-index: 30; transform: translateX(105%); transition: transform .2s; box-shadow: var(--shadow); }
  #sidebar.open { transform: none; }
  .mobile-only { display: inline-grid; }
  .bubble { max-width: 86%; }
  .messages { padding: 10px; }
  .auth-card { padding: 20px; }
  .composer .send { padding: 0 12px; }
}
