:root {
  --bg: #f6f7f9; --panel: #fff; --line: #e4e7ec; --text: #101828; --muted: #667085;
  --accent: #0f766e; --accent-2: #ccfbf1; --danger: #b42318; --warn: #b54708;
  --in: #ffffff; --out: #dcf5ec; --radius: 10px;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 12px; } .error { color: var(--danger); min-height: 1em; }
a { color: var(--accent); cursor: pointer; text-decoration: none; }
h1 { font-size: 20px; margin: 0 0 4px; } h2 { font-size: 15px; margin: 0 0 12px; } h3 { font-size: 13px; margin: 0 0 8px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; width: 100%; color: var(--text); }
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-2); border-color: var(--accent); }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
label input, label select, label textarea { margin-top: 4px; }
.btn { font: inherit; border: 1px solid var(--line); background: #fff; padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { background: #f2f4f7; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); } .btn.sm { padding: 4px 10px; font-size: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stack > * + * { margin-top: 16px; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; background: #f2f4f7; padding: 2px 6px; border-radius: 4px; word-break: break-all; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; }
.login-card { width: 340px; background: #fff; padding: 28px; border-radius: 14px; border: 1px solid var(--line); box-shadow: 0 10px 30px rgba(16,24,40,.06); }
.login-card .btn { width: 100%; margin-top: 6px; }

/* Shell */
.app { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.sidebar { background: #0b1f1d; color: #d0e7e3; padding: 18px 14px; display: flex; flex-direction: column; gap: 14px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; }
.logo { background: var(--accent); color: #fff; width: 28px; height: 28px; border-radius: 7px; display: grid; place-items: center; font-size: 12px; }
.tenant-select { background: #123430; color: #fff; border-color: #1f4a44; }
nav { display: flex; flex-direction: column; gap: 2px; }
nav a { color: #c4dcd8; padding: 8px 10px; border-radius: 7px; }
nav a:hover { background: #123430; } nav a.active { background: var(--accent); color: #fff; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; }
.sidebar-foot a { color: #8fc9c0; }
.mode { font-size: 11px; padding: 4px 8px; border-radius: 6px; display: inline-block; }
.mode.mock { background: #fef0c7; color: #7a2e0e; } .mode.live { background: #d1fadf; color: #05603a; }
main { padding: 22px 26px; min-width: 0; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat b { font-size: 22px; display: block; } .stat span { color: var(--muted); font-size: 12px; }

/* Board */
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input { max-width: 260px; } .toolbar select { max-width: 200px; }
.board { display: grid; grid-template-columns: repeat(5, minmax(210px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.col { background: #eef0f3; border-radius: var(--radius); padding: 8px; min-height: 200px; }
.col-head { display: flex; justify-content: space-between; font-weight: 600; font-size: 12px; text-transform: uppercase; color: var(--muted); padding: 4px 6px 8px; }
.col.drop { outline: 2px dashed var(--accent); }
.lead-card { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 8px; cursor: pointer; }
.lead-card:hover { border-color: #b8c0cc; }
.lead-card .name { font-weight: 600; display: flex; justify-content: space-between; gap: 6px; }
.lead-card .last { color: var(--muted); font-size: 12px; margin-top: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 999px; background: #f2f4f7; color: #344054; white-space: nowrap; display: inline-block; }
.badge.ctwa_ad { background: #d1fadf; color: #05603a; } .badge.whatsapp { background: #e3f8ef; color: #05603a; }
.badge.meta_lead_form { background: #dbe8fe; color: #1849a9; } .badge.google_lead_form { background: #fef0c7; color: #93370d; }
.badge.instagram_dm { background: #fce7f6; color: #9e165f; } .badge.facebook_dm { background: #e0eaff; color: #2d31a6; }
.badge.bot-off { background: #fee4e2; color: var(--danger); }

/* Drawer */
.drawer { position: fixed; top: 0; right: 0; width: min(560px, 100%); height: 100vh; background: #fff; border-left: 1px solid var(--line); box-shadow: -10px 0 30px rgba(16,24,40,.08); display: flex; flex-direction: column; z-index: 20; }
.drawer-head { padding: 16px 18px; border-bottom: 1px solid var(--line); }
.drawer-head .top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.drawer-head .controls { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; margin-top: 12px; align-items: center; }
.tabs { display: flex; gap: 4px; padding: 0 18px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 10px 10px; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs a.active { color: var(--text); border-color: var(--accent); }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px 18px; }
.thread { display: flex; flex-direction: column; gap: 8px; background: #efeae2; padding: 14px; border-radius: var(--radius); min-height: 100%; }
.bubble { max-width: 80%; padding: 8px 10px; border-radius: 10px; white-space: pre-wrap; box-shadow: 0 1px 1px rgba(0,0,0,.06); }
.bubble.in { background: var(--in); align-self: flex-start; }
.bubble.out { background: var(--out); align-self: flex-end; }
.bubble.failed { background: #fee4e2; }
.bubble .meta { font-size: 10.5px; color: var(--muted); margin-top: 4px; text-align: right; }
.composer { border-top: 1px solid var(--line); padding: 12px 18px; display: flex; gap: 8px; }
.composer textarea { min-height: 42px; height: 42px; }
.notice { background: #fffaeb; border: 1px solid #fedf89; color: #7a2e0e; padding: 10px 12px; border-radius: 8px; font-size: 13px; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-word; }
.events { list-style: none; padding: 0; margin: 0; } .events li { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; }

/* Tables / lists */
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
.kb-item { border: 1px solid var(--line); border-radius: 8px; padding: 12px; background: #fff; }
.kb-item + .kb-item { margin-top: 8px; }
.kb-item .q { font-weight: 600; } .kb-item .a { color: #344054; margin-top: 4px; white-space: pre-wrap; }
.channel { border: 1px solid var(--line); border-radius: 8px; padding: 12px; background: #fff; display: flex; justify-content: space-between; gap: 12px; }
.channel + .channel { margin-top: 8px; }
.sim-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #101828; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 50; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  nav { flex-direction: row; flex-wrap: wrap; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .grid2 { grid-template-columns: 1fr; }
  main { padding: 16px; }
}
