/* ===============================
   CHAT PAGE LAYOUT (FIXED)
================================ */

.chat-page{
  padding: 20px 0;
}

/* Desktop: 2 column */
.chat-layout{
  display: grid;
  grid-template-columns: 320px 1fr;
  min-height: calc(100vh - 140px);
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0,0,0,0.08);
}

/* ===============================
   SIDEBAR (CHAT LIST)
================================ */

.chat-sidebar{
  border-right: 1px solid #eee;
  background: #fafafa;
  flex-direction: column;
  min-width: 0;
}

.chat-sidebar-header{
  padding: 16px;
  font-weight: 700;
  border-bottom: 1px solid #eee;
}

.chat-list{
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.chat-item{
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  border-bottom: 1px solid #f1f1f1;
  transition: 0.2s;
  min-width: 0;
}

.chat-item:hover{ background:#f3f4f6; }
.chat-item.active{ background:#e8f0ff; }

.chat-avatar{
  width: 46px;
  height: 46px;
  border-radius: 50%;
  flex: 0 0 46px;
}

.chat-item-info{
  flex: 1;
  min-width: 0;
}

.chat-item-title{
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-last{
  font-size: 13px;
  color: #666;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-time{
  font-size: 12px;
  color: #888;
  white-space: nowrap;
  margin-left: 8px;
}

/* ===============================
   MAIN CHAT AREA
================================ */

.chat-main{
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-header{
  padding: 14px 18px;
  border-bottom: 1px solid #eee;
  display: flex;
  align-items: center;
  gap: 12px;
  background: #fff;
}

.chat-header-user{
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.chat-title{
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-sub{
  font-size: 13px;
  color: #888;
}

/* ===============================
   MESSAGES
================================ */

.chat-messages{
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px;
  background: #f4f6fa;
}

/* message wrapper */
.msg{
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  max-width: 72%;
}

/* left/right alignment */
.msg.me{
  margin-left: auto;
  text-align: right;
}
.msg.them{
  margin-right: auto;
  text-align: left;
}

/* bubble */
.msg-bubble{
  padding: 10px 14px;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.05);
  word-break: break-word;
  overflow-wrap: anywhere;
}

.msg.me .msg-bubble{
  background:#3b82f6;
  color:#fff;
}

.msg-time{
  font-size: 11px;
  color: #888;
  margin-top: 4px;
}

/* ===============================
   INPUT AREA
================================ */

.chat-input{
  border-top: 1px solid #eee;
  padding: 12px;
  background: #fff;
}

#chatForm{
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

#chatText{
  flex: 1;
  min-width: 0;
  resize: none;
  border: 1px solid #ddd;
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
  outline: none;
  line-height: 1.35;
  max-height: 140px;
  overflow-y: auto;
}

#chatText:focus{
  border-color: rgba(59,130,246,.55);
  box-shadow: 0 0 0 4px rgba(59,130,246,.12);
}

#chatSendBtn{
  background: #3b82f6;
  color: #fff;
  border: none;
  height: 42px;
  padding: 0 18px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 700;
  white-space: nowrap;
}

#chatSendBtn:hover{ background:#2563eb; }

/* ===============================
   EMPTY STATES
================================ */

.chat-placeholder,
.chat-empty{
  padding: 40px;
  text-align: center;
  color: #777;
}

/* ===============================
   SCROLLBAR (optional)
================================ */
.chat-messages::-webkit-scrollbar,
.chat-list::-webkit-scrollbar{ width: 6px; }
.chat-messages::-webkit-scrollbar-thumb,
.chat-list::-webkit-scrollbar-thumb{
  background:#ddd;
  border-radius:10px;
}

/* ===============================
   MOBILE
   ✅ breakpoint küçültüldü (desktop bozulmasın)
   Mobilde chat listesi üstte YATAY şerit olur
================================ */

/* ===============================
   MOBILE FIX (boşluk / stretch sorunu)
================================ */
@media (max-width: 768px){

  /* ✅ 2 satır: üstte list (auto), altta sohbet (1fr) */
  .chat-layout{
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    align-content: start;
    min-height: calc(100vh - 140px);
  }

  /* ✅ sidebar artık yüksekliği doldurmasın */
  .chat-sidebar{
    align-self: start;
    height: auto;
    border-right: none;
    border-bottom: 1px solid #eee;
    background: #fff;
    display: block; /* flex kapatıyoruz ki flex:1 şişirmesin */
  }

  .chat-sidebar-header{
    padding: 12px 14px;
    border-bottom: 1px solid #eee;
    background: #fff;
  }

  /* ✅ liste yatay kayar, kendi yüksekliği kadar yer kaplar */
  .chat-list{
    display: flex;
    gap: 10px;
    padding: 10px 12px 12px;
    overflow-x: auto;
    overflow-y: hidden;

    /* önemli: eski flex/height etkilerini sıfırla */
    flex: 0 0 auto;
    min-height: auto;
    height: auto;
  }

  .chat-list::-webkit-scrollbar{ height: 0; }
  .chat-list{ scrollbar-width: none; }

  /* kartlar */
  .chat-item{
    flex: 0 0 220px;
    border: 1px solid #f1f1f1;
    border-radius: 12px;
    background: #fafafa;
    margin: 0;
  }

  .chat-item-time{
    display: none; /* mobilde taşırıyor */
  }

  /* ✅ chat-main kalan alanı doldursun */
  .chat-main{
    min-height: 0;
    height: auto;
  }

  .chat-messages{
    padding: 12px;
    min-height: 0;
  }

  .msg{
    max-width: 88%;
  }
}

@media (max-width: 420px){
  .chat-item{ flex-basis: 200px; }
  #chatSendBtn{ padding: 0 14px; }
}

.chat-avatar{
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
  flex: 0 0 42px;
}

.chat-item{
  gap: 12px;
}

.chat-item-time{
  white-space: nowrap;
  font-size: 12px;
  opacity: .7;
}