:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6eb;
  --text: #16191f;
  --muted: #5d6676;
  --accent: #2457d6;
  --accent-ink: #ffffff;
  --accent-soft: #e8eefc;
  --good: #14804a;
  --good-soft: #e3f4ea;
  --warn: #a36100;
  --warn-soft: #fcf0d8;
  --bad: #b3261e;
  --bad-soft: #fbe6e4;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216; --surface: #171b21; --surface-2: #1e242c; --border: #2a313b;
    --text: #e8ebf0; --muted: #9aa4b2; --accent: #6b93f5; --accent-ink: #0b1220; --accent-soft: #1b2744;
    --good: #4cc38a; --good-soft: #14291f; --warn: #e5a93d; --warn-soft: #2e2410;
    --bad: #f2736b; --bad-soft: #2f1816; --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1216; --surface: #171b21; --surface-2: #1e242c; --border: #2a313b;
  --text: #e8ebf0; --muted: #9aa4b2; --accent: #6b93f5; --accent-ink: #0b1220; --accent-soft: #1b2744;
  --good: #4cc38a; --good-soft: #14291f; --warn: #e5a93d; --warn-soft: #2e2410;
  --bad: #f2736b; --bad-soft: #2f1816; --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Bengali", sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 0 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; }

/* ---------- top nav ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1200px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 20px; height: 56px; }
.brand { font-weight: 700; letter-spacing: -.01em; color: var(--text); white-space: nowrap; }
.brand span { color: var(--accent); }
.nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { padding: 8px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; white-space: nowrap; }
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.linkbtn { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; padding: 8px; }
.linkbtn:hover { color: var(--text); }

.page { max-width: 1200px; margin: 0 auto; padding: 24px 16px 64px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.crumbs { font-size: .85rem; color: var(--muted); margin-bottom: 6px; }

/* ---------- surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 20px; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 20px; }
.grid.two { grid-template-columns: 1fr 1fr; }
.grid.side { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 860px) { .grid.two, .grid.side { grid-template-columns: 1fr; } }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat .num { display: block; font-size: 1.6rem; font-weight: 700; line-height: 1.2; }
.stat .lbl { color: var(--muted); font-size: .82rem; }
.stat.good .num { color: var(--good); } .stat.warn .num { color: var(--warn); } .stat.bad .num { color: var(--bad); }

/* ---------- controls ---------- */
label { font-weight: 600; font-size: .88rem; display: block; margin-bottom: 6px; }
input[type=text], input[type=password], input[type=search], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit;
}
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { resize: vertical; min-height: 120px; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.field { margin-bottom: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--accent); color: var(--accent-ink); border: 1px solid transparent;
  padding: 9px 14px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; filter: none; }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.good { background: var(--good); color: #fff; }
.btn.sm { padding: 5px 10px; font-size: .85rem; }
.btn.block { width: 100%; padding: 12px; }

.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; color: var(--muted); padding: 7px 14px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- badges ---------- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.high, .badge.good, .badge.messaged, .badge.converted { background: var(--good-soft); color: var(--good); }
.badge.medium, .badge.warn, .badge.replied { background: var(--warn-soft); color: var(--warn); }
.badge.bad, .badge.not_interested { background: var(--bad-soft); color: var(--bad); }
.badge.info, .badge.new, .badge.search { background: var(--accent-soft); color: var(--accent); }
.badge.low, .badge.skipped_small, .badge.skipped { background: var(--surface-2); color: var(--muted); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr.click { cursor: pointer; }
table.data tbody tr.click:hover { background: var(--surface-2); }
.cell-main { font-weight: 600; color: var(--text); }
.cell-sub { color: var(--muted); font-size: .82rem; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; max-width: 340px; }

/* ---------- key/value details ---------- */
dl.kv { display: grid; grid-template-columns: 150px 1fr; gap: 10px 16px; margin: 0; }
dl.kv dt { color: var(--muted); font-size: .85rem; }
dl.kv dd { margin: 0; word-break: break-word; }
@media (max-width: 520px) { dl.kv { grid-template-columns: 1fr; gap: 2px; } dl.kv dt { margin-top: 10px; } }

.msg { white-space: pre-wrap; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; font-size: .9rem; }

/* ---------- timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 18px 26px; }
.timeline li::before { content: ""; position: absolute; left: 6px; top: 6px; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.timeline li::after { content: ""; position: absolute; left: 10px; top: 18px; bottom: 0; width: 1px; background: var(--border); }
.timeline li:last-child::after { display: none; }
.timeline .when { color: var(--muted); font-size: .8rem; }

/* ---------- feedback ---------- */
.alert { padding: 12px 14px; border-radius: 8px; font-size: .9rem; margin-bottom: 14px; }
.alert.error { background: var(--bad-soft); color: var(--bad); }
.alert.ok { background: var(--good-soft); color: var(--good); }
.alert.info { background: var(--accent-soft); color: var(--accent); }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -3px; margin-right: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; z-index: 50; font-size: .9rem; }

/* ---------- map / uploads ---------- */
#map { height: 380px; width: 100%; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); }
.drop { border: 2px dashed var(--border); border-radius: 10px; min-height: 150px; display: flex; align-items: center; justify-content: center; text-align: center; color: var(--muted); cursor: pointer; position: relative; overflow: hidden; background: var(--surface-2); }
.drop:hover { border-color: var(--accent); }
.drop img { width: 100%; height: 150px; object-fit: cover; display: none; }
.drop .x { position: absolute; top: 8px; right: 8px; width: 28px; height: 28px; border-radius: 50%; border: 0; background: rgba(0,0,0,.65); color: #fff; cursor: pointer; display: none; }

/* ---------- board ---------- */
.board { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.col { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); min-width: 270px; width: 270px; padding: 12px; }
.col h2 { display: flex; justify-content: space-between; font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.kcard { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin-bottom: 10px; }
.kcard h3 { margin: 6px 0 2px; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; }

@media (max-width: 600px) {
  .page { padding: 16px 12px 48px; }
  .card { padding: 14px; }
  .topbar-inner { gap: 10px; }
  .btn.sm-block { width: 100%; }
}
