:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #15181d;
  --muted: #5f6672;
  --line: #e2e5ea;
  --brand: #128c4a;
  --brand-ink: #ffffff;
  --danger: #c62828;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --card: #1a1d23;
    --ink: #eceef1;
    --muted: #9aa1ad;
    --line: #2c3139;
    --brand: #2bb36a;
    --brand-ink: #06140b;
    --danger: #ef6b6b;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
a { color: var(--brand); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--danger); font-size: 14px; margin: 0; min-height: 1em; }
.loading { padding: 40px; text-align: center; color: var(--muted); }

.wrap { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }

input, select, textarea {
  font: inherit; color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); border-color: transparent; }
input[type="color"] { padding: 2px; height: 40px; width: 60px; }
input[type="checkbox"] { width: auto; accent-color: var(--brand); }
label { display: flex; flex-direction: column; gap: 5px; font-size: 14px; font-weight: 500; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }

.btn {
  font: inherit; font-weight: 600; border: 0; border-radius: 9px; padding: 9px 16px;
  background: var(--brand); color: var(--brand-ink); cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn:disabled { opacity: .6; cursor: wait; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 13px; }

/* top bar */
.top { background: var(--card); border-bottom: 1px solid var(--line); }
.top .wrap { padding-top: 12px; padding-bottom: 12px; }
.logo { font-weight: 800; font-size: 17px; color: var(--ink); text-decoration: none; }
.badge { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 99px; background: var(--bg); border: 1px solid var(--line); }

/* auth */
.auth { max-width: 380px; margin: 8vh auto; }
[hidden] { display: none !important; }
.connect-site { display: flex; flex-direction: column; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); word-break: break-all; }
.choice { flex-direction: row; align-items: flex-start; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; font-weight: 400; }
.choice.on { border-color: var(--brand); outline: 1px solid var(--brand); }
.choice input { width: auto; margin-top: 4px; accent-color: var(--brand); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; overflow-y: hidden; }
.tab { font: inherit; background: none; border: 0; padding: 10px 14px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab.active { color: var(--ink); border-bottom-color: var(--brand); font-weight: 600; }

/* stats */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.tile b { display: block; font-size: 26px; font-variant-numeric: tabular-nums; }
.tile span { font-size: 13px; color: var(--muted); }
@media (max-width: 700px) { .tiles { grid-template-columns: repeat(2, 1fr); } }

/* settings */
.settings { display: grid; grid-template-columns: 1fr 380px; gap: 20px; align-items: start; }
.preview { position: sticky; top: 16px; }
.preview iframe { width: 100%; height: 620px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
@media (max-width: 900px) { .settings { grid-template-columns: 1fr; } .preview { position: static; } }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 0; display: flex; flex-direction: column; gap: 12px; }
legend { font-weight: 700; padding: 0 6px; }
.agent-row { display: grid; grid-template-columns: 1fr 1fr 1.3fr auto; gap: 8px; align-items: center; }
@media (max-width: 560px) { .agent-row { grid-template-columns: 1fr 1fr; } }
.days { display: flex; flex-wrap: wrap; gap: 10px; }

/* leads */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
td.msg { max-width: 260px; white-space: pre-wrap; word-break: break-word; }
td.page { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 99px; border: 1px solid var(--line); background: none; cursor: pointer; color: var(--ink); }
.pill.new { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.empty { text-align: center; padding: 30px; color: var(--muted); }
/* Phones: each lead becomes a stacked card so "Reply on WhatsApp" is always visible */
@media (max-width: 640px) {
  table thead { display: none; }
  table, tbody, tr, td { display: block; }
  tr { padding: 12px 0; border-bottom: 1px solid var(--line); }
  td { border: 0; padding: 3px 0; max-width: none !important; }
  td.empty { padding: 30px 0; }
}

pre.code { background: #0f1115; color: #d7f5e2; padding: 14px; border-radius: 10px; overflow-x: auto; font-size: 13px; white-space: pre-wrap; word-break: break-all; margin: 0; }
ol.steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--ink); padding: 22px; width: min(420px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.45); }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 9px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 10; }
#toast.show { opacity: 1; }
