/* ============================================================
   Faz 4 — Mesajlar sayfası, özel mesaj ve genel sohbet
   Pencere ve balonlar app.js üretir; yalnızca görünüm.
   Yükseklik için !important kullanılmaz: klavye açılınca app.js
   görünür alana göre satır içi yükseklik verir.
   ============================================================ */

/* ---------- 1) Sohbet penceresi ---------- */
body .ss-modal-root:has(#dmHead) > .ss-chat-modal { height: 100vh; max-height: 100vh; height: 100dvh; max-height: 100dvh; border: 0; border-radius: 0; background: var(--bg) !important; }
@media (min-width: 640px) {
  body .ss-modal-root:has(#dmHead) > .ss-chat-modal {
    height: min(780px, 90vh); height: min(780px, 90dvh); max-height: 90vh; max-height: 90dvh;
    border: 1px solid var(--line); border-radius: 32px;
  }
}
body #dmHead {
  flex: none; gap: 8px; min-height: 68px; margin: 0;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 12px 12px;
  border: 0 !important; border-radius: 0 0 26px 26px;
  background: var(--ui-plum-900) !important; color: #fff;
}
body #dmHead [style*="var(--muted)"] { color: #b8c7dc !important; }
body #dmWho { gap: 9px; }
body #dmWho > span:first-child { padding-left: 6px; font-family: var(--ui-font-display); font-size: 21px; }
body #dmHead button[data-x], body #dmBack, body #dmBackGeneral {
  display: inline-flex; flex: none; width: 40px; height: 40px; align-items: center; justify-content: center;
  margin: 0; padding: 0; border-radius: 50%; background: rgba(255, 255, 255, .12); color: #fff !important;
}
body #dmHead button:active { background: rgba(255, 255, 255, .24); }
body #dmGeneralShortcut { min-height: 36px; padding: 0 14px; border: 0 !important; border-radius: 999px; background: var(--ui-aqua); color: var(--ui-plum-950) !important; font-size: 12px; }
body #dmTyping { color: var(--ui-aqua) !important; white-space: nowrap; }

body .ss-chat-modal #dmBody { flex: 1 1 auto; padding: 16px 12px; background: var(--bg); }

/* ---------- 2) Özel mesaj balonları ---------- */
body #dmMsgs { gap: 4px; }
body #dmMsgs:empty, body #generalMsgs:empty { display: flex; min-height: 220px; align-items: center; justify-content: center; }
body #dmMsgs:empty::before, body #generalMsgs:empty::before {
  content: "Henüz mesaj yok. İlk mesajı sen yaz.";
  max-width: 240px; padding: 16px 20px; border: 1px dashed var(--line); border-radius: 22px 22px 22px 6px;
  background: var(--card); color: var(--muted); font-size: 13px; font-weight: 600; line-height: 1.5; text-align: center;
}
body #dmMsgs [data-dm-message] > div > span:first-child { width: fit-content; max-width: 100%; overflow-wrap: anywhere; padding: 10px 14px; border-radius: 22px; font-size: 14.5px; line-height: 1.45; }
body #dmMsgs [data-dm-message].justify-start > div > span:first-child { border: 1px solid var(--line); border-bottom-left-radius: 6px !important; background: var(--card) !important; }
body #dmMsgs [data-dm-message].justify-end > div > span:first-child { margin-left: auto; border-bottom-right-radius: 6px !important; background: linear-gradient(135deg, #0b2a52, #1c4a86) !important; color: #fff !important; }
body #dmMsgs [data-dm-message].justify-end [data-dm-reactions],
body #dmMsgs [data-dm-message].justify-end [data-dm-reaction-open] { justify-content: flex-end; }
body #dmMsgs [data-dm-message].justify-end > div > div:last-child { display: flex; justify-content: flex-end; }
body #dmMsgs [data-dm-message].justify-end [data-dm-reaction-picker] { right: 0; left: auto; }
body #dmMsgs [data-dm-message] > div > span:first-child > span { font-size: 10.5px; white-space: nowrap; }
body #dmMsgs [data-dm-tick] { color: var(--ui-aqua); font-weight: 800; letter-spacing: -.12em; opacity: 1; }
body #dmMsgs [data-dm-reactions]:empty { display: none; }
body #dmMsgs [data-dm-reaction-open] { position: relative; min-width: 28px; min-height: 24px; color: var(--muted); opacity: .75; }
body #dmMsgs [data-dm-reaction-open]::after { content: ""; position: absolute; inset: -2px -12px -8px; }

/* ---------- 3) Genel sohbet balonları ---------- */
body #generalMsgs { gap: 14px; }
body #generalMsgs [data-general-message] > .flex-1 > div.w-fit { border-radius: 6px 22px 22px 22px; background: var(--card); font-size: 14px; }
body #generalMsgs [data-general-message]:has(> .flex-1 > div.w-fit[style*="color-mix"]) { flex-direction: row-reverse; }
body #generalMsgs [data-general-message]:has(> .flex-1 > div.w-fit[style*="color-mix"]) > a { display: none; }
body #generalMsgs [data-general-message] > .flex-1:has(> div.w-fit[style*="color-mix"]) { display: flex; flex-direction: column; align-items: flex-end; }
body #generalMsgs [data-general-message] > .flex-1 > div.w-fit[style*="color-mix"] { border-color: transparent !important; border-radius: 22px 6px 22px 22px; background: linear-gradient(135deg, #0b2a52, #1c4a86) !important; color: #fff; }
body #generalMsgs [data-general-message] > .flex-1 > div.w-fit[style*="color-mix"] a { color: #fff !important; text-decoration: underline; }
body #generalMsgs [data-general-message] > .flex-1 > div:last-child { flex-wrap: wrap; row-gap: 4px; }
body #generalMsgs [data-general-reply], body #generalMsgs [data-general-pin], body #generalMsgs [data-general-delete] { min-height: 26px; }
body #generalMsgs .border-l-2 { width: fit-content; max-width: 88%; border-color: var(--ui-rose) !important; border-radius: 0 12px 12px 0; background: var(--card) !important; }

/* ---------- 4) Yazma alanı ---------- */
body .ss-chat-modal #dmFoot { flex: none; margin: 0; padding: 10px 10px calc(env(safe-area-inset-bottom, 0px) + 10px); border: 0 !important; border-radius: 26px 26px 0 0; background: var(--card); box-shadow: 0 -10px 30px -24px rgba(3, 23, 50, .55); }
body .ss-chat-modal #dmFoot:empty { display: none; }
body .ss-chat-modal #dmFoot > div:last-child, body .ss-chat-modal #cmBox > div:last-child { gap: 6px; }
body #dmInput, body #generalInput, body #cmInput { flex: 1 1 0%; width: 0; min-width: 0; min-height: 46px; border-radius: 23px; background: var(--bg); font-size: 16px; }
body #generalInput { padding-top: 12px; padding-bottom: 12px; line-height: 20px; }
body #generalInput::placeholder { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body #dmInput:focus, body #generalInput:focus, body #cmInput:focus { border-color: var(--accent) !important; }
body .ss-chat-modal #dmFoot label, body .ss-chat-modal [id$="EmojiButton"], body .ss-chat-modal [id$="EmojiButton"] + div[id$="Panel"] { flex: none; }
body .ss-chat-modal #dmFoot label, body .ss-chat-modal button[id$="Button"][aria-label="Emoji ekle"] { width: 46px; height: 46px; border-radius: 50%; }
body .ss-chat-modal div[id$="Panel"] { max-width: calc(100vw - 72px); }
body #dmSend, body #generalSend, body #cmSend {
  position: relative; display: inline-flex; flex: none; width: 46px; height: 46px; align-items: center; justify-content: center;
  padding: 0; border-radius: 18px 18px 6px 18px; font-size: 0;
}
body #dmSend::before, body #generalSend::before, body #cmSend::before {
  content: ""; width: 20px; height: 20px; background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M2.5 3.2 22 12 2.5 20.8 5.6 13.2 14 12 5.6 10.8Z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M2.5 3.2 22 12 2.5 20.8 5.6 13.2 14 12 5.6 10.8Z'/%3E%3C/svg%3E") center / contain no-repeat;
}
body #dmSend:disabled, body #generalSend:disabled { opacity: .5; }
body #dmNew { min-height: 50px; border-radius: 999px; }
body #dmMediaInfo, body #generalMediaInfo, body #generalReply { overflow-wrap: anywhere; }

/* ---------- 5) Konuşma listesi ve Mesajlar sayfası ---------- */
body #dmBody [data-open], body #threadList [data-open] { min-height: 70px; margin: 0; padding: 9px 8px; border: 0; border-radius: 16px; background: transparent; transition: background-color .15s ease, transform .15s ease; }
body #threadList { gap: 2px; }
body #dmBody [data-open]:active, body #threadList [data-open]:active { background: var(--accent-soft); transform: scale(.985); }
@media (hover:hover) and (pointer:fine) { body #dmBody [data-open]:hover, body #threadList [data-open]:hover { background: var(--card); } }
body #dmBody [data-open] > :first-child, body #threadList [data-open] > :first-child { width: 54px; height: 54px; flex: none; border-radius: 50% !important; box-shadow: 0 0 0 2px var(--bg), 0 0 0 3.5px var(--line); }
body [data-open]:has(> span.rounded-full.text-white) > :first-child { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--ui-rose) !important; }
body [data-open]:has(> span.rounded-full.text-white) .block.truncate { color: var(--ink) !important; font-weight: 700; }
body [data-open] > span.rounded-full.text-white { min-width: 22px; background: var(--ui-rose) !important; color: #fff !important; text-align: center; }
body #generalChatOpen, body #openGeneralChat { position: relative; min-height: 78px; overflow: hidden; border: 0 !important; border-radius: 22px; background: linear-gradient(115deg, #031732 35%, #123a6b 75%, #031732) !important; color: #fff; box-shadow: none; }
body #generalChatOpen [style*="var(--muted)"], body #openGeneralChat [style*="var(--muted)"] { color: #dde6f2 !important; }
body #generalChatOpen > span:first-child, body #openGeneralChat > span:first-child { width: 52px; height: 52px; border-radius: 50%; box-shadow: 0 0 0 2px #031732, 0 0 0 4px var(--ui-aqua); }
body #openGeneralChat::after { content: ""; width: 10px; height: 10px; flex: none; margin-right: 6px; border-radius: 50%; background: var(--ui-aqua); animation: ui-pulse 1.8s ease-out infinite; }
@keyframes ui-pulse { 0% { box-shadow: 0 0 0 0 rgba(252, 177, 64, .6); } 100% { box-shadow: 0 0 0 11px rgba(252, 177, 64, 0); } }
body [data-general-badge] { background: var(--ui-rose) !important; }
body #openGeneralChat { margin-top: 12px; }
body #ssSearchInline { min-height: 46px; border-color: transparent !important; border-radius: 14px; background: var(--card) !important; font-size: 16px; }
body #ssSearchInline:focus { border-color: var(--accent) !important; }
body #ssSearchResults { top: 52px; border-radius: 16px; }
body #openGeneralChat ~ h2 { margin-bottom: 4px; font-size: 18px; font-weight: 800; }
body #threadList > p { padding-right: 18px; padding-left: 18px; border-radius: 22px; background: var(--card); }
body main div > section:has(> div > a[href*="kullanici.php?u="]) { padding: 10px 12px; border: 0 !important; border-radius: 16px !important; }
body main section:has(> a[href*="giris.php?next=mesajlar"]) { border-radius: 24px !important; padding: 28px 20px; }
body main section:has(> a[href*="giris.php?next=mesajlar"]) h2 { font-size: 23px; line-height: 1.15; }
body main section:has(> a[href*="giris.php?next=mesajlar"]) > a { border-radius: 999px; padding-right: 26px; padding-left: 26px; }
/* Kullanıcı adı olmayan misafirde boş kimlik kartı gösterilmez */
body section:has(> div > a[href$="kullanici.php?u="]) { display: none; }

/* ---------- 6) Canlı mesaj hissi ---------- */
@keyframes ui-msg-in { from { opacity: 0; translate: 0 8px; } to { opacity: 1; translate: 0 0; } }
body #dmMsgs [data-dm-message]:last-child, body #generalMsgs [data-general-message]:last-child { animation: ui-msg-in .24s ease-out backwards; }
/* Sohbet duvar kağıdı: logo, buzlu cam gibi hafifçe arkadan görünür (yalnızca mesaj ekranları) */
body .ss-chat-modal #dmBody:has(#dmMsgs, #generalMsgs) {
  background: linear-gradient(rgba(243, 246, 250, .86), rgba(243, 246, 250, .86)), url("img/chat-wallpaper.jpg") center / cover no-repeat, #031732;
}
html[data-ss-mode='dark'] body .ss-chat-modal #dmBody:has(#dmMsgs, #generalMsgs) {
  background: linear-gradient(rgba(4, 16, 31, .78), rgba(4, 16, 31, .78)), url("img/chat-wallpaper.jpg") center / cover no-repeat, #031732;
}
body #generalMsgs:empty::before, body #dmMsgs:empty::before { background: var(--card); }
/* Duvar kağıdı üstünde isim, saat ve düğmeler okunaklı kalsın */
body .ss-chat-modal #generalMsgs [data-general-message] [style*="var(--muted)"] { color: var(--ink) !important; opacity: .72; }
@media (min-width: 900px) { body .ss-modal-root:has(#dmHead) > .ss-chat-modal { width: min(640px, 92vw); max-width: 640px; } }
@media (prefers-reduced-motion: reduce) { body #openGeneralChat::after, body #dmMsgs [data-dm-message]:last-child, body #generalMsgs [data-general-message]:last-child { animation: none; } }
@supports not (inset: 0) {
  body #dmMsgs [data-dm-reaction-open]::after { top: -2px; right: -12px; bottom: -8px; left: -12px; }
}
