:root {
  --accent: #4b3fc4;
  --accent-2: #6a5ff0;
  --accent-soft: #ece9ff;
  --bg: #f3f2f8;
  --panel: #ffffff;
  --panel-2: #f7f6fb;
  --text: #1d1b2a;
  --muted: #6e6a85;
  --line: #e5e2f0;
  --mine: #dcd7ff;
  --theirs: #ffffff;
  --chat-bg: #eceaf4;
  --read: #2f7de1;
  --danger: #d23c4b;
  --green: #1fa463;
  --shadow: 0 1px 2px rgba(20, 16, 60, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --accent: #8b7ff7;
    --accent-2: #a69cff;
    --accent-soft: #2c2850;
    --bg: #12111a;
    --panel: #1b1a26;
    --panel-2: #22202f;
    --text: #ecebf5;
    --muted: #9b97b3;
    --line: #2d2b3d;
    --mine: #3a3378;
    --theirs: #262435;
    --chat-bg: #15141e;
    --read: #63a8ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-tap-highlight-color: transparent; overflow: hidden;
}
button, input, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.accent { color: var(--accent) !important; }
.grow { flex: 1; min-width: 0; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Butonlar & formlar ---------- */
.btn {
  border: 1px solid var(--line); background: var(--panel-2); border-radius: 10px;
  padding: 10px 14px; cursor: pointer; font-weight: 600; text-decoration: none; display: inline-block; text-align: center;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.block { display: block; width: 100%; margin: 8px 0; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .6; cursor: wait; }
.icon-btn { border: 0; background: none; padding: 8px; border-radius: 50%; cursor: pointer; color: var(--muted); display: inline-flex; }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.input, .form input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); outline: none;
}
.input:focus, .form input:focus { border-color: var(--accent); }
.form { display: flex; flex-direction: column; gap: 10px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.err { color: var(--danger); min-height: 1.2em; text-align: center; }
.note { font-size: 12.5px; color: var(--muted); background: var(--panel-2); padding: 8px 10px; border-radius: 8px; margin: 0; }

/* ---------- Giriş ---------- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 16px; overflow: auto; height: 100dvh; }
.auth-card { width: 100%; max-width: 380px; background: var(--panel); border-radius: 18px; padding: 24px; box-shadow: 0 10px 40px rgba(40, 30, 120, .12); }
.brand { display: flex; align-items: center; gap: 12px; justify-content: center; }
.brand h1 { margin: 0; font-size: 28px; }
.tabs { display: flex; background: var(--panel-2); border-radius: 10px; padding: 4px; margin: 16px 0; }
.tab { flex: 1; border: 0; background: none; padding: 8px; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--muted); }
.tab.active { background: var(--panel); color: var(--accent); box-shadow: var(--shadow); }

/* ---------- Yerleşim ---------- */
.app { display: flex; height: 100dvh; max-width: 1500px; margin: 0 auto; background: var(--panel); }
.sidebar { width: 360px; min-width: 300px; border-right: 1px solid var(--line); display: flex; flex-direction: column; background: var(--panel); }
.pane { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--chat-bg); }
.side-head, .chat-head {
  display: flex; align-items: center; gap: 6px; padding: 8px 10px; min-height: 60px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  padding-top: max(8px, env(safe-area-inset-top));
}
.me-btn { display: flex; align-items: center; gap: 10px; border: 0; background: none; cursor: pointer; padding: 4px 8px 4px 4px; border-radius: 24px; min-width: 0; }
.me-btn:hover { background: var(--panel-2); }
.me-btn b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conn-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--danger); margin-right: 4px; }
.conn-dot.on { background: var(--green); }
.search { padding: 8px 10px; }
.search input { width: 100%; padding: 9px 14px; border-radius: 20px; border: 1px solid var(--line); background: var(--panel-2); outline: none; }
.req-banner { margin: 0 10px 6px; padding: 10px 12px; border: 0; border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-weight: 600; cursor: pointer; text-align: left; }
.chat-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.chat-item { display: flex; gap: 12px; padding: 10px 14px; cursor: pointer; align-items: center; }
.chat-item:hover { background: var(--panel-2); }
.chat-item.active { background: var(--accent-soft); }
.ci-body { flex: 1; min-width: 0; border-bottom: 1px solid var(--line); padding-bottom: 10px; }
.ci-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.ci-title, .ci-prev { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ci-prev { color: var(--muted); font-size: 14px; flex: 1; }
.ci-time { color: var(--muted); font-size: 12px; flex-shrink: 0; }
.badge { background: var(--accent); color: #fff; border-radius: 12px; min-width: 22px; height: 22px; padding: 0 6px; font-size: 12px; display: grid; place-items: center; font-weight: 700; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.avatar { border-radius: 50%; display: inline-grid; place-items: center; color: #fff; font-weight: 700; flex-shrink: 0; user-select: none; }
.av-wrap { position: relative; display: inline-flex; }
.online-dot { position: absolute; right: 1px; bottom: 1px; width: 12px; height: 12px; border-radius: 50%; background: var(--green); border: 2px solid var(--panel); }

.placeholder { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 20px; }
.placeholder h2 { margin: 12px 0 4px; }
.chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-head .back { display: none; }
.chat-title-btn { flex: 1; display: flex; align-items: center; gap: 10px; border: 0; background: none; cursor: pointer; text-align: left; min-width: 0; padding: 2px; }
.titles { display: flex; flex-direction: column; min-width: 0; }
.titles b, .titles small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.titles small { color: var(--muted); }

/* ---------- Mesajlar ---------- */
.messages { flex: 1; overflow-y: auto; padding: 12px 6% 16px; display: flex; flex-direction: column; gap: 3px; overscroll-behavior: contain; }
.day-sep, .sys { text-align: center; margin: 10px 0; }
.day-sep span, .sys span { background: var(--panel); color: var(--muted); font-size: 12.5px; padding: 4px 12px; border-radius: 8px; box-shadow: var(--shadow); display: inline-block; }
.msg { display: flex; }
.msg.mine { justify-content: flex-end; }
.bubble {
  max-width: min(75%, 560px); padding: 6px 9px 4px; border-radius: 12px; background: var(--theirs);
  box-shadow: var(--shadow); position: relative; word-wrap: break-word; overflow-wrap: anywhere;
}
.msg.mine .bubble { background: var(--mine); border-top-right-radius: 4px; }
.msg.theirs .bubble { border-top-left-radius: 4px; }
.sender { display: block; font-size: 13px; margin-bottom: 2px; }
.text { white-space: pre-wrap; }
.text a { color: var(--read); }
.meta { float: right; font-size: 11px; color: var(--muted); margin: 6px 0 0 10px; display: inline-flex; gap: 3px; align-items: center; position: relative; top: 2px; }
.tick { font-size: 11px; letter-spacing: -3px; padding-right: 3px; }
.tick.read { color: var(--read); font-weight: 700; }
.media { margin: 2px -5px 0; border-radius: 9px; overflow: hidden; min-height: 60px; min-width: 120px; background: rgba(0, 0, 0, .06); display: grid; place-items: center; }
.media.loading::after { content: '🔓 açılıyor…'; color: var(--muted); font-size: 12px; position: absolute; }
.media-img { display: block; max-width: 100%; max-height: 360px; width: auto; height: auto; cursor: zoom-in; }
.voice { display: flex; align-items: center; gap: 6px; }
.voice audio { height: 36px; max-width: 240px; }
.file-chip { display: flex; gap: 10px; align-items: center; border: 0; background: rgba(0, 0, 0, .05); padding: 8px 12px; border-radius: 10px; cursor: pointer; text-align: left; width: 100%; }
.file-chip.busy { opacity: .6; cursor: progress; }
.fi { font-size: 26px; }
.fn { display: flex; flex-direction: column; min-width: 0; }
.fn b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px; }
.fn small { color: var(--muted); }

.upload-bar { display: flex; gap: 10px; align-items: center; padding: 6px 14px; background: var(--panel); font-size: 13px; border-top: 1px solid var(--line); }
.upload-bar progress { flex: 1; accent-color: var(--accent); }

/* ---------- Yazma alanı ---------- */
.composer { background: var(--panel-2); padding: 8px 10px; padding-bottom: max(8px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.compose-normal, .compose-rec { display: flex; align-items: flex-end; gap: 6px; }
.compose-rec { align-items: center; min-height: 44px; padding-left: 4px; }
#msgInput {
  flex: 1; resize: none; border: 1px solid var(--line); border-radius: 22px; padding: 10px 16px; max-height: 140px;
  background: var(--panel); outline: none; line-height: 1.35; overflow-y: hidden;
}
#msgInput:focus { border-color: var(--accent); }
.send-btn { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; display: grid; place-items: center; cursor: pointer; flex-shrink: 0; }
.send-btn .i-mic { display: none; }
.send-btn.mic-mode .i-mic { display: block; }
.send-btn.mic-mode .i-send { display: none; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }

/* ---------- Menü, görüntüleyici, bildirim ---------- */
.ctx { position: fixed; z-index: 60; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 30px rgba(0, 0, 0, .18); padding: 4px; min-width: 160px; }
.ctx button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 10px 12px; border-radius: 6px; cursor: pointer; }
.ctx button:hover { background: var(--panel-2); }
.viewer { position: fixed; inset: 0; z-index: 70; background: rgba(0, 0, 0, .92); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 16px; }
.viewer img { max-width: 100%; max-height: 85dvh; object-fit: contain; }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: #2b2840; color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 90; max-width: calc(100% - 32px); text-align: center; box-shadow: 0 6px 24px rgba(0, 0, 0, .25); }

/* ---------- Modal ---------- */
.modal-wrap { position: fixed; inset: 0; background: rgba(15, 12, 35, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border-radius: 16px; width: 100%; max-width: 440px; max-height: 88dvh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.modal header { display: flex; justify-content: space-between; align-items: center; padding: 12px 12px 12px 18px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 12px 18px 18px; overflow-y: auto; }
.modal h4 { margin: 16px 0 6px; }
.pick-list { list-style: none; margin: 8px 0; padding: 0; }
.pick { display: flex; gap: 10px; align-items: center; padding: 8px; border-radius: 10px; cursor: pointer; }
.pick:hover { background: var(--panel-2); }
.pick.sel { background: var(--accent-soft); }
.pick .check { color: var(--accent); font-weight: 700; width: 20px; }
.pad { padding: 10px; }
.tag { background: var(--accent-soft); color: var(--accent); padding: 2px 8px; border-radius: 8px; }
.profile { text-align: center; }
.profile h3 { margin: 8px 0 0; }
.code { font-family: ui-monospace, Consolas, monospace; background: var(--panel-2); padding: 10px; border-radius: 10px; text-align: center; letter-spacing: 1px; word-spacing: 6px; line-height: 1.8; }
details { margin: 12px 0; }
summary { cursor: pointer; font-weight: 600; padding: 6px 0; }
code { font-family: ui-monospace, Consolas, monospace; }

/* ---------- Arama ---------- */
.call { position: fixed; inset: 0; z-index: 80; background: linear-gradient(160deg, #2a2266, #120f2b); color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: max(40px, env(safe-area-inset-top)) 16px max(32px, env(safe-area-inset-bottom)); }
.remote-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: none; background: #000; }
.local-video { position: absolute; right: 16px; top: max(16px, env(safe-area-inset-top)); width: 28vw; max-width: 200px; border-radius: 12px; display: none; z-index: 2; background: #000; transform: scaleX(-1); }
.call.video .remote-video, .call.video .local-video { display: block; }
.call-info { position: relative; z-index: 1; text-align: center; display: flex; flex-direction: column; align-items: center; }
.call.video .call-info { background: rgba(0, 0, 0, .35); border-radius: 14px; padding: 8px 16px; }
.call.video .call-info #callAvatar { display: none; }
.call-info h2 { margin: 12px 0 4px; }
.call-actions { position: relative; z-index: 1; display: flex; gap: 22px; }
.round { width: 62px; height: 62px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .18); color: #fff; display: grid; place-items: center; cursor: pointer; }
.round svg { width: 26px; height: 26px; }
.round.off { background: #fff; color: #222; }
.round.green { background: var(--green); }
.round.red { background: var(--danger); }
.round.red svg { transform: rotate(135deg); }

/* ---------- Mobil ---------- */
@media (max-width: 760px) {
  .sidebar { width: 100%; min-width: 0; border-right: 0; }
  .pane { display: none; }
  .app.show-chat .sidebar { display: none; }
  .app.show-chat .pane { display: flex; }
  .chat-head .back { display: inline-flex; }
  .messages { padding: 10px 10px 14px; }
  .bubble { max-width: 85%; }
  #placeholder { display: none; }
}
