:root {
  --bg: #f6f5f3;
  --surface: #ffffff;
  --surface-2: #f0eeeb;
  --ink: #111111;
  --ink-2: #4a4a48;
  --ink-3: #8a8985;
  --line: #e3e1dd;
  --coral: #e8837c;
  --coral-ink: #b4524b;
  --green: #94b8a2;
  --green-ink: #4f7a60;
  --focus: #e8837c;

  --s-need: #b9b7b2;
  --s-req: #a99bd1;
  --s-wait: #e3b55b;
  --s-our: #e8837c;
  --s-conv: #7ea6d6;
  --s-active: #94b8a2;
  --s-parked: #d7d5d0;

  --org-node: #111111;
  --edge-intro: #4f7a60;
  --edge-soft: #b9b7b2;
  --shadow: 0 8px 30px rgba(17, 17, 17, 0.12);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111111; --surface: #1a1a1a; --surface-2: #232322; --ink: #f1efeb; --ink-2: #c3c0ba; --ink-3: #85827c;
    --line: #2e2d2b; --coral-ink: #f0a39d; --green-ink: #a9cbb6; --s-need: #6c6a66; --s-parked: #3d3c3a;
    --org-node: #f1efeb; --edge-intro: #94b8a2; --edge-soft: #5b5955; --shadow: 0 8px 30px rgba(0,0,0,.5); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111111; --surface: #1a1a1a; --surface-2: #232322; --ink: #f1efeb; --ink-2: #c3c0ba; --ink-3: #85827c;
  --line: #2e2d2b; --coral-ink: #f0a39d; --green-ink: #a9cbb6; --s-need: #6c6a66; --s-parked: #3d3c3a;
  --org-node: #f1efeb; --edge-intro: #94b8a2; --edge-soft: #5b5955; --shadow: 0 8px 30px rgba(0,0,0,.5); color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: 14px/1.45 "DM Sans", system-ui, -apple-system, sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
.mono, .lbl, .count, .pill, .date { font-family: "IBM Plex Mono", ui-monospace, monospace; }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 20px; padding: 10px 18px;
  background: var(--surface); border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.brand { font-weight: 700; letter-spacing: .02em; display: flex; align-items: center; gap: 8px; }
.brand-sub { font-weight: 500; color: var(--ink-3); }
.mark { width: 14px; height: 14px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, var(--coral), #111 75%); }
.tabs { display: flex; gap: 2px; background: var(--surface-2); padding: 3px; border-radius: 9px; }
.tab { border: 0; background: transparent; padding: 6px 14px; border-radius: 7px; cursor: pointer; color: var(--ink-2); font-weight: 500; }
.tab[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.search { width: 240px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.badge { font-size: 12px; color: var(--ink-3); padding: 0 4px; white-space: nowrap; }
.badge.demo { color: var(--coral-ink); font-weight: 600; }

.btn {
  border: 1px solid var(--line); background: var(--surface); padding: 7px 12px; border-radius: 8px;
  cursor: pointer; font-weight: 500; white-space: nowrap;
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--coral-ink); }
.btn.icon { padding: 6px 9px; }
.btn.active { background: var(--coral); border-color: var(--coral); color: #111; }
.btn.sm { padding: 4px 8px; font-size: 12px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.add-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow); padding: 4px; z-index: 30; min-width: 190px;
}
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 7px; cursor: pointer; }
.menu button:hover { background: var(--surface-2); }

.banner { padding: 10px 18px; background: color-mix(in srgb, var(--coral) 18%, var(--surface)); border-bottom: 1px solid var(--line); display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }

main { flex: 1; min-height: 0; position: relative; }
.view { height: 100%; overflow: auto; padding: 18px; }

/* Toolbar */
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.chipset { display: flex; gap: 4px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: var(--surface); padding: 4px 10px; border-radius: 999px; cursor: pointer; font-size: 12.5px; color: var(--ink-2);
}
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
select, input[type="text"], input[type="email"], input[type="date"], input[type="url"], input:not([type]), textarea {
  border: 1px solid var(--line); background: var(--surface); padding: 7px 9px; border-radius: 8px; width: 100%;
}
.toolbar select { width: auto; }
textarea { min-height: 80px; resize: vertical; }

/* Companies table */
.table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.table th { text-align: left; font: 500 11px "IBM Plex Mono", monospace; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { cursor: pointer; }
.table tbody tr:hover td { background: var(--surface-2); }
.org-name { font-weight: 600; }
.sub { color: var(--ink-3); font-size: 12.5px; }
.pill { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.pill.stage-Active, .pill.stage-Partner { background: color-mix(in srgb, var(--green) 30%, transparent); color: var(--green-ink); }
.pill.stage-Talking { background: color-mix(in srgb, var(--s-conv) 25%, transparent); }
.pill.stage-Prospect { background: color-mix(in srgb, var(--s-wait) 25%, transparent); }
.people-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.pchip { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; padding: 2px 8px 2px 6px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--s-need); }
.empty { padding: 40px; text-align: center; color: var(--ink-3); }

/* Kanban */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(230px, 1fr); gap: 12px; height: calc(100% - 52px); min-height: 400px; }
.col { background: var(--surface-2); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 0; border: 1px solid transparent; }
.col.drop { border-color: var(--coral); background: color-mix(in srgb, var(--coral) 10%, var(--surface-2)); }
.col-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; font-weight: 600; }
.col-head .count { margin-left: auto; color: var(--ink-3); font-size: 12px; font-weight: 400; }
.col-body { padding: 0 8px 8px; overflow: auto; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 10px 11px; cursor: grab; }
.card:hover { border-color: var(--ink-3); }
.card.dragging { opacity: .5; }
.card .nm { font-weight: 600; }
.card .org { color: var(--ink-2); font-size: 12.5px; }
.card .next { margin-top: 6px; font-size: 12.5px; color: var(--ink-2); display: flex; gap: 6px; align-items: baseline; }
.card .via { margin-top: 4px; font-size: 12px; color: var(--ink-3); }
.date { font-size: 11px; color: var(--ink-3); white-space: nowrap; }
.date.overdue { color: var(--coral-ink); font-weight: 500; }
.date.soon { color: #b0861f; }
.card.overdue { border-left: 3px solid var(--coral); }

/* Graph */
.graph-view { padding: 0; overflow: hidden; }
#cy { position: absolute; inset: 0; }
.graph-panel {
  position: absolute; top: 14px; left: 14px; width: 230px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 8px; box-shadow: var(--shadow); z-index: 5;
}
.chk { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); }
.gp-sep { height: 1px; background: var(--line); margin: 2px 0; }
.path-out { font-size: 12.5px; color: var(--ink-2); }
.path-out .step { display: block; }
.hint { font-size: 12px; color: var(--coral-ink); }
.legend { position: absolute; bottom: 14px; left: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; max-width: calc(100% - 28px); z-index: 5; }
.legend span { display: inline-flex; align-items: center; gap: 5px; color: var(--ink-2); }
.legend .ln { width: 18px; height: 0; border-top: 2px solid var(--edge-intro); }
.legend .ln.dash { border-top-style: dashed; border-color: var(--coral); }
.legend .ln.soft { border-color: var(--edge-soft); border-top-width: 1px; }

/* Drawer */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100vw); background: var(--surface); border-left: 1px solid var(--line);
  box-shadow: var(--shadow); z-index: 40; display: flex; flex-direction: column;
}
.drawer-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.drawer-title { font-weight: 700; font-size: 16px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-body { padding: 16px; overflow: auto; flex: 1; display: flex; flex-direction: column; gap: 18px; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font: 500 11px "IBM Plex Mono", monospace; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.actions .left { margin-right: auto; }
.section h4 { margin: 0 0 8px; font: 500 11px "IBM Plex Mono", monospace; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); display: flex; align-items: center; gap: 8px; }
.rows { display: flex; flex-direction: column; gap: 6px; }
.row { display: flex; align-items: center; gap: 8px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; }
.row .grow { flex: 1; min-width: 0; }
.row .x { border: 0; background: none; color: var(--ink-3); cursor: pointer; padding: 2px 6px; border-radius: 5px; }
.row .x:hover { background: var(--surface-2); color: var(--coral-ink); }
.link { color: var(--ink); text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 3px; cursor: pointer; background: none; border: 0; padding: 0; font-weight: 500; }
.link:hover { text-decoration-color: var(--coral); }
.inline-add { display: flex; gap: 6px; flex-wrap: wrap; }
.inline-add > * { flex: 1 1 120px; }
.inline-add .btn { flex: 0 0 auto; }
.chain { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; font-size: 13px; }
.chain .arrow { color: var(--ink-3); }
.chain .us { font-weight: 700; }
.timeline .row { align-items: flex-start; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(17,17,17,.35); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 8vh 16px; overflow: auto; }
.modal-card { background: var(--surface); border-radius: 14px; width: min(520px, 100%); box-shadow: var(--shadow); }
#modalBody { padding: 16px; display: flex; flex-direction: column; gap: 14px; }

/* Toasts */
.toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--ink); color: var(--bg); padding: 9px 14px; border-radius: 9px; box-shadow: var(--shadow); font-size: 13px; max-width: 360px; }
.toast.err { background: var(--coral-ink); color: #fff; }

@media (max-width: 760px) {
  .topbar { gap: 10px; padding: 10px 16px; }
  .topbar-right { margin-left: 0; width: 100%; min-width: 0; }
  .badge { display: none; }
  .brand-sub { display: none; }
  .search { flex: 1; width: auto; }
  .view { padding: 16px; }
  .table .hide-sm { display: none; }
  .graph-panel { width: auto; right: 14px; }
  .graph-panel .chk, .graph-panel #gConnect, .graph-panel #gFit { display: none; }
  .legend { display: none; }
  .form { grid-template-columns: 1fr; }
}

/* Segmented control */
.seg { display: flex; background: var(--surface-2); padding: 3px; border-radius: 8px; gap: 2px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 5px 8px; border-radius: 6px; cursor: pointer; color: var(--ink-2); font-weight: 500; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

/* Logos */
.logo { width: 40px; height: 40px; border-radius: 9px; background: #fff; border: 1px solid var(--line); display: grid; place-items: center; flex: none; overflow: hidden; font: 700 15px "DM Sans", sans-serif; color: #111; }
.logo img { width: 72%; height: 72%; object-fit: contain; }
.logo.lg { width: 56px; height: 56px; border-radius: 12px; font-size: 20px; }

/* Company grid */
.org-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.org-card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px; cursor: pointer; display: flex; flex-direction: column; gap: 10px; text-align: left; }
.org-card:hover { border-color: var(--ink-3); }
.org-card .head { display: flex; gap: 12px; align-items: center; }
.org-card .about { color: var(--ink-2); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.org-card .meta { display: flex; gap: 6px; flex-wrap: wrap; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }

/* Profile (read view) */
.profile-head { display: flex; gap: 14px; align-items: center; }
.profile-head .nm { font-size: 18px; font-weight: 700; line-height: 1.2; }
.kv { display: grid; grid-template-columns: 90px 1fr; gap: 6px 12px; font-size: 13.5px; }
.kv dt { color: var(--ink-3); font: 500 11px "IBM Plex Mono", monospace; text-transform: uppercase; letter-spacing: .06em; padding-top: 3px; }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.prose { font-size: 14px; color: var(--ink); white-space: pre-wrap; margin: 0; }
.muted-empty { color: var(--ink-3); font-style: italic; }
a.plain { color: var(--ink); text-underline-offset: 3px; text-decoration-color: var(--line); }
a.plain:hover { text-decoration-color: var(--coral); }

/* Auto-fill */
.with-btn { display: flex; gap: 6px; align-items: center; }
.with-btn input { flex: 1; min-width: 0; }
.filled { animation: filled 1.6s ease-out; }
@keyframes filled { 0% { background: color-mix(in srgb, var(--green) 45%, var(--surface)); } 100% { background: var(--surface); } }
.cands { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.cand { text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: 9px; padding: 9px 11px; cursor: pointer; }
.cand:hover { border-color: var(--coral); }
.cand .sub { display: inline; }
.cand div.sub { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-top: 2px; }

/* Header Investors / Customers / All switch */
.topseg { min-width: 0; }
.topseg button { padding: 5px 12px; }
@media (max-width: 760px) { .topseg { order: 3; width: 100%; } }
