:root {
  --bg: #ffffff; --side: #fafafb; --head: #f6f6f8; --line: #e4e4e8; --line-soft: #eeeef1;
  --ink: #1b1b21; --muted: #6c6c78; --accent: #2f5bff; --accent-ink: #ffffff; --danger: #c62828;
  --row-hover: #f6f8ff; --row-sel: #e9efff; --skel: #ececf0; --chip-bg: #eef0f4;
  --err-bg: #fdecec; --err-ink: #b3261e; --pop-shadow: 0 8px 28px rgba(20, 20, 40, .16);
  --action: #c26a00; --source: #7a3fd0;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121316; --side: #17181c; --head: #1a1b1f; --line: #2a2b31; --line-soft: #202126;
    --ink: #ececf1; --muted: #9a9aa6; --accent: #7c9cff; --accent-ink: #0d1020; --danger: #ff8a80;
    --row-hover: #191b22; --row-sel: #1f2740; --skel: #26272d; --chip-bg: #24252b;
    --err-bg: #3a1c1c; --err-ink: #ff9a92; --pop-shadow: 0 8px 28px rgba(0, 0, 0, .55);
    --action: #f0a04b; --source: #b48cff;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 13px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1 { margin: 0; }
.muted { color: var(--muted); }
.error { color: var(--danger); }
.spacer { flex: 1; }
.icon { flex: none; }

/* ---- shell ---------------------------------------------------------------------------- */
.shell { display: grid; grid-template-columns: 288px minmax(0, 1fr); grid-template-rows: 48px minmax(0, 1fr); height: 100vh; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 0 14px; border-bottom: 1px solid var(--line); background: var(--bg); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 14px; }
.brand.big { font-size: 17px; margin-bottom: 8px; }
.menu-btn { display: none; }
.main { min-width: 0; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 7px; background: var(--bg); }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.ghost { border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--ink); background: var(--chip-bg); }
.btn.block { width: 100%; justify-content: center; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }
.btn:disabled { opacity: .45; cursor: default; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); }
.icon-btn:hover { background: var(--chip-bg); color: var(--ink); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn.done { color: var(--accent); }

/* ---- sidebar -------------------------------------------------------------------------- */
.sidebar { display: flex; flex-direction: column; min-height: 0; background: var(--side); border-right: 1px solid var(--line); }
.side-nav { padding: 10px 8px 0; }
.nav-item { display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 10px; border: 0; border-radius: 7px; background: transparent; text-align: left; color: var(--ink); }
.nav-item:hover { background: var(--chip-bg); }
.nav-item.active { background: var(--row-sel); font-weight: 600; }
.side-label { margin: 14px 10px 6px; font-size: 11px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.side-search { margin: 0 10px 8px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--bg); }
.side-list { flex: 1; min-height: 0; overflow: auto; padding: 0 6px 16px; }
.side-empty { padding: 14px 12px; color: var(--muted); }
.node { display: flex; align-items: center; gap: 6px; width: 100%; min-height: 28px; padding: 3px 8px; border: 0; border-radius: 6px; background: transparent; text-align: left; color: var(--ink); }
.node:hover { background: var(--chip-bg); }
.node.active { background: var(--row-sel); font-weight: 600; }
.node.has-active { font-weight: 600; }
.node .twisty { display: inline-flex; width: 12px; flex: none; color: var(--muted); }
.node .icon { color: var(--muted); }
.node.active .icon { color: var(--accent); }
.nname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ncount { flex: none; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---- sheet header, tabs, toolbar ------------------------------------------------------- */
.sheet, .people { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.sheet-head { padding: 12px 18px 6px; }
.crumbs { display: flex; align-items: center; gap: 4px; min-height: 18px; color: var(--muted); font-size: 12px; }
.sheet-title { display: flex; align-items: baseline; gap: 12px; font-size: 19px; font-weight: 650; }
.sheet-meta { font-size: 12px; font-weight: 400; color: var(--muted); }
.sheet-meta .chip { margin-left: 8px; }
.tabs { display: flex; gap: 2px; padding: 0 14px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { display: inline-flex; align-items: center; gap: 6px; max-width: 240px; padding: 7px 12px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); white-space: nowrap; }
.tab span { overflow: hidden; text-overflow: ellipsis; }
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.toolbar { display: flex; align-items: center; gap: 6px; padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--bg); flex-wrap: wrap; }
.searchbox { display: flex; align-items: center; gap: 6px; padding: 0 10px; height: 30px; width: 260px; border: 1px solid var(--line); border-radius: 7px; color: var(--muted); }
.searchbox:focus-within { border-color: var(--accent); }
.search { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; }
.tool { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px; border: 1px solid transparent; border-radius: 7px; background: transparent; color: var(--ink); }
.tool:hover { background: var(--chip-bg); }
.tool.on { background: var(--row-sel); border-color: var(--accent); }
.tool:disabled { opacity: .5; cursor: default; }
.badge { min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-size: 11px; text-align: center; }
.tb-status { color: var(--muted); font-size: 12px; padding: 0 8px; }
.tb-status.error { color: var(--danger); }

/* ---- grid ----------------------------------------------------------------------------- */
.sheet-body { display: flex; flex: 1; min-height: 0; }
.grid { position: relative; flex: 1; min-width: 0; }
.grid-scroll { position: absolute; inset: 0; overflow: auto; outline: 0; }
.grid-canvas { position: relative; }
.grid-head { position: sticky; top: 0; z-index: 4; display: flex; background: var(--head); border-bottom: 1px solid var(--line); }
.grid-body { position: absolute; left: 0; }
.hcell { position: relative; flex: none; display: flex; align-items: center; height: 100%; padding: 0; border-right: 1px solid var(--line); background: var(--head); overflow: hidden; }
.hcell.rownum { position: sticky; left: 0; z-index: 3; width: 64px; justify-content: center; color: var(--muted); font-size: 11px; }
.hcell-title { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; height: 100%; padding: 0 10px; border: 0; background: transparent; text-align: left; font-weight: 600; }
.hcell-title:hover { background: var(--chip-bg); }
.hcell-title .icon { color: var(--muted); }
.hcell.type-action .hcell-title .icon-bolt { color: var(--action); }
.hcell.type-source .hcell-title .icon-source { color: var(--source); }
.hcell-title.sorted .icon-sort-asc, .hcell-title.sorted .icon-sort-desc { color: var(--accent); }
.hname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.resizer { position: absolute; right: 0; top: 0; width: 6px; height: 100%; cursor: col-resize; touch-action: none; }
.resizer:hover { background: var(--accent); opacity: .5; }
.grow { position: absolute; left: 0; display: flex; background: var(--bg); border-bottom: 1px solid var(--line-soft); }
.grow:hover { background: var(--row-hover); }
.grow.selected { background: var(--row-sel); }
.gcell { flex: none; height: 100%; padding: 0 10px; line-height: 31px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-right: 1px solid var(--line-soft); }
.gcell.empty { color: var(--muted); }
.gcell.skeleton::after { content: ""; display: block; width: 55%; height: 10px; margin-top: 11px; border-radius: 3px; background: var(--skel); }
.gcell.rownum { position: sticky; left: 0; z-index: 2; width: 64px; display: flex; align-items: center; justify-content: space-between; padding: 0 6px 0 10px; background: inherit; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.gcell.rownum, .hcell.rownum { box-shadow: 1px 0 0 var(--line); }
.expand { display: none; align-items: center; justify-content: center; width: 20px; height: 20px; border: 0; border-radius: 4px; background: transparent; color: var(--muted); }
.expand:hover { background: var(--chip-bg); color: var(--accent); }
.grow:hover .expand, .grow.selected .expand { display: inline-flex; }
.cell-link { color: var(--accent); text-decoration: none; }
.cell-link:hover { text-decoration: underline; }
.chip { display: inline-block; padding: 0 8px; border-radius: 999px; font-size: 11px; line-height: 18px; background: var(--chip-bg); color: var(--muted); }
.chip.error { background: var(--err-bg); color: var(--err-ink); }
.grid-message { position: absolute; inset: 40px 0 0 0; padding: 0 24px; text-align: center; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 10px; color: var(--muted); pointer-events: none; }
.grid-message.show { display: flex; }
.grid-message .btn { pointer-events: auto; }

/* ---- record panel ---------------------------------------------------------------------- */
.record { flex: none; width: 400px; display: flex; flex-direction: column; min-height: 0; border-left: 1px solid var(--line); background: var(--bg); }
.rec-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px 6px 16px; }
.rec-title { font-size: 15px; font-weight: 650; }
.rec-actions { display: flex; gap: 2px; }
.rec-extra { padding: 0 12px 6px; }
.rec-find { margin: 0 14px 8px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--bg); }
.rec-fields { flex: 1; min-height: 0; overflow: auto; padding: 0 0 16px; }
.rec-empty { padding: 14px 16px; color: var(--muted); }
.field { padding: 8px 16px; border-top: 1px solid var(--line-soft); }
.flabel { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; font-size: 11px; color: var(--muted); }
.fvalue { display: flex; align-items: flex-start; gap: 6px; white-space: pre-wrap; overflow-wrap: anywhere; }
.fvalue .copy { margin-left: auto; opacity: 0; }
.field:hover .copy, .copy:focus-visible { opacity: 1; }

/* ---- popovers and menus ------------------------------------------------------------------ */
.popover { position: fixed; z-index: 50; max-width: calc(100vw - 16px); max-height: 70vh; overflow: auto; padding: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--pop-shadow); }
.pf-title { margin-bottom: 8px; font-weight: 650; }
.pf-rows { display: flex; flex-direction: column; gap: 6px; }
.pf-row { display: flex; align-items: center; gap: 6px; }
.pf-empty { padding: 6px 0; color: var(--muted); }
.pf-select, .pf-value { height: 30px; padding: 0 8px; border: 1px solid var(--line); border-radius: 7px; background: var(--bg); min-width: 0; }
.pf-select { flex: 1; }
.pf-select.wide { width: 100%; margin-bottom: 8px; }
.pf-value { flex: 1.2; }
.pf > .pf-value { width: 100%; margin-bottom: 6px; }
.pf-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; }
.seg { display: flex; gap: 6px; }
.seg-btn { display: inline-flex; align-items: center; gap: 6px; flex: 1; justify-content: center; height: 30px; border: 1px solid var(--line); border-radius: 7px; background: var(--bg); }
.seg-btn.on { border-color: var(--accent); background: var(--row-sel); }
.fields-list { max-height: 300px; overflow: auto; }
.field-row { display: flex; align-items: center; gap: 8px; padding: 4px 2px; }
.menu { display: flex; flex-direction: column; gap: 2px; }
.menu-note { padding: 2px 4px 8px; color: var(--muted); font-size: 12px; }
.menu-item { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border: 0; border-radius: 6px; background: transparent; text-align: left; }
.menu-item:hover { background: var(--chip-bg); }

/* ---- people form, home, login ------------------------------------------------------------- */
.people-form { padding: 10px 18px; border-bottom: 1px solid var(--line); }
.people-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px 10px; }
.pfield { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--muted); }
.pfield input, .pfield select { height: 30px; padding: 0 8px; border: 1px solid var(--line); border-radius: 7px; background: var(--bg); font-size: 13px; }
.check-body { padding: 18px; max-width: 900px; }
.people-actions { display: flex; align-items: center; gap: 16px; margin-top: 10px; flex-wrap: wrap; }
.check { display: flex; align-items: center; gap: 6px; }
.home { padding: 28px 32px; max-width: 760px; }
.stats { display: flex; gap: 28px; flex-wrap: wrap; margin: 22px 0; }
.stat-n { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat-l { color: var(--muted); }
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: var(--side); }
.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; padding: 24px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); box-shadow: var(--pop-shadow); }
.login-error { margin: 0; font-size: 12.5px; }
.login-card input { height: 36px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }

/* ---- small screens -------------------------------------------------------------------------- */
@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .menu-btn { display: inline-flex; }
  .sidebar { position: fixed; top: 48px; bottom: 0; left: 0; width: 300px; z-index: 30; transform: translateX(-100%); transition: transform .15s; }
  body.side-open .sidebar { transform: none; }
  .record { position: absolute; inset: 0; width: auto; z-index: 20; }
  .sheet-body { position: relative; }
  .searchbox { width: 100%; }
  .home { padding: 20px 16px; }
}

/* ---- home extras ---------------------------------------------------------------------- */
.home-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.sync-line { margin: 18px 0 0; font-size: 12.5px; }

/* ---- dialogs and the import screen ---------------------------------------------------- */
.modal-overlay { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(10, 10, 20, .45); }
.modal { width: min(720px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--pop-shadow); }
.modal-head { display: flex; align-items: center; gap: 8px; padding: 14px 18px 8px; }
.modal-title { margin: 0; font-size: 16px; font-weight: 650; }
.modal-body { padding: 6px 18px 18px; overflow: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-foot { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.modal-error { margin: 0; }
.drop { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 26px 16px; text-align: center; border: 2px dashed var(--line); border-radius: 10px; color: var(--muted); }
.drop.over { border-color: var(--accent); background: var(--row-hover); }
.drop p { margin: 0; }
.drop-title { color: var(--ink); font-weight: 600; }
.file-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.paste { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); resize: vertical; font: inherit; }
.file-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.preview-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 8px; max-height: 220px; }
.preview { border-collapse: collapse; width: 100%; font-size: 12px; }
.preview th, .preview td { max-width: 190px; padding: 5px 10px; border-bottom: 1px solid var(--line-soft); text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.preview th { position: sticky; top: 0; background: var(--head); font-weight: 600; }
.dest { display: flex; flex-direction: column; gap: 8px; }
.dest-title { font-size: 11px; letter-spacing: .04em; text-transform: uppercase; }
.radio { display: flex; align-items: center; gap: 8px; }
.fields { display: flex; flex-direction: column; gap: 8px; margin: 0 0 4px 24px; }
.field { display: flex; flex-direction: column; gap: 3px; }
.field input, .confirm-input { padding: 7px 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--bg); }
.progress { height: 8px; border-radius: 999px; background: var(--skel); overflow: hidden; }
.bar { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.done-line { display: flex; align-items: center; gap: 6px; margin: 0; }
@media (max-width: 720px) { .fields { margin-left: 0; } }

/* Prospects Pulse standard: import panel and home totals */
.std-title { font-size: 13px; margin: 18px 0 6px; }
.std-map, .std-report { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }
.std-counts { margin: 0; padding-left: 18px; }
.std-stats { margin-top: 0; }
