:root {
  --bg: #f5f4f2;
  --surface: #ffffff;
  --surface-2: #faf9f7;
  --border: #e6e2dd;
  --text: #1f1b1d;
  --muted: #6f6970;
  --accent: #8a1c4a;
  --accent-soft: #f6e8ee;
  --accent-text: #ffffff;
  --ok: #2e9e6a;
  --warn: #b7791f;
  --danger: #c0434f;
  --bubble-in: #ffffff;
  --bubble-out: #f3e6ec;
  --chat-bg: #efece8;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 4px 16px rgb(0 0 0 / 0.05);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141214;
    --surface: #1c191c;
    --surface-2: #221e22;
    --border: #322c31;
    --text: #efe9ec;
    --muted: #a59ca2;
    --accent: #d0588c;
    --accent-soft: #3a1f2c;
    --accent-text: #1a0d13;
    --bubble-in: #262126;
    --bubble-out: #3a2330;
    --chat-bg: #171417;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

/* ---------- Ortak bileşenler ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 7px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; }

input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], input[type=url], input[type=tel], select, textarea {
  width: 100%; border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 8px 10px;
}
textarea { resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 1px; }
label.field { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
label.field > span { font-weight: 500; }
label.check { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; cursor: pointer; }
label.check input { margin-top: 2px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.grow { flex: 1; min-width: 0; }
.stack { display: grid; gap: 12px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 500;
}
.chip button { border: 0; background: none; padding: 0; cursor: pointer; color: inherit; font-size: 14px; line-height: 1; }
.badge { min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--accent); color: var(--accent-text); font-size: 11px; font-weight: 700; text-align: center; line-height: 18px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); }

/* ---------- Giriş ---------- */
.auth { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.auth .card { width: min(380px, 100%); padding: 28px; }
.auth h1 { margin: 0 0 4px; font-size: 22px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.brand .logo { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; color: #fff; font-weight: 800; }

/* ---------- Çatı ---------- */
.shell { display: grid; grid-template-columns: 220px 1fr; height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 14px 10px; gap: 4px; }
.sidebar .brand { padding: 4px 8px 14px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav a .badge { margin-left: auto; }
.nav svg { width: 18px; height: 18px; flex: none; }
.sidebar .foot { margin-top: auto; padding: 10px 8px 0; border-top: 1px solid var(--border); display: grid; gap: 8px; }
.sync { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.main { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.banner { padding: 9px 16px; font-size: 13px; border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--warn) 14%, var(--surface)); }
.banner.error { background: color-mix(in srgb, var(--danger) 14%, var(--surface)); }
.view { flex: 1; min-height: 0; overflow: auto; }
.page { padding: 20px 24px; max-width: 1280px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 20px; }
.mobile-nav { display: none; }

/* ---------- Gelen kutusu ---------- */
.inbox { display: grid; grid-template-columns: 320px 1fr 320px; height: 100%; min-height: 0; }
.conv-list { border-right: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; min-height: 0; }
.conv-list .head { padding: 12px; display: grid; gap: 8px; border-bottom: 1px solid var(--border); }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: 8px; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 5px 6px; border-radius: 6px; cursor: pointer; font-size: 13px; color: var(--muted); }
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }
.conv-items { overflow: auto; flex: 1; }
.conv-item { display: grid; grid-template-columns: 38px 1fr auto; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--border); cursor: pointer; text-decoration: none; color: inherit; }
.conv-item:hover { background: var(--surface-2); }
.conv-item.active { background: var(--accent-soft); }
.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; font-size: 14px; flex: none; }
.conv-item .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item .last { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item .meta { display: grid; justify-items: end; gap: 4px; font-size: 11px; color: var(--muted); }
.conv-item.unread .name, .conv-item.unread .last { color: var(--text); font-weight: 700; }

.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--chat-bg); }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.chat-head .who { flex: 1; min-width: 140px; }
.chat-head .who b { display: block; }
.chat-head select { width: auto; min-width: 150px; padding: 5px 8px; }
.chat-head .back, .chat-head .info-btn { display: none; }
.messages { flex: 1; overflow: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; }
.day { align-self: center; font-size: 12px; color: var(--muted); background: var(--surface); padding: 2px 10px; border-radius: 999px; margin: 8px 0; box-shadow: var(--shadow); }
.bubble { max-width: min(560px, 78%); padding: 7px 10px 5px; border-radius: 10px; background: var(--bubble-in); box-shadow: var(--shadow); white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble.out { align-self: flex-end; background: var(--bubble-out); }
.bubble img { display: block; max-width: 100%; border-radius: 6px; margin-bottom: 6px; }
.bubble .foot { display: flex; justify-content: flex-end; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); margin-top: 2px; }
.bubble .tick.read { color: #3b82f6; }
.bubble .tick.failed { color: var(--danger); }
.bubble .err { color: var(--danger); font-size: 12px; margin-top: 4px; }
.composer { background: var(--surface); border-top: 1px solid var(--border); padding: 10px 12px; display: grid; gap: 8px; }
.composer textarea { min-height: 44px; max-height: 180px; resize: none; }
.notice { font-size: 13px; padding: 8px 10px; border-radius: 8px; background: color-mix(in srgb, var(--warn) 14%, var(--surface)); }

.contact-panel { border-left: 1px solid var(--border); background: var(--surface); overflow: auto; padding: 16px; display: grid; gap: 12px; align-content: start; }
.contact-panel h3 { margin: 0; font-size: 16px; }
.tag-editor { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; border: 1px solid var(--border); border-radius: 8px; padding: 6px; }
.tag-editor input { border: 0; padding: 2px 4px; min-width: 90px; flex: 1; background: transparent; }
.tag-editor input:focus { outline: none; }

/* ---------- Huni ---------- */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(260px, 1fr); gap: 12px; padding: 0 24px 24px; overflow-x: auto; align-items: start; min-height: calc(100% - 70px); }
.column { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; max-height: calc(100vh - 120px); }
.column.over { outline: 2px dashed var(--accent); outline-offset: -2px; }
.column .col-head { padding: 10px 12px; display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--border); }
.column .col-head b { flex: 1; }
.column .cards { padding: 8px; display: grid; gap: 8px; overflow: auto; min-height: 60px; }
.deal { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 9px 10px; cursor: grab; display: grid; gap: 4px; }
.deal:active { cursor: grabbing; }
.deal.dragging { opacity: .5; }
.deal .top { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }

/* ---------- Tablo ---------- */
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; }
tbody tr:hover { background: var(--surface-2); }
tr.clickable { cursor: pointer; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input, .toolbar select { width: auto; min-width: 180px; }

/* ---------- Toplu gönderim ---------- */
.bc-grid { display: grid; grid-template-columns: minmax(320px, 420px) 1fr; gap: 16px; align-items: start; }
.preview { background: var(--chat-bg); border-radius: 8px; padding: 12px; }
.preview .bubble { max-width: 100%; }
.preview .img-ph { height: 120px; border-radius: 6px; background: var(--border); display: grid; place-items: center; color: var(--muted); margin-bottom: 6px; font-size: 12px; overflow: hidden; }
.preview .img-ph img { width: 100%; height: 100%; object-fit: cover; }
.progress { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; display: flex; }
.progress span { display: block; height: 100%; }
.bc-item { padding: 14px; display: grid; gap: 8px; }
.stats { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.stats b { color: var(--text); }

/* ---------- Şablonlar ---------- */
.tpl-preview { display: grid; gap: 4px; max-width: 360px; }
.tpl-preview .bubble { max-width: 100%; }
.tpl-buttons { display: grid; gap: 4px; }
.tpl-btn { background: var(--bubble-in); border-radius: 8px; box-shadow: var(--shadow); text-align: center; padding: 7px 10px; color: #2b7bd6; font-weight: 500; font-size: 13px; }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.tpl-card { padding: 14px; display: grid; gap: 10px; align-content: start; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.media-card { overflow: hidden; }
.media-card img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; background: var(--surface-2); }
.page-head .tabs button { flex: none; padding: 5px 12px; }
@media (max-width: 760px) { .page-head .tabs { width: 100%; overflow-x: auto; } }

/* ---------- Modal & bildirim ---------- */
.modal-back { position: fixed; inset: 0; background: rgb(0 0 0 / .4); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { width: min(520px, 100%); max-height: calc(100vh - 32px); overflow: auto; padding: 20px; display: grid; gap: 14px; }
.modal.wide { width: min(820px, 100%); }
.modal h2 { margin: 0; font-size: 18px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; }
#toasts { position: fixed; bottom: 16px; right: 16px; display: grid; gap: 8px; z-index: 60; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 360px; font-size: 13px; }
.toast.error { background: var(--danger); color: #fff; }

/* ---------- Dar ekranlar ---------- */
@media (max-width: 1100px) {
  .inbox { grid-template-columns: 280px 1fr; }
  .contact-panel { display: none; }
  .inbox.show-contact .contact-panel { display: grid; position: fixed; right: 0; top: 0; bottom: 0; width: min(340px, 100%); z-index: 20; box-shadow: var(--shadow); }
  .bc-grid { grid-template-columns: 1fr; }
  .chat-head .info-btn { display: inline-flex; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .sidebar { display: none; }
  .mobile-nav { display: flex; justify-content: space-around; background: var(--surface); border-top: 1px solid var(--border); padding: 6px 4px; }
  .mobile-nav a { display: grid; justify-items: center; gap: 2px; font-size: 11px; color: var(--muted); text-decoration: none; padding: 4px 6px; }
  .mobile-nav a.active { color: var(--accent); }
  .mobile-nav svg { width: 20px; height: 20px; }
  .page { padding: 16px; }
  .board { padding: 0 16px 16px; }
  .inbox { grid-template-columns: 1fr; }
  .inbox.has-active .conv-list { display: none; }
  .inbox:not(.has-active) .chat { display: none; }
  .chat-head .back { display: inline-flex; }
}
