:root {
  --bg: #F3F5F7;
  --surface: #FFFFFF;
  --ink: #1B2430;
  --muted: #6B7785;
  --line: #DEE3E8;
  --side: #15202B;
  --side-ink: #C9D3DC;
  --accent: #0E7C6B;
  --accent-ink: #FFFFFF;
  --accent-soft: #DCF2EE;
  --visitor-soft: #E8EEF4;
  --danger: #B3261E;
  --warn: #B7791F;
  --warn-soft: #FFF4DF;
  --radius: 10px;
  --font: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font-family: var(--font); font-size: 15px; line-height: 1.5; color: var(--ink); background: var(--bg); }
a { color: var(--accent); }
h1 { font-size: 24px; font-weight: 600; margin: 0 0 12px; }
h2 { font-size: 17px; font-weight: 600; margin: 0 0 14px; }
h3 { font-size: 15px; font-weight: 600; margin: 20px 0 10px; }
p { margin: 0 0 10px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* Uygulama iskeleti */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; padding: 20px 14px; }
.side-brand { color: #fff; font-weight: 600; font-size: 17px; padding: 4px 10px 18px; }
.side-brand .brand img { background: #fff; border-radius: 6px; padding: 2px; }
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-nav a { color: var(--side-ink); text-decoration: none; padding: 9px 10px; border-radius: 7px; }
.side-nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.side-nav a.on { background: rgba(255,255,255,.12); color: #fff; }
.side-user { margin-top: auto; padding: 14px 10px 0; border-top: 1px solid rgba(255,255,255,.1); font-size: 14px; }
.side-user-name { color: #fff; font-weight: 500; }
.side-user-role { color: var(--muted); font-size: 13px; }
.side-logout { display: inline-block; margin-top: 8px; color: var(--side-ink); font-size: 13px; }
.main { padding: 24px; min-width: 0; }
.main-plain { min-height: 100vh; display: flex; align-items: center; justify-content: center; }

/* Marka */
.brand { display: inline-flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { height: 28px; width: auto; max-width: 120px; object-fit: contain; }
.brand > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plain-wrap { width: 100%; max-width: 400px; }
.plain-brand { display: flex; justify-content: center; margin-bottom: 18px; font-weight: 600; font-size: 18px; }
.plain-brand .brand img { height: 40px; max-width: 200px; }
.logo-preview { background: var(--visitor-soft); border-radius: 7px; padding: 12px; margin-bottom: 10px; display: inline-block; }
.logo-preview img { height: 48px; width: auto; max-width: 240px; display: block; }
.widget-logo { height: 34px; width: auto; max-width: 110px; object-fit: contain; margin-right: 12px; background: #fff; border-radius: 6px; padding: 3px; }
.widget-head-text { flex: 1; min-width: 0; }

/* Kartlar, formlar */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; }
.card-narrow { width: 100%; max-width: 400px; }
.card-warn { border-color: var(--warn); background: var(--warn-soft); }
.two-col { display: grid; grid-template-columns: minmax(280px, 380px) 1fr; gap: 20px; align-items: start; }
label { display: block; font-size: 14px; font-weight: 500; margin-bottom: 12px; }
label.check { display: flex; gap: 8px; align-items: center; }
input, select, textarea { font: inherit; color: inherit; width: 100%; padding: 9px 11px; margin-top: 4px; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
label.check input { width: auto; margin: 0; }
input.small { width: 130px; display: inline-block; padding: 5px 8px; margin: 0 6px 0 0; font-size: 13px; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn { font: inherit; font-weight: 500; padding: 9px 16px; border-radius: 7px; border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer; text-decoration: none; display: inline-block; }
.btn:hover { background: #F3F5F7; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #0A6657; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: #FBEDEC; }
.link-btn { font: inherit; font-size: 13px; background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; }
form.inline { display: inline; margin-right: 10px; }
.flash { padding: 10px 14px; border-radius: 7px; margin-bottom: 16px; font-size: 14px; }
.flash-ok { background: var(--accent-soft); color: #0A5147; }
.flash-err { background: #FBEDEC; color: var(--danger); }

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-weight: 500; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--line); }
.table td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr.inactive td { color: var(--muted); }
.table td.actions { white-space: nowrap; }
.pill { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--visitor-soft); }
.pill-on { background: var(--accent-soft); color: #0A5147; }
.pill-off { background: #EEE; color: var(--muted); }
.linkcode { user-select: all; }

.stats { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; min-width: 120px; }
.stat-v { font-size: 22px; font-weight: 600; }
.stat-k { font-size: 13px; color: var(--muted); }

/* Görüşme ekranı */
.inbox { display: grid; grid-template-columns: 320px 1fr; height: calc(100vh - 48px); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.inbox-list { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.inbox-list-head { padding: 12px 14px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; }
.tab { font: inherit; font-size: 14px; border: 0; background: none; padding: 5px 10px; border-radius: 6px; cursor: pointer; color: var(--muted); }
.tab.on { background: var(--visitor-soft); color: var(--ink); font-weight: 500; }
.conv-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.conv-list li { padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.conv-list li:hover { background: #F7F9FA; }
.conv-list li.on { background: var(--accent-soft); }
.conv-list li.empty { color: var(--muted); cursor: default; }
.conv-top { display: flex; justify-content: space-between; gap: 8px; }
.conv-name { font-weight: 500; }
.conv-time { font-size: 12px; color: var(--muted); white-space: nowrap; }
.conv-sub { font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.conv-last { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { background: var(--accent); color: #fff; font-size: 12px; font-weight: 600; border-radius: 99px; padding: 0 7px; line-height: 18px; }

.inbox-chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.chat-empty { margin: auto; text-align: center; color: var(--ink); max-width: 320px; }
.chat { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-head { padding: 12px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.chat-title { font-weight: 600; }
.chat-meta { font-size: 13px; color: var(--muted); }
.chat-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.chat-actions select { width: auto; margin: 0; padding: 7px 10px; }
.msgs { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 72%; padding: 9px 13px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; }
.msg-visitor { align-self: flex-start; background: var(--visitor-soft); border-bottom-left-radius: 4px; }
.msg-agent { align-self: flex-end; background: var(--accent-soft); border-bottom-right-radius: 4px; }
.msg-system { align-self: center; background: none; color: var(--muted); font-size: 13px; padding: 2px 0; }
.msg-meta { display: block; font-size: 11px; color: var(--muted); margin-top: 3px; }
.composer { display: flex; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); align-items: flex-end; }
.composer textarea { margin: 0; resize: none; max-height: 140px; }
.readonly { padding: 12px 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: 14px; }

/* Form yönetimi ve ziyaretçi bilgileri */
.dept-pick { max-width: 320px; margin-bottom: 16px; }
.field-row { padding: 14px 0; border-top: 1px solid var(--line); }
.field-row:first-of-type { border-top: 0; padding-top: 0; }
.field-grid { display: grid; grid-template-columns: 1fr 160px 70px; gap: 10px; }
.field-foot { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.field-foot label { margin: 0; }
.info-pane { padding: 12px 18px; border-bottom: 1px solid var(--line); background: #F7F9FA; font-size: 14px; }
.info-pane dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; }
.info-pane dt { color: var(--muted); }
.info-pane dd { margin: 0; white-space: pre-wrap; }
.info-pane .kvkk-line { margin: 8px 0 0; font-size: 13px; }

/* Google Forms yönetimi */
.routing-form label.check { margin-bottom: 6px; }
.gform-add { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: end; margin-bottom: 8px; }
.gform-add label { margin: 0; }
.gform-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 10px; }
.gform-head .field-foot label { margin: 0; }
.gform-fields { font-size: 13px; margin-bottom: 10px; }
.gform-fields ul { margin: 6px 0 0; padding-left: 18px; }
.inactive-row { opacity: .6; }

/* Ziyaretçi sayfası */
.visitor-body { display: flex; align-items: center; justify-content: center; padding: 16px; }
.widget { width: 100%; max-width: 440px; height: min(640px, calc(100vh - 32px)); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; display: flex; flex-direction: column; overflow: hidden; }
.widget-head { background: var(--side); color: #fff; padding: 14px 18px; display: flex; justify-content: space-between; align-items: center; }
.widget-title { font-weight: 600; }
.widget-sub { font-size: 13px; color: var(--side-ink); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #7A8794; }
.dot.on { background: #3DD598; }
.widget-intro { padding: 22px; display: flex; flex-direction: column; gap: 6px; overflow-y: auto; }
.widget-intro label { margin-bottom: 6px; }
.widget-intro label.check { align-items: flex-start; font-weight: 400; font-size: 13px; margin: 6px 0 10px; }
.widget-intro label.check input { margin-top: 3px; }
.form-section { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 6px; }
.form-section-title { font-weight: 600; margin-bottom: 8px; }
fieldset.choice { border: 0; padding: 0; margin: 0 0 10px; }
fieldset.choice legend { font-size: 14px; font-weight: 500; padding: 0; margin-bottom: 4px; }
fieldset.choice label.check { margin: 2px 0; font-size: 14px; }
fieldset.scale { display: flex; flex-wrap: wrap; gap: 10px; }
fieldset.scale legend { width: 100%; }
fieldset.scale label.check { margin: 0; }
.kvkk { border: 1px solid var(--line); border-radius: 7px; padding: 8px 12px; font-size: 13px; margin-top: 6px; }
.kvkk summary { cursor: pointer; font-weight: 500; }
.kvkk-text { margin-top: 8px; color: var(--muted); max-height: 180px; overflow-y: auto; line-height: 1.5; }
.widget-errors { background: #FBEDEC; color: var(--danger); border-radius: 7px; padding: 8px 12px; font-size: 13px; margin-bottom: 8px; }
.widget-errors ul { margin: 0; padding-left: 18px; }
.widget-notice { margin: 16px 18px; padding: 12px 14px; border-radius: 8px; background: var(--warn-soft); color: #6F4A0E; font-size: 14px; }
.widget .msgs { padding: 16px; }
.widget .composer { padding: 10px 12px; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .side { flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 12px; gap: 6px; }
  .side-brand { padding: 0 8px 0 0; }
  .side-nav { flex-direction: row; }
  .side-user { margin: 0 0 0 auto; padding: 0; border: 0; display: flex; gap: 10px; align-items: center; }
  .side-user-role { display: none; }
  .side-logout { margin: 0; }
  .main { padding: 12px; }
  .two-col { grid-template-columns: 1fr; }
  .inbox { grid-template-columns: 1fr; height: calc(100vh - 80px); }
  .inbox-list { border-right: 0; }
  .inbox.chat-open .inbox-list { display: none; }
  .inbox:not(.chat-open) .inbox-chat { display: none; }
  .msg { max-width: 88%; }
  .field-grid { grid-template-columns: 1fr; }
  .gform-add { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: no-preference) {
  .conv-list li, .btn, .tab { transition: background .12s; }
}
