/* ===== Theme tokens ===== */
:root {
  --bg: #05070d;
  --bg-2: #080d18;
  --panel: #0b1220;
  --panel-2: #101a2e;
  --panel-3: #15223b;
  --line: #1c2b47;
  --line-2: #273a5e;
  --text: #e6eefc;
  --muted: #8ea3c4;
  --dim: #5d7194;
  --navy: #0a1a3a;
  --blue: #1f6bff;
  --blue-hover: #3b7eff;
  --blue-2: #7cc4ff;
  --red: #ff3b3b;          /* tiny accents only */
  --ok: #4fd1a5;
  --radius: 10px;
  --radius-sm: 7px;
  --topbar-h: 60px;
  --shadow: 0 10px 40px rgba(0, 0, 0, .45);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--blue-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ===== Buttons & inputs ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-2); background: var(--panel-2); cursor: pointer;
  font-weight: 600; white-space: nowrap; text-decoration: none !important; color: var(--text);
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--panel-3); border-color: var(--blue); }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-hover); }
.btn-ghost { background: transparent; }
.btn-danger:hover { border-color: var(--red); color: #ffd6d6; }
.btn-small { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px;
  border: 0; background: transparent; border-radius: 8px; cursor: pointer; color: var(--muted);
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.link-btn { background: none; border: 0; padding: 0; color: var(--blue-2); cursor: pointer; font-size: 13px; }
.link-btn:hover { text-decoration: underline; }

input[type="text"], input[type="email"], input[type="password"], input[type="search"],
input[type="number"], input[type="date"], input[type="tel"], select, textarea {
  width: 100%; height: 38px; padding: 0 12px;
  background: var(--bg-2); border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  outline: none;
}
textarea { height: auto; min-height: 84px; padding: 10px 12px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(31, 107, 255, .25); }
:focus-visible { outline: 2px solid var(--blue-2); outline-offset: 2px; }
label { display: block; color: var(--muted); font-size: 12px; font-weight: 500; }
label > input, label > select, label > textarea { margin-top: 4px; color: var(--text); font-size: 14px; }

/* ===== Top bar ===== */
.topbar {
  position: sticky; top: 0; z-index: 50;
  height: var(--topbar-h); display: flex; align-items: center; gap: 24px; padding: 0 20px;
  background: rgba(5, 7, 13, .92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none !important; flex-shrink: 0; }
.brand-mark { width: 34px; height: 34px; }
.brand-text { display: flex; flex-direction: column; line-height: 1; }
.brand-text small { font-size: 9px; letter-spacing: .28em; color: var(--muted); font-weight: 600; }
.brand-text strong { font-size: 20px; font-weight: 800; letter-spacing: -.01em; }
.brand-text strong b { color: var(--blue-2); }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a {
  padding: 8px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; text-decoration: none;
}
.nav a:hover { color: var(--text); background: var(--panel); }
.nav a.active { color: var(--text); background: var(--panel-2); box-shadow: inset 0 -2px 0 var(--blue); }
.topbar-right { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.mode-pill {
  font-size: 11px; font-weight: 600; color: var(--blue-2); border: 1px solid var(--line-2);
  padding: 3px 9px; border-radius: 99px; cursor: help;
}
.nav-toggle { display: none; }

/* ===== Views ===== */
main { min-height: calc(100vh - var(--topbar-h)); }
.view-search {
  display: grid; grid-template-columns: 400px 1fr;
  height: calc(100vh - var(--topbar-h));
}

/* ===== Home ===== */
#view-home { max-width: 1120px; margin: 0 auto; padding: 72px 24px 48px; }
.hero { display: grid; grid-template-columns: 1.6fr 1fr; gap: 48px; align-items: center; }
.eyebrow { color: var(--blue-2); font-weight: 600; letter-spacing: .14em; text-transform: uppercase; font-size: 12px; margin: 0 0 14px; }
.hero h1 { font-size: clamp(34px, 5vw, 54px); font-weight: 800; letter-spacing: -.025em; }
.hero h1 span { color: var(--blue-2); position: relative; }
.hero h1 span::after { content: ""; position: absolute; left: 0; right: 0; bottom: -2px; height: 3px; background: var(--red); border-radius: 2px; }
.lede { color: var(--muted); font-size: 17px; max-width: 60ch; }
.hero-cta { display: flex; gap: 12px; margin-top: 28px; flex-wrap: wrap; }
.hero-stats { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.hero-stats li {
  background: linear-gradient(135deg, var(--panel-2), var(--navy)); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 20px; display: flex; flex-direction: column;
}
.hero-stats strong { font-size: 26px; font-weight: 800; color: var(--blue-2); }
.hero-stats span { color: var(--muted); }
.features { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-top: 64px; }
.features article { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.features h3 { font-size: 16px; }
.features p { color: var(--muted); margin: 0; }
.fineprint { color: var(--dim); font-size: 12px; margin-top: 32px; text-align: center; }

/* ===== Sidebar / search ===== */
.sidebar { border-right: 1px solid var(--line); background: var(--panel); overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
.search-panel { display: flex; flex-direction: column; min-height: 0; flex: 1; padding: 16px 16px 0; }
.searchbox { position: relative; }
.searchbox svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--dim); }
.searchbox input { padding-left: 38px; height: 42px; font-size: 15px; }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px;
  border: 1px solid var(--line-2); border-radius: 99px; background: transparent; cursor: pointer;
  font-size: 12px; color: var(--muted);
}
.chip i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.chip[aria-pressed="true"] { color: var(--text); background: var(--panel-3); border-color: var(--blue); }
.results-head { display: flex; justify-content: space-between; align-items: center; margin: 14px 0 6px; color: var(--muted); font-size: 12px; }
.results { list-style: none; margin: 0 -16px; padding: 0 8px 16px; overflow-y: auto; flex: 1; min-height: 0; }
.result {
  display: block; width: 100%; text-align: left; padding: 12px; margin: 2px 0;
  border: 1px solid transparent; border-radius: var(--radius-sm); background: none; cursor: pointer;
}
.result:hover { background: var(--panel-2); border-color: var(--line); }
.result.active { background: var(--panel-3); border-color: var(--blue); }
.result-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.result h4 { margin: 0; font-size: 14px; font-weight: 600; }
.result .co { color: var(--blue-2); font-size: 13px; }
.result .meta { color: var(--muted); font-size: 12px; margin-top: 4px; display: flex; gap: 10px; flex-wrap: wrap; }
.badge {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 99px; background: var(--bg-2); border: 1px solid var(--line-2); white-space: nowrap;
}
.badge i { width: 7px; height: 7px; border-radius: 50%; }
.empty { color: var(--muted); text-align: center; padding: 36px 16px; }

/* ===== Detail ===== */
.detail { overflow-y: auto; padding: 16px; flex: 1; min-height: 0; }
.detail .back { margin-bottom: 12px; }
.detail h2 { font-size: 20px; margin-top: 10px; }
.detail .co { color: var(--blue-2); font-weight: 600; }
.detail .desc { color: var(--text); margin: 14px 0; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; font-size: 13px; margin: 14px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin: 22px 0 8px; font-weight: 600; }
.person { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.person b { display: block; }
.person span { color: var(--muted); font-size: 12px; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 2px solid var(--line-2); }
.timeline li { position: relative; padding: 4px 0 12px 10px; }
.timeline li::before { content: ""; position: absolute; left: -21px; top: 9px; width: 10px; height: 10px; border-radius: 50%; background: var(--panel); border: 2px solid var(--blue-2); }
.timeline li.current::before { background: var(--red); border-color: var(--red); }
.timeline .date { color: var(--muted); font-size: 12px; }

/* ===== Map ===== */
.map-wrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: radial-gradient(circle at 50% 50%, #0a1a3a 0%, #05070d 70%); }
.map-legend {
  position: absolute; left: 12px; bottom: 28px; background: rgba(8, 13, 24, .88); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 8px 10px; font-size: 11px; color: var(--muted);
  display: grid; grid-template-columns: repeat(2, auto); gap: 3px 14px;
}
.map-legend span { display: flex; align-items: center; gap: 6px; }
.map-legend i { width: 8px; height: 8px; border-radius: 50%; }
.map-reset { position: absolute; top: 12px; left: 12px; box-shadow: var(--shadow); }
.maplibregl-ctrl-attrib { background: rgba(5, 7, 13, .7) !important; color: var(--muted); }
.maplibregl-ctrl-attrib a { color: var(--muted) !important; }
.maplibregl-popup-content { background: var(--panel); color: var(--text); border: 1px solid var(--line-2); border-radius: 8px; padding: 8px 12px; font-size: 12px; box-shadow: var(--shadow); }
.maplibregl-popup-tip { border-top-color: var(--panel) !important; border-bottom-color: var(--panel) !important; }

/* ===== CRM ===== */
.view-crm { max-width: 1400px; margin: 0 auto; padding: 28px 24px 48px; }
.crm-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.crm-head h1 { font-size: 26px; margin: 0; }
.crm-head p { color: var(--muted); margin: 4px 0 0; }
.crm-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.crm-tools input[type="search"] { width: 240px; }

.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(230px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.col { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 320px; }
.col-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 12px 8px; font-weight: 600; }
.col-head small { color: var(--muted); font-weight: 500; }
.col-body { padding: 4px 8px 10px; flex: 1; display: flex; flex-direction: column; gap: 8px; border-radius: var(--radius); transition: background .15s; }
.col.drag-over .col-body { background: rgba(31, 107, 255, .1); outline: 1px dashed var(--blue); outline-offset: -4px; }
.card {
  background: var(--panel-2); border: 1px solid var(--line-2); border-radius: var(--radius-sm); padding: 10px 12px;
  cursor: grab; user-select: none;
}
.card:hover { border-color: var(--blue); }
.card.dragging { opacity: .45; }
.card h4 { margin: 0 0 2px; font-size: 14px; }
.card .co { color: var(--blue-2); font-size: 12px; }
.card .meta { color: var(--muted); font-size: 12px; margin-top: 6px; display: flex; justify-content: space-between; }

.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; background: var(--bg-2); }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--panel-2); }
td .sub { color: var(--muted); font-size: 12px; }
td.actions { white-space: nowrap; text-align: right; }
.status { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; border: 1px solid var(--line-2); }
.status-new { color: var(--blue-2); }
.status-qualified, .status-won { color: var(--ok); }
.status-dismissed, .status-lost { color: var(--dim); }

.gate { max-width: 460px; margin: 60px auto; text-align: center; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 36px 28px; }
.gate p { color: var(--muted); }

/* ===== Modal ===== */
.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .65); }
.modal-card {
  position: relative; width: min(520px, 100%); max-height: calc(100vh - 32px); overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 14px; padding: 24px; box-shadow: var(--shadow);
}
.modal-card h2 { font-size: 20px; padding-right: 32px; }
.modal-x { position: absolute; top: 14px; right: 14px; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form .full { grid-column: 1 / -1; }
.form-actions { grid-column: 1 / -1; display: flex; justify-content: space-between; gap: 8px; margin-top: 6px; }
.form-actions .right { display: flex; gap: 8px; margin-left: auto; }
.form-error { grid-column: 1 / -1; color: #ffb4b4; font-size: 13px; min-height: 0; }
.form-note { grid-column: 1 / -1; color: var(--muted); font-size: 13px; margin: 0; }
.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.tabs button { background: none; border: 0; padding: 8px 12px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--blue); }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 200;
  background: var(--panel-3); border: 1px solid var(--line-2); border-left: 3px solid var(--blue);
  padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); max-width: calc(100vw - 32px);
}

/* ===== Responsive ===== */
@media (max-width: 1100px) {
  .nav a { padding: 8px 8px; font-size: 13px; }
  .features { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 900px) {
  .topbar { gap: 12px; padding: 0 16px; }
  .nav-toggle { display: inline-grid; }
  .nav {
    display: none; position: absolute; top: var(--topbar-h); left: 0; right: 0; flex-direction: column;
    background: var(--bg); border-bottom: 1px solid var(--line); padding: 8px 16px 14px;
  }
  .nav.open { display: flex; }
  .mode-pill { display: none; }
  .view-search { grid-template-columns: 1fr; grid-template-rows: 45vh auto; height: auto; }
  .map-wrap { grid-row: 1; height: 45vh; }
  .sidebar { grid-row: 2; border-right: 0; border-top: 1px solid var(--line); overflow: visible; }
  .results { overflow: visible; }
  .detail { overflow: visible; }
  .hero { grid-template-columns: 1fr; gap: 28px; }
  #view-home { padding: 40px 16px; }
  .view-crm { padding: 20px 16px 40px; }
  .crm-tools input[type="search"] { width: 100%; }
}
@media (max-width: 560px) {
  .features { grid-template-columns: 1fr; }
  .form { grid-template-columns: 1fr; }
  .brand-text strong { font-size: 18px; }
  .map-legend { display: none; }
}
