/* APD CRM - mobile-first */
:root {
  --blue: #1e3a6e; --blue-dark: #2a4c8c; --bg: #f4f6fa; --card: #fff;
  --text: #111827; --muted: #6b7280; --border: #e5e7eb; --green: #16a34a;
  --warn-bg: #fef3c7; --warn-border: #f59e0b; --error: #dc2626;
  /* Blue used as text/accents on surfaces (headers, links, % to goal). Kept
     separate from --blue, which stays a solid fill carrying white text. */
  --accent: var(--blue);
  /* Theme native form controls (date picker icon + its popup, dropdowns) to the
     OS scheme, so the calendar glyph isn't a dark-on-dark blob in dark mode. */
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a; --card: #1e293b; --text: #e2e8f0; --muted: #94a3b8; --border: #334155;
    /* Lighten on-surface colors so they read against the dark card, not blue-on-blue. */
    --accent: #7ea6e0; --green: #4ade80; --warn-border: #fbbf24; --error: #f87171;
  }
}
* { box-sizing: border-box; margin: 0; }
/* The `hidden` attribute must always win. Author display rules (e.g.
   `dialog label { display:block }`, `.pp-overlay { display:flex }`) otherwise
   override the browser default of display:none and leak hidden elements. */
[hidden] { display: none !important; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg); color: var(--text); min-height: 100vh;
  padding-bottom: 4.5rem; /* clears the fixed values footer */
}

.topbar {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  background: var(--blue); color: #fff; padding: .85rem 1.25rem;
  /* Above the fixed values-footer (20) so a tall open nav dropdown isn't
     clipped by it; still below the price-page overlay (50) and toasts (100). */
  position: sticky; top: 0; z-index: 30;
}
.brand { font-weight: 800; font-size: 1.5rem; letter-spacing: .02em; display: flex; align-items: center; gap: .65rem; }
.brand-logo { height: 66px; width: 66px; border-radius: 50%; background: #fff; padding: 3px; object-fit: contain; }

/* Core values footer — fixed to the bottom of the viewport */
.values-footer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center; gap: 1rem; flex-wrap: wrap;
  background: var(--blue); color: #fff;
  padding: 1.1rem 1rem;
  font-size: 1.5rem; font-weight: 800; letter-spacing: .02em;
  box-shadow: 0 -2px 12px rgba(0,0,0,.15);
}
.values-footer i { color: #7f9bd0; font-size: 1rem; }
/* Running build, pinned to the footer's lower right. Absolutely positioned so
   it never shifts the centered values text. Populated by renderFooterBuild(). */
.footer-build {
  position: absolute; right: .9rem; bottom: .4rem;
  font-size: .7rem; font-weight: 600; letter-spacing: .02em;
  color: rgba(255,255,255,.55);
}
@media (max-width: 560px) {
  body { padding-bottom: 4.6rem; }
  /* Extra bottom padding reserves a row for the build line, so it can't
     collide with the values text when that wraps. */
  .values-footer { font-size: 1.05rem; gap: .55rem; padding: .8rem .6rem 1.5rem; }
  .values-footer i { font-size: .7rem; }
  .footer-build { right: .6rem; bottom: .35rem; font-size: .62rem; }
}
/* Nav wrapper — one flex row on desktop, a collapsible dropdown on narrow
   screens (see the max-width: 900px block below). */
.nav-panel { display: flex; align-items: center; gap: 1rem; flex: 1; }
#tabs { display: flex; gap: .25rem; flex: 1; }
.tab {
  background: transparent; color: #cbd5e1; border: none; padding: .45rem .8rem;
  border-radius: 8px; font-size: .95rem; cursor: pointer;
}
.tab.active { background: rgba(255,255,255,.18); color: #fff; font-weight: 600; }
.whoami { font-size: .85rem; opacity: .9; }
.logout { color: #cbd5e1; font-size: .82rem; text-decoration: none; }
.logout:hover { color: #fff; text-decoration: underline; }

/* Hamburger — shown only once the tabs collapse. */
.nav-toggle {
  display: none; margin-left: auto;
  background: transparent; border: 1px solid rgba(255,255,255,.35); color: #fff;
  font-size: 1.3rem; line-height: 1; padding: .3rem .62rem; border-radius: 8px; cursor: pointer;
}
.nav-toggle:hover { background: rgba(255,255,255,.14); }

/* Eight tabs plus the user block need real width; below this the header
   collapses to brand + hamburger, with everything else in a dropdown. */
@media (max-width: 900px) {
  .topbar { flex-wrap: nowrap; gap: .6rem; padding: .6rem .9rem; }
  .brand { font-size: 1.15rem; gap: .45rem; }
  .brand-logo { height: 42px; width: 42px; }
  .nav-toggle { display: block; }
  .nav-panel {
    display: none;
    position: absolute; top: 100%; left: 0; right: 0;
    flex: none; flex-direction: column; align-items: stretch; gap: .15rem;
    background: var(--blue); padding: .5rem .9rem .9rem;
    border-top: 1px solid rgba(255,255,255,.15);
    box-shadow: 0 10px 24px rgba(0,0,0,.28);
    max-height: 80vh; overflow-y: auto;
  }
  .nav-panel.open { display: flex; }
  #tabs { flex: none; flex-direction: column; gap: .15rem; }
  .tab { text-align: left; padding: .7rem .75rem; font-size: 1rem; }
  /* Keep the signed-in name visible in the menu (the ≤560px rule hides it in
     the bar); higher specificity, so it wins at every width. */
  .nav-panel .whoami {
    display: block; margin-top: .5rem; padding: .6rem .75rem .1rem;
    border-top: 1px solid rgba(255,255,255,.15); font-size: .9rem;
  }
  .nav-panel .logout { padding: .5rem .75rem; font-size: .95rem; }
}

main { max-width: 1200px; margin: 0 auto; padding: 1rem; }
h2 { font-size: 1.2rem; margin: .8rem 0 .4rem; }
h3 { font-size: .95rem; margin: 1.1rem 0 .4rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.center { text-align: center; }

.weekbar { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .6rem; text-align: center; }
.weekbar h2 { margin: 0; }
/* "Jump to this week" — only rendered while viewing another week (see
   syncWeekToday), so it never takes up space on the normal view. */
.week-today { margin-top: .3rem; color: var(--accent); }

.banner { padding: .7rem .9rem; border-radius: 10px; margin: .6rem 0; }
.banner.warn { background: var(--warn-bg); border: 1px solid var(--warn-border); color: #78350f; }

.progress-wrap { display: flex; align-items: center; gap: .7rem; margin: .5rem 0 .8rem; }
.progress { flex: 1; height: 10px; background: var(--border); border-radius: 6px; overflow: hidden; }
#progress-bar { height: 100%; width: 0; background: var(--green); transition: width .3s; }

.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin: .6rem 0 .2rem; }
.spacer { flex: 1; }
button { font: inherit; cursor: pointer; border-radius: 9px; border: 1px solid transparent; padding: .55rem .95rem; }
button.primary { background: var(--blue); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--blue-dark); }
button.secondary { background: var(--card); border-color: var(--accent); color: var(--accent); font-weight: 600; }
button.ghost { background: transparent; border-color: var(--border); color: var(--text); }
button:disabled { opacity: .45; cursor: default; }

.dash-top { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .6rem; }
.dash-top h2 { margin: 0; }
.dash-h { display: flex; align-items: center; gap: .5rem; }
.dash-h .count { background: var(--border); color: var(--text); border-radius: 999px; padding: 0 .55rem; font-size: .75rem; }
.dash-h.overdue { color: var(--error); }
.dash-h.today { color: #92400e; }
.dash-h.tomorrow { color: var(--accent); }
#team-stats { margin: -.3rem 0 .8rem; }
.mysales-head { font-weight: 700; color: var(--accent); margin-bottom: .4rem; display: flex; align-items: center; justify-content: space-between; gap: .6rem; }
.team-hist-head { display: flex; align-items: center; justify-content: space-between; gap: .6rem; }
button.ghost.small { padding: .25rem .55rem; font-size: .85rem; font-weight: 700; text-transform: none; letter-spacing: 0; white-space: nowrap; line-height: 1; }
/* Year navigation (‹ 2026 ›) */
.year-nav { display: inline-flex; align-items: center; gap: .5rem; }
.year-nav b { min-width: 2.6rem; text-align: center; font-variant-numeric: tabular-nums; }
/* Month-by-month sales tables */
.monthly-head { display: flex; align-items: center; justify-content: space-between; gap: .6rem; }
.monthly-head .monthly-rep { font-size: .85rem; padding: .2rem .4rem; border: 1px solid var(--border); border-radius: 6px; background: var(--card); color: var(--text); max-width: 12rem; }
.monthly-table .mo-name { font-weight: 600; white-space: nowrap; }
.monthly-table th { text-align: right; }
.monthly-table th:first-child { text-align: left; }
.gpct { font-weight: 700; font-variant-numeric: tabular-nums; }
.gpct.done { color: var(--green); }
.gpct.ok { color: var(--accent); }
.gpct.low { color: var(--warn-border); }
.mysales-row { display: grid; grid-template-columns: 6rem 6.5rem minmax(4rem, 1fr) auto; align-items: center; gap: .7rem; padding: .3rem 0; }
.mysales-label { color: var(--muted); font-size: .9rem; }
.mysales-val { font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.mysales-pct { white-space: nowrap; }
.nord-row { display: flex; justify-content: space-between; align-items: baseline; gap: .6rem; padding: .4rem 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.nord-row:last-child { border-bottom: 0; }
.nord-row:hover .nord-name { color: var(--accent); }
.nord-name { font-weight: 600; }
.nord-counts { white-space: nowrap; }
.sales-group { margin-bottom: .8rem; }
.sales-group-head { font-weight: 700; color: var(--accent); margin-bottom: .5rem; }
.sales-table th, .sales-table td { padding: .5rem .6rem; }
.sales-table .sr-name { font-weight: 600; }
.sales-table .sr-num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.sales-table .sr-bar { min-width: 8rem; }
.goalbar { display: inline-block; width: calc(100% - 3rem); height: .55rem; background: var(--border); border-radius: 999px; overflow: hidden; vertical-align: middle; }
.goalbar-fill { height: 100%; border-radius: 999px; }
.goalbar-fill.done { background: var(--green); }
.goalbar-fill.ok { background: var(--accent); }
.goalbar-fill.low { background: var(--warn-border); }
.sales-table .sr-pct { display: inline-block; width: 2.6rem; text-align: right; font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.sales-table tr.sales-total td { border-top: 2px solid var(--border); font-weight: 700; }
.team-chart { display: flex; flex-direction: column; gap: .55rem; }
#team-managers { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: .8rem; }
.mgr-card { margin-bottom: 0; }
.mgr-head { display: flex; align-items: baseline; justify-content: space-between; gap: .6rem; margin-bottom: .45rem; }
.mgr-progress { height: .55rem; background: var(--border); border-radius: 999px; overflow: hidden; margin-bottom: .6rem; }
.mgr-progress div { height: 100%; background: var(--green); border-radius: 999px; }
.mgr-types { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: .6rem; }
.type-pill { background: var(--bg); border: 1px solid var(--border); border-radius: 999px; padding: .1rem .6rem; font-size: .75rem; }
.type-pill b.ok { color: var(--green); }
.type-pill b.warn { color: var(--error); }
.mgr-reps { list-style: none; padding: 0; margin: 0; }
.mgr-reps > li { display: flex; justify-content: space-between; gap: .6rem; padding: .3rem 0; border-top: 1px solid var(--border); font-size: .88rem; }
.mgr-reps > li.clickable { cursor: pointer; }
.mgr-reps > li.clickable:hover { color: var(--accent); }
.mgr-reps .chev { font-style: normal; display: inline-block; margin-right: .35rem; color: var(--muted); transition: transform .15s; }
.mgr-reps > li.open .chev { transform: rotate(90deg); }
.mgr-reps > li.member-detail { display: block; background: var(--bg); border-radius: 8px; padding: .5rem .65rem; border-top: none; }
.mgr-rep-meta { display: flex; align-items: center; gap: .35rem; white-space: nowrap; }
.sub-badge { font-size: .66rem; font-weight: 700; padding: .05rem .35rem; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }
.sub-badge.on { color: #15803d; border-color: #bbf7d0; background: #f0fdf4; }
@media (prefers-color-scheme: dark) { .sub-badge.on { color: #86efac; border-color: #166534; background: #052e16; } }
/* Team dashboard: new customers ordering, by rep (expandable) */
#team-neworders { display: flex; flex-direction: column; gap: .5rem; margin-bottom: 1rem; }
.tno-rep { margin-bottom: 0; padding: .55rem .8rem; }
.tno-head { display: flex; align-items: baseline; justify-content: space-between; gap: .6rem; font-weight: 600; }
.tno-head.clickable { cursor: pointer; }
.tno-head.clickable:hover { color: var(--accent); }
.tno-head .chev { font-style: normal; display: inline-block; margin-right: .4rem; color: var(--muted); transition: transform .15s; }
.tno-head.open .chev { transform: rotate(90deg); }
.tno-custs { list-style: none; padding: 0; margin: .5rem 0 0; }
.tno-cust { display: flex; justify-content: space-between; gap: .6rem; padding: .35rem 0; border-top: 1px solid var(--border); font-size: .88rem; cursor: pointer; }
.tno-cust:hover { color: var(--accent); }
.bar-row { display: grid; grid-template-columns: minmax(6rem, 10rem) 1fr 3.4rem; align-items: center; gap: .7rem; }
.bar-label { font-size: .85rem; font-weight: 600; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-total { background: var(--border); border-radius: 6px; height: 1.15rem; overflow: hidden; min-width: 3px; }
.bar-done { background: var(--green); height: 100%; }
.bar-count { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.bar-legend { display: flex; gap: 1.1rem; margin-top: .45rem; font-size: .75rem; color: var(--muted); }
.bar-legend .sw { display: inline-block; width: .8rem; height: .8rem; border-radius: 3px; margin-right: .35rem; vertical-align: -2px; }
.sw.done { background: var(--green); }
.sw.open { background: var(--border); }
.daygroups { display: flex; flex-direction: column; }
.day-head {
  font-size: .78rem; font-weight: 700; color: var(--accent); text-transform: uppercase;
  letter-spacing: .05em; margin: .9rem 0 .4rem; padding-bottom: .25rem;
  border-bottom: 1px solid var(--border);
}
.daygroups .day-head:first-child { margin-top: .2rem; }
.tasklist { list-style: none; padding: 0; display: flex; flex-direction: column; gap: .45rem; }
/* Space between the activity lists and the sales-by-month card below them */
#dash-mymonthly { margin-top: 1.5rem; }
.tasklist li {
  display: flex; gap: .7rem; align-items: flex-start;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: .65rem .8rem;
}
.tasklist li.done .task-subject { text-decoration: line-through; color: var(--muted); }
.tasklist li.overdue { border-left: 3px solid var(--error); }
.tasklist li.today { border-left: 3px solid var(--warn-border); }
.due-badge {
  display: inline-block; font-size: .68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .03em; padding: .08rem .42rem; border-radius: 999px; vertical-align: middle; margin-left: .4rem;
}
.due-badge.overdue { background: var(--error); color: #fff; }
.due-badge.today { background: var(--warn-bg); color: #92400e; border: 1px solid var(--warn-border); }
.check input { width: 1.35rem; height: 1.35rem; accent-color: var(--green); margin-top: .1rem; }
.task-subject { font-weight: 600; }
.task-body { flex: 1; min-width: 0; }
.task-actions { display: flex; align-items: center; gap: .15rem; align-self: center; }
.task-edit, .task-card {
  background: transparent; border: none; color: var(--muted); cursor: pointer;
  font-size: 1rem; line-height: 1; padding: .25rem .4rem; border-radius: 6px;
}
.task-edit:hover, .task-card:hover { color: var(--accent); background: rgba(30,64,110,.08); }
/* Reach-out block under a task: customer link + company phone, then contact. */
.task-contact-info { margin-top: .35rem; display: flex; flex-direction: column; gap: .15rem; font-size: .82rem; }
.task-cust-row, .task-contact-row { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .8rem; }
.task-cust { font-weight: 600; color: var(--accent); text-decoration: none; }
.task-cust:hover { text-decoration: underline; }
/* Subject heading opens the task for editing: keep the heading look, just clickable. */
a.task-subject { color: inherit; text-decoration: none; cursor: pointer; }
a.task-subject:hover { text-decoration: underline; }
.task-cust-plain { font-weight: 600; }
.task-contact-name { font-weight: 600; color: var(--text); }
.task-tel, .task-email { color: var(--muted); text-decoration: none; white-space: nowrap; }
.task-tel:hover, .task-email:hover { color: var(--accent); text-decoration: underline; }
.empty { text-align: center; color: var(--muted); padding: 2.2rem 1rem; }

.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; background: var(--card); border-radius: 12px; overflow: hidden; }
th, td { text-align: left; padding: .55rem .7rem; border-bottom: 1px solid var(--border); font-size: .92rem; }
th { background: rgba(30,64,175,.07); font-weight: 700; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 1rem; margin-bottom: 1.2rem; }

/* ── Admin: collapsible sections ────────────────────────────────────────── */
.admin-toolbar { display: flex; align-items: center; justify-content: space-between; gap: .5rem; flex-wrap: wrap; margin-bottom: .8rem; }
.admin-title { margin: 0; }
.admin-toolbar-actions { display: flex; gap: .4rem; }
.admin-sec { border: 1px solid var(--border); border-radius: 12px; background: var(--card); margin-bottom: .6rem; overflow: hidden; }
.admin-sec > summary { cursor: pointer; list-style: none; user-select: none; display: flex; align-items: center; gap: .6rem; padding: .7rem .9rem; font-size: 1.05rem; font-weight: 700; }
.admin-sec > summary::-webkit-details-marker { display: none; }
.admin-sec > summary::before { content: "▸"; color: var(--muted); font-size: .9em; transition: transform .15s ease; }
.admin-sec[open] > summary::before { transform: rotate(90deg); }
.admin-sec > summary:hover { color: var(--accent); }
.admin-sec[open] > summary { border-bottom: 1px solid var(--border); }
.admin-sec-h { font-weight: 700; }
.admin-sec-note { color: var(--muted); font-weight: 400; font-size: .72em; margin-left: .35rem; }
/* The card already sits inside the section frame — drop its own border/margin. */
.admin-sec > .card { border: 0; border-radius: 0; margin: 0; }
/* Dashboard section × role visibility matrix. */
.dash-sec-grid-wrap { overflow-x: auto; margin-bottom: .8rem; }
.dsa-table { border-collapse: collapse; width: 100%; font-size: .88rem; }
.dsa-table th, .dsa-table td { border-bottom: 1px solid var(--border); padding: .4rem .5rem; text-align: center; }
.dsa-table th { background: var(--bg); color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .03em; }
.dsa-table th.dsa-sec, .dsa-table td.dsa-sec { text-align: left; white-space: normal; }
.dsa-table .dsa-group td { text-align: left; font-weight: 700; color: var(--accent); background: var(--bg); font-size: .78rem; }
.dsa-cell input { width: auto; margin: 0; cursor: pointer; }
.card label { display: block; margin-bottom: .7rem; font-size: .9rem; font-weight: 600; }
.card input:not([type=checkbox]), .card select, dialog input:not([type=checkbox]), dialog select, dialog textarea {
  width: 100%; padding: .5rem .6rem; margin-top: .25rem; font: inherit;
  border: 1.5px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text);
}
.edit-table input:not([type=checkbox]), .edit-table select { width: 100%; min-width: 6rem; margin: 0; }
/* Make the native date picker's calendar button easy to spot and click. */
input[type=date]::-webkit-calendar-picker-indicator { cursor: pointer; opacity: .85; }
input[type=date]:hover::-webkit-calendar-picker-indicator { opacity: 1; }
.card label.check-inline, dialog label.check-inline { display: flex; align-items: center; gap: .5rem; font-weight: 500; cursor: pointer; flex-wrap: wrap; }
.card label.check-inline input, dialog label.check-inline input { width: auto; margin: 0; }
.card select.inline-select { width: auto; margin: 0; padding: .25rem .4rem; }
#test-banner {
  background: var(--error); color: #fff; text-align: center; font-weight: 700;
  font-size: .85rem; letter-spacing: .06em; padding: .4rem .8rem; text-transform: uppercase;
}
.linkish { background: none; border: none; padding: 0; color: var(--accent); text-decoration: underline; cursor: pointer; font: inherit; font-size: .85rem; }
.row-del { background: transparent; border: none; color: var(--error); font-size: 1rem; line-height: 1; padding: .2rem .4rem; cursor: pointer; }
.row-del:hover { color: #fff; background: var(--error); border-radius: 6px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.row { display: flex; gap: .6rem; justify-content: flex-end; margin-top: .4rem; }
.row button:first-child { margin-right: auto; }
pre#test-result { white-space: pre-wrap; background: var(--bg); padding: .7rem; border-radius: 8px; font-size: .8rem; }

dialog {
  border: none; border-radius: 14px; padding: 1.4rem; width: min(94vw, 560px);
  background: var(--card); color: var(--text); box-shadow: 0 10px 40px rgba(0,0,0,.25);
}
dialog textarea { resize: vertical; min-height: 5.5rem; }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog h3 { margin: 0 0 .8rem; text-transform: none; color: var(--text); font-size: 1.1rem; }
dialog label { display: block; margin-bottom: .7rem; font-size: .9rem; font-weight: 600; position: relative; }

.autocomplete {
  list-style: none; padding: 0; margin: .2rem 0 0; border: 1px solid var(--border);
  border-radius: 8px; max-height: 180px; overflow-y: auto; background: var(--card);
  position: absolute; width: 100%; z-index: 5;
}
.autocomplete li { padding: .5rem .6rem; cursor: pointer; font-weight: 400; }
.autocomplete li:hover, .autocomplete li.kb-active { background: rgba(30,64,175,.09); }

.rep-row { cursor: pointer; }
.rep-row:hover td { background: rgba(30,64,175,.05); }
.detail-row td { background: var(--bg); }
.detail-list { list-style: none; padding: .2rem 0; display: flex; flex-direction: column; gap: .45rem; }
.detail-list li { display: flex; gap: .5rem; align-items: baseline; flex-wrap: wrap; }
.detail-subject { font-weight: 600; }
.done-mark { color: var(--green); font-weight: 700; }
.open-mark { color: var(--muted); }

#toast {
  position: fixed; bottom: 5.5rem; left: 50%; transform: translateX(-50%);
  background: #111827; color: #fff; padding: .65rem 1.1rem; border-radius: 10px;
  font-size: .92rem; z-index: 100; max-width: 90vw;
}
#toast.error { background: var(--error); }

@media (max-width: 560px) {
  .whoami { display: none; }
  .actions button { flex: 1 1 45%; }
  th, td { font-size: .85rem; padding: .45rem .5rem; }
}

/* ── Customer 360 ───────────────────────────────────────────────────────── */
.cust-mode { display: inline-flex; gap: 0; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin: .3rem 0 .2rem; }
.cust-mode .seg { border: none; border-radius: 0; background: var(--card); color: var(--muted); padding: .4rem .9rem; font-size: .85rem; font-weight: 600; cursor: pointer; }
.cust-mode .seg + .seg { border-left: 1px solid var(--border); }
.cust-mode .seg.active { background: var(--blue); color: #fff; }
.cust-search { position: relative; max-width: 30rem; margin: .2rem 0 1rem; }
#cust-search-input { width: 100%; padding: .6rem .8rem; font-size: 1rem; border: 1px solid var(--border); border-radius: 8px; background: var(--card); color: var(--text); }
.cust-results { position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; right: 0; margin: 0; padding: .3rem; list-style: none; background: var(--card); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.12); max-height: 20rem; overflow-y: auto; }
.cust-results li { display: flex; flex-direction: column; gap: .1rem; padding: .5rem .6rem; border-radius: 6px; cursor: pointer; }
.cust-results li[data-id]:hover, .cust-results li.kb-active { background: var(--bg); }
.cust-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .6rem; }
.cust-name { margin: 0; font-size: 1.2rem; }
.cust-head-side { display: flex; flex-direction: column; align-items: flex-end; gap: .5rem; }
.cust-add-btn { padding: .4rem .8rem; font-size: .9rem; white-space: nowrap; }
.contact-li { justify-content: space-between; gap: .6rem; }
.contact-info { min-width: 0; }
.contact-name { font-weight: 600; }
.add-act-btn { flex-shrink: 0; padding: .25rem .55rem; font-size: .8rem; font-weight: 600; white-space: nowrap; border: 1px solid var(--accent); background: var(--card); color: var(--accent); border-radius: 6px; cursor: pointer; }
.add-act-btn:hover { background: var(--blue); color: #fff; }
.cust-phone { margin-top: .2rem; font-size: .9rem; }
.cust-phone a, .mini-list a { color: var(--accent); text-decoration: none; font-weight: 600; }
.cust-phone a:hover, .mini-list a:hover { text-decoration: underline; }
.cust-tags { display: flex; flex-wrap: wrap; gap: .4rem; }
.pill { display: inline-block; padding: .2rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--bg); border: 1px solid var(--border); color: var(--muted); }
.pill.ok { background: #ecfdf5; border-color: #a7f3d0; color: #047857; }
.pill.warn { background: #fef2f2; border-color: #fecaca; color: #b91c1c; }
/* Account type: Customer (blue) vs Prospect (amber). Translucent fills so both
   read on light and dark cards; text uses theme tokens / a dark-mode override. */
.pill.customer { background: rgba(37,99,235,.12); border-color: rgba(37,99,235,.30); color: var(--accent); }
.pill.prospect { background: rgba(217,119,6,.15); border-color: rgba(217,119,6,.38); color: #b45309; }
.acct-name-row { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.acct-badge { font-size: .62rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: .06rem .4rem; border-radius: 999px; white-space: nowrap; }
.acct-badge.customer { background: rgba(37,99,235,.12); color: var(--accent); }
.acct-badge.prospect { background: rgba(217,119,6,.16); color: #b45309; }
@media (prefers-color-scheme: dark) {
  .pill.prospect, .acct-badge.prospect { color: #fbbf24; }
}
.cust-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: .8rem; margin-top: .8rem; }
.cust-card-h { font-weight: 700; color: var(--accent); margin-bottom: .6rem; }
.cust-card-h.with-action { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.cust-card-actions .ghost.small { color: var(--accent); }
/* Clickable Recent-activity rows open the task dialog. */
.detail-list li.act-item { cursor: pointer; border-radius: 8px; padding: .25rem .35rem; margin: 0 -.35rem; }
.detail-list li.act-item:hover { background: var(--bg); }
.cust-card-h .count { font-weight: 700; color: var(--muted); font-size: .85rem; margin-left: .2rem; }
.panel-sub { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .5rem; }
.grow { font-weight: 700; font-size: .82rem; white-space: nowrap; }
.grow.up { color: var(--green); }
.grow.down { color: var(--warn-border); }
.trend-row { display: grid; grid-template-columns: 3rem 1fr auto; align-items: center; gap: .5rem; padding: .18rem 0; }
.trend-yr { color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.trend-track { height: .6rem; background: var(--border); border-radius: 999px; overflow: hidden; }
.trend-fill { height: 100%; background: var(--accent); border-radius: 999px; }
.trend-val { font-weight: 700; font-variant-numeric: tabular-nums; font-size: .9rem; }
.recency-list { display: flex; flex-direction: column; }
.recency-row { display: grid; grid-template-columns: 4.5rem auto 1fr; align-items: baseline; gap: .5rem; padding: .28rem 0; border-bottom: 1px solid var(--border); }
.recency-row:last-child { border-bottom: 0; }
.recency-lbl { color: var(--muted); font-size: .85rem; font-weight: 600; }
.recency-val { font-variant-numeric: tabular-nums; font-size: .95rem; }
.recency-when { justify-self: end; }
/* New Customers table — fixed layout so it always fits the page width (no
   sideways scrolling); the name column absorbs the squeeze by wrapping. */
.nc-count { margin: .2rem 0 .6rem; }
.nc-table { width: 100%; table-layout: fixed; border-collapse: collapse; font-size: .9rem; border: 1px solid var(--border); border-radius: 10px; }
.nc-c-id { width: 7%; } .nc-c-name { width: 18%; } .nc-c-date { width: 9%; } .nc-c-cnt { width: 6%; } .nc-c-task { width: 12%; }
/* Order/quote count headers stack each word on its own line, so the columns
   stay narrow. Header and value centered together, tight line-height. */
.nc-table th.nc-th-cnt { text-align: center; letter-spacing: 0; line-height: 1.1; }
.nc-table td.nc-cnt { text-align: center; }
.nc-table th, .nc-table td { padding: .5rem .55rem; text-align: left; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; vertical-align: top; }
.nc-table thead th { background: var(--bg); color: var(--muted); font-weight: 700; font-size: .74rem; text-transform: uppercase; letter-spacing: .03em; }
.nc-table th.nc-th { cursor: pointer; user-select: none; }
.nc-table th.nc-th:hover, .nc-table th.nc-th.active { color: var(--accent); }
.nc-table td.num, .nc-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.nc-table td.nc-name { font-weight: 600; }
.nc-table tbody tr:hover { background: var(--bg); }
.nc-table tbody tr:last-child td { border-bottom: 0; }
.nc-actions { display: flex; flex-wrap: wrap; gap: .35rem; }
.nc-btn { padding: .25rem .55rem; font-size: .8rem; border: 1px solid var(--border); border-radius: 7px; background: var(--card); color: var(--accent); cursor: pointer; white-space: nowrap; }
.nc-btn:hover { background: var(--bg); }
/* ── Leaders & Bleeders ─────────────────────────────────────────────────── */
.lb-controls { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem 1rem; margin: .3rem 0 .8rem; }
.lb-rep-wrap { font-size: .85rem; color: var(--muted); }
.lb-rep-wrap select { margin-left: .35rem; padding: .25rem .4rem; border: 1px solid var(--border); border-radius: 7px; background: var(--card); color: var(--text); }
.lb-filters { display: flex; flex-wrap: wrap; gap: .35rem; }
.lb-chip { display: inline-flex; align-items: center; gap: .3rem; padding: .2rem .5rem; border: 1px solid var(--border); border-radius: 999px; font-size: .78rem; color: var(--muted); cursor: pointer; user-select: none; }
.lb-chip input { margin: 0; }
.lb-chip b { font-weight: 800; }
.lb-chip.on.lb-leader { color: #15803d; border-color: #bbf7d0; background: #f0fdf4; }
.lb-chip.on.lb-bleeder { color: #b91c1c; border-color: #fecaca; background: #fef2f2; }
.lb-only { font-size: .8rem; color: var(--muted); display: inline-flex; align-items: center; gap: .35rem; cursor: pointer; }
.lb-count { margin: .2rem 0 .6rem; }
.lb-tag { padding: .05rem .4rem; border-radius: 999px; font-weight: 700; font-size: .72rem; }
.lb-tag.leader { color: #15803d; background: #f0fdf4; }
.lb-tag.bleeder { color: #b91c1c; background: #fef2f2; }
/* Fixed layout so all columns (including the actions) fit without sideways
   scrolling; the name column absorbs the squeeze by wrapping. */
.lb-table { width: 100%; table-layout: fixed; border-collapse: collapse; font-size: .86rem; border: 1px solid var(--border); border-radius: 10px; }
.lb-c-grade { width: 6%; } .lb-c-id { width: 7%; } .lb-c-name { width: 16%; }
.lb-c-money { width: 9%; } .lb-c-var { width: 7%; } .lb-c-date { width: 8%; }
.lb-c-task { width: 10%; } .lb-c-act { width: 10%; }
.lb-table th, .lb-table td { padding: .45rem .4rem; text-align: left; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; vertical-align: top; }
.lb-table thead th { background: var(--bg); color: var(--muted); font-weight: 700; font-size: .7rem; text-transform: uppercase; letter-spacing: .02em; line-height: 1.1; }
.lb-table th.lb-th { cursor: pointer; user-select: none; }
.lb-table th.lb-th:hover, .lb-table th.lb-th.active { color: var(--accent); }
.lb-table td.num, .lb-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.lb-table td.lb-name { font-weight: 600; }
.lb-name-link { display: inline; padding: 0; border: 0; background: none; color: var(--accent); font: inherit; font-weight: 600; text-align: left; cursor: pointer; overflow-wrap: anywhere; }
.lb-name-link:hover { text-decoration: underline; }
.lb-table tbody tr:hover { background: var(--bg); }
.lb-table tbody tr:last-child td { border-bottom: 0; }
.lb-grade-cell { text-align: center; }
.lb-badge { display: inline-block; min-width: 1.5rem; padding: .05rem .3rem; border-radius: 6px; font-weight: 800; text-align: center; font-size: .8rem; }
.lb-badge.lb-leader { color: #fff; background: #16a34a; }
.lb-badge.lb-bleeder { color: #fff; background: #dc2626; }
.lb-badge.lb-flat { color: var(--muted); background: var(--bg); border: 1px solid var(--border); }
.lb-badge sup { font-size: .6em; }
.lb-var.up { color: #16a34a; font-weight: 700; }
.lb-var.down { color: #dc2626; font-weight: 700; }
.lb-new { color: #2563eb; font-weight: 800; font-size: .72rem; letter-spacing: .03em; }
.lb-task-link { display: inline; padding: 0; border: 0; background: none; color: var(--accent); font: inherit; text-align: left; cursor: pointer; }
.lb-task-link:hover { text-decoration: underline; }
.lb-done { color: #16a34a; font-weight: 700; }
.lb-more { font-size: .72rem; color: var(--muted); font-weight: 700; }
.lb-pending { display: inline-block; min-width: 1.3rem; padding: 0 .35rem; border-radius: 999px; background: #fffbeb; color: #b45309; border: 1px solid #fde68a; font-weight: 700; font-size: .78rem; }
.lb-actions { display: flex; flex-wrap: wrap; gap: .35rem; }
.lb-btn { padding: .25rem .55rem; font-size: .8rem; border: 1px solid var(--border); border-radius: 7px; background: var(--card); color: var(--accent); cursor: pointer; white-space: nowrap; }
.lb-btn:hover { background: var(--bg); }
@media (prefers-color-scheme: dark) {
  .lb-chip.on.lb-leader { color: #86efac; border-color: #166534; background: #052e16; }
  .lb-chip.on.lb-bleeder { color: #fca5a5; border-color: #7f1d1d; background: #2a0a0a; }
  .lb-tag.leader { color: #86efac; background: #052e16; }
  .lb-tag.bleeder { color: #fca5a5; background: #2a0a0a; }
  .lb-pending { background: #3a2a05; color: #fcd34d; border-color: #78560a; }
}
.ar-buckets { display: grid; grid-template-columns: repeat(3, 1fr); gap: .4rem; margin-bottom: .6rem; }
.ar-cell { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: .45rem .5rem; text-align: center; }
.ar-cell.hot { background: #fef2f2; border-color: #fecaca; }
.ar-cell.total { background: #eef1f7; }
.ar-amt { font-weight: 700; font-variant-numeric: tabular-nums; font-size: .95rem; }
.ar-cell.hot .ar-amt { color: #b91c1c; }
.ar-lbl { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
/* .hot and .total hardcode light backgrounds; give them dark equivalents so the
   figures (which use --text/--muted) don't render light-on-light in dark mode. */
@media (prefers-color-scheme: dark) {
  .ar-cell.hot { background: #3a1e1e; border-color: #7f1d1d; }
  .ar-cell.hot .ar-amt { color: #fca5a5; }
  .ar-cell.total { background: #29374d; border-color: var(--border); }
}
.panel-filter { width: 100%; padding: .4rem .6rem; margin-bottom: .5rem; font-size: .88rem; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); }
.mini-list { list-style: none; margin: 0; padding: 0; }
.mini-list.scroll { max-height: 15rem; overflow-y: auto; }
.mini-list li { display: flex; align-items: center; gap: .5rem; padding: .35rem 0; border-top: 1px solid var(--border); }
.mini-list li:first-child { border-top: none; }
.mini-list li > span:first-child { font-weight: 600; }
.mini-list li .muted { margin-left: auto; text-align: right; }
.mini-list li b { font-variant-numeric: tabular-nums; }

/* ---- Price Pages ---- */
.pp-new-btn { margin-bottom: .6rem; }
.pp-list a { color: var(--accent); text-decoration: none; font-weight: 600; }
.pp-list a:hover { text-decoration: underline; }
.pp-unsent { color: var(--error); font-weight: 600; }

/* Builder overlay */
.pp-overlay { position: fixed; inset: 0; z-index: 50; background: rgba(15,23,42,.55); display: flex; align-items: flex-start; justify-content: center; padding: 1.25rem 1rem; overflow-y: auto; }
/* The display:flex above would otherwise override the `hidden` attribute and
   leave the overlay permanently covering (and blocking) the page. */
.pp-overlay[hidden] { display: none; }
.pp-modal { background: var(--card); color: var(--text); width: 100%; max-width: 960px; border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.35); display: flex; flex-direction: column; min-height: min(640px, calc(100vh - 2.5rem)); max-height: calc(100vh - 2.5rem); }
.pp-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; padding: 1.1rem 1.25rem; border-bottom: 1px solid var(--border); }
.pp-head h2 { margin: 0 0 .2rem; font-size: 1.15rem; }
.pp-x { font-size: 1.1rem; line-height: 1; color: var(--muted); padding: .1rem .3rem; }
.pp-x:hover { color: var(--text); }
.pp-body { padding: 1.1rem 1.25rem; overflow-y: auto; flex: 1 1 auto; }
.pp-qll-row { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; margin-bottom: 1rem; }
.pp-qll-label { display: flex; align-items: center; gap: .5rem; font-weight: 600; }
.pp-qll-label select { padding: .35rem .5rem; border: 1px solid var(--border); border-radius: 8px; background: var(--card); color: var(--text); font-weight: 700; }
.pp-supp-search { position: relative; margin-bottom: .8rem; }
.pp-supp-search input { width: 100%; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 8px; background: var(--card); color: var(--text); }
.pp-note { background: #fff7ed; border: 1px solid #fdba74; color: #9a3412; border-radius: 8px; padding: .5rem .7rem; font-size: .8rem; font-weight: 600; margin: 0 0 .8rem; }
.pp-empty { padding: 1rem 0; }
.pp-supp { border: 1px solid var(--border); border-radius: 10px; padding: .7rem .8rem; margin-bottom: .7rem; }
.pp-supp-top { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-bottom: .55rem; }
.pp-supp-fields { display: flex; gap: 1rem; flex-wrap: wrap; align-items: flex-end; }
.pp-supp-fields label { display: flex; flex-direction: column; gap: .25rem; font-size: .8rem; font-weight: 600; color: var(--muted); }
.pp-supp-fields input, .pp-supp-fields select { padding: .4rem .5rem; border: 1px solid var(--border); border-radius: 8px; background: var(--card); color: var(--text); font-size: .95rem; font-weight: 600; }
.pp-supp-fields input[type=number] { width: 6rem; }
.pp-warn { margin-top: .5rem; font-size: .8rem; font-weight: 600; color: var(--warn-border); }
.pp-warn.err { color: var(--error); }
.pp-just { display: flex; flex-direction: column; gap: .25rem; margin-top: .55rem; font-size: .8rem; font-weight: 600; color: var(--muted); }
.pp-just textarea { padding: .45rem .55rem; border: 1px solid var(--border); border-radius: 8px; background: var(--card); color: var(--text); font: inherit; resize: vertical; }
.pp-compare { margin-top: .6rem; border-top: 1px dashed var(--border); padding-top: .55rem; }
.pp-cmp-head { margin-bottom: .35rem; }
.pp-bands { display: grid; grid-template-columns: repeat(4, 1fr); gap: .4rem; }
.pp-band { border: 1px solid var(--border); border-radius: 8px; padding: .4rem .35rem; text-align: center; background: var(--bg); }
.pp-band.own-band { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.pp-band-lbl { display: block; font-size: .68rem; color: var(--muted); text-transform: uppercase; letter-spacing: .02em; }
.pp-band-margin { display: block; font-weight: 700; font-size: 1rem; font-variant-numeric: tabular-nums; }
.pp-band-cust { display: block; }
.pp-own { margin-top: .5rem; font-size: .85rem; }
.pp-foot { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .9rem 1.25rem; border-top: 1px solid var(--border); flex-wrap: wrap; }
.pp-foot-btns { display: flex; gap: .6rem; margin-left: auto; align-items: center; }
.pp-foot-btns #pp-ceiling-hint { margin: 0; }
.pp-foot-btns .primary:disabled { opacity: .5; cursor: not-allowed; }
.pp-msg { font-size: .85rem; font-weight: 600; }
.pp-msg.err { color: var(--error); }

/* Admin: per-supplier tier programs */
.tier-supplier { border: 1px solid var(--border); border-radius: 10px; padding: .7rem .8rem; margin-bottom: .7rem; }
.tier-supplier-head { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-bottom: .5rem; }
.tier-override { display: flex; flex-direction: column; gap: .25rem; font-size: .8rem; font-weight: 600; color: var(--muted); margin-bottom: .6rem; }
.tier-override input { padding: .4rem .5rem; border: 1px solid var(--border); border-radius: 8px; background: var(--card); color: var(--text); font-size: .95rem; font-weight: 600; }
.tier-rows-label { text-transform: uppercase; letter-spacing: .03em; margin-bottom: .3rem; }
.tier-rows { display: flex; flex-direction: column; gap: .4rem; }
.tier-row { display: flex; gap: .5rem; align-items: center; }
.tier-row input { flex: 1; padding: .35rem .5rem; border: 1px solid var(--border); border-radius: 8px; background: var(--card); color: var(--text); }
.tier-add-supplier { position: relative; }
@media (prefers-color-scheme: dark) {
  .pp-note { background: #3a2a17; border-color: #b45309; color: #fed7aa; }
}
@media (max-width: 560px) {
  .pp-bands { grid-template-columns: repeat(2, 1fr); }
}
