:root {
  --bg:        #f6f7f9;
  --panel:     #ffffff;
  --border:    #e6e9ef;
  --text:      #131a26;
  --muted:     #66718a;
  --accent:    #2f6df6;
  --accent-2:  #1f5ae0;
  --warn:      #b46a17;
  --danger:    #c0392b;
  --ok:        #1a7f4b;
  --shadow:    0 1px 2px rgba(16,24,40,0.05);
  --shadow-md: 0 6px 20px rgba(16,24,40,0.10);
  --row:       #f8fafc;
  --dist-blue: #1e4084;
  /* Corporate chrome */
  --sidebar-bg:     #121826;
  --sidebar-ink:    #aab4c8;
  --sidebar-ink-2:  #6b768c;
  --sidebar-active: #ffffff;
  --brand-red:      #c8102e;
  --radius:    10px;
  --radius-sm: 7px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; background: var(--bg); color: var(--text);
             font: 14px/1.5 "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
             -webkit-font-smoothing: antialiased; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; }
::selection { background: rgba(47,109,246,0.18); }

/* ===== App shell: fixed dark sidebar + main column ===== */
.app-shell { display: flex; height: 100vh; overflow: hidden; }

.sidebar { width: 240px; flex-shrink: 0; background: var(--sidebar-bg); color: var(--sidebar-ink);
           display: flex; flex-direction: column; transition: width 0.16s ease; }
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px;
                  font-weight: 700; font-size: 15px; letter-spacing: 0.2px; color: #fff; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.nav-ic { width: 20px; text-align: center; font-size: 14px; flex-shrink: 0; opacity: 0.92; }
.nav-tx { white-space: nowrap; overflow: hidden; }

/* Collapsed (icon-only) sidebar */
.app-shell.nav-collapsed .sidebar { width: 64px; }
.app-shell.nav-collapsed .brand-text,
.app-shell.nav-collapsed .nav-tx,
.app-shell.nav-collapsed .nav-group-label { display: none; }
.app-shell.nav-collapsed .sidebar .brand { justify-content: center; padding: 18px 0 14px; }
.app-shell.nav-collapsed .nav { padding: 6px 8px 16px; }
.app-shell.nav-collapsed .nav button { justify-content: center; padding: 10px 0; }
.app-shell.nav-collapsed .nav-ic { width: auto; font-size: 16px; }

.nav-toggle { background: none; border: 1px solid var(--border); border-radius: 8px; width: 34px; height: 34px;
              color: var(--muted); font-size: 15px; line-height: 1; display: inline-flex; align-items: center;
              justify-content: center; flex-shrink: 0; }
.nav-toggle:hover { background: #f3f5f8; color: var(--text); }

.sidebar-foot { padding: 8px 10px; border-top: 1px solid rgba(255,255,255,0.08); }
.nav-collapse-btn { width: 100%; background: rgba(255,255,255,0.06); color: var(--sidebar-ink); border: none;
                    border-radius: 7px; padding: 8px; font-size: 12px; font-weight: 500; }
.nav-collapse-btn:hover { background: rgba(255,255,255,0.12); color: #fff; }
.sidebar .brand .logo-dot { width: 22px; height: 22px; border-radius: 6px; background: var(--brand-red);
                  display: inline-flex; align-items: center; justify-content: center; color: #fff;
                  font-size: 12px; font-weight: 800; flex-shrink: 0; }
.sidebar .brand .sub { display: block; font-weight: 400; font-size: 11px; color: var(--sidebar-ink-2);
                  letter-spacing: 0.04em; text-transform: uppercase; margin-top: 1px; }

.nav { display: flex; flex-direction: column; gap: 1px; padding: 6px 10px 16px; overflow-y: auto; flex: 1; }
.nav::-webkit-scrollbar { width: 8px; }
.nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 8px; }
.nav-group-label { font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em;
                   color: var(--sidebar-ink-2); padding: 14px 12px 5px; }
.nav button { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
              background: none; border: none; color: var(--sidebar-ink); padding: 8px 12px;
              border-radius: var(--radius-sm); font-weight: 500; font-size: 13.5px; line-height: 1.2;
              transition: background 0.12s, color 0.12s; }
.nav button:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav button.active { background: rgba(47,109,246,0.16); color: var(--sidebar-active); font-weight: 600;
                     box-shadow: inset 2px 0 0 var(--accent); }
.nav button .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.5; flex-shrink: 0; }

.main-area { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }

.topbar { background: var(--panel); border-bottom: 1px solid var(--border); padding: 0 20px;
          height: 54px; display: flex; align-items: center; gap: 16px; flex-shrink: 0; }
.topbar .app-title { font-weight: 650; font-size: 15px; color: var(--text); }
.brand { font-weight: 700; }
.spacer { flex: 1; }
.user-pill { background: #eef1f6; color: var(--text); padding: 5px 12px; border-radius: 999px;
             font-size: 12.5px; font-weight: 500; display: inline-flex; align-items: center; gap: 7px; }
.user-pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.hubspot-status { font-size: 12px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border); }
.hubspot-status.ok { background: #e7f6ee; color: var(--ok); border-color: #bfe6cf; }
.hubspot-status.bad { background: #fdeceA; color: var(--danger); border-color: #f2c4bd; }

main { padding: 20px; flex: 1; overflow: auto; }
/* Embedded comms frames fill the content area edge-to-edge. */
.frame-section { margin: -20px; height: calc(100vh - 54px); }
.frame-section.active { display: block; }
.frame-section iframe { width: 100%; height: 100%; border: 0; display: block; }
.section { display: none; }
.section.active { display: block; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
         box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 16px; }
.panel h2 { margin: 0 0 12px; font-size: 15px; font-weight: 650; letter-spacing: 0.1px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.muted { color: var(--muted); }
.flex { display: flex; }
.flex.col { flex-direction: column; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 180px; }
.field label { font-size: 12px; color: var(--muted); }
.field input, .field select, .field textarea {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 7px; background: white;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47,109,246,0.14);
}
.field textarea { min-height: 64px; resize: vertical; }
.btn { padding: 8px 13px; border: 1px solid var(--border); background: white; color: var(--text);
       border-radius: 7px; font-weight: 500; transition: background 0.12s, border-color 0.12s, box-shadow 0.12s; }
.btn:hover { background: #f3f5f8; }
.btn:active { box-shadow: inset 0 1px 2px rgba(16,24,40,0.10); }
.btn.primary { background: var(--accent); color: white; border-color: var(--accent); box-shadow: 0 1px 2px rgba(47,109,246,0.25); }
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn.danger { background: var(--danger); color: white; border-color: #8d2f23; }
.btn.warn { background: var(--warn); color: white; border-color: #8d6822; }
.btn.ok { background: var(--ok); color: white; border-color: #1d5a2c; }
.btn.small { padding: 4px 8px; font-size: 12px; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; background: #eef2f7;
       color: var(--muted); border: 1px solid var(--border); }
.tag.ok { background: #def2e1; color: var(--ok); border-color: #b8d9c0; }
.tag.warn { background: #faecd4; color: var(--warn); border-color: #e8d2a0; }
.tag.bad { background: #f7d9d4; color: var(--danger); border-color: #e6b1a8; }

table.tbl { width: 100%; border-collapse: collapse; background: white; }
table.tbl th, table.tbl td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left;
                              vertical-align: top; }
table.tbl th { background: var(--row); color: var(--muted); font-weight: 600; font-size: 12px; }
table.tbl tr:hover { background: var(--row); }

.schedule-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.schedule-range-label { font-size: 16px; font-weight: 650; color: var(--text); margin: 2px 0 2px; }
.grid-wrap { background: white; border: 1px solid var(--border); border-radius: 6px; overflow: auto;
             box-shadow: var(--shadow); }
.grid { display: grid; position: relative; min-height: 600px; }
.grid .col-header { position: sticky; top: 0; z-index: 3; background: var(--row);
                    padding: 8px 10px; border-bottom: 1px solid var(--border); font-weight: 600;
                    border-right: 1px solid var(--border); text-align: center; }
.grid .time-col-header { background: var(--row); border-right: 1px solid var(--border); }
.grid .time-cell { font-size: 11px; color: var(--muted); padding: 2px 6px;
                   border-bottom: 1px dashed #eef0f4; border-right: 1px solid var(--border); }
/* Half-hour cells stripe slightly to show the 30-min mark */
.grid .time-cell.half { color: #aab1bb; }
/* Current-time indicator: shade elapsed time + a red "now" line on today */
.grid .past-shade { position: absolute; background: rgba(99, 110, 130, 0.10); z-index: 1; pointer-events: none; }
.grid .now-line { position: absolute; height: 0; border-top: 2px solid #e8413a; z-index: 6; pointer-events: none; }
.grid .now-dot { position: absolute; left: -4px; top: -4px; width: 9px; height: 9px; border-radius: 50%; background: #e8413a; }
.grid .now-time { position: absolute; left: 4px; top: -17px; font-size: 10px; font-weight: 700; color: #e8413a;
                  background: rgba(255, 255, 255, 0.9); padding: 0 4px; border-radius: 6px; line-height: 15px; white-space: nowrap; }
/* Keep appointment cards above the shade overlay */
.grid .card, .grid .offblock, .grid .travel { z-index: 2; }
.grid .slot { border-bottom: 1px dashed #f0f2f5; border-right: 1px solid var(--border);
              position: relative; cursor: pointer; }
.grid .slot.hour-mark { border-bottom: 1px dashed #d8dde5; }
.grid .slot:hover { background: #f3f8ff; }

.grid .card { position: absolute; left: 4px; right: 4px; z-index: 2;
              background: #e7f0fb; border: 1px solid #b6d0ef; border-left: 4px solid var(--accent);
              border-radius: 4px; padding: 4px 6px; font-size: 12px; overflow: hidden; cursor: pointer; }
.grid .card.storm { background: #ffefe7; border-color: #f0c0a3; border-left-color: #c97a3a; }
.grid .card.cash  { background: #e8f5ec; border-color: #b6dac0; border-left-color: var(--ok); }
.grid .card .ttl { font-weight: 600; }
.grid .card .sub { color: var(--muted); font-size: 11px; }

.grid .travel {
  position: absolute; left: 0; right: 0; z-index: 1;
  background: repeating-linear-gradient(45deg,
              rgba(120,130,150,0.05) 0 6px,
              rgba(120,130,150,0.12) 6px 12px);
  border-top:    1px dashed rgba(120,130,150,0.25);
  border-bottom: 1px dashed rgba(120,130,150,0.25);
  font-size: 10px; color: rgba(95, 107, 122, 0.85);
  padding: 1px 4px; white-space: nowrap; overflow: hidden;
  display: flex; align-items: center; justify-content: flex-end;
  pointer-events: auto;
}
.grid .travel:hover { z-index: 4; background: rgba(245, 247, 250, 0.98); color: var(--text);
                      font-weight: 600; box-shadow: 0 1px 4px rgba(0,0,0,0.08); }

.grid .offblock {
  position: absolute; left: 0; right: 0; z-index: 1;
  background: repeating-linear-gradient(135deg, rgba(192, 137, 43, 0.10) 0 8px, rgba(192, 137, 43, 0.18) 8px 16px);
  border-top: 1px solid rgba(192, 137, 43, 0.35);
  border-bottom: 1px solid rgba(192, 137, 43, 0.35);
  pointer-events: none;
  color: rgba(192, 137, 43, 0.95); font-size: 11px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}

.modal-backdrop { position: fixed; inset: 0; background: rgba(20,28,40,0.45); display: none;
                  align-items: flex-start; justify-content: center; z-index: 50; padding: 60px 16px; }
.modal-backdrop.show { display: flex; }
.modal { background: white; border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,0.25);
         padding: 16px 18px; width: 100%; max-width: 720px; max-height: 80vh; overflow: auto; }
.modal h2 { margin: 0 0 10px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 6px 10px; border: 1px solid var(--border); border-radius: 999px; background: white;
        cursor: pointer; font-size: 12px; display: inline-flex; align-items: center; gap: 6px; }
.chip .repdot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.chip.selected { background: var(--accent); color: white; border-color: var(--accent-2); }
.chip:hover { background: #eef4fb; }
.chip.selected:hover { background: var(--accent-2); }
.chip.selected .repdot { box-shadow: 0 0 0 1px white; }

#map, #territoryMap { width: 100%; height: 600px; border: 1px solid var(--border); border-radius: 6px; background: #eef2f7; }

/* -------- Map view: calendar/agenda + map split -------- */
.map-split { display: grid; grid-template-columns: 340px 1fr; gap: 12px; align-items: start; }
.map-agenda { height: 600px; overflow-y: auto; background: var(--panel); border: 1px solid var(--border);
              border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px; }
.map-agenda .agenda-empty { color: var(--muted); padding: 16px; text-align: center; font-size: 13px; }
.map-agenda .day-h { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase;
                     letter-spacing: 0.05em; padding: 9px 8px 5px; position: sticky; top: 0; background: var(--panel);
                     border-bottom: 1px solid var(--border); }
.appt-item { display: flex; gap: 9px; align-items: flex-start; padding: 8px; border-radius: 8px; cursor: pointer; }
.appt-item:hover { background: #eef4fb; }
.appt-item.active { background: #e3edfb; box-shadow: inset 2px 0 0 var(--accent); }
.appt-item .dot { width: 9px; height: 9px; border-radius: 50%; margin-top: 4px; flex-shrink: 0; box-shadow: 0 0 0 1px rgba(0,0,0,0.1); }
.appt-item .t { font-weight: 600; font-size: 12px; min-width: 58px; flex-shrink: 0; color: var(--text); }
.appt-item .body .nm { font-size: 13px; font-weight: 600; }
.appt-item .body .meta { color: var(--muted); font-size: 12px; }
@media (max-width: 920px) {
  .map-split { grid-template-columns: 1fr; }
  .map-agenda { height: auto; max-height: 280px; }
}

.split { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(280px, 1fr); gap: 12px; }
.split > .left, .split > .right { background: white; border: 1px solid var(--border); border-radius: 6px;
                                   padding: 10px; }
.conf-detail .kv { display: grid; grid-template-columns: 130px 1fr; gap: 4px 12px; margin-bottom: 8px; }
.conf-detail .kv > div:nth-child(odd) { color: var(--muted); font-size: 12px; }
.conf-detail .ext-link { color: var(--accent); text-decoration: none; font-weight: 600; }
.conf-detail .ext-link:hover { text-decoration: underline; }
.conf-detail h3 { margin: 0 0 4px; font-size: 18px; }
.conf-detail .section-title { font-size: 12px; color: var(--muted); text-transform: uppercase;
                              letter-spacing: 0.5px; margin: 8px 0 4px; }

.contact-pick-row { padding: 6px 8px; border-bottom: 1px solid var(--border); cursor: pointer; display: flex; gap: 8px; }
.contact-pick-row:last-child { border-bottom: none; }
.contact-pick-row:hover { background: #f3f8ff; }
.contact-pick-row .nm { font-weight: 600; }
.contact-pick-row .sub { color: var(--muted); font-size: 12px; }
.contact-pick-row .pick { margin-left: auto; }

.toast-stack { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px;
               z-index: 100; }
.toast { padding: 10px 14px; border-radius: 6px; box-shadow: var(--shadow); background: white;
         border-left: 4px solid var(--accent); min-width: 220px; }
.toast.error { border-left-color: var(--danger); }
.toast.ok    { border-left-color: var(--ok); }
.toast .ttl { font-weight: 600; margin-bottom: 2px; }

.loading-bar { height: 3px; background: var(--accent); width: 0%; transition: width 0.2s; position: fixed;
               top: 0; left: 0; z-index: 200; }
.kbd { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px;
       background: #eef2f7; padding: 1px 4px; border-radius: 3px; }
.hint { color: var(--muted); font-size: 12px; }
/* Text automations editor */
.auto-card { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; background: #fff; }
.auto-head { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 13px; margin-bottom: 6px; cursor: pointer; }
.auto-body { width: 100%; box-sizing: border-box; min-height: 60px; resize: vertical; font: inherit; font-size: 13px;
  padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px; }
/* "Why this rep" routing chip in the schedule modal */
.why-rep { margin: 8px 0 2px; font-size: 12.5px; line-height: 1.4; padding: 7px 10px;
           border-radius: 8px; background: #eef4ff; border: 1px solid #cfe0ff; color: #22314d; }
.why-rep:empty { display: none; }
.why-rep b { color: #1a3f7a; }
.why-rep .why-override { color: var(--warn, #b26a00); font-weight: 600; }
.divider { height: 1px; background: var(--border); margin: 10px 0; }

/* -------- Workspace dashboards -------- */
.dash { display: flex; flex-direction: column; gap: 18px; max-width: 1100px; }
.dash-head h1 { font-size: 22px; margin: 0; font-weight: 700; letter-spacing: -0.2px; }
.dash-head p { color: var(--muted); margin: 4px 0 0; font-size: 13.5px; }
.dash-section-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.06em;
                      color: var(--muted); font-weight: 600; margin-bottom: -6px; }
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; }
.kpi { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
       padding: 16px 18px; box-shadow: var(--shadow); }
.kpi .v { font-size: 28px; font-weight: 700; letter-spacing: -0.5px; line-height: 1.1; }
.kpi .l { color: var(--muted); font-size: 13px; margin-top: 4px; }
.kpi.accent { border-top: 3px solid var(--accent); }
.tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.tile { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
        padding: 16px; box-shadow: var(--shadow); cursor: pointer; text-align: left; display: block;
        text-decoration: none; color: inherit; width: 100%; font: inherit;
        transition: box-shadow 0.12s, transform 0.12s, border-color 0.12s; }
.tile:hover { box-shadow: var(--shadow-md); border-color: #cfd6e2; transform: translateY(-1px); }
.tile .ic { font-size: 22px; }
.tile .t { font-weight: 650; margin-top: 10px; font-size: 14.5px; }
.tile .d { color: var(--muted); font-size: 12.5px; margin-top: 3px; }

/* -------- Distribution sheet (Bella Construction style) -------- */
.dist-sheet { background: white; border: 1px solid var(--border); border-radius: 6px; overflow: auto;
              box-shadow: var(--shadow); }
.dist-sheet table { width: 100%; border-collapse: collapse; font-size: 12px; }
.dist-sheet th, .dist-sheet td { border: 1px solid #cfd6e1; padding: 3px 6px; vertical-align: middle; }
.dist-sheet .month-banner td { background: var(--dist-blue); color: white; font-weight: 700;
                                text-align: center; font-size: 14px; padding: 6px; }
.dist-sheet .ch-banner td { background: var(--dist-blue); color: white; font-weight: 700; text-align: center; }
.dist-sheet .rep-cell { background: #f3f5f8; font-weight: 600; min-width: 140px; }
.dist-sheet .x-cell  { width: 18px; text-align: center; color: var(--text); }
.dist-sheet .x-cell.cash { background: #e8f5ec; }
.dist-sheet .x-cell.storm { background: #ffefe7; }
.dist-sheet .total { background: #eef2f7; font-weight: 700; text-align: center; }
.dist-sheet .ytd   { background: #d6e4fa; font-weight: 700; text-align: center; }
.dist-sheet .title-cell td { background: white; text-align: center; font-weight: 700; font-size: 16px;
                              color: var(--dist-blue); padding: 6px; }
.dist-sheet .subtitle-cell td { background: white; text-align: center; font-style: italic;
                                  color: var(--muted); padding: 2px; }

/* Territory map per-rep zone list */
.zone-row { display: flex; gap: 8px; align-items: center; padding: 4px 6px; border-bottom: 1px solid #eef0f4; }
.zone-row .swatch { width: 12px; height: 12px; border-radius: 50%; flex: 0 0 auto; }
.zone-row .nm  { font-weight: 600; }
.zone-row .meta { color: var(--muted); font-size: 12px; }
.zone-row .del { margin-left: auto; }
