:root {
  --bg: #f4f5f2; --surface: #ffffff; --surface-2: #f8f9f6; --border: #e4e6e0; --text: #1a1d1a; --muted: #6b716a;
  --accent: #0e9f6e; --accent-ink: #ffffff; --accent-soft: #e3f5ec; --danger: #d64545; --warn-bg: #fff6e0; --warn: #8a5a00;
  --bubble-in: #ffffff; --bubble-out: #dcf5e6; --shadow: 0 1px 2px rgba(20,30,20,.05), 0 4px 16px rgba(20,30,20,.05);
  --radius: 14px; --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1311; --surface: #161b18; --surface-2: #1b211e; --border: #26302b; --text: #e7ece8; --muted: #8d978f;
    --accent: #22c38e; --accent-ink: #04140d; --accent-soft: #133126; --danger: #f06a6a; --warn-bg: #2a2310; --warn: #f0c46a;
    --bubble-in: #1e2522; --bubble-out: #12392a; --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
h1 { font-size: 22px; margin: 0 0 2px; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
a { color: var(--accent); text-decoration: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.sm { font-size: 12.5px; }
.error { color: var(--danger); min-height: 1em; margin: 6px 0 0; }
.warn { background: var(--warn-bg); color: var(--warn); padding: 10px 12px; border-radius: 10px; font-size: 13px; }
.row { display: flex; align-items: center; }
.row.gap { gap: 10px; flex-wrap: wrap; }
.row.between { justify-content: space-between; gap: 10px; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; }
.w100 { width: 100%; }

/* butonlar & form */
.btn { appearance: none; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: 600 13.5px var(--font); padding: 9px 16px; border-radius: 10px; cursor: pointer; transition: background .15s, border-color .15s, transform .05s; }
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger-ghost { color: var(--danger); }
.btn.sm { padding: 6px 11px; font-size: 12.5px; }
.btn.icon { padding: 0; width: 42px; height: 42px; display: grid; place-items: center; flex: none; }
input, textarea, select { width: 100%; font: 14px var(--font); color: var(--text); background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; outline: none; transition: border-color .15s, box-shadow .15s; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; }
input[type=file] { padding: 7px; font-size: 13px; }
.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 13px; }
.form .row.gap > label { flex: 1; min-width: 120px; }
label.inline { flex-direction: row !important; align-items: center; }
label.file.inline input { width: auto; }

/* düzen */
.app { display: grid; grid-template-columns: 236px 1fr; height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 18px 12px; gap: 18px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 750; font-size: 16px; padding: 0 8px; letter-spacing: -.01em; }
.brand.big { font-size: 22px; justify-content: center; }
.logo { width: 28px; height: 28px; border-radius: 9px; background: var(--accent); position: relative; flex: none; }
.logo::after { content: ""; position: absolute; inset: 6px; background: var(--accent-ink); -webkit-mask: var(--i-chat) center/contain no-repeat; mask: var(--i-chat) center/contain no-repeat; }
nav { display: flex; flex-direction: column; gap: 2px; }
nav a { display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: 10px; color: var(--muted); font-weight: 560; }
nav a:hover { background: var(--surface-2); color: var(--text); }
nav a.active { background: var(--accent-soft); color: var(--accent); }
.badge { margin-left: auto; background: var(--accent); color: var(--accent-ink); border-radius: 99px; font-size: 11px; padding: 1px 7px; font-weight: 700; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 0 4px; }
.conn { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #c9a227; flex: none; }
.conn.open .dot { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.conn.closed .dot { background: var(--danger); }
.main { min-width: 0; overflow-y: auto; padding: 28px 32px 48px; }
.view { min-width: 0; display: none; flex-direction: column; gap: 18px; max-width: 1180px; }
.view.active { display: flex; }
.page-head p { margin: 0; }
.card { min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.narrow { max-width: 640px; }
.grid-2 { display: grid; grid-template-columns: 1.15fr 1fr; gap: 18px; }
.grid-2.top { align-items: start; }

/* bağlantı */
.status-tag { font-size: 12px; font-weight: 650; padding: 3px 10px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.status-tag.open { background: var(--accent-soft); color: var(--accent); }
.qr-box { display: flex; gap: 22px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.qr-box img { width: 220px; height: 220px; border-radius: 12px; background: #fff; padding: 8px; border: 1px solid var(--border); }
.steps { margin: 0; padding-left: 18px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }
.steps b { color: var(--text); font-weight: 600; }
.me-box { display: flex; gap: 14px; align-items: center; margin-bottom: 14px; }
.me-name { font-weight: 650; font-size: 16px; }
.wait-box { display: flex; gap: 10px; align-items: center; color: var(--muted); margin-bottom: 14px; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#lastErr { margin: 0 0 14px; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-content: start; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; display: flex; flex-direction: column; gap: 4px; box-shadow: var(--shadow); }
.stat-label { color: var(--muted); font-size: 12.5px; font-weight: 560; }
.stat-val { font-size: 28px; font-weight: 720; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-sub { color: var(--muted); font-size: 12px; }
.meter { height: 5px; background: var(--surface-2); border-radius: 9px; overflow: hidden; border: 1px solid var(--border); }
.meter span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s; }

.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 14px; flex: none; color: #fff; }
.avatar.lg { width: 52px; height: 52px; font-size: 19px; }

.feed { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.feed li { display: flex; gap: 12px; align-items: center; padding: 10px 4px; border-top: 1px solid var(--border); cursor: pointer; }
.feed li:first-child { border-top: none; }
.feed li.empty, .camp-list li.empty { color: var(--muted); cursor: default; justify-content: center; padding: 24px; }
.feed .meta { flex: 1; min-width: 0; }
.feed .who { font-weight: 620; }
.feed .txt { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.feed time, .chat-list time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.dir { font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 99px; margin-right: 6px; }
.dir.in { background: var(--accent-soft); color: var(--accent); }
.dir.out { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

/* sohbetler */
#view-chats { max-width: none; height: calc(100vh - 76px); }
.chats { display: grid; grid-template-columns: 320px 1fr; height: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.chat-list { border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.chat-search { padding: 12px; border-bottom: 1px solid var(--border); }
.chat-list ul { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
.chat-list li { display: flex; gap: 11px; align-items: center; padding: 10px; border-radius: 10px; cursor: pointer; }
.chat-list li:hover { background: var(--surface-2); }
.chat-list li.active { background: var(--accent-soft); }
.chat-list .meta { flex: 1; min-width: 0; }
.chat-list .top { display: flex; justify-content: space-between; gap: 8px; }
.chat-list .who { font-weight: 620; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-list .txt { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-pane { display: flex; flex-direction: column; min-height: 0; background: var(--surface-2); }
.chat-head { padding: 12px 18px; border-bottom: 1px solid var(--border); background: var(--surface); display: flex; gap: 12px; align-items: center; min-height: 63px; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 18px 22px; display: flex; flex-direction: column; gap: 6px; }
.bubble { max-width: min(560px, 75%); padding: 8px 12px 6px; border-radius: 12px; background: var(--bubble-in); border: 1px solid var(--border); align-self: flex-start; white-space: pre-wrap; word-wrap: break-word; }
.bubble.out { background: var(--bubble-out); align-self: flex-end; border-color: transparent; }
.bubble .bmeta { display: flex; gap: 8px; justify-content: flex-end; font-size: 11px; color: var(--muted); margin-top: 2px; }
.bubble .kind { font-style: italic; color: var(--muted); }
.day-sep { align-self: center; font-size: 11.5px; color: var(--muted); background: var(--surface); border: 1px solid var(--border); padding: 2px 10px; border-radius: 99px; margin: 8px 0; }
.chat-input { display: flex; gap: 10px; padding: 12px; border-top: 1px solid var(--border); background: var(--surface); align-items: flex-end; }
.chat-input textarea { resize: none; max-height: 160px; }
.mobile-back { display: none; }

/* kampanyalar */
.camp-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.camp { border: 1px solid var(--border); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 8px; background: var(--surface-2); }
.camp .top { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.camp .name { font-weight: 650; cursor: pointer; }
.camp .sub { color: var(--muted); font-size: 12.5px; }
.progress { height: 6px; border-radius: 9px; background: var(--border); overflow: hidden; display: flex; }
.progress .ok { background: var(--accent); }
.progress .bad { background: var(--danger); }
.pill { font-size: 11.5px; font-weight: 650; padding: 2px 9px; border-radius: 99px; background: var(--surface); border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.pill.running { color: var(--accent); border-color: var(--accent); }
.pill.scheduled { color: #3b82f6; border-color: #3b82f6; }
.pill.done { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.pill.cancelled, .pill.failed { color: var(--danger); }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border); }
.tbl th { color: var(--muted); font-weight: 600; font-size: 12px; }

/* kurallar */
.rules { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.rule { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 10px; box-shadow: var(--shadow); }
.rule.off { opacity: .6; }
.rule .top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.rule .name { font-weight: 650; }
.rule .cond { font-size: 12.5px; color: var(--muted); }
.rule .cond code { background: var(--surface-2); border: 1px solid var(--border); padding: 1px 6px; border-radius: 6px; color: var(--text); }
.rule .reply { background: var(--bubble-out); border-radius: 10px; padding: 8px 11px; white-space: pre-wrap; font-size: 13.5px; }
.rule .foot { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); }
.empty-rules { color: var(--muted); padding: 30px; text-align: center; border: 1px dashed var(--border); border-radius: var(--radius); grid-column: 1/-1; }

.switch { display: inline-flex !important; flex-direction: row !important; align-items: center; gap: 9px; cursor: pointer; font-weight: 600; user-select: none; }
.switch input { display: none; }
.switch span { width: 38px; height: 22px; border-radius: 99px; background: var(--border); position: relative; transition: background .15s; flex: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); }

/* API */
.keybox { display: flex; gap: 10px; align-items: center; background: var(--surface-2); border: 1px solid var(--border); padding: 10px 12px; border-radius: 10px; }
.keybox code { flex: 1; word-break: break-all; }
.code { background: #0d1210; color: #cfe8db; padding: 14px 16px; border-radius: 10px; overflow-x: auto; font: 12.5px/1.6 var(--mono); margin: 0 0 18px; }
.notice p { margin: 0; color: var(--muted); }
.filters { margin-bottom: 14px; }
.filters select { width: auto; }
.table-wrap { overflow-x: auto; }
.hist td { vertical-align: top; }
.hist td.msg { max-width: 420px; white-space: pre-wrap; word-break: break-word; }
.hist td.when { white-space: nowrap; color: var(--muted); }
.st-ok { color: var(--accent); font-weight: 650; white-space: nowrap; }
.st-bad { color: var(--danger); font-weight: 650; white-space: nowrap; }
.feed .st { font-size: 12px; }
.groups { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.groups td { padding: 9px 8px; border-top: 1px solid var(--border); vertical-align: middle; }
.groups td.id { font-family: var(--mono); font-size: 12px; color: var(--muted); word-break: break-all; }
.groups tr:first-child td { border-top: none; }
.bubble .sender { font-size: 12px; font-weight: 650; color: var(--accent); margin-bottom: 1px; }
@media (max-width: 900px) { .groups td.id { display: none; } }

/* dialog & toast */
dialog { border: 1px solid var(--border); border-radius: 16px; padding: 22px; background: var(--surface); color: var(--text); width: min(620px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(10,15,12,.45); backdrop-filter: blur(2px); }
#campDlg { width: min(760px, calc(100vw - 32px)); }
#campDlgBody { max-height: 60vh; overflow-y: auto; }
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 560; box-shadow: 0 6px 24px rgba(0,0,0,.18); animation: up .2s ease-out; max-width: 380px; }
.toast.err { background: var(--danger); color: #fff; }
@keyframes up { from { transform: translateY(8px); opacity: 0; } }

/* giriş */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 32px; width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow); text-align: center; }
.login-card p { margin: 0; }

/* ikonlar */
:root {
  --i-home: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 10.5 12 3l9 7.5V20a1 1 0 0 1-1 1h-5v-6h-6v6H4a1 1 0 0 1-1-1z'/%3E%3C/svg%3E");
  --i-chat: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 20l1.3-3.9A8 8 0 1 1 8 19z'/%3E%3C/svg%3E");
  --i-send: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M22 2 11 13M22 2l-7 20-4-9-9-4z'/%3E%3C/svg%3E");
  --i-bulk: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='9' cy='8' r='3.5'/%3E%3Cpath d='M2.5 20a6.5 6.5 0 0 1 13 0M16 4.5a3.5 3.5 0 0 1 0 7M21.5 20a6.5 6.5 0 0 0-4-6'/%3E%3C/svg%3E");
  --i-bolt: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M13 2 4 14h7l-1 8 9-12h-7z'/%3E%3C/svg%3E");
  --i-code: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m8 6-6 6 6 6M16 6l6 6-6 6'/%3E%3C/svg%3E");
  --i-gear: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3Cpath d='M19.4 15a1.7 1.7 0 0 0 .3 1.8l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.7 1.7 0 0 0-1.8-.3 1.7 1.7 0 0 0-1 1.5V21a2 2 0 1 1-4 0v-.1a1.7 1.7 0 0 0-1.1-1.5 1.7 1.7 0 0 0-1.8.3l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1a1.7 1.7 0 0 0 .3-1.8 1.7 1.7 0 0 0-1.5-1H3a2 2 0 1 1 0-4h.1a1.7 1.7 0 0 0 1.5-1.1 1.7 1.7 0 0 0-.3-1.8l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1a1.7 1.7 0 0 0 1.8.3H9a1.7 1.7 0 0 0 1-1.5V3a2 2 0 1 1 4 0v.1a1.7 1.7 0 0 0 1 1.5 1.7 1.7 0 0 0 1.8-.3l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1.7 1.7 0 0 0-.3 1.8V9a1.7 1.7 0 0 0 1.5 1H21a2 2 0 1 1 0 4h-.1a1.7 1.7 0 0 0-1.5 1z'/%3E%3C/svg%3E");
}
.ic { width: 18px; height: 18px; background: currentColor; flex: none; display: inline-block; -webkit-mask: center/contain no-repeat; mask: center/contain no-repeat; }
.ic-home { -webkit-mask-image: var(--i-home); mask-image: var(--i-home); }
.ic-chat { -webkit-mask-image: var(--i-chat); mask-image: var(--i-chat); }
.ic-send { -webkit-mask-image: var(--i-send); mask-image: var(--i-send); }
.ic-bulk { -webkit-mask-image: var(--i-bulk); mask-image: var(--i-bulk); }
.ic-bolt { -webkit-mask-image: var(--i-bolt); mask-image: var(--i-bolt); }
.ic-code { -webkit-mask-image: var(--i-code); mask-image: var(--i-code); }
.ic-gear { -webkit-mask-image: var(--i-gear); mask-image: var(--i-gear); }

/* mobil */
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; height: auto; min-height: 100vh; }
  .sidebar { flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 12px; gap: 10px; border-right: none; border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
  nav { flex-direction: row; overflow-x: auto; width: 100%; order: 3; }
  nav a { white-space: nowrap; padding: 7px 10px; }
  .side-foot { margin: 0 0 0 auto; flex-direction: row; }
  .main { padding: 18px 16px 40px; overflow: visible; }
  .grid-2, .stats { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; }
  #view-chats { height: calc(100vh - 140px); }
  .chats { grid-template-columns: 1fr; }
  .chats.open .chat-list { display: none; }
  .chats:not(.open) .chat-pane { display: none; }
  .mobile-back { display: inline-block; }
}
