/* ============================================================
   DekaPipe Mesaj — telefon öncelikli PWA arayüzü
   ============================================================ */
:root {
  --bg: #0b141a;
  --panel: #111b21;
  --panel-2: #202c33;
  --panel-3: #2a3942;
  --header: #202c33;
  --border: #222d34;
  --text: #e9edef;
  --muted: #8696a0;
  --accent: #00a884;
  --accent-2: #06cf9c;
  --bubble-out: #005c4b;
  --bubble-in: #202c33;
  --danger: #f15c6d;
  --link: #53bdeb;
  --unread: #00a884;
  --shadow: 0 6px 24px rgba(0,0,0,.4);
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text);
  font-size: 15px; overflow: hidden;
  overscroll-behavior: none;
}
button, input, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
input, textarea { outline: none; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: #374248; border-radius: 3px; }
.hidden { display: none !important; }

/* güvenli alan (çentikli telefonlar) */
.safe-top { padding-top: env(safe-area-inset-top); }
.safe-bottom { padding-bottom: env(safe-area-inset-bottom); }

/* ---------- Giriş ---------- */
#loginScreen {
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px; background: var(--bg);
}
.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; }
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 18px; }
.login-brand .mark { width: 64px; height: 64px; }
.login-brand h1 { font-size: 22px; font-weight: 700; }
.login-brand p { color: var(--muted); font-size: 13.5px; }
.field label { display: block; color: var(--muted); font-size: 12.5px; font-weight: 600; margin-bottom: 6px; }
.field input {
  width: 100%; background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 13px 14px; color: var(--text);
}
.field input:focus { border-color: var(--accent); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--accent); color: #fff; font-weight: 600;
  border-radius: 10px; padding: 13px; transition: background .15s;
}
.btn:hover { background: #017a63; }
.btn:disabled { opacity: .5; }
.btn-block { width: 100%; }
.btn-ghost { background: var(--panel-2); }
.btn-ghost:hover { background: var(--panel-3); }
.btn-danger { background: var(--danger); }
.login-err {
  display: none; background: rgba(241,92,109,.12); border: 1px solid rgba(241,92,109,.4);
  color: #ff9aa5; padding: 10px 12px; border-radius: 8px; font-size: 13px;
}

/* ---------- Uygulama kabuk ---------- */
#app { display: none; height: 100%; }
#app.active { display: block; }
.view { position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--bg); }

/* İki panel: geniş ekranda yan yana, telefonda tek tek */
@media (min-width: 800px) {
  #app { display: none; }
  #app.active { display: flex; }
  #listView { position: relative; width: 380px; flex: none; border-right: 1px solid var(--border); }
  #chatView { position: relative; flex: 1; }
  #chatView.empty-desktop::after {
    content: 'Sohbet seçin'; position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center; color: var(--muted);
  }
  .back-btn { display: none !important; }
}

/* ---------- Üst bar ---------- */
.topbar {
  flex: none; background: var(--header);
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; min-height: 56px;
}
.topbar .title { font-weight: 600; font-size: 17px; flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .sub { font-size: 12px; color: var(--muted); font-weight: 400; }
.topbar .icon-btn { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--text); }
.topbar .icon-btn:hover { background: rgba(255,255,255,.06); }
.back-btn { width: 36px; height: 40px; display: flex; align-items: center; justify-content: center; }

.avatar {
  width: 42px; height: 42px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff; font-size: 16px;
}
.avatar.sm { width: 34px; height: 34px; font-size: 13px; }
.avatar.lg { width: 90px; height: 90px; font-size: 34px; }

/* ---------- Sohbet listesi ---------- */
.list-scroll { flex: 1; overflow-y: auto; }
.conv {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,.03);
}
.conv:hover { background: var(--panel); }
.conv.active { background: var(--panel-2); }
.conv .cbody { flex: 1; min-width: 0; }
.conv .crow { display: flex; align-items: baseline; gap: 8px; }
.conv .cname { font-weight: 600; font-size: 16px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .ctime { font-size: 11.5px; color: var(--muted); flex: none; }
.conv .cprev { color: var(--muted); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; display: flex; align-items: center; gap: 5px; }
.conv .cbadge {
  background: var(--unread); color: #04231c; font-size: 11px; font-weight: 700;
  min-width: 20px; height: 20px; border-radius: 10px; padding: 0 6px;
  display: flex; align-items: center; justify-content: center; margin-left: auto;
}
.online-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent-2); border: 2px solid var(--panel); position: absolute; bottom: 0; right: 0; }
.avatar-wrap { position: relative; }

.fab {
  position: absolute; right: 18px; bottom: 20px;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow);
}
.fab:hover { background: #017a63; }

.list-empty { padding: 40px 24px; text-align: center; color: var(--muted); font-size: 14px; line-height: 1.6; }

/* ---------- Mesaj ekranı ---------- */
#chatView .messages {
  flex: 1; overflow-y: auto; padding: 12px;
  display: flex; flex-direction: column; gap: 4px;
  background-color: #0b141a;
  background-image: radial-gradient(rgba(255,255,255,.02) 1px, transparent 1px);
  background-size: 22px 22px;
}
.msg { max-width: 78%; padding: 6px 9px 8px; border-radius: 8px; position: relative; word-wrap: break-word; }
.msg.in { align-self: flex-start; background: var(--bubble-in); border-top-left-radius: 2px; }
.msg.out { align-self: flex-end; background: var(--bubble-out); border-top-right-radius: 2px; }
.msg .sender { font-size: 12.5px; font-weight: 700; margin-bottom: 2px; }
.msg .text { font-size: 14.5px; line-height: 1.4; white-space: pre-wrap; }
.msg .meta { font-size: 10.5px; color: var(--muted); text-align: right; margin-top: 2px; display: flex; gap: 4px; align-items: center; justify-content: flex-end; }
.msg.out .meta { color: #8fd3c4; }
.msg .tick.read { color: var(--link); }
.msg.system { align-self: center; background: rgba(255,255,255,.06); color: var(--muted); font-size: 12px; padding: 4px 12px; border-radius: 12px; max-width: 90%; text-align: center; }

.msg img.photo { max-width: 260px; max-height: 320px; border-radius: 6px; display: block; cursor: pointer; }
.msg .filecard { display: flex; align-items: center; gap: 10px; padding: 6px 4px; min-width: 180px; }
.msg .filecard .fico { width: 40px; height: 40px; border-radius: 8px; background: rgba(255,255,255,.1); display: flex; align-items: center; justify-content: center; flex: none; }
.msg .filecard .fmeta { min-width: 0; }
.msg .filecard .fname { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px; }
.msg .filecard .fsize { font-size: 11.5px; color: var(--muted); }

/* sesli mesaj oynatıcı */
.voice { display: flex; align-items: center; gap: 10px; min-width: 200px; padding: 2px 2px; }
.voice .play { width: 38px; height: 38px; border-radius: 50%; background: rgba(255,255,255,.15); display: flex; align-items: center; justify-content: center; flex: none; }
.voice .track { flex: 1; height: 4px; background: rgba(255,255,255,.25); border-radius: 2px; position: relative; }
.voice .track .fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0%; background: var(--accent-2); border-radius: 2px; }
.voice .dur { font-size: 11.5px; color: var(--muted); min-width: 34px; }

/* ---------- Alt yazma çubuğu ---------- */
.composer {
  flex: none; background: var(--header);
  display: flex; align-items: flex-end; gap: 8px; padding: 8px 10px;
}
.composer .grow { flex: 1; background: var(--panel-2); border-radius: 22px; display: flex; align-items: center; padding: 4px 6px 4px 14px; }
.composer textarea {
  flex: 1; background: transparent; border: none; color: var(--text);
  resize: none; max-height: 120px; padding: 8px 0; line-height: 1.35;
}
.composer .icon-btn { width: 42px; height: 42px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--muted); flex: none; }
.composer .icon-btn:hover { color: var(--text); }
.composer .send-btn { width: 46px; height: 46px; border-radius: 50%; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; flex: none; }
.composer .send-btn:hover { background: #017a63; }

/* kayıt modu */
.recording-bar { display: flex; align-items: center; gap: 12px; flex: 1; padding: 0 8px; }
.recording-bar .rec-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
.recording-bar .rec-time { font-variant-numeric: tabular-nums; }
@keyframes blink { 50% { opacity: .3; } }
.typing-line { padding: 2px 14px 4px; font-size: 12px; color: var(--accent-2); min-height: 0; }

/* ---------- Sesli arama ekranı ---------- */
#callScreen {
  position: fixed; inset: 0; z-index: 200; background: #0b141a;
  display: none; flex-direction: column; align-items: center;
  padding: 40px 24px; text-align: center;
}
#callScreen.active { display: flex; }
#callScreen .call-title { font-size: 20px; font-weight: 700; margin-top: 10px; }
#callScreen .call-status { color: var(--muted); margin-top: 6px; }
.call-peers { flex: 1; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 24px; align-content: center; }
.call-peer { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.call-peer .avatar { width: 84px; height: 84px; font-size: 30px; box-shadow: 0 0 0 0 rgba(6,207,156,.6); transition: box-shadow .1s; }
.call-peer.speaking .avatar { box-shadow: 0 0 0 5px rgba(6,207,156,.7); }
.call-peer .pname { font-size: 14px; }
.call-peer .pstate { font-size: 12px; color: var(--muted); }
.call-actions { display: flex; gap: 24px; padding: 20px 0; }
.call-btn { width: 62px; height: 62px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #fff; }
.call-btn.mute { background: var(--panel-3); }
.call-btn.mute.on { background: #fff; color: #111; }
.call-btn.spk { background: var(--panel-3); }
.call-btn.spk.on { background: #fff; color: #111; }
.call-btn.hangup { background: var(--danger); }

/* gelen çağrı bildirimi */
#incomingCall {
  position: fixed; top: 0; left: 0; right: 0; z-index: 210;
  background: var(--panel-2); box-shadow: var(--shadow);
  display: none; align-items: center; gap: 12px; padding: 14px 16px;
  animation: slidedown .3s;
}
#incomingCall.active { display: flex; }
@keyframes slidedown { from { transform: translateY(-100%); } }
#incomingCall .ic-body { flex: 1; min-width: 0; }
#incomingCall .ic-name { font-weight: 600; }
#incomingCall .ic-sub { font-size: 12.5px; color: var(--muted); }
#incomingCall .ic-accept { width: 46px; height: 46px; border-radius: 50%; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; }
#incomingCall .ic-decline { width: 46px; height: 46px; border-radius: 50%; background: var(--danger); color: #fff; display: flex; align-items: center; justify-content: center; }

/* ---------- Modal / alt sayfa ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 150; background: rgba(0,0,0,.6); display: none; align-items: flex-end; justify-content: center; }
.sheet-backdrop.active { display: flex; }
@media (min-width: 800px) { .sheet-backdrop.active { align-items: center; } }
.sheet {
  width: 100%; max-width: 460px; background: var(--panel);
  border-radius: 16px 16px 0 0; max-height: 85vh; display: flex; flex-direction: column;
  animation: sheetup .25s;
}
@media (min-width: 800px) { .sheet { border-radius: 16px; } }
@keyframes sheetup { from { transform: translateY(30px); opacity: .6; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.sheet-head h3 { font-size: 17px; font-weight: 700; }
.sheet-head .x { color: var(--muted); font-size: 22px; line-height: 1; }
.sheet-body { padding: 12px 0; overflow-y: auto; }
.sheet-body.pad { padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; }

.user-row { display: flex; align-items: center; gap: 12px; padding: 11px 18px; cursor: pointer; }
.user-row:hover { background: var(--panel-2); }
.user-row .urbody { flex: 1; min-width: 0; }
.user-row .urname { font-weight: 600; }
.user-row .ursub { font-size: 12.5px; color: var(--muted); }
.user-row input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); }

.toast-wrap { position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%); z-index: 300; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: #2a3942; color: var(--text); padding: 10px 18px; border-radius: 20px; font-size: 13.5px; box-shadow: var(--shadow); animation: fadein .2s; }
.toast.err { background: #5a2a30; color: #ffb3ba; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } }

.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--panel-2); border-radius: 16px; padding: 5px 12px; font-size: 13px; }
label.inline { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
