:root {
  --accent: #ff5100;
  --accent-soft: #fff1ea;
  --ink: #1d2433;
  --muted: #6b7385;
  --line: #e7e9ef;
  --bg: #f5f6f9;
  --panel: #fff;
  --rail: #171c2c;
  --ok: #19a463;
  --warn: #e8a10c;
  --danger: #e5243b;
  --ai: #6c5ce7;
  --ai-soft: #f0eefe;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
[hidden] { display: none !important; }

/* ---------- giriş ---------- */
#auth { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px 16px; background: linear-gradient(160deg, #171c2c, #2a2f4a); }
.auth-card { width: 100%; max-width: 380px; background: #fff; border-radius: 16px; padding: 32px 28px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.auth-card h1 { margin: 0 0 4px; font-size: 22px; }
.auth-card p { margin: 0 0 20px; color: var(--muted); }
.auth-logo { width: 48px; height: 48px; border-radius: 14px; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; margin-bottom: 16px; }

/* ---------- form ---------- */
label.f { display: block; margin-bottom: 14px; }
label.f > span { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; }
label.f > small, .hint { display: block; color: var(--muted); font-size: 12px; margin-top: 5px; }
.inp, input[type=text], input[type=password], input[type=search], input[type=number], textarea, select {
  width: 100%; border: 1px solid var(--line); border-radius: 9px; padding: 9px 12px; background: #fff; outline: none; transition: border-color .15s, box-shadow .15s;
}
.inp:focus, input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 80px; }
.btn { border: 0; border-radius: 9px; padding: 9px 16px; font-weight: 600; background: var(--accent); color: #fff; display: inline-flex; align-items: center; gap: 6px; transition: filter .15s; }
.btn:hover { filter: brightness(.95); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn.ghost:hover { background: var(--bg); }
.btn.danger { background: #fff; color: var(--danger); border: 1px solid #f6c5cc; }
.btn.ai { background: var(--ai); }
.btn.sm { padding: 6px 10px; font-size: 12.5px; }
.btn.block { width: 100%; justify-content: center; padding: 11px; }
.err { color: var(--danger); font-size: 13px; min-height: 18px; margin: 4px 0 10px; }
.switch { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; cursor: pointer; }
.switch input { display: none; }
.switch i { width: 38px; height: 22px; border-radius: 11px; background: #cfd3dc; position: relative; transition: background .2s; flex: none; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch input:checked + i { background: var(--ok); }
.switch input:checked + i::after { transform: translateX(16px); }
.switch b { font-weight: 600; font-size: 13px; }
.switch small { display: block; color: var(--muted); font-weight: 400; }

/* ---------- uygulama iskeleti ---------- */
#app { display: flex; height: 100vh; height: 100dvh; }
.rail { width: 76px; flex: none; background: var(--rail); display: flex; flex-direction: column; align-items: center; padding: 14px 0; gap: 4px; }
.rail-logo { width: 42px; height: 42px; border-radius: 12px; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; margin-bottom: 14px; }
.rail a, .rail button { position: relative; width: 64px; padding: 8px 0 6px; border-radius: 10px; border: 0; background: none; color: #9aa3b8; display: flex; flex-direction: column; align-items: center; gap: 3px; text-decoration: none; }
.rail a small, .rail button small { font-size: 10.5px; }
.rail a:hover, .rail button:hover { color: #fff; background: rgba(255,255,255,.06); }
.rail a.on { color: #fff; background: rgba(255,255,255,.1); }
.rail-spacer { flex: 1; }
.rail-badge { position: absolute; top: 3px; right: 10px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.view { flex: 1; min-width: 0; display: none; }
.view.on { display: flex; }

/* ---------- sohbet listesi ---------- */
.list { width: 330px; flex: none; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.list-head { display: flex; align-items: baseline; justify-content: space-between; padding: 18px 18px 10px; }
.list-head h2 { margin: 0; font-size: 19px; }
.live { font-size: 12px; color: var(--ok); font-weight: 600; }
.list-tools { padding: 0 14px 10px; border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 4px; margin-top: 10px; }
.tabs button { flex: 1; border: 0; background: var(--bg); border-radius: 8px; padding: 6px 0; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.tabs button.on { background: var(--ink); color: #fff; }
.items { flex: 1; overflow-y: auto; }
.item { display: flex; gap: 11px; padding: 12px 14px; border-bottom: 1px solid #f1f2f5; cursor: pointer; text-decoration: none; color: inherit; position: relative; }
.item:hover { background: #fafbfc; }
.item.on { background: var(--accent-soft); }
.item.on::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); }
.item-body { flex: 1; min-width: 0; }
.item-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.item-name { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-time { color: var(--muted); font-size: 11.5px; flex: none; }
.item-last { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.item-last.typing { color: var(--ok); font-style: italic; }
.item.unread .item-name, .item.unread .item-last { color: var(--ink); font-weight: 650; }
.item-tags { display: flex; gap: 5px; margin-top: 5px; align-items: center; }
.tag { font-size: 10.5px; font-weight: 700; padding: 2px 7px; border-radius: 6px; background: var(--bg); color: var(--muted); }
.tag.ai { background: var(--ai-soft); color: var(--ai); }
.tag.human { background: #e6f6ee; color: var(--ok); }
.tag.alert { background: #fff4dc; color: #a26c00; }
.count { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.vav { position: relative; flex: none; width: 40px; height: 40px; border-radius: 50%; color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; }
.vav .on-dot { position: absolute; right: 0; bottom: 0; width: 11px; height: 11px; border-radius: 50%; background: var(--ok); border: 2px solid #fff; }
.empty-list { padding: 40px 20px; text-align: center; color: var(--muted); }

/* ---------- sohbet penceresi ---------- */
.chat { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }
.chat-empty { margin: auto; text-align: center; color: var(--muted); padding: 20px; }
.chat-empty .big { font-size: 46px; margin-bottom: 8px; }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 12px 18px; background: var(--panel); border-bottom: 1px solid var(--line); }
.chat-head .back { display: none; border: 0; background: none; font-size: 22px; padding: 0 6px 0 0; }
.chat-title { flex: 1; min-width: 0; }
.chat-title b { display: block; font-size: 15.5px; }
.chat-title small { color: var(--muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.msgs { flex: 1; overflow-y: auto; padding: 20px 22px 10px; }
.m { display: flex; margin: 3px 0; }
.m .bub { max-width: 68%; padding: 9px 13px; border-radius: 16px; overflow-wrap: anywhere; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.m .meta { font-size: 11px; color: var(--muted); margin: 3px 6px 8px; }
.m-col { display: flex; flex-direction: column; max-width: 100%; }
.m.visitor .bub { background: #fff; border-bottom-left-radius: 5px; }
.m.agent, .m.ai { justify-content: flex-end; }
.m.agent .m-col, .m.ai .m-col { align-items: flex-end; }
.m.agent .bub { background: var(--accent); color: #fff; border-bottom-right-radius: 5px; }
.m.ai .bub { background: var(--ai-soft); color: #2d2560; border-bottom-right-radius: 5px; }
.m .bub a { color: inherit; }
.m.system { justify-content: center; }
.m.system .bub { background: none; box-shadow: none; color: var(--muted); font-size: 12px; padding: 6px; }
.peek { margin: 4px 0 6px; color: var(--muted); font-size: 13px; font-style: italic; }
.peek b { color: var(--ok); font-style: normal; }
.composer { background: var(--panel); border-top: 1px solid var(--line); padding: 12px 16px; }
.composer-note { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.composer-note.ai { color: var(--ai); }
.composer-row { display: flex; gap: 10px; align-items: flex-end; }
.composer textarea { min-height: 44px; max-height: 180px; resize: none; }

/* ---------- ziyaretçi bilgisi ---------- */
.info { width: 290px; flex: none; background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 20px 18px; }
.info h3 { margin: 0 0 14px; font-size: 14px; }
.info dl { margin: 0; }
.info dt { font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; margin-top: 12px; }
.info dd { margin: 3px 0 0; overflow-wrap: anywhere; }
.persona-chip { display: inline-flex; align-items: center; gap: 8px; }

/* ---------- sayfalar (ayarlar vb.) ---------- */
.page { overflow-y: auto; display: none; }
.page.on { display: block; }
.page-inner { max-width: 900px; margin: 0 auto; padding: 28px 24px 80px; }
.page h1 { margin: 0 0 4px; font-size: 24px; }
.page .lead { color: var(--muted); margin: 0 0 24px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; margin-bottom: 18px; }
.card h2 { margin: 0 0 4px; font-size: 16px; }
.card > .hint:first-of-type { margin: 0 0 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.savebar { position: sticky; bottom: 0; background: rgba(245,246,249,.92); backdrop-filter: blur(6px); padding: 12px 0; display: flex; gap: 10px; align-items: center; border-top: 1px solid var(--line); }
.status-line { font-size: 12.5px; margin-top: -6px; margin-bottom: 14px; }
.status-line.ok { color: var(--ok); }
.status-line.bad { color: var(--danger); }
.icons { display: flex; gap: 10px; flex-wrap: wrap; }
.icon-opt { width: 56px; height: 56px; border-radius: 50%; border: 3px solid transparent; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; padding: 0; overflow: hidden; }
.icon-opt.on { border-color: var(--ink); box-shadow: 0 0 0 2px #fff inset; }
.icon-opt img { width: 62%; height: 62%; object-fit: contain; }
.icon-opt.full img { width: 100%; height: 100%; object-fit: cover; }
.icon-opt.upload { background: #fff; color: var(--muted); border: 2px dashed var(--line); font-size: 22px; }
.color-row { display: flex; gap: 10px; align-items: center; }
.color-row input[type=color] { width: 44px; height: 38px; border: 1px solid var(--line); border-radius: 9px; padding: 3px; background: #fff; }
.personas { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 14px; }
.persona { border: 1px solid var(--line); border-radius: 12px; padding: 14px; text-align: center; background: #fcfcfd; }
.pav { width: 84px; height: 84px; border-radius: 50%; margin: 0 auto 10px; overflow: hidden; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 30px; font-weight: 700; }
.pav img { width: 100%; height: 100%; object-fit: cover; }
.pav img.crop, .vav img.crop, .sav img.crop { transform: scale(1.32) translateY(4%); }
.sav { width: 26px; height: 26px; border-radius: 50%; overflow: hidden; background: var(--accent); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; flex: none; }
.sav img { width: 100%; height: 100%; object-fit: cover; }
.persona input { text-align: center; font-weight: 600; margin-bottom: 8px; }
.persona-btns { display: flex; gap: 4px; justify-content: center; flex-wrap: wrap; }
.persona-btns .btn { padding: 5px 8px; font-size: 12px; }
.preview { display: flex; gap: 18px; align-items: flex-end; flex-wrap: wrap; padding: 16px; background: var(--bg); border-radius: 12px; }
.pv-win { width: 280px; border-radius: 14px; overflow: hidden; background: #fff; box-shadow: 0 8px 28px rgba(0,0,0,.12); }
.pv-head { padding: 12px 14px; color: #fff; display: flex; gap: 10px; align-items: center; }
.pv-head .pav { width: 38px; height: 38px; margin: 0; font-size: 15px; background: rgba(255,255,255,.25); }
.pv-head b { display: block; }
.pv-head small { opacity: .9; font-size: 11.5px; }
.pv-body { padding: 14px; background: #f4f5f7; font-size: 13px; }
.pv-bub { background: #fff; padding: 8px 11px; border-radius: 14px; border-bottom-left-radius: 5px; display: inline-block; }
.pv-launch { width: 58px; height: 58px; border-radius: 50%; color: #fff; display: flex; align-items: center; justify-content: center; box-shadow: 0 6px 20px rgba(0,0,0,.2); overflow: hidden; }
.pv-launch img { width: 62%; height: 62%; object-fit: contain; }
.pv-launch.full img { width: 100%; height: 100%; object-fit: cover; }
pre.code { background: #171c2c; color: #e9edf7; padding: 16px; border-radius: 10px; overflow-x: auto; font-size: 13px; margin: 0 0 12px; white-space: pre-wrap; word-break: break-all; }
table.users { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
table.users td { padding: 10px 6px; border-bottom: 1px solid var(--line); }
table.users td:last-child { text-align: right; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 10px; opacity: 0; pointer-events: none; transition: all .25s; z-index: 100; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.bad { background: var(--danger); }

/* ---------- duyarlı ---------- */
@media (max-width: 1200px) { .info { display: none; } }
@media (max-width: 760px) {
  #app { flex-direction: column-reverse; }
  .rail { width: 100%; height: 60px; flex-direction: row; justify-content: space-around; padding: 0 4px; }
  .rail-logo, .rail-spacer { display: none; }
  .rail a, .rail button { width: auto; flex: 1; }
  .view { min-height: 0; }
  .list { width: 100%; border-right: 0; }
  .chats.has-chat .list { display: none; }
  .chats:not(.has-chat) .chat { display: none; }
  .chat-head .back { display: block; }
  .m .bub { max-width: 85%; }
  .grid2 { grid-template-columns: 1fr; }
  .page-inner { padding: 20px 16px 80px; }
}
