:root {
  --bg: #f4f6fa; --panel: #fff; --line: #e3e7ef; --text: #1b2330; --muted: #6b7587;
  --brand: #2457d6; --brand-soft: #e8eefc; --green: #16884a; --green-soft: #e3f5ea;
  --red: #c4372f; --red-soft: #fbe9e7; --amber: #a86400; --amber-soft: #fff3dc;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 12px; line-height: 1.25; }
h1 { font-size: 20px; } h2 { font-size: 17px; } h3 { font-size: 15px; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.center { display: grid; place-items: center; min-height: 60vh; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.hidden { display: none !important; }

/* buttons & inputs */
button, .btn { font: inherit; border: 1px solid var(--line); background: #fff; color: var(--text); border-radius: 8px; padding: 7px 12px; cursor: pointer; white-space: nowrap; }
button:hover { border-color: #c9d0dc; background: #fafbfd; }
button.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
button.primary:hover { background: #1d49b8; }
button.danger { color: var(--red); }
button.ghost { border-color: transparent; background: transparent; }
button.sm { padding: 4px 9px; font-size: 12px; }
button:disabled { opacity: .55; cursor: default; }
input, select, textarea { font: inherit; width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
textarea { resize: vertical; min-height: 160px; }
label { display: block; font-weight: 600; font-size: 12px; color: #3b4556; margin: 10px 0 4px; }
label.inline { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; font-size: 13px; margin: 8px 12px 0 0; }
label.inline input { width: auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.grid3 { display: grid; grid-template-columns: 2fr 1fr auto; gap: 0 10px; align-items: end; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* layout */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 4px; padding: 0 16px; height: 54px; background: #fff; border-bottom: 1px solid var(--line); }
.logo { font-weight: 700; font-size: 16px; margin-right: 16px; display: flex; align-items: center; gap: 8px; }
.logo i { width: 26px; height: 26px; border-radius: 7px; background: var(--brand); display: inline-block; }
.nav a { padding: 7px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.nav a:hover { background: var(--bg); text-decoration: none; }
.nav a.active { background: var(--brand-soft); color: var(--brand); }
.badge { display: inline-block; min-width: 18px; padding: 0 6px; border-radius: 9px; background: var(--red); color: #fff; font-size: 11px; font-weight: 700; text-align: center; line-height: 18px; margin-left: 4px; }
.badge.grey { background: #d7dce5; color: #3b4556; }
.page { padding: 18px; max-width: 1400px; margin: 0 auto; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 16px; }

/* inbox */
.inbox { display: grid; grid-template-columns: 220px 360px 1fr; gap: 12px; height: calc(100vh - 54px - 36px); }
.inbox > .panel { overflow: auto; }
.sitelist a { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; color: var(--text); border-left: 3px solid transparent; }
.sitelist a:hover { background: var(--bg); text-decoration: none; }
.sitelist a.active { background: var(--brand-soft); border-left-color: var(--brand); font-weight: 600; }
.sitelist .warn { color: var(--red); font-size: 11px; }
.tl-head { padding: 10px; border-bottom: 1px solid var(--line); display: flex; gap: 6px; position: sticky; top: 0; background: #fff; }
.thread-item { display: block; padding: 10px 12px; border-bottom: 1px solid var(--line); color: var(--text); cursor: pointer; }
.thread-item:hover { background: #f9fafc; text-decoration: none; }
.thread-item.active { background: var(--brand-soft); }
.thread-item.unread .ti-who, .thread-item.unread .ti-subj { font-weight: 700; }
.thread-item.unread .ti-who::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--brand); margin-right: 6px; }
.ti-top { display: flex; justify-content: space-between; gap: 8px; }
.ti-who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ti-subj { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ti-snip { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 10px; background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.chip.green { background: var(--green-soft); color: var(--green); border-color: transparent; }
.chip.red { background: var(--red-soft); color: var(--red); border-color: transparent; }
.chip.amber { background: var(--amber-soft); color: var(--amber); border-color: transparent; }
.chip.blue { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.conv-head { padding: 14px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; z-index: 1; }
.msg { margin: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius); }
.msg.out { background: #f7f9ff; border-color: #d9e2fb; }
.msg-head { padding: 9px 12px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 10px; font-size: 13px; }
.msg-body { padding: 12px; white-space: pre-wrap; word-break: break-word; }
.msg-body.html { white-space: normal; padding: 0; }
.msg-body iframe { width: 100%; height: 480px; border: 0; background: #fff; border-radius: 0 0 var(--radius) var(--radius); }
.reply-box { margin: 14px 16px 20px; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* leads */
.lead { padding: 14px 16px; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; }
.lead:last-child { border-bottom: 0; }
.lead.new { border-left: 4px solid var(--amber); }
.lead-main .who { font-size: 15px; font-weight: 600; }
.lead-contact a { margin-right: 14px; }
.lead-summary { margin-top: 6px; white-space: pre-wrap; }
.lead-actions { display: flex; flex-direction: column; gap: 6px; align-items: stretch; }
details summary { cursor: pointer; color: var(--muted); font-size: 12px; margin-top: 6px; }
dl.kv { display: grid; grid-template-columns: 140px 1fr; gap: 3px 10px; margin: 8px 0 0; font-size: 13px; }
dl.kv dt { color: var(--muted); text-transform: capitalize; }
dl.kv dd { margin: 0; word-break: break-word; }

/* tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfd; }
.matrix-wrap { overflow: auto; }
.matrix th.site { writing-mode: initial; min-width: 130px; text-align: center; }
.matrix td { text-align: center; }
.matrix td.user { text-align: left; white-space: nowrap; }
.tog { border: 1px solid var(--line); background: #fff; border-radius: 14px; padding: 2px 9px; font-size: 12px; color: var(--muted); margin: 2px; }
.tog.on { background: var(--green-soft); color: var(--green); border-color: #b9e3c9; font-weight: 600; }
.tog.on.alert { background: var(--amber-soft); color: var(--amber); border-color: #f1d49c; }

/* modal & toast */
.overlay { position: fixed; inset: 0; background: rgba(20,28,40,.45); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { background: #fff; border-radius: 12px; width: min(680px, 100%); max-height: 92vh; overflow: auto; padding: 20px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: #1b2330; color: #fff; padding: 10px 14px; border-radius: 10px; max-width: 360px; box-shadow: 0 8px 24px rgba(0,0,0,.25); white-space: pre-line; cursor: pointer; }
.toast.alert { background: #fff; color: var(--text); border-left: 5px solid var(--amber); }
.toast.error { background: var(--red); }
.dropdown { position: absolute; right: 12px; top: 50px; width: 380px; max-height: 70vh; overflow: auto; z-index: 30; }
.notif { padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.notif:hover { background: #f9fafc; }
.notif.unread { background: #fffaf0; }
.notif .t { font-weight: 600; } .notif .b { white-space: pre-line; color: var(--muted); font-size: 12px; }
.auth-box { width: min(380px, 92vw); margin: 10vh auto; }
code.copy { display: block; padding: 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; word-break: break-all; font-size: 12px; }
ol.steps li { margin-bottom: 6px; }
.err { color: var(--red); font-size: 13px; margin-top: 8px; }

@media (max-width: 1000px) {
  .inbox { grid-template-columns: 1fr; height: auto; }
  .inbox > .panel { max-height: none; }
  .grid2 { grid-template-columns: 1fr; }
  .nav a { padding: 7px 8px; }
}
