:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --danger: #dc2626;
  --warning: #b45309;
  --success: #15803d;
  --unread: #2563eb;
  --read: #6b7280;
  --answered: #15803d;
  --sidebar: #0f172a;
  --sidebar-text: #cbd5e1;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; }
.h2 { font-size: 20px; }
h3 { font-size: 14px; margin-bottom: 10px; }
code, kbd { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; background: #f1f5f9; border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; }
pre { margin: 0; }

/* Yardımcılar */
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; }
.min0 { min-width: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; min-width: 0; }
.text-error { color: var(--danger); }
.text-warning { color: var(--warning); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack-sm { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
[hidden] { display: none !important; }

/* Form */
label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; font-size: 13px; }
input, select, textarea {
  font: inherit; color: inherit; background: #fff;
  border: 1px solid #d1d5db; border-radius: 8px; padding: 8px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--primary); }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--primary); }
input[type=color] { width: 44px; height: 36px; padding: 2px; }
textarea { resize: vertical; line-height: 1.55; }
.check-row { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.row3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 14px; }
.form-grid { display: flex; flex-direction: column; gap: 16px; max-width: 860px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; }
.inline-form { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.inline-form input:not([type=color]):not([type=hidden]) { width: 220px; }

/* Butonlar */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 500; font-size: 13px; color: var(--text);
  background: #fff; border: 1px solid #d1d5db; border-radius: 8px;
  padding: 7px 12px; cursor: pointer; white-space: nowrap; text-decoration: none !important;
}
.btn:hover { background: #f9fafb; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: #fef2f2; border-color: #fecaca; }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .6; cursor: wait; }
.btn-link { background: none; border: 0; padding: 0; color: var(--primary); cursor: pointer; font: inherit; }
.btn-link:hover { text-decoration: underline; }
form { margin: 0; }

/* Kart, uyarı */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; border: 1px solid; }
.alert-success { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.alert-error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.empty { text-align: center; padding: 48px 18px; color: var(--muted); }
.empty-icon { font-size: 36px; margin-bottom: 8px; color: var(--text); }

/* Çip, etiket, durum */
.chip { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; background: #f1f5f9; color: #475569; border: 1px solid var(--border); white-space: nowrap; }
.chip-admin { background: #eef2ff; color: #4338ca; border-color: #c7d2fe; }
.chip-mb { background: #f8fafc; }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 500; padding: 1px 8px; border-radius: 999px;
  color: var(--tag); background: color-mix(in srgb, var(--tag) 12%, white); border: 1px solid color-mix(in srgb, var(--tag) 30%, white); }
.status-pill { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 999px; }
.pill-unread { background: #dbeafe; color: #1d4ed8; }
.pill-read { background: #f1f5f9; color: #475569; }
.pill-answered { background: #dcfce7; color: #15803d; }
.lock-pill { font-size: 11px; color: #92400e; background: #fef3c7; padding: 1px 8px; border-radius: 999px; }
.badge { min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--primary); color: #fff; font-size: 11px; font-weight: 600; text-align: center; line-height: 18px; }
.badge:empty { display: none; }

/* Avatar */
.avatar { flex: none; width: 34px; height: 34px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  background: #e0e7ff; color: #3730a3; font-weight: 600; font-size: 12px; }
.avatar-sm { width: 30px; height: 30px; font-size: 11px; }
.avatar-out { background: #dcfce7; color: #166534; }

/* Yerleşim */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 240px; flex: none; background: var(--sidebar); color: var(--sidebar-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 12px; color: #fff; font-weight: 700; font-size: 16px; text-decoration: none !important; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--primary); display: inline-flex; align-items: center; justify-content: center; font-size: 15px; color: #fff; }
.nav { flex: 1; overflow-y: auto; padding: 4px 10px; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #64748b; padding: 14px 8px 6px; }
.nav a { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 7px 10px; border-radius: 7px; color: var(--sidebar-text); text-decoration: none; font-size: 13px; }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: rgba(255,255,255,.1); color: #fff; font-weight: 500; }
.sidebar-foot { padding: 12px 14px; border-top: 1px solid rgba(255,255,255,.08); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sidebar-foot .btn-link { color: #94a3b8; font-size: 12px; }
.me { display: flex; align-items: center; gap: 8px; min-width: 0; }
.me-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.me-text strong { color: #fff; font-size: 13px; }
.me-text small { color: #64748b; font-size: 11px; }
.main { flex: 1; min-width: 0; padding: 24px 28px 48px; }
.menu-toggle { display: none; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }
.head-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.back-link { font-size: 12px; display: inline-block; margin-bottom: 4px; }
.section-title { margin: 22px 0 10px; font-size: 15px; }

/* Gelen kutusu */
.search input { width: 300px; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.tabs { display: flex; gap: 2px; background: #e9ebef; padding: 3px; border-radius: 9px; }
.tab { padding: 5px 12px; border-radius: 7px; color: var(--muted); font-size: 13px; font-weight: 500; text-decoration: none !important; }
.tab:hover { color: var(--text); }
.tab.active { background: #fff; color: var(--text); box-shadow: var(--shadow); }
.filters { display: flex; gap: 8px; align-items: center; }
.filters select { width: auto; padding: 5px 8px; font-size: 13px; }
.bulk-bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; margin-bottom: 8px; background: var(--primary-soft); border: 1px solid #bfdbfe; border-radius: 8px; flex-wrap: wrap; }
.select-sm { width: auto; padding: 4px 8px; font-size: 12px; }

.thread-list { padding: 0; overflow: hidden; }
.thread-list-head { display: flex; align-items: center; gap: 4px; padding: 6px 14px; border-bottom: 1px solid var(--border); background: #fafafa; }
.thread-row { display: flex; align-items: stretch; border-bottom: 1px solid var(--border); position: relative; }
.thread-row:last-child { border-bottom: 0; }
.thread-row:hover { background: #f9fafb; }
.thread-row.status-unread { background: #f8fbff; }
.thread-row.status-unread::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--unread); }
.check { display: flex; align-items: flex-start; padding: 16px 4px 0 14px; flex-direction: row; }
.thread-link { flex: 1; min-width: 0; display: flex; gap: 12px; padding: 12px 16px 12px 8px; color: inherit; text-decoration: none !important; }
.thread-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.thread-top { display: flex; align-items: center; gap: 6px; min-width: 0; }
.thread-top .sender { font-weight: 500; }
.status-unread .sender, .status-unread .subject { font-weight: 700; }
.thread-top .count { color: var(--muted); font-size: 12px; }
.thread-top .time { margin-left: auto; flex: none; font-size: 12px; color: var(--muted); }
.status-unread .time { color: var(--unread); font-weight: 600; }
.subject { font-size: 13.5px; }
.preview { font-size: 12.5px; }
.thread-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 16px; }

/* Konuşma */
.thread-head { align-items: flex-start; }
.thread-title { font-size: 20px; word-break: break-word; }
.thread-sub { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.thread-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 18px; align-items: start; }
.conversation { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.message { padding: 0; overflow: hidden; }
.message-out { border-left: 3px solid #86efac; }
.message-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; cursor: pointer; list-style: none; }
.message-head::-webkit-details-marker { display: none; }
.message[open] .message-head { border-bottom: 1px solid var(--border); }
.message[open] .collapsed-preview { display: none; }
.message-head .time { margin-left: auto; font-size: 12px; color: var(--muted); flex: none; }
.message-body { padding: 14px 16px; }
.mail-frame { width: 100%; border: 0; min-height: 60px; display: block; }
.mail-text { white-space: normal; word-wrap: break-word; overflow-wrap: anywhere; }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border); }
.attachment { display: inline-flex; align-items: center; gap: 6px; max-width: 280px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; background: #fafafa; color: var(--text); font-size: 12px; text-decoration: none !important; }
.attachment:hover { border-color: var(--primary); }

.composer { display: flex; flex-direction: column; gap: 10px; position: relative; }
.composer-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.composer-head .btn-link { margin-left: auto; }
.composer textarea#reply-body { min-height: 200px; font-size: 14px; }
.template-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.template-popover { position: absolute; left: 18px; right: 18px; top: 92px; z-index: 20; background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 12px 32px rgba(15, 23, 42, .16); padding: 10px; }
.template-results { max-height: 320px; overflow-y: auto; margin-top: 8px; }
.template-cat { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 8px 8px 4px; }
.template-item { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 8px; border-radius: 7px; cursor: pointer; font: inherit; color: inherit; }
.template-item:hover, .template-item.active { background: var(--primary-soft); }
.template-item strong { display: block; font-size: 13px; }
.template-item span { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.signature-preview { font-size: 12px; color: var(--muted); border-left: 2px solid var(--border); padding-left: 10px; }
.signature-preview div { margin-top: 2px; }
.composer-foot { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.composer-foot label { flex-direction: row; align-items: center; gap: 6px; font-weight: 400; }
.file-input { cursor: pointer; color: var(--primary); font-size: 13px; }
.file-input input { display: none; }
.lock-warning { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; padding: 8px 12px; border-radius: 8px; font-size: 13px; }
.force-send { color: var(--warning); }

.thread-side { display: flex; flex-direction: column; gap: 12px; position: sticky; top: 16px; }
.side-card { padding: 14px; }
.customer { display: flex; align-items: center; gap: 10px; }
.tevkilim { margin-top: 12px; padding: 10px; background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 8px; }
.tevkilim-title { font-weight: 600; font-size: 12px; color: #166534; margin-bottom: 6px; }
.tevkilim dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; margin: 0 0 8px; font-size: 12px; }
.tevkilim dt { color: var(--muted); }
.tevkilim dd { margin: 0; word-break: break-word; }
.tag-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-toggle { cursor: pointer; opacity: .45; flex-direction: row; }
.tag-toggle:has(input:checked) { opacity: 1; }
.tag-toggle input { display: none; }
.note { padding: 8px 10px; background: #fefce8; border: 1px solid #fef08a; border-radius: 8px; margin-bottom: 8px; }
.note-head { display: flex; align-items: center; gap: 6px; }
.note-head form { margin-left: auto; }
.history-item { display: flex; flex-direction: column; padding: 7px 0; border-bottom: 1px solid var(--border); color: inherit; text-decoration: none !important; font-size: 13px; }
.history-item:last-child { border-bottom: 0; }
.history-item:hover span:first-child { color: var(--primary); }

/* Tablo */
.table-wrap { padding: 0; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--border); background: #fafafa; }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table-compact td, .table-compact th { padding: 7px 8px; }
.card > .table-compact th { background: none; }
.table select { width: auto; }
.actions { display: flex; gap: 6px; justify-content: flex-end; align-items: center; flex-wrap: wrap; }
.row-muted td { opacity: .55; }

/* Hesap formu */
.test-box { display: flex; align-items: flex-start; gap: 12px; padding: 12px; background: #f8fafc; border: 1px dashed #cbd5e1; border-radius: 8px; }
.test-box #test-result div { margin: 2px 0; }
.ok { color: var(--success); }

/* Şablonlar */
.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.template-card { display: flex; flex-direction: column; gap: 6px; }
.template-card-head { display: flex; justify-content: space-between; gap: 8px; }
.template-body { white-space: pre-wrap; font: inherit; font-size: 12.5px; color: #374151; background: #f9fafb; border-radius: 6px; padding: 8px; max-height: 160px; overflow: auto; flex: 1; }
.template-card .actions { justify-content: flex-start; }

/* Raporlar */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 14px; }
.stat { display: flex; flex-direction: column; gap: 4px; }
.stat strong { font-size: 26px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 14px; }
.bar-chart { display: flex; align-items: flex-end; gap: 3px; height: 180px; padding-top: 8px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; min-width: 0; }
.bars { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 1px; }
.bar { width: 45%; max-width: 12px; border-radius: 3px 3px 0 0; min-height: 1px; }
.bar-in, .dot-in { background: #3b82f6; }
.bar-out, .dot-out { background: #22c55e; }
.bar-label { font-size: 10px; color: var(--muted); margin-top: 4px; }
.legend { display: flex; align-items: center; gap: 6px; margin-top: 8px; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-left: 8px; }

/* Giriş */
.guest { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; background: linear-gradient(160deg, #0f172a, #1e293b); }
.guest-box { width: 100%; max-width: 380px; }
.brand-center { justify-content: center; padding-bottom: 20px; }

/* Mobil */
@media (max-width: 1100px) {
  .thread-layout { grid-template-columns: 1fr; }
  .thread-side { position: static; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 800px) {
  .sidebar { position: fixed; left: -260px; z-index: 50; transition: left .2s; }
  .sidebar.open { left: 0; box-shadow: 0 0 0 100vmax rgba(0,0,0,.4); }
  .menu-toggle { display: inline-block; background: none; border: 1px solid var(--border); border-radius: 8px; padding: 4px 10px; font-size: 18px; margin-bottom: 10px; cursor: pointer; }
  .main { padding: 14px; }
  .row2, .row3, .grid2 { grid-template-columns: 1fr; }
  .search input { width: 100%; }
  .head-actions, .search { width: 100%; }
}
