:root {
  --mint: #7C3AED; --mint-dark: #6D28D9; --mint-soft: #ede9fe; --accent: #A78BFA;
  --ink: #1d2430; --muted: #6b7380; --line: #e3e7ec; --line-soft: #f0f2f5; --bg: #f6f5fb; --surface: #fff; --surface-2: #faf9ff;
  --red: #d64545; --red-soft: #fdecec; --amber: #b7791f; --amber-soft: #fff6e0; --sel: #eaf4ff; --shadow: 0 10px 40px rgba(15,23,42,.18);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Inter, sans-serif; color: var(--ink);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --ink: #e6e9ee; --muted: #9aa3af; --line: #2c333d; --line-soft: #242a33; --bg: #14181d; --surface: #1b2027; --surface-2: #20262e;
    --mint: #A78BFA; --mint-dark: #C4B5FD; --mint-soft: #2e2150; --accent: #A78BFA;
    --red-soft: #3a1f22; --amber-soft: #3a311c; --sel: #2a2150; --shadow: 0 10px 40px rgba(0,0,0,.5); }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); font-size: 14px; color: var(--ink); }
a { color: var(--mint-dark); }
[hidden] { display: none !important; }
.muted { color: var(--muted); } .small-text { font-size: 12px; } .pad { padding: 0 20px; }
.error { color: var(--red); min-height: 1em; margin: 0; } .warn-text { color: var(--amber); font-weight: 600; }
code, pre { background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; font-size: 12px; word-break: break-all; }
pre { padding: 10px; overflow: auto; white-space: pre; word-break: normal; }
kbd { font: 11px ui-monospace, Menlo, monospace; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 1px 5px; color: var(--muted); background: var(--surface); }
.brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.logo { width: 24px; height: 24px; } .logo.big { width: 32px; height: 32px; }

.btn { border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 7px 13px; border-radius: 8px;
  font: inherit; cursor: pointer; text-decoration: none; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--mint); border-color: var(--mint); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--mint-dark); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--ink); }
.btn.small { padding: 4px 9px; font-size: 12.5px; }
.btn.danger { color: var(--red); } .btn.danger-solid { background: var(--red); border-color: var(--red); color: #fff; font-weight: 600; }
.btn:disabled { opacity: .4; cursor: default; }
.icon { border: 0; background: none; cursor: pointer; opacity: .55; font-size: 15px; color: var(--ink); padding: 4px 6px; border-radius: 6px; }
.icon:hover { opacity: 1; background: var(--line-soft); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; margin: 16px 20px; }
.field, input, select, textarea { font: inherit; color: var(--ink); }
.field { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.field:focus { outline: 2px solid var(--mint); outline-offset: -1px; border-color: transparent; }
textarea.field { resize: vertical; }
.stack { display: grid; gap: 5px; } .lbl { font-size: 12px; font-weight: 600; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.row-btns { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; } .row-btns.left { justify-content: flex-start; }
.chip { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; background: var(--line-soft); color: var(--muted); white-space: nowrap; }
.chip.bad { background: var(--red-soft); color: var(--red); font-weight: 600; } .chip.warn { background: var(--amber-soft); color: var(--amber); font-weight: 600; }
.tag { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; background: var(--mint-soft); color: var(--mint-dark); display: inline-flex; align-items: center; gap: 2px; }
.tag .x { border: 0; background: none; color: inherit; cursor: pointer; padding: 0 0 0 2px; font-size: 13px; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.tags.editable { border: 1px solid var(--line); border-radius: 8px; padding: 6px; background: var(--surface); }
.tag-input { border: 0; outline: 0; background: transparent; min-width: 80px; flex: 1; padding: 2px 4px; }
.value { font-weight: 600; color: var(--mint-dark); font-size: 12.5px; }
h2 { font-size: 15px; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; } h3 { font-size: 14px; margin: 18px 0 8px; }
.count { font-size: 12px; background: var(--line-soft); color: var(--muted); border-radius: 999px; padding: 1px 8px; }
.count.bad { background: var(--red-soft); color: var(--red); } .count.warn { background: var(--amber-soft); color: var(--amber); }
.badge { background: var(--red); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 6px; margin-left: 2px; font-weight: 700; }

/* Top bar */
.shell-bar, .topbar { display: flex; align-items: center; gap: 16px; padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 21; flex-wrap: wrap; }
.mod-subnav { display: flex; gap: 4px; padding: 6px 20px; background: var(--surface-2); border-bottom: 1px solid var(--line); flex-wrap: wrap; position: sticky; top: 52px; z-index: 19; }
.module-nav { display: flex; gap: 4px; flex-wrap: wrap; }
.module-nav a, .mod-subnav a { color: var(--muted); text-decoration: none; font-weight: 500; padding: 6px 10px; border-radius: 8px; }
.module-nav a.active, .mod-subnav a.active { background: var(--mint-soft); color: var(--mint-dark); }
.module-nav a.soon { opacity: .7; }
.module-nav a:hover, .mod-subnav a:hover { color: var(--ink); }
.topbar { top: 0; }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; }
.topbar nav a { color: var(--muted); text-decoration: none; font-weight: 500; padding: 6px 10px; border-radius: 8px; }
.topbar nav a:hover { color: var(--ink); background: var(--line-soft); }
.topbar nav a.active { color: var(--mint-dark); background: var(--mint-soft); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.kbd-btn { border: 1px solid var(--line); color: var(--muted); min-width: 200px; justify-content: space-between; }
body.desktop .topbar { -webkit-app-region: drag; }
body.mac .topbar { padding-left: 86px; }
body.desktop .topbar a, body.desktop .topbar button, body.desktop .topbar input { -webkit-app-region: no-drag; }

/* Toolbar */
.toolbar { display: flex; gap: 8px; padding: 14px 20px 10px; flex-wrap: wrap; align-items: center; }
.toolbar input, .toolbar select { padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.toolbar input[type=search] { min-width: 220px; flex: 0 1 300px; }
.spacer { flex: 1; }
body[data-view=dashboard] #add, body[data-view=dashboard] #quick-add { display: none; }
.bulkbar { display: flex; gap: 8px; align-items: center; margin: 0 20px 10px; padding: 8px 12px; border-radius: 10px; background: var(--sel); flex-wrap: wrap; }
.bulkbar select { padding: 4px 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); font-size: 12.5px; }

/* Spreadsheet */
.sheet-wrap { margin: 0 20px 20px; overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; max-height: calc(100vh - 170px); }
.sheet { border-collapse: separate; border-spacing: 0; width: 100%; }
.sheet th { position: sticky; top: 0; background: var(--surface-2); text-align: left; font-weight: 600; font-size: 11.5px; z-index: 2;
  text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: 10px 8px; border-bottom: 1px solid var(--line); cursor: pointer; user-select: none; white-space: nowrap; }
.sheet th:hover { color: var(--ink); }
.sheet td { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line-soft); padding: 0; height: 38px; background: var(--surface); }
.sheet td input, .sheet td select { width: 100%; height: 37px; border: 0; padding: 0 8px; background: transparent; outline: none; }
.sheet td input:focus, .sheet td select:focus { box-shadow: inset 0 0 0 2px var(--mint); background: var(--surface); }
.sheet td.ro { color: var(--muted); font-size: 12px; padding: 0 8px; white-space: nowrap; }
.sheet .num { text-align: right; }
.sheet .sel { width: 34px; min-width: 34px; text-align: center; position: sticky; left: 0; z-index: 1; }
.sheet th.sel { z-index: 3; }
.sheet .sel input { width: auto; height: auto; }
.sheet td.actions, .sheet th.actions { width: 64px; text-align: center; cursor: default; white-space: nowrap; }
.sheet tbody tr:hover td { background: var(--surface-2); }
.sheet tr.overdue td { background: var(--red-soft); } .sheet tr.due-today td { background: var(--amber-soft); }
.sheet tr.selected td { background: var(--sel); }
.sheet tr.overdue input[type=date] { color: var(--red); font-weight: 600; } .sheet tr.due-today input[type=date] { color: var(--amber); font-weight: 600; }
.sheet tfoot td { font-weight: 600; padding: 10px 8px; background: var(--surface-2); border-bottom: 0; position: sticky; bottom: 0; }
.sheet tfoot .total { color: var(--mint-dark); }
.sheet th:nth-child(2), .sheet td:nth-child(2) { position: sticky; left: 34px; z-index: 1; box-shadow: 1px 0 0 var(--line); }
.sheet thead th:nth-child(2) { z-index: 3; }
select.status { font-weight: 600; }
.s-new { color: #0369A1; } .s-qualified { color: #15803D; } .s-warm { color: #A16207; }
.s-hot { color: #C2410C; } .s-won { color: #047857; } .s-lost { color: #475569; } .s-dropped { color: #7C3AED; }
.s-contacted { color: #15803D; } /* migrated alias */
li.warn { color: #A16207; }

.empty { text-align: center; padding: 40px 20px; }

/* Pipeline */
.board { display: grid; grid-template-columns: repeat(7, minmax(200px, 1fr)); gap: 14px; padding: 4px 20px 20px; overflow-x: auto; align-items: start; }
.col { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px; min-height: 200px; transition: background .15s; }
.col.drop { background: var(--mint-soft); border-color: var(--mint); }
.col header { display: flex; align-items: center; gap: 8px; padding: 2px 4px 10px; }
.col header .muted { margin-left: auto; font-size: 12px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.cards { display: grid; gap: 8px; min-height: 30px; }
.card-title { font-weight: 600; }
.board .card { margin: 0; padding: 10px 12px; cursor: grab; display: grid; gap: 6px; border-radius: 10px; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.board .card:hover { border-color: var(--muted); }
.board .card.dragging { opacity: .5; } .board .card.overdue { border-left: 3px solid var(--red); } .board .card.selected { outline: 2px solid #3b82f6; }
.card-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.add-card { width: 100%; justify-content: center; margin-top: 6px; }

/* Side panel */
.overlay { position: fixed; inset: 0; background: rgba(15,23,42,.25); z-index: 30; }
.panel { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); background: var(--surface); z-index: 40; box-shadow: var(--shadow);
  display: flex; flex-direction: column; animation: slide .18s ease-out; }
@keyframes slide { from { transform: translateX(30px); opacity: 0; } }
.panel-head { display: flex; justify-content: space-between; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0 0 4px; font-size: 18px; }
.panel-body { overflow: auto; padding: 16px 20px 40px; display: grid; gap: 14px; align-content: start; }
.composer { display: grid; gap: 8px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.composer .btn { justify-self: end; }
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.act { display: flex; gap: 10px; align-items: flex-start; padding: 8px 4px; border-bottom: 1px solid var(--line-soft); }
.act-icon { width: 26px; text-align: center; } .act-main { flex: 1; } .act-body { white-space: pre-wrap; }
.act-system .act-body { color: var(--muted); font-size: 13px; }

/* Modal & palette */
.modal { position: fixed; inset: 0; display: grid; place-items: start center; padding-top: 12vh; z-index: 60; pointer-events: none; }
.modal-card { pointer-events: auto; width: min(560px, 94vw); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px 0; }
.modal-head h2 { margin: 0; }
.modal-body { padding: 14px 18px; display: grid; gap: 10px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 0 18px 16px; }
.palette { padding: 8px; }
.palette-input { font-size: 16px; padding: 12px; border: 0; }
.palette-input:focus { outline: 0; }
.palette-list { list-style: none; margin: 6px 0 0; padding: 6px 0 0; border-top: 1px solid var(--line); max-height: 50vh; overflow: auto; }
.palette-list li { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.palette-list li.active { background: var(--mint-soft); }
.pi-label { font-weight: 500; } .palette-list kbd { margin-left: auto; }
.pi-icon { width: 18px; text-align: center; color: var(--muted); }

/* Dashboard */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; padding: 4px 20px 0; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; display: grid; gap: 4px; }
.kpi strong { font-size: 24px; } .kpi.good strong { color: var(--mint-dark); } .kpi.bad strong { color: var(--red); }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 12px; padding: 12px 20px 20px; }
.charts .card { margin: 0; } .chart.wide { grid-column: 1 / -1; }
.chart-area { position: relative; height: 240px; }

/* Follow-ups */
.followups { max-width: 1000px; }
.fu-list { list-style: none; margin: 0; padding: 0; }
.fu { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line-soft); flex-wrap: wrap; }
.fu-main { display: flex; gap: 10px; align-items: center; background: none; border: 0; cursor: pointer; text-align: left; font: inherit; color: inherit; flex-wrap: wrap; padding: 4px 0; }
.fu-main:hover strong { color: var(--mint-dark); }

/* Data & users */
.data-page { max-width: 1100px; }
.map-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 12px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.import-summary { margin: 14px 0 8px; }
.preview-wrap { max-height: 300px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 12px; }
.plain { width: 100%; border-collapse: collapse; }
.plain th, .plain td { text-align: left; padding: 9px 6px; border-bottom: 1px solid var(--line); }
.plain.compact th, .plain.compact td { padding: 5px 8px; font-size: 12.5px; }
.plain tr.dup td { background: var(--amber-soft); }
.notice { background: var(--mint-soft); border-radius: 8px; padding: 10px 12px; margin-top: 10px; }
.dupe-group { display: flex; justify-content: space-between; align-items: center; gap: 10px; border-top: 1px solid var(--line-soft); padding: 8px 0; flex-wrap: wrap; }
.dupe-group ul { margin: 0; padding-left: 18px; }
.field-list { list-style: none; padding: 0; margin: 0 0 12px; } .field-list li { display: flex; gap: 6px; align-items: center; padding: 6px 0; }
.field-list .btn { margin-left: auto; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; } .inline-form .field { width: auto; flex: 1 1 180px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; align-items: center; }
.form-grid h2 { grid-column: 1 / -1; margin: 0 0 4px; }
.check { display: flex; gap: 6px; align-items: center; }
details summary { cursor: pointer; color: var(--mint-dark); margin: 8px 0; }

/* Login */
.login-page { display: grid; place-items: center; min-height: 100vh; }
.login-card { width: min(400px, 92vw); display: grid; gap: 14px; }
.login-card label { display: grid; gap: 6px; font-weight: 500; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1d2430; color: #fff; z-index: 80;
  padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); }
.toast.bad { background: var(--red); }

@media (max-width: 760px) {
  .card { margin: 12px; } .toolbar { padding: 12px; } .sheet-wrap { margin: 0 12px 12px; }
  .toolbar input[type=search] { min-width: 0; flex: 1 1 100%; }
  .kbd-btn, #me { display: none; } .grid2 { grid-template-columns: 1fr; }
  .board { grid-template-columns: repeat(4, 80vw); }
}
.login-page::before { content: ''; position: fixed; top: 0; left: 0; right: 0; height: 36px; -webkit-app-region: drag; }

.sheet tfoot td.num.total { white-space: normal; line-height: 1.35; }
.kpi strong { font-size: 18px; word-break: break-word; }

/* ----- Deal value, products picker, catalog, org tree ----- */
.deal-cell { display: flex; align-items: center; gap: 4px; min-width: 0; }
.deal-cell input { flex: 1; min-width: 0; }
.badge-manual, .badge-missing, .badge-range { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 1px 6px; border-radius: 999px; white-space: nowrap; }
.badge-manual { background: var(--amber-soft); color: var(--amber); }
.badge-missing { background: var(--red-soft); color: var(--red); }
.badge-range { background: var(--mint-soft); color: var(--mint-dark); }
.btn.tiny { padding: 1px 6px; font-size: 11px; }
.prod-cell { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; padding: 4px 6px; min-height: 37px; cursor: pointer; }
.prod-cell .tag { cursor: default; }
.prod-thumb { width: 22px; height: 22px; object-fit: cover; border-radius: 4px; background: var(--line-soft); }
.picker { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 12px; width: min(420px, 92vw); max-height: 70vh; overflow: auto; }
.picker-row { display: grid; grid-template-columns: 1fr auto auto; gap: 6px; align-items: center; padding: 4px 0; border-bottom: 1px solid var(--line-soft); }
.price-grid { border-collapse: collapse; width: 100%; }
.price-grid th, .price-grid td { border: 1px solid var(--line); padding: 6px; vertical-align: top; min-width: 120px; }
.price-grid th { background: var(--surface-2); position: sticky; top: 0; }
.price-type { font-size: 11px; }
.org { list-style: none; padding-left: 16px; }
.org > li { margin: 6px 0; }
.org-card { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.perm-table { border-collapse: collapse; width: 100%; }
.perm-table th, .perm-table td { border-bottom: 1px solid var(--line); padding: 8px 6px; text-align: left; }
.product-hero { display: grid; grid-template-columns: 280px 1fr; gap: 20px; }
@media (max-width: 800px) { .product-hero { grid-template-columns: 1fr; } }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.gallery img, .gallery .doc { width: 100%; height: 110px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); }
.gallery .doc { display: flex; align-items: center; justify-content: center; padding: 8px; text-align: center; font-size: 12px; height: auto; min-height: 80px; }
.specs { width: 100%; } .specs td { padding: 4px 8px; }
.coming-soon { text-align: center; padding: 60px 20px; }
.login-page { min-height: 100vh; display: grid; place-items: center; }
.login-card { width: min(400px, 92vw); display: grid; gap: 10px; }
.shell-bar .brand { color: inherit; text-decoration: none; }
#export-csv[hidden], #export-json[hidden] { display: none !important; }
