:root {
  --bg:        #f4f6f9;
  --panel:     #ffffff;
  --border:    #d8dde5;
  --text:      #1f2933;
  --muted:     #5f6b7a;
  --accent:    #2266cc;
  --accent-2:  #1d4f9c;
  --warn:      #c0892b;
  --danger:    #c0392b;
  --ok:        #27733a;
  --shadow:    0 1px 2px rgba(0,0,0,0.06);
  --row:       #fafbfc;
  --dist-blue: #1e4084;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text);
             font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; }

.topbar { background: #1f2933; color: white; padding: 8px 16px; display: flex; align-items: center;
          gap: 16px; box-shadow: var(--shadow); }
.brand { font-weight: 700; font-size: 16px; letter-spacing: 0.3px; }
.brand .sub { opacity: 0.7; font-weight: 400; margin-left: 8px; font-size: 12px; }
.spacer { flex: 1; }
.user-pill { background: #2d3a48; padding: 4px 10px; border-radius: 999px; font-size: 12px; }
.hubspot-status { font-size: 12px; padding: 2px 8px; border-radius: 999px; }
.hubspot-status.ok { background: #234e2d; color: #b8e8c0; }
.hubspot-status.bad { background: #4e2323; color: #f0bcb6; }

.nav { background: var(--panel); border-bottom: 1px solid var(--border); display: flex; padding: 0 8px;
       overflow-x: auto; }
.nav button { background: none; border: none; padding: 12px 14px; font-weight: 500; color: var(--muted);
              border-bottom: 2px solid transparent; white-space: nowrap; }
.nav button.active { color: var(--accent); border-bottom-color: var(--accent); }
.nav button:hover { color: var(--text); }

main { padding: 16px; }
.section { display: none; }
.section.active { display: block; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 6px;
         box-shadow: var(--shadow); padding: 14px; margin-bottom: 14px; }
.panel h2 { margin: 0 0 10px; font-size: 16px; }
.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: 6px 8px; border: 1px solid var(--border); border-radius: 4px; background: white;
}
.field textarea { min-height: 64px; resize: vertical; }
.btn { padding: 7px 12px; border: 1px solid var(--border); background: white; color: var(--text);
       border-radius: 4px; }
.btn:hover { background: #f3f5f8; }
.btn.primary { background: var(--accent); color: white; border-color: var(--accent-2); }
.btn.primary:hover { background: 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; }
.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; }
.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; }

.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; }
.divider { height: 1px; background: var(--border); margin: 10px 0; }

/* -------- 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; }
