/* MilyonPark WhatsApp Paneli — WhatsApp Web gorsel diline yakin tema */

:root {
  --app-bg: #d1d7db;
  --panel: #ffffff;
  --header: #f0f2f5;
  --chat-bg: #efeae2;
  --bubble-in: #ffffff;
  --bubble-out: #d9fdd3;
  --text: #111b21;
  --muted: #667781;
  --divider: #e9edef;
  --accent: #00a884;
  --accent-strong: #008069;
  --hover: #f5f6f6;
  --active: #f0f2f5;
  --badge: #25d366;
  --danger: #d93025;
  --shadow: 0 1px 2px rgba(11, 20, 26, .12);
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --app-bg: #0b141a;
    --panel: #111b21;
    --header: #202c33;
    --chat-bg: #0b141a;
    --bubble-in: #202c33;
    --bubble-out: #005c4b;
    --text: #e9edef;
    --muted: #8696a0;
    --divider: #222d34;
    --accent: #00a884;
    --accent-strong: #00a884;
    --hover: #202c33;
    --active: #2a3942;
    --badge: #00a884;
    --danger: #f28b82;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }

/* hidden ozniteligi, .overlay/.app uzerindeki display kurallarini yenmelidir.
   Aksi halde giris/QR/bekleme/uygulama ekranlari ust uste biner. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Noto Sans", sans-serif;
  background: var(--app-bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* ---------------- Kaplama ekranlari (giris / QR / bekleme) ---------------- */

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--app-bg);
  z-index: 20;
}

.card {
  width: min(400px, 100%);
  background: var(--panel);
  border-radius: 12px;
  padding: 34px 30px;
  box-shadow: var(--shadow);
  text-align: center;
}

.card h1 {
  margin: 0 0 8px;
  font-size: 21px;
  font-weight: 600;
}

.card p { margin: 0 0 18px; font-size: 14px; }

.card-mark {
  width: 60px;
  height: 60px;
  margin: 0 auto 16px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
}

.field {
  display: block;
  text-align: left;
  margin-bottom: 14px;
}

.field span {
  display: block;
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  padding: 11px 13px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  background: var(--header);
  border: 1px solid transparent;
  border-radius: var(--radius);
  outline: none;
}

.field input:focus {
  border-color: var(--accent);
  background: var(--panel);
}

.btn-primary {
  width: 100%;
  padding: 12px;
  font-size: 15px;
  font-family: inherit;
  font-weight: 500;
  color: #fff;
  background: var(--accent-strong);
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
}

.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled { opacity: .6; cursor: default; }

.btn-ghost {
  margin-top: 16px;
  padding: 9px 16px;
  font-size: 14px;
  font-family: inherit;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--divider);
  border-radius: var(--radius);
  cursor: pointer;
}

.btn-ghost:hover { background: var(--hover); }

.error {
  color: var(--danger);
  font-size: 13.5px;
  margin: 0 0 12px !important;
}

.qr-frame {
  background: #fff;
  padding: 14px;
  border-radius: var(--radius);
  display: inline-block;
  margin-bottom: 14px;
  min-height: 200px;
  min-width: 200px;
}

.qr-frame img { display: block; width: 260px; height: 260px; }

.spinner {
  width: 34px;
  height: 34px;
  margin: 0 auto 18px;
  border: 3px solid var(--divider);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 3s; }
}

/* ---------------- Ana yerlesim ---------------- */

.app {
  display: grid;
  grid-template-columns: minmax(300px, 30%) 1fr;
  height: 100%;
  max-width: 1600px;
  margin: 0 auto;
  background: var(--panel);
  /* Grid satiri icerikle birlikte buyumesin; ic kaydirma buna bagli. */
  overflow: hidden;
}

/* ---------------- Kenar cubugu ---------------- */

.sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  /* Grid ogesinin varsayilan min-height:auto degeri, icerik uzun oldugunda
     kutunun buyumesine ve ic kaydirmanin devre disi kalmasina yol acar. */
  min-height: 0;
  background: var(--panel);
  border-right: 1px solid var(--divider);
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px;
  background: var(--header);
  flex: 0 0 auto;
}

.me { display: flex; align-items: center; gap: 12px; min-width: 0; }
.me-text { display: flex; flex-direction: column; min-width: 0; }
.me-text strong { font-size: 15px; font-weight: 600; }

.status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--badge);
  flex: 0 0 auto;
}

.status.offline .dot { background: var(--danger); }
.status.pending .dot { background: #f0a500; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  flex: 0 0 auto;
}

.icon-btn:hover { background: var(--hover); color: var(--text); }

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: var(--accent-strong);
  flex: 0 0 auto;
  text-transform: uppercase;
  user-select: none;
}

.avatar-me { background: var(--accent-strong); }

.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 12px;
  padding: 0 12px;
  background: var(--header);
  border-radius: var(--radius);
  color: var(--muted);
  flex: 0 0 auto;
}

.search-wrap input {
  flex: 1;
  min-width: 0;
  padding: 9px 0;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: transparent;
  border: 0;
  outline: none;
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.list-empty {
  padding: 28px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.chat-row {
  display: flex;
  align-items: center;
  gap: 13px;
  width: 100%;
  padding: 11px 16px;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--divider);
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
}

.chat-row:hover { background: var(--hover); }
.chat-row[aria-selected="true"] { background: var(--active); }

.chat-row-body { flex: 1; min-width: 0; }

.chat-row-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.chat-row-name {
  font-size: 15.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-row-time { font-size: 11.5px; color: var(--muted); flex: 0 0 auto; }

.chat-row-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
}

.chat-row-preview {
  font-size: 13.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--badge);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

/* ---------------- Sohbet paneli ---------------- */

.chat {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  /* min-height:0 olmadan mesaj listesi kaydirilmaz, kutu ekrani tasar. */
  min-height: 0;
  background: var(--chat-bg);
}

/* WhatsApp'in desenli arka planina yakin, hafif bir doku */
.chat::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: .045;
  pointer-events: none;
  background-image: radial-gradient(circle at 20% 30%, currentColor 1.2px, transparent 1.3px),
                    radial-gradient(circle at 70% 65%, currentColor 1.2px, transparent 1.3px);
  background-size: 46px 46px, 62px 62px;
}

.chat-placeholder {
  margin: auto;
  padding: 30px;
  text-align: center;
  max-width: 420px;
  position: relative;
}

.placeholder-mark { color: var(--muted); opacity: .45; margin-bottom: 10px; }
.chat-placeholder h2 { margin: 0 0 8px; font-size: 20px; font-weight: 500; }

.chat-open {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  position: relative;
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 9px 16px;
  background: var(--header);
  border-bottom: 1px solid var(--divider);
  flex: 0 0 auto;
}

.chat-head-text { display: flex; flex-direction: column; min-width: 0; }
.chat-head-text strong { font-size: 16px; font-weight: 500; }

.back-btn { display: none; }

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 6% 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

/* Az mesaj varken WhatsApp gibi alta yaslansin; tasma halinde
   kaydirma dogru calismaya devam eder (justify-content: flex-end
   kullanilsaydi tasan icerik ustten kirpilirdi). */
.messages > *:first-child { margin-top: auto; }

.day-sep {
  align-self: center;
  margin: 12px 0;
  padding: 5px 12px;
  border-radius: 7px;
  background: var(--header);
  color: var(--muted);
  font-size: 12.5px;
  box-shadow: var(--shadow);
}

.bubble {
  position: relative;
  max-width: min(65%, 520px);
  padding: 6px 9px 8px 9px;
  border-radius: 7.5px;
  background: var(--bubble-in);
  box-shadow: var(--shadow);
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  font-size: 14.2px;
}

.bubble.out { align-self: flex-end; background: var(--bubble-out); }
.bubble.in { align-self: flex-start; }

.bubble.first-in { border-top-left-radius: 0; margin-top: 8px; }
.bubble.first-out { border-top-right-radius: 0; margin-top: 8px; }

.bubble-author {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 2px;
}

.bubble-meta {
  float: right;
  margin: 6px 0 -4px 10px;
  font-size: 11px;
  color: var(--muted);
  user-select: none;
}

.bubble-media {
  display: inline-block;
  margin-bottom: 3px;
  padding: 3px 7px;
  border-radius: 5px;
  background: rgba(0, 0, 0, .06);
  font-size: 12.5px;
  color: var(--muted);
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 10px 16px;
  background: var(--header);
  flex: 0 0 auto;
}

.composer textarea {
  flex: 1;
  min-width: 0;
  max-height: 120px;
  padding: 10px 13px;
  font-size: 15px;
  font-family: inherit;
  line-height: 1.35;
  color: var(--text);
  background: var(--panel);
  border: 0;
  border-radius: var(--radius);
  outline: none;
  resize: none;
}

.send-btn {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  color: #fff;
  background: var(--accent-strong);
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  flex: 0 0 auto;
}

.send-btn:disabled { opacity: .45; cursor: default; }

.composer-error {
  margin: 0;
  padding: 6px 16px 10px;
  background: var(--header);
  color: var(--danger);
  font-size: 13px;
}

/* ---------------- Duyarli yerlesim ---------------- */

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; }
  .app[data-view="chat"] .sidebar { display: none; }
  .app[data-view="list"] .chat { display: none; }
  .back-btn { display: grid; }
  .bubble { max-width: 82%; }
  .messages { padding: 14px 12px 10px; }
}
