:root {
  --bg: #f4f6f8;
  --card: #fff;
  --ink: #1c2530;
  --muted: #6b7785;
  --line: #e3e8ee;
  --brand: #128c7e;
  --brand-dark: #0d6b60;
  --danger: #c0392b;
  --ok: #1d9e75;
  --warn: #b8860b;
  --radius: 10px;
  /* WhatsApp sohbet renkleri */
  --wa-bg: #efeae2;
  --wa-out: #d9fdd3;
  --wa-in: #fff;
  --wa-panel: #f0f2f5;
  --wa-tick: #53bdeb;
}
* { box-sizing: border-box; }
/* display: grid/flex tanimlari [hidden] ozniteligini ezmesin. */
[hidden] { display: none !important; }
body {
  margin: 0;
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
code { background: #eef2f5; padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* Giriş / açılış */
.login { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(160deg, #0f5f57, #128c7e); }
.login-card { width: 340px; }
.login-card label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.login-card input { width: 100%; margin-top: 4px; }
.spinner {
  display: inline-block; width: 13px; height: 13px; vertical-align: -1px;
  border: 2px solid rgba(255, 255, 255, 0.5); border-top-color: #fff; border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.login-card .spinner { border-color: #cfd8e0; border-top-color: var(--brand); }
@keyframes spin { to { transform: rotate(360deg); } }

/* Bağlantı uyarısı */
.offline {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  background: #8a6200; color: #fff; text-align: center; padding: 6px; font-size: 13px;
}

/* Yerleşim */
.topbar {
  display: flex; align-items: center; gap: 20px;
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: 10px 20px; position: sticky; top: 0; z-index: 10; flex-wrap: wrap;
}
.brand { font-weight: 600; }
.brand span { color: var(--muted); font-weight: 400; font-size: 13px; }
.topbar nav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.topbar nav button {
  background: transparent; border: 0; padding: 7px 12px; border-radius: 8px;
  cursor: pointer; color: var(--muted); font-size: 14px;
}
.topbar nav button:hover { background: #f0f3f6; }
.topbar nav button.active { background: var(--brand); color: #fff; }
.who { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
main { padding: 20px; max-width: 1200px; margin: 0 auto; }

/* Kartlar */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stat b { display: block; font-size: 24px; margin-bottom: 2px; }
.stat span { color: var(--muted); font-size: 13px; }

/* Form öğeleri */
input, select, textarea, button { font: inherit; }
input, select, textarea {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #b6e3dc; border-color: var(--brand); }
button {
  background: var(--brand); color: #fff; border: 0; padding: 9px 14px; border-radius: 8px; cursor: pointer;
}
button:hover { background: var(--brand-dark); }
button:disabled { opacity: 0.55; cursor: default; }
button.link { background: none; color: var(--brand); padding: 0 4px; font-size: 13px; }
button.link:hover { background: none; text-decoration: underline; }
button.link.del { color: var(--danger); }
button.ghost { background: #eef2f5; color: var(--ink); }
button.ghost:hover { background: #e2e8ee; }
button.danger { background: var(--danger); }
button.icon {
  background: none; color: var(--muted); font-size: 16px; padding: 4px 8px; line-height: 1;
}
button.icon:hover { background: #e7ebef; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; align-items: start; }
.form-rows { display: grid; gap: 10px; }
.form-rows label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.form-rows input, .form-rows select, .form-rows textarea { width: 100%; color: var(--ink); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.filters { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.row-actions { display: flex; gap: 10px; margin-top: 12px; align-items: center; flex-wrap: wrap; }
.error { color: var(--danger); font-size: 13px; }
.result { background: #f7f9fb; padding: 10px; border-radius: 8px; font-size: 12px; white-space: pre-wrap; }

/* Tablo */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.table td { padding: 7px 8px; border-bottom: 1px solid #f0f3f6; vertical-align: middle; }
.table tr:hover td { background: #fafcfd; }

/* Rozetler */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; }
.badge.ok { background: #e1f5ee; color: #0f6e56; }
.badge.warn { background: #fdf3e0; color: #8a6200; }
.badge.no { background: #fdecea; color: #a12d22; }
.badge.info { background: #e8f0fe; color: #1a4b8f; }

/* ---------- Sohbetler: WhatsApp benzeri ---------- */
.wa {
  display: grid; grid-template-columns: 330px 1fr;
  /* Sabit yukseklik: sohbet govdesi kendi icinde kayar, yazma alani her zaman altta kalir. */
  height: calc(100vh - 140px); min-height: 420px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
/* Grid/flex ogeleri varsayilan min-height:auto ile icerige gore buyur ve tasar;
   min-height:0 olmadan sohbet govdesi kayacagina yazma alanini disari iter. */
.wa > * { min-height: 0; }
.wa-sidebar { border-right: 1px solid var(--line); display: flex; flex-direction: column; background: var(--card); min-width: 0; }
.wa-search { display: flex; gap: 6px; padding: 10px; background: var(--wa-panel); border-bottom: 1px solid var(--line); }
.wa-search input { flex: 1; border-radius: 999px; background: #fff; }
.conv-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; overflow-x: hidden; flex: 1; }
.conv-list li { display: flex; gap: 10px; padding: 10px 12px; cursor: pointer; border-bottom: 1px solid #f0f3f6; align-items: center; }
.conv-list li:hover { background: #f7f9fb; }
.conv-list li.active { background: #e9f5f3; }
.conv-list li.empty { cursor: default; color: var(--muted); justify-content: center; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: 0 0 40px;
  background: #c8d3dc; color: #fff; display: grid; place-items: center; font-weight: 600; font-size: 15px;
}
.conv-main { min-width: 0; flex: 1; }
.conv-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.conv-top b { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-top time { font-size: 11px; color: var(--muted); flex: 0 0 auto; }
.conv-prev { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.wa-chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--wa-bg); }
.wa-header {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 14px; background: var(--wa-panel); border-bottom: 1px solid var(--line); min-height: 56px;
}
.wa-header .grow { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.wa-body {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 14px 18px;
  background-color: var(--wa-bg);
  background-image: radial-gradient(#e2dcd4 1px, transparent 1px);
  background-size: 22px 22px;
}
.day { text-align: center; margin: 12px 0; }
.day span { background: #ffffffcc; color: #54656f; font-size: 12px; padding: 4px 10px; border-radius: 8px; }
.bubble {
  /* Balon metne gore daralsin (WhatsApp gibi), satir sonunda %72'de kirilsin. */
  position: relative; width: fit-content; max-width: min(72%, 560px); min-width: 90px;
  margin-bottom: 8px; padding: 7px 10px 18px;
  border-radius: 8px; font-size: 14px; white-space: pre-wrap; word-break: break-word;
  box-shadow: 0 1px 1px rgba(11, 20, 26, 0.13);
}
.bubble.in { background: var(--wa-in); border-top-left-radius: 0; }
.bubble.out { background: var(--wa-out); margin-left: auto; border-top-right-radius: 0; }
.bubble .who-tag { display: block; font-size: 11px; font-weight: 600; color: var(--brand); margin-bottom: 2px; }
.bubble.agent .who-tag { color: #7b4ea8; }
.bubble .meta {
  position: absolute; right: 8px; bottom: 3px; font-size: 11px; color: #667781;
  display: flex; gap: 3px; align-items: center;
}
.bubble .tick.read { color: var(--wa-tick); }
.bubble .tick.failed { color: var(--danger); }
.bubble .del {
  position: absolute; top: 2px; right: 4px; opacity: 0; transition: opacity 0.15s;
  background: none; border: 0; color: #667781; cursor: pointer; font-size: 13px; padding: 2px 4px;
}
.bubble:hover .del { opacity: 1; }
.bubble.tool {
  background: #f3f0fa; color: #5b5570; font-size: 12px; font-family: ui-monospace, Menlo, monospace;
  max-width: 100%; margin: 0 auto 8px; text-align: left;
}
.wa-empty { display: grid; place-items: center; height: 100%; color: var(--muted); }
.wa-note { flex: 0 0 auto; padding: 8px 14px; font-size: 13px; background: #fff8e1; color: #6b5200; border-top: 1px solid #f0e4c0; }
.wa-note.ok { background: #eaf7f2; color: #0f6e56; border-top-color: #cfe9df; }
.wa-compose {
  flex: 0 0 auto; display: flex; gap: 8px; padding: 10px;
  background: var(--wa-panel); border-top: 1px solid var(--line); align-items: flex-end;
}
.wa-compose textarea { flex: 1; border-radius: 18px; padding: 9px 14px; max-height: 120px; }
.wa-compose .send { border-radius: 50%; width: 40px; height: 40px; padding: 0; flex: 0 0 40px; }

/* ---------- Bilgi bankası ---------- */
.chat-test { display: flex; gap: 8px; }
.chat-test input { flex: 1; }
.answer { margin-top: 12px; }
.answer .bubble { max-width: 100%; }
.tool-trace { margin-top: 8px; font-size: 12px; color: var(--muted); font-family: ui-monospace, Menlo, monospace; }
.kn-content { max-width: 420px; }
.kn-content small { display: block; white-space: pre-wrap; }

/* ---------- Şablonlar ---------- */
.tpl { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; }
.tpl header { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.tpl header b { font-size: 15px; }
.tpl .acts { margin-left: auto; display: flex; gap: 6px; }
.wa-preview {
  background: var(--wa-bg); border-radius: 8px; padding: 12px;
  background-image: radial-gradient(#e2dcd4 1px, transparent 1px); background-size: 22px 22px;
}
.wa-preview .bubble { max-width: 100%; margin: 0; }
.wa-preview .bubble .hdr { font-weight: 600; margin-bottom: 4px; }
.wa-preview .bubble .ftr { color: #667781; font-size: 12px; margin-top: 6px; }
.wa-preview .btns { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.wa-preview .btns span {
  background: #fff; color: #027eb5; text-align: center; padding: 6px; border-radius: 6px; font-size: 13px;
  box-shadow: 0 1px 1px rgba(11, 20, 26, 0.13);
}
.ph { background: #fff3c4; border-radius: 3px; padding: 0 2px; }

/* Gorsel secici */
.image-picker { margin-top: 12px; padding: 12px; background: #f7f9fb; border-radius: 8px; }
.image-picker label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.image-thumb {
  margin-top: 8px; display: flex; gap: 10px; align-items: center; font-size: 13px;
}
.image-thumb img { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.wa-preview .hero {
  display: block; width: 100%; max-height: 180px; object-fit: cover; border-radius: 6px; margin-bottom: 6px;
}
.wa-preview .hero-ph {
  display: grid; place-items: center; height: 110px; border-radius: 6px; margin-bottom: 6px;
  background: #e6e1da; color: #7a7168; font-size: 13px;
}

/* ---------- Kampanya ---------- */
.campaign { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; }
.campaign header { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.campaign header b { font-size: 15px; }
.bar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: #eef2f5; margin: 8px 0; }
.bar i { display: block; height: 100%; }
.bar .s-sent { background: #9fd3ff; }
.bar .s-delivered { background: #6fb7f5; }
.bar .s-read { background: var(--ok); }
.bar .s-failed { background: var(--danger); }
.bar .s-skipped { background: #ccd4dc; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.param-row { display: grid; grid-template-columns: 60px 150px 1fr; gap: 8px; align-items: center; margin-bottom: 6px; }

/* ---------- Kalıcı pencere ---------- */
.modal { position: fixed; inset: 0; background: rgba(15, 25, 35, 0.45); z-index: 60; display: grid; place-items: center; padding: 16px; }
.modal-card {
  background: var(--card); border-radius: var(--radius); width: min(560px, 100%);
  max-height: 88vh; overflow: auto; padding: 16px;
}
.modal-card > header { display: flex; align-items: center; margin-bottom: 12px; }
.modal-card > header b { font-size: 16px; }
.modal-card > header button { margin-left: auto; }

/* Bildirim */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #1c2530; color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px; z-index: 80;
  max-width: 90vw;
}
.toast.err { background: var(--danger); }

@media (max-width: 860px) {
  .wa { grid-template-columns: 1fr; height: calc(100vh - 120px); }
  .wa-sidebar { flex: 0 0 200px; border-right: 0; border-bottom: 1px solid var(--line); }
  .two { grid-template-columns: 1fr; }
  .topbar nav { width: 100%; margin-left: 0; }
  .param-row { grid-template-columns: 1fr; }
}
