:root {
  --bg: #0e1621;
  --side: #17212b;
  --panel: #17212b;
  --panel2: #202b36;
  --hover: #202b36;
  --active: #2b5278;
  --line: #0b121a;
  --line2: #2a3644;
  --text: #f5f7fa;
  --muted: #7f91a4;
  --accent: #5288c1;
  --accent-2: #64a0e0;
  --mine: #2b5278;
  --theirs: #182533;
  --danger: #e5484d;
  --ok: #4fbf67;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}
button, input { font: inherit; color: inherit; }
a { color: var(--accent-2); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
svg { width: 22px; height: 22px; flex: none; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 10px; border: 0;
  background: var(--panel2); cursor: pointer; transition: background .15s;
}
.btn:hover { filter: brightness(1.12); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.small { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 0; background: transparent;
  display: grid; place-items: center; cursor: pointer; color: var(--muted); flex: none;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.send { background: var(--accent); color: #fff; }
.icon-btn.send:hover { background: var(--accent-2); }

input[type="text"], input:not([type]), input[type="password"] {
  background: var(--bg); border: 1px solid var(--line2); border-radius: 10px;
  padding: 10px 12px; outline: none; width: 100%;
}
input:focus { border-color: var(--accent); }

/* Avatars */
.av {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; flex: none;
  font-weight: 600; color: #fff; font-size: 17px; position: relative; user-select: none;
}
.av.sm { width: 34px; height: 34px; font-size: 14px; }
.av.lg { width: 96px; height: 96px; font-size: 38px; }
.av.online::after {
  content: ""; position: absolute; right: 0; bottom: 0; width: 12px; height: 12px;
  background: var(--ok); border: 2px solid var(--side); border-radius: 50%;
}

/* Auth */
.auth { height: 100dvh; display: grid; place-items: center; padding: 20px; overflow: auto; }
.card {
  width: min(380px, 100%); background: var(--panel); border-radius: 16px; padding: 26px;
  display: flex; flex-direction: column; gap: 14px; box-shadow: 0 10px 40px rgba(0,0,0,.35);
}
.card p { margin: 0; }
.card label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.card label input { color: var(--text); }
.error { color: var(--danger); min-height: 1em; font-size: 14px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 22px; }
.logo {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
  background: linear-gradient(135deg, #5288c1, #3fb6a8); color: #fff; font-weight: 800;
}
.logo.big { width: 84px; height: 84px; font-size: 38px; margin: 0 auto 10px; }
.tabs { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; }
.tabs button {
  flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 8px; cursor: pointer; color: var(--muted);
}
.tabs button.active { background: var(--panel2); color: var(--text); }

/* Layout */
.app { height: 100dvh; display: grid; grid-template-columns: 360px 1fr; }
.sidebar { background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-top { display: flex; align-items: center; gap: 4px; padding: 10px 10px 6px 14px; }
.me-box { flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0; }
.me-box .who { min-width: 0; }
.me-box .who div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-box .who .u { font-size: 13px; color: var(--muted); }
.search-box { padding: 4px 12px 10px; }
.search-box input { border-radius: 20px; background: #242f3d; border-color: transparent; padding: 8px 14px; }

.chat-list { flex: 1; overflow-y: auto; padding: 0 6px 8px; }
.dl-desktop { font-size: 13px; text-align: center; color: var(--muted); text-decoration: none; }
.dl-desktop:hover { color: var(--accent-2); text-decoration: underline; }
.dl-desktop.side { padding: 10px; border-top: 1px solid var(--line); }
.chat-item {
  display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 10px; cursor: pointer;
}
.chat-item:hover { background: var(--hover); }
.chat-item.active { background: var(--active); }
.chat-item .ci-body { flex: 1; min-width: 0; }
.chat-item .ci-row { display: flex; align-items: center; gap: 6px; }
.chat-item .ci-name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .ci-time { font-size: 12px; color: var(--muted); }
.chat-item .ci-last { flex: 1; font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .ci-last .who { color: var(--text); }
.chat-item.active .ci-time, .chat-item.active .ci-last { color: #c5d6e8; }
.chat-item .badge {
  min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px; background: var(--accent);
  color: #fff; font-size: 12px; font-weight: 600; display: grid; place-items: center;
}
.chat-item .in-call-ic { color: var(--ok); display: inline-flex; }
.chat-item .in-call-ic svg { width: 16px; height: 16px; }
.list-empty { padding: 30px 20px; text-align: center; color: var(--muted); font-size: 14px; }

.main { position: relative; min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--bg); }
.empty { flex: 1; display: grid; place-items: center; text-align: center; color: var(--muted); padding: 20px; }
.chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.chat-head {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--panel);
  border-bottom: 1px solid var(--line); min-height: 60px;
}
.chat-head .back { display: none; }
.head-info { flex: 1; min-width: 0; }
.head-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.head-status { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.head-status.on { color: var(--accent-2); }

.call-banner {
  display: flex; align-items: center; gap: 10px; padding: 8px 14px; background: #1c3a2a; font-size: 14px;
}
.call-banner span:nth-child(2) { flex: 1; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; animation: blink 1.4s infinite; }
@keyframes blink { 50% { opacity: .35; } }

/* Messages */
.messages {
  flex: 1; overflow-y: auto; padding: 12px 6% 8px; display: flex; flex-direction: column; gap: 2px;
  background: radial-gradient(circle at 20% 10%, #13202e 0, transparent 40%), radial-gradient(circle at 80% 90%, #112130 0, transparent 40%);
}
.day-sep { align-self: center; margin: 10px 0; font-size: 13px; background: rgba(0,0,0,.3); padding: 3px 12px; border-radius: 12px; color: #d0dae5; }
.sys { align-self: center; font-size: 13px; background: rgba(0,0,0,.3); padding: 4px 12px; border-radius: 12px; color: #d0dae5; margin: 6px 0; text-align: center; max-width: 90%; }
.msg { display: flex; flex-direction: column; max-width: min(75%, 520px); align-self: flex-start; margin-top: 6px; }
.msg.cont { margin-top: 0; }
.msg.mine { align-self: flex-end; }
.bubble {
  position: relative; background: var(--theirs); padding: 6px 10px 6px 12px; border-radius: 14px;
  white-space: pre-wrap; overflow-wrap: anywhere; min-width: 64px;
}
.msg.mine .bubble { background: var(--mine); }
.msg:not(.cont) .bubble { border-top-left-radius: 4px; }
.msg.mine:not(.cont) .bubble { border-top-left-radius: 14px; border-top-right-radius: 4px; }
.bubble .sender { font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.bubble .meta-line {
  position: absolute; right: 8px; bottom: 4px; display: inline-flex; align-items: center; gap: 3px;
  font-size: 11px; color: #8fa6bd; white-space: nowrap;
}
.spacer { display: inline-block; width: 44px; height: 1px; }
.spacer.mine { width: 62px; }
.voice-bubble { padding-bottom: 8px; }
.msg.mine .bubble .meta-line { color: #9fc1e3; }
.meta-line svg { width: 16px; height: 16px; }
.meta-line .read { color: #6fc3ff; }
.bubble.media { padding: 3px; }
.bubble.media .sender { padding: 3px 8px 0; }
.bubble.media img { display: block; max-width: 100%; width: 320px; max-height: 360px; object-fit: cover; border-radius: 11px; cursor: zoom-in; }
.bubble.media .caption { padding: 4px 8px 4px; }
.bubble.media .meta-line.over {
  position: absolute; right: 8px; bottom: 8px; margin: 0; background: rgba(0,0,0,.5); padding: 1px 6px; border-radius: 8px; color: #fff;
}
.call-msg { display: flex; align-items: center; gap: 10px; padding-right: 4px; }
.call-msg .ic { width: 36px; height: 36px; border-radius: 50%; background: rgba(255,255,255,.08); display: grid; place-items: center; }
.call-msg.missed .ic { color: var(--danger); }
.call-msg .ic svg { width: 18px; height: 18px; }

/* Voice message */
.voice { display: flex; align-items: center; gap: 10px; min-width: 220px; padding: 2px 0; }
.voice .play {
  width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--accent); color: #fff;
  display: grid; place-items: center; cursor: pointer; flex: none;
}
.msg.mine .voice .play { background: #fff; color: var(--mine); }
.voice .play svg { width: 18px; height: 18px; }
.voice .wave { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.voice .bar { height: 26px; display: flex; align-items: center; gap: 2px; cursor: pointer; }
.voice .bar i { flex: 1; background: #4b6a8a; border-radius: 2px; min-height: 3px; }
.voice .bar i.done { background: var(--accent-2); }
.msg.mine .voice .bar i { background: #5b85b3; }
.msg.mine .voice .bar i.done { background: #fff; }
.voice .dur { font-size: 12px; color: var(--muted); }
.msg.mine .voice .dur { color: #9fc1e3; }

.typing { min-height: 0; padding: 0 6%; font-size: 13px; color: var(--accent-2); }
.typing:not(:empty) { padding-bottom: 4px; }
.composer {
  display: flex; align-items: center; gap: 6px; padding: 8px 10px; background: var(--panel);
  border-top: 1px solid var(--line); padding-bottom: max(8px, env(safe-area-inset-bottom));
}
.composer #msgInput { flex: 1; min-width: 0; background: transparent; border: 0; padding: 10px 6px; }
.recorder .rec-info { flex: 1; display: flex; align-items: center; gap: 10px; padding-left: 6px; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }

/* Call view */
.call-view {
  position: fixed; inset: 0; z-index: 40; background: #0a0f15; display: flex; flex-direction: column;
}
.call-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; }
.call-title { font-weight: 600; font-size: 17px; }
.call-waiting { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center; }
.call-waiting .av { animation: pulse 1.6s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(82,136,193,.6); } 100% { box-shadow: 0 0 0 28px rgba(82,136,193,0); } }
.grid {
  flex: 1; min-height: 0; display: grid; gap: 10px; padding: 0 12px;
  grid-template-columns: repeat(var(--cols, 1), 1fr); grid-auto-rows: 1fr;
}
.tile { position: relative; background: #17212b; border-radius: var(--radius); overflow: hidden; min-height: 0; outline: 3px solid transparent; transition: outline-color .15s; }
.tile.speaking { outline-color: var(--ok); }
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; background: #000; }
.tile.mirror video { transform: scaleX(-1); }
.tile.screen video { object-fit: contain; }
.tile.no-video video { opacity: 0; }
.tile .avatar-wrap { position: absolute; inset: 0; display: none; place-items: center; }
.tile.no-video .avatar-wrap { display: grid; }
.tile .label {
  position: absolute; left: 10px; bottom: 10px; display: flex; align-items: center; gap: 6px;
  background: rgba(0,0,0,.55); padding: 4px 10px; border-radius: 8px; font-size: 13px; max-width: calc(100% - 20px);
}
.tile .label .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .label .mic-off { display: none; color: var(--danger); }
.tile .label .mic-off svg { width: 15px; height: 15px; }
.tile.muted .label .mic-off { display: inline-flex; }
.tile .status { position: absolute; top: 10px; left: 10px; font-size: 12px; background: rgba(0,0,0,.55); padding: 3px 8px; border-radius: 6px; display: none; }
.tile.connecting .status { display: block; }
.controls { display: flex; justify-content: center; gap: 14px; padding: 16px; padding-bottom: max(16px, env(safe-area-inset-bottom)); }
.ctl {
  width: 56px; height: 56px; border-radius: 50%; border: 0; background: #2a3644; color: #fff;
  display: grid; place-items: center; cursor: pointer;
}
.ctl:hover { filter: brightness(1.15); }
.ctl.off { background: #fff; color: #17212b; }
.ctl.active { background: var(--accent); }
.ctl.danger { background: var(--danger); }
.ctl.danger svg { transform: rotate(135deg); }
.ctl.accept { background: var(--ok); }

.call-bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 35; display: flex; align-items: center; gap: 10px;
  background: #1c3a2a; padding: 6px 14px; font-size: 14px; box-shadow: 0 2px 10px rgba(0,0,0,.3);
}
.call-bar #callBarText { flex: 1; }
body.has-call-bar .app { padding-top: 42px; }

/* Modals */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { width: min(420px, 100%); max-height: min(640px, 90dvh); gap: 10px; padding: 18px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { margin: 0; font-size: 18px; }
.results { overflow-y: auto; min-height: 120px; flex: 1; margin: 0 -8px; }
.result { display: flex; align-items: center; gap: 12px; padding: 8px; border-radius: 10px; cursor: pointer; }
.result:hover { background: var(--hover); }
.result .r-body { flex: 1; min-width: 0; }
.result .r-body div:last-child { font-size: 13px; color: var(--muted); }
.result .check {
  width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line2); display: grid; place-items: center;
}
.result.sel .check { background: var(--accent); border-color: var(--accent); }
.result .check svg { width: 14px; height: 14px; color: #fff; display: none; }
.result.sel .check svg { display: block; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips:empty { display: none; }
.chip { background: var(--active); padding: 4px 10px; border-radius: 14px; font-size: 13px; cursor: pointer; }
.incoming { align-items: center; text-align: center; gap: 8px; padding: 30px; }
.incoming .av { animation: pulse 1.6s infinite; margin-bottom: 8px; }
.inc-name { font-size: 20px; font-weight: 600; }
.inc-actions { display: flex; gap: 48px; margin-top: 18px; }

/* Yönetim paneli */
.admin-btn { color: #e5ca77; }
.modal.admin { width: min(620px, 100%); max-height: min(780px, 92dvh); }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 6px; }
.stat { background: var(--bg); border-radius: 10px; padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; }
.stat b { font-size: 18px; }
.stat span { font-size: 12px; color: var(--muted); }
.admin-tab { display: flex; flex-direction: column; gap: 10px; min-height: 0; flex: 1; }
.admin-tab.hidden { display: none; }
.filters { display: flex; flex-wrap: wrap; gap: 6px; }
.filters button {
  border: 1px solid var(--line2); background: transparent; color: var(--muted); padding: 4px 11px; border-radius: 14px;
  cursor: pointer; font-size: 13px;
}
.filters button.active { background: var(--active); border-color: var(--active); color: var(--text); }
.r-top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.badge { font-size: 11px; padding: 1px 7px; border-radius: 8px; background: var(--panel2); color: var(--muted); font-weight: 600; }
.badge.admin { background: #e5ca77; color: #1b1b1b; }
.badge.ban { background: var(--danger); color: #fff; }
.badge.mute { background: #faa774; color: #1b1b1b; }
.badge.me { background: var(--accent); color: #fff; }
.switch-row { flex-direction: row !important; align-items: center; justify-content: space-between; gap: 12px; color: var(--text) !important; }
.switch-row span { display: flex; flex-direction: column; gap: 2px; }
.switch-row input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.log .log-row { padding: 8px; border-bottom: 1px solid var(--line2); font-size: 14px; display: flex; flex-direction: column; gap: 2px; }
.log .log-row .tgt { color: var(--accent-2); }
.log .log-row .when { font-size: 12px; }
.user-info { display: flex; flex-direction: column; gap: 10px; }
.ui-head { display: flex; align-items: center; gap: 12px; }
.ui-name { font-size: 18px; font-weight: 600; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.ui-facts { font-size: 14px; color: var(--muted); display: flex; flex-direction: column; gap: 3px; }
.punish { display: grid; grid-template-columns: 130px 1fr; gap: 8px; }
.punish.hidden { display: none; }
select {
  background: var(--bg); border: 1px solid var(--line2); border-radius: 10px; color: var(--text); padding: 10px; font: inherit; outline: 0;
}
.user-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.user-actions .btn { padding: 10px 12px; }
.btn.warn { background: #b4632b; color: #fff; }
.temp-pass { background: var(--bg); border: 1px dashed var(--accent); border-radius: 10px; padding: 10px; font-size: 14px; display: flex; flex-direction: column; gap: 8px; }
.temp-pass.hidden { display: none; }
.tp-row { display: flex; align-items: center; gap: 10px; }
.tp-row code { font-size: 18px; letter-spacing: 1px; flex: 1; user-select: all; }
@media (max-width: 760px) {
  .punish, .user-actions { grid-template-columns: 1fr; }
}

.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.9); display: grid; place-items: center; z-index: 60; cursor: zoom-out; padding: 20px; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 6px; }
.toasts { position: fixed; top: 60px; left: 50%; transform: translateX(-50%); z-index: 70; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: #2a3644; padding: 9px 16px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.4); font-size: 14px; animation: pop .2s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(-6px); } }

/* Mobile */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; }
  .app.chat-open .sidebar { display: none; }
  .app:not(.chat-open) .main { display: none; }
  .chat-head .back { display: grid; }
  .chat-head { padding: 6px 6px; gap: 6px; }
  .messages { padding: 10px 8px; }
  .typing { padding: 0 10px; }
  .msg { max-width: 86%; }
  .grid { padding: 0 8px; gap: 6px; }
  .ctl { width: 52px; height: 52px; }
}
