:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --text: #1d1d1b;
  --muted: #6b6a66;
  --line: #e4e1da;
  --accent: #b5532f;
  --accent-soft: #f6e6de;
  --accent-text: #8f3e20;
  --ok: #2f7a4f;
  --ok-soft: #e1f0e6;
  --warn: #9a6a00;
  --warn-soft: #fbefd2;
  --danger: #b3261e;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  --radius: 12px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141413;
    --surface: #1d1d1b;
    --surface-2: #232321;
    --text: #edebe6;
    --muted: #9c9a94;
    --line: #33322f;
    --accent: #e07a52;
    --accent-soft: #3a2519;
    --accent-text: #f0a383;
    --ok: #6cc391;
    --ok-soft: #1c3426;
    --warn: #e2b14a;
    --warn-soft: #3a2f14;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text); font-family: var(--font);
  font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
code { background: var(--surface-2); border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; font-size: .9em; }

/* Layout */
.app { display: grid; grid-template-columns: 232px 1fr; height: 100vh; height: 100dvh; }
.sidebar {
  border-right: 1px solid var(--line); background: var(--surface-2);
  display: flex; flex-direction: column; padding: 20px 14px; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 0 8px 18px; letter-spacing: -.01em; }
.brand svg { width: 28px; height: 28px; }
.nav-btn {
  display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; cursor: pointer;
  padding: 9px 10px; border-radius: 9px; color: var(--muted); font-weight: 500; text-align: left;
}
.nav-btn svg { width: 19px; height: 19px; flex: none; }
.nav-btn:hover { background: var(--line); color: var(--text); }
.nav-btn.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.badge { margin-left: auto; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; border-radius: 99px; padding: 1px 7px; }
.badge:empty { display: none; }
.sidebar .foot { margin-top: auto; font-size: 12.5px; color: var(--muted); padding: 8px; }

main { overflow: hidden; display: flex; flex-direction: column; min-width: 0; }
.view { display: none; flex: 1; overflow-y: auto; }
.view.active { display: flex; flex-direction: column; }
.page { width: 100%; max-width: 920px; margin: 0 auto; padding: 28px 24px 40px; }
.page-head { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 24px; letter-spacing: -.02em; }
.page-head .sub { color: var(--muted); font-size: 14px; }
.page-head .spacer { flex: 1; }

/* Task banner */
.taskbar { display: none; align-items: center; gap: 10px; padding: 9px 20px; background: var(--accent-soft); color: var(--accent-text); font-size: 13.5px; border-bottom: 1px solid var(--line); }
.taskbar.show { display: flex; }
.spinner { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Controls */
.btn {
  border: 1px solid var(--line); background: var(--surface); padding: 8px 14px; border-radius: 9px; cursor: pointer;
  font-weight: 500; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: none; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }
.input {
  border: 1px solid var(--line); background: var(--surface); padding: 9px 12px; border-radius: 9px; width: 100%; outline: none;
}
.input:focus { border-color: var(--accent); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > .input { flex: 1; min-width: 140px; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 500; font-size: 13.5px; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .input { flex: 1; min-width: 160px; width: auto; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.list { display: flex; flex-direction: column; gap: 10px; }
.job { padding: 14px 16px; display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: start; }
.job .title { font-weight: 600; font-size: 15.5px; line-height: 1.35; }
.job .title a { color: var(--text); }
.job .meta { color: var(--muted); font-size: 13.5px; grid-column: 1; }
.job .meta a { color: var(--muted); }
.job .actions { grid-row: 1 / span 2; grid-column: 2; display: flex; gap: 4px; }
.job.unseen { border-left: 3px solid var(--accent); }
.job.closed { opacity: .6; }
.pill { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 1px 8px; border-radius: 99px; margin-left: 6px; vertical-align: 2px; }
.pill.new { background: var(--accent-soft); color: var(--accent-text); }
.pill.match { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.src { background: #e3ecf7; color: #2b5797; }
@media (prefers-color-scheme: dark) { .pill.src { background: #1d2a3b; color: #8fb3e6; } }
.pill.muted { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.icon-btn { border: 0; background: none; cursor: pointer; padding: 6px; border-radius: 8px; color: var(--muted); display: inline-flex; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }
.empty { text-align: center; color: var(--muted); padding: 48px 20px; }
.empty b { color: var(--text); display: block; font-size: 16px; margin-bottom: 4px; }

.firm { padding: 12px 16px; display: flex; align-items: center; gap: 12px; cursor: pointer; }
.firm:hover { border-color: var(--muted); }
.firm .name { font-weight: 600; }
.firm .meta { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.firm .meta .pill { margin-top: 2px; }
.firm .grow { flex: 1; min-width: 0; }
.firm .count { text-align: right; font-size: 13px; color: var(--muted); white-space: nowrap; }
.firm .count b { color: var(--ok); font-size: 15px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 22px; }
.stat { padding: 14px 16px; }
.stat .n { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.stat .l { color: var(--muted); font-size: 12.5px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 99px; padding: 4px 6px 4px 12px; font-size: 13.5px; }
.chip button { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0 4px; font-size: 16px; line-height: 1; }
.chip.region { padding-right: 6px; }
.chip.region small { color: var(--muted); }

section.block { margin-bottom: 26px; }
section.block h2 { font-size: 15px; margin: 0 0 4px; }
section.block p.help { color: var(--muted); font-size: 13.5px; margin: 0 0 10px; }
.settings-card { padding: 18px; margin-bottom: 14px; }
.toggle { display: flex; align-items: center; gap: 10px; padding: 6px 0; cursor: pointer; }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }

/* Chat */
.chat-wrap { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.messages { flex: 1; overflow-y: auto; padding: 24px 0 12px; }
.messages-inner { max-width: 780px; margin: 0 auto; padding: 0 20px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 88%; padding: 10px 14px; border-radius: 14px; white-space: normal; word-wrap: break-word; }
.msg p { margin: 0 0 6px; } .msg p:last-child { margin-bottom: 0; }
.msg ul { margin: 4px 0 6px; padding-left: 20px; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg.user code { background: rgba(255,255,255,.15); border-color: transparent; color: #fff; }
.msg.bot { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 4px; box-shadow: var(--shadow); }
.msg.bot.wide { max-width: 100%; width: 100%; }
.msg .list { margin-top: 10px; }
.msg .job, .msg .firm { box-shadow: none; }
.msg .more { color: var(--muted); font-size: 13px; margin-top: 8px; }
.composer { border-top: 1px solid var(--line); background: var(--surface-2); padding: 12px 20px calc(12px + env(safe-area-inset-bottom)); }
.composer-inner { max-width: 780px; margin: 0 auto; }
.suggestions { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 10px; scrollbar-width: none; }
.suggestions::-webkit-scrollbar { display: none; }
.suggestions button { flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 5px 12px; font-size: 13px; cursor: pointer; color: var(--muted); }
.suggestions button:hover { color: var(--text); border-color: var(--muted); }
.composer form { display: flex; gap: 8px; }
.composer .input { border-radius: 12px; padding: 11px 14px; font-size: 16px; }

/* Drawer */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.3); display: none; z-index: 1100; }
.overlay.show { display: block; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(480px, 100%); background: var(--bg); z-index: 1101;
  transform: translateX(100%); transition: transform .2s ease; overflow-y: auto; border-left: 1px solid var(--line);
}
.drawer.show { transform: none; }
.drawer .inner { padding: 22px; }
.drawer h2 { margin: 0 0 2px; font-size: 20px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
.kv { font-size: 13.5px; color: var(--muted); }
.kv div { padding: 2px 0; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: all .2s; z-index: 1200; max-width: 90vw; }
.toast.show { opacity: 1; transform: translateX(-50%); }

/* Mobile */
.tabbar { display: none; }
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .sidebar { display: none; }
  .tabbar {
    display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--line); background: var(--surface-2);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tabbar .nav-btn { flex-direction: column; gap: 2px; font-size: 11px; padding: 8px 0 6px; align-items: center; border-radius: 0; position: relative; }
  .tabbar .nav-btn.active { background: none; box-shadow: none; color: var(--accent); }
  .tabbar .badge { position: absolute; top: 4px; left: 54%; margin: 0; font-size: 10px; padding: 0 5px; }
  .page { padding: 18px 16px 28px; }
  .page-head h1 { font-size: 21px; }
  .stats { grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .stat { padding: 10px; }
  .stat .n { font-size: 19px; }
  .stat .l { font-size: 11px; line-height: 1.25; }
  .composer { padding-bottom: 12px; }
  .msg { max-width: 94%; }
  .messages-inner, .composer { padding-left: 14px; padding-right: 14px; }
  .job { grid-template-columns: 1fr; }
  .job .actions { grid-row: auto; grid-column: 1; justify-content: flex-start; margin-left: -6px; }
}

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { padding: 30px; width: 100%; max-width: 360px; }
.login h1 { font-size: 22px; margin: 12px 0 4px; }
.login p { color: var(--muted); margin: 0 0 18px; font-size: 14px; }
.login .err { color: var(--danger); font-size: 13.5px; margin-bottom: 10px; }

/* ---- More menu (phone) ---- */
.more-sheet { display: none; }
@media (max-width: 760px) {
  .tabbar { grid-template-columns: repeat(5, 1fr); }
  .more-sheet {
    position: fixed; right: 8px; bottom: calc(64px + env(safe-area-inset-bottom)); z-index: 45;
    background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 8px 30px rgba(0,0,0,.18);
    padding: 6px; min-width: 180px; flex-direction: column;
  }
  .more-sheet.show { display: flex; }
  .more-sheet .nav-btn { padding: 11px 12px; font-size: 15px; }
}

/* ---- Map ---- */
.map-wrap { flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative; }
.map-bar { display: flex; gap: 8px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2); flex-wrap: wrap; }
.map-bar .input { width: auto; min-width: 150px; flex: 0 1 220px; padding: 7px 10px; }
.map-count { color: var(--muted); font-size: 13px; margin-left: auto; }
#map { flex: 1; min-height: 300px; background: var(--surface-2); position: relative; z-index: 0; isolation: isolate; }  /* keeps Leaflet's layers (z-index 400-1000) inside the map */
.map-legend { position: absolute; left: 10px; bottom: 10px; z-index: 500; background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 7px 10px; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow); }
.map-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
.leaflet-popup-content { font-family: var(--font); font-size: 13.5px; }
.leaflet-popup-content b { font-size: 14.5px; }
.leaflet-popup-content .btn { margin-top: 8px; }
@media (prefers-color-scheme: dark) {
  .leaflet-tile-pane { filter: brightness(.75) contrast(1.1) saturate(.7); }
  .leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--text); }
}
@media (max-width: 760px) {
  .map-legend { display: none; }
  .map-bar { padding: 8px 10px; }
  .map-bar .seg button { padding: 5px 9px; font-size: 13px; }
}

/* ---- Autocomplete ---- */
.ac { position: relative; }
.ac-list { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 30; background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.12); max-height: 300px; overflow-y: auto; display: none; }
.ac-list.show { display: block; }
.ac-item { padding: 9px 12px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.ac-item:hover, .ac-item.active { background: var(--surface-2); }
.ac-item small { color: var(--muted); font-size: 12px; white-space: nowrap; }
.ac-item .k { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.scan-target { margin-top: 10px; padding: 10px 12px; border-radius: 10px; background: var(--accent-soft); color: var(--accent-text); font-size: 14px; }
.radio { display: flex; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; cursor: pointer; align-items: flex-start; }
.radio:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.radio input { margin-top: 3px; accent-color: var(--accent); width: 17px; height: 17px; flex: none; }
.radio small { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
.scan-warn { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 10px 12px; font-size: 13.5px; margin-bottom: 12px; }
.region-row { padding: 12px 14px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.region-row .grow { flex: 1; min-width: 160px; }
.region-row .meta { color: var(--muted); font-size: 13px; }
.task-row { padding: 12px 14px; display: flex; gap: 10px; align-items: center; }
.task-row .meta { color: var(--muted); font-size: 13px; }

/* ---- Log ---- */
.log-list { padding: 4px 0; }
.log-row { display: grid; grid-template-columns: 74px 10px 1fr; gap: 10px; padding: 8px 14px; border-bottom: 1px solid var(--line); font-size: 13.5px; align-items: baseline; }
.log-row:last-child { border-bottom: 0; }
.log-row time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.log-row .dot { width: 8px; height: 8px; border-radius: 50%; background: #b9b6ae; align-self: center; }
.log-row .dot.job_match { background: var(--ok); }
.log-row .dot.job { background: var(--accent); }
.log-row .dot.jobspage, .log-row .dot.firms { background: #5b6b7f; }
.log-row .dot.task, .log-row .dot.board { background: #2b5797; }
.log-row .dot.warn, .log-row .dot.error { background: var(--danger); }
.log-row .txt { overflow-wrap: anywhere; }
.log-row .txt a { margin-left: 6px; font-size: 12.5px; }
.log-day { padding: 10px 14px 4px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
@media (max-width: 760px) { .log-row { grid-template-columns: 52px 8px 1fr; gap: 8px; padding: 8px 12px; } }

/* ---- Pop-up stack ---- */
.toasts { position: fixed; top: 14px; right: 14px; z-index: 1200; display: flex; flex-direction: column; gap: 8px; width: min(360px, calc(100vw - 28px)); pointer-events: none; }
.pop { pointer-events: auto; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid #5b6b7f; border-radius: 12px; padding: 10px 12px 10px 14px;
  box-shadow: 0 8px 30px rgba(0,0,0,.14); font-size: 13.5px; display: flex; gap: 8px; align-items: flex-start; cursor: pointer;
  animation: popin .2s ease; transition: opacity .3s, transform .3s; }
.pop.out { opacity: 0; transform: translateX(20px); }
.pop b { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 1px; }
.pop .x { margin-left: auto; border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1; padding: 0 2px; }
.pop.job_match { border-left-color: var(--ok); }
.pop.job { border-left-color: var(--accent); }
.pop.warn { border-left-color: var(--danger); }
@keyframes popin { from { opacity: 0; transform: translateY(-8px); } }
@media (max-width: 760px) {
  .toasts { top: auto; bottom: calc(70px + env(safe-area-inset-bottom)); right: 10px; left: 10px; width: auto; }
  .pop { padding: 8px 10px 8px 12px; font-size: 13px; }
}

/* ---- Settings bits ---- */
.guide { margin: 10px 0 14px; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; background: var(--surface-2); }
.guide summary { cursor: pointer; font-weight: 600; font-size: 14px; }
.guide ol { padding-left: 20px; margin: 10px 0 4px; font-size: 13.5px; }
.guide li { margin-bottom: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 110px; gap: 10px; }
.imap-form { margin-top: 6px; }
.help.ok { color: var(--ok); }
.help.bad { color: var(--danger); }

.target-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 20px; }
.sub-label { display: block; font-size: 12.5px; color: var(--muted); font-weight: 600; margin: 4px 0 2px; }
@media (max-width: 760px) { .target-grid { grid-template-columns: 1fr; } }

/* Multi-select dropdown (role filter) */
.ms { position: relative; flex: 0 0 auto; }
.ms-btn { text-align: left; cursor: pointer; padding-right: 30px !important; min-width: 150px; white-space: nowrap;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 15px) 52%, calc(100% - 10px) 52%; background-size: 5px 5px; background-repeat: no-repeat; }
.ms-panel { display: none; position: absolute; top: calc(100% + 4px); left: 0; z-index: 1050; min-width: 230px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.12); }
.ms.open .ms-panel { display: block; }
.ms-panel label { display: flex; gap: 8px; align-items: center; padding: 7px 8px; border-radius: 6px; cursor: pointer; font-size: 14px; }
.ms-panel label:hover { background: var(--surface-2); }
.ms-panel .ms-clear { width: 100%; margin-top: 4px; }
.inline-check { margin: 0; white-space: nowrap; font-size: 14px; }
