/* ============================================================================
   Dispatch Board — bespoke design system (Scheduler v2 / Visit Scheduler).
   Everything is namespaced under .dsp so none of the Metronic admin theme bleeds
   in and nothing here leaks out. A calm, dense "ops console" aesthetic.
   ============================================================================ */

.dsp {
    /* ---- tokens ---- */
    --bg: #0d1117;
    --bg-2: #131a24;
    --panel: #161d29;
    --panel-2: #1c2533;
    --panel-3: #222d3d;
    --line: #263043;
    --line-2: #313e54;
    --text: #e6edf6;
    --text-2: #9fb0c4;
    --text-3: #6b7c93;
    --accent: #5b8def;
    --accent-2: #6ee7d3;
    --good: #38d39f;
    --warn: #ffb454;
    --bad: #ff6b6b;
    --sla: #ff5470;
    --missed: #ff8f5a;
    --skipped: #b692f6;
    --atrisk: #ffd166;
    --radius: 12px;
    --radius-sm: 9px;
    --shadow: 0 10px 30px rgba(0,0,0,.35);
    --font: 'Inter', -apple-system, 'Segoe UI', Roboto, sans-serif;

    /* In-slot: absolute + inset:0 anchors to the shell's position:relative <main> (above the .scrl overflow
       div, so it isn't clipped), filling the content area. No body-park, no zoom, no viewport units. */
    position: absolute;
    inset: 0;
    /* !important beats Durandal/jQuery's inline display:block on the composed view root (which would
       otherwise break the flex column and collapse the body to ~2in). */
    display: flex !important;
    flex-direction: column;
    background: radial-gradient(1200px 600px at 70% -10%, #18263b 0%, var(--bg) 55%);
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    z-index: 1;
    overflow: hidden;
}
.dsp * { box-sizing: border-box; }
.dsp button { font-family: inherit; cursor: pointer; }

/* ---- light theme (temporary comparison toggle) ---- */
.dsp.light {
    --bg: #eef1f6; --bg-2: #ffffff; --panel: #ffffff; --panel-2: #f7f9fc; --panel-3: #eef2f8;
    --line: #e3e8f0; --line-2: #cfd8e6; --text: #16202e; --text-2: #475467; --text-3: #7a8aa0;
    --accent: #3a6fe0; --accent-2: #0d9488; --good: #16a34a; --warn: #d97706; --bad: #dc2626;
    --sla: #e11d48; --missed: #ea580c; --skipped: #7c3aed; --atrisk: #ca8a04;
    --shadow: 0 10px 28px rgba(30,41,59,.12);
    background: radial-gradient(1200px 600px at 70% -10%, #eef3fc 0%, var(--bg-2) 60%);
    color: var(--text);
}
.dsp.light .dsp-topbar { background: linear-gradient(180deg, #ffffff, #f3f6fc); }
.dsp.light .dsp-btn-primary, .dsp.light .dsp-logo { color: #fff; }
.dsp.light .dsp-chip-missed, .dsp.light .dsp-chip-atrisk { color: #2a1a05; }
.dsp.light .dsp-visit.commercial { background: linear-gradient(180deg, var(--panel-2), #eef4ff); }

/* ---- top bar ---- */
.dsp-topbar {
    display: flex; align-items: center; gap: 18px;
    padding: 12px 20px;
    background: linear-gradient(180deg, rgba(28,37,51,.9), rgba(19,26,36,.9));
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(8px);
}
.dsp-brand { display: flex; align-items: center; gap: 12px; }
.dsp-logo {
    width: 38px; height: 38px; border-radius: 11px; border: 0;
    display: grid; place-items: center; font-size: 22px; line-height: 1;
    background: linear-gradient(135deg, var(--accent), #7b6ef0);
    color: #fff; box-shadow: 0 6px 18px rgba(91,141,239,.4);
    cursor: pointer; transition: filter .15s ease;
}
.dsp-logo:hover { filter: brightness(1.12); }
.dsp-title { font-weight: 800; font-size: 16px; letter-spacing: .3px; }
.dsp-sub { color: var(--text-3); font-size: 11px; margin-top: 1px; }

.dsp-horizon { display: flex; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.dsp-htab {
    border: 0; background: transparent; color: var(--text-2);
    padding: 6px 14px; border-radius: 7px; font-weight: 600; font-size: 12px;
    transition: all .15s ease;
}
.dsp-htab:hover { color: var(--text); }
.dsp-htab.active { background: var(--accent); color: #fff; box-shadow: 0 4px 12px rgba(91,141,239,.4); }

.dsp-spacer { flex: 1; }

.dsp-readiness { display: flex; align-items: center; gap: 10px; min-width: 220px; border: 0; background: transparent; cursor: pointer; padding: 4px 6px; border-radius: 9px; transition: background .15s ease; }
.dsp-readiness:hover { background: var(--panel-2); }
.dsp-readiness:hover .dsp-ready-meta { color: var(--accent); }
.dsp-ready-meter { width: 120px; height: 8px; border-radius: 6px; background: var(--panel-3); overflow: hidden; }
.dsp-ready-fill { height: 100%; border-radius: 6px; transition: width .4s ease; background: var(--good); }
.dsp-ready-fill.mid { background: var(--warn); }
.dsp-ready-fill.low { background: var(--bad); }
.dsp-ready-label { font-size: 11px; color: var(--text-2); white-space: nowrap; }
.dsp-ready-pct { font-weight: 800; color: var(--text); font-size: 13px; }
.dsp-ready-meta { color: var(--text-3); margin-left: 4px; }

.dsp-actions { display: flex; align-items: center; gap: 8px; }
.dsp-btn {
    border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text);
    padding: 8px 14px; border-radius: 9px; font-weight: 600; font-size: 12px;
    transition: all .15s ease; white-space: nowrap;
}
.dsp-btn:hover { border-color: var(--accent); background: var(--panel-3); }
.dsp-btn-ghost { background: transparent; }
.dsp-btn-primary { background: linear-gradient(135deg, var(--accent), #7b6ef0); border-color: transparent; box-shadow: 0 6px 16px rgba(91,141,239,.35); }
.dsp-btn-primary:hover { filter: brightness(1.08); }
.dsp-btn-sm { padding: 6px 11px; font-size: 11px; }
.dsp-btn.is-busy { opacity: .5; pointer-events: none; }
.dsp-btn.active { border-color: var(--accent); color: var(--accent); background: rgba(91,141,239,.12); }

/* ---- view controls (filter / sort / pan) ---- */
.dsp-viewctl { display: flex; align-items: center; gap: 8px; }
.dsp-nav { padding: 8px 12px; font-size: 16px; line-height: 1; }
.dsp-menuwrap { position: relative; }
.dsp-menu {
    position: absolute; top: calc(100% + 8px); left: 0; z-index: 40;
    background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 11px;
    box-shadow: var(--shadow); padding: 10px; min-width: 248px; display: flex; flex-direction: column; gap: 4px;
}
.dsp-menu-head { font-size: 10px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-3); font-weight: 800; padding: 4px 6px 2px; }
.dsp-menu-check { display: flex; align-items: center; gap: 8px; padding: 7px 6px; font-size: 12.5px; color: var(--text); border-radius: 7px; cursor: pointer; }
.dsp-menu-check:hover { background: var(--panel-3); }
.dsp-menu-check input { accent-color: var(--accent); width: 15px; height: 15px; }
.dsp-menu-sep { height: 1px; background: var(--line); margin: 4px 2px; }
.dsp-menu-input {
    background: var(--panel); border: 1px solid var(--line-2); border-radius: 8px; color: var(--text);
    padding: 8px 10px; font-size: 12.5px; font-family: inherit; outline: none;
}
.dsp-menu-input:focus { border-color: var(--accent); }
.dsp-menu-input::placeholder { color: var(--text-3); }
.dsp-menu-clear { margin-top: 4px; background: transparent; border: 0; color: var(--accent); font-weight: 700; font-size: 12px; padding: 6px; text-align: left; }
.dsp-menu-opt {
    display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
    background: transparent; border: 0; color: var(--text); text-align: left;
    padding: 8px 8px; border-radius: 8px; font-size: 12.5px; font-weight: 600;
}
.dsp-menu-opt:hover { background: var(--panel-3); }
.dsp-menu-opt.active { color: var(--accent); background: rgba(91,141,239,.1); }
.dsp-menu-hint { font-size: 10.5px; color: var(--text-3); font-weight: 400; }

/* ---- body / 3-pane ---- */
/* Flex row (not grid): flex children stretch to the row height reliably, so every pane gets a bounded
   height and its own overflow scrolls. The visible board/week pane flexes; rail + inspector are fixed. */
.dsp-body { flex: 1; display: flex; min-height: 0; overflow: hidden; }

/* ---- exceptions rail ---- */
.dsp-rail { flex: 0 0 290px; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.dsp-rail-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 8px; }
.dsp-rail-title { font-weight: 700; font-size: 13px; letter-spacing: .2px; }
.dsp-rail-count { background: var(--sla); color: #fff; font-weight: 800; font-size: 11px; padding: 2px 9px; border-radius: 20px; }
.dsp-rail-filters { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 10px; }
.dsp-chip { border: 0; border-radius: 7px; padding: 4px 9px; font-size: 10.5px; font-weight: 700; color: #0d1117; }
.dsp-chip.dim { opacity: .3; }
.dsp-chip { cursor: pointer; transition: box-shadow .12s ease, transform .1s ease; }
.dsp-chip:hover { transform: translateY(-1px); }
.dsp-chip.sel { box-shadow: 0 0 0 2px var(--text) inset; }
.dsp-chip-sla { background: var(--sla); color: #fff; }
.dsp-chip-missed { background: var(--missed); }
.dsp-chip-skipped { background: var(--skipped); }
.dsp-chip-atrisk { background: var(--atrisk); }
.dsp-rail-active { font-size: 11px; color: var(--text-2); padding: 0 16px 8px; }
.dsp-rail-active b { text-transform: capitalize; color: var(--text); }
.dsp-rail-active a { color: var(--accent); text-decoration: none; margin-left: 4px; }

/* flex:1 + min-height:0 is the canonical scrollable-flex-child recipe — without min-height:0 a flex
   item keeps its content height (min-height:auto) and overflow-y never engages. */
.dsp-rail-list { flex: 1 1 0; min-height: 0; overflow-y: auto; padding: 4px 12px 16px; }
.dsp-exc {
    display: flex; gap: 0; align-items: stretch;
    background: var(--panel-2); border: 1px solid var(--line);
    border-radius: var(--radius-sm); margin-bottom: 8px; overflow: hidden;
    cursor: grab; transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease;
}
.dsp-exc:hover { border-color: var(--line-2); transform: translateY(-1px); box-shadow: var(--shadow); }
.dsp-exc:active { cursor: grabbing; }
.dsp-exc.dragging { opacity: .4; }
.dsp-exc-flag { width: 4px; flex-shrink: 0; background: var(--atrisk); }
.dsp-exc.kind-sla .dsp-exc-flag { background: var(--sla); }
.dsp-exc.kind-missed .dsp-exc-flag { background: var(--missed); }
.dsp-exc.kind-skipped .dsp-exc-flag { background: var(--skipped); }
.dsp-exc.kind-atrisk .dsp-exc-flag { background: var(--atrisk); }
.dsp-exc-main { flex: 1; padding: 9px 10px; min-width: 0; }
.dsp-exc-row1 { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.dsp-exc-cust { font-weight: 700; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dsp-exc-kind { font-size: 9px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-3); font-weight: 800; flex-shrink: 0; }
.dsp-exc-row2 { display: flex; align-items: center; gap: 5px; color: var(--text-2); font-size: 11px; margin-top: 2px; }
.dsp-exc-reason { font-size: 10.5px; color: var(--text-3); margin-top: 4px; }
.dsp-exc-bump {
    border: 0; background: transparent; color: var(--accent); font-weight: 700; font-size: 10.5px;
    writing-mode: vertical-rl; transform: rotate(180deg); padding: 6px 3px; border-left: 1px solid var(--line);
    transition: background .12s ease;
}
.dsp-exc-bump:hover { background: var(--accent); color: #fff; }
.dsp-rail-empty { text-align: center; color: var(--text-3); padding: 40px 20px; font-size: 12px; }
.dsp-empty-mark { font-size: 32px; color: var(--good); margin-bottom: 8px; }

/* ---- board / crew columns ---- */
.dsp-board { flex: 1 1 0; overflow-x: auto; overflow-y: hidden; padding: 16px; min-height: 0; min-width: 0; }
.dsp-cols { display: flex; gap: 14px; height: 100%; align-items: stretch; }
.dsp-col {
    flex: 0 0 248px; display: flex; flex-direction: column; min-height: 0;
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
    transition: border-color .12s ease, background .12s ease;
}
.dsp-col.drop-hover { border-color: var(--accent); background: var(--panel-2); box-shadow: 0 0 0 2px rgba(91,141,239,.25) inset; }
.dsp-col-head {
    padding: 11px 12px; border-bottom: 1px solid var(--line); cursor: pointer;
    border-top: 3px solid var(--crew, var(--accent)); border-radius: var(--radius) var(--radius) 0 0;
}
.dsp-col-id { display: flex; align-items: center; gap: 8px; }
.dsp-col-swatch { width: 9px; height: 9px; border-radius: 3px; background: var(--crew, var(--accent)); flex-shrink: 0; }
.dsp-col-name { font-weight: 700; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dsp-col-metrics { display: flex; gap: 6px; margin-top: 7px; }
.dsp-metric { font-size: 10.5px; font-weight: 700; color: var(--text-2); background: var(--panel-3); padding: 2px 7px; border-radius: 6px; }
.dsp-metric-bill { color: var(--good); }
.dsp-metric-bill.low { color: var(--warn); }
.dsp-metric-count { margin-left: auto; background: transparent; color: var(--text-3); }

.dsp-col-body { flex: 1 1 0; min-height: 0; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 7px; }
.dsp-visit {
    display: flex; align-items: center; gap: 9px; padding: 8px 9px;
    background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
    cursor: grab; transition: transform .1s ease, border-color .1s ease, box-shadow .1s ease;
}
.dsp-visit:hover { border-color: var(--line-2); transform: translateY(-1px); box-shadow: var(--shadow); }
.dsp-visit:active { cursor: grabbing; }
.dsp-visit.dragging { opacity: .4; }
.dsp-visit.done { opacity: .55; }
.dsp-visit.active { border-color: var(--accent-2); box-shadow: 0 0 0 1px rgba(110,231,211,.4); }
.dsp-visit.commercial { background: linear-gradient(180deg, var(--panel-2), #1a2436); }
.dsp-visit-eta { font-size: 11px; font-weight: 800; color: var(--accent-2); width: 52px; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.dsp-visit-main { flex: 1; min-width: 0; }
.dsp-visit-cust { font-weight: 700; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dsp-visit-loc { font-size: 10.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dsp-visit-tags { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.dsp-visit-status { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); }
.dsp-visit-status.s-scheduled { background: var(--accent); }
.dsp-visit-status.s-started { background: var(--warn); box-shadow: 0 0 8px var(--warn); }
.dsp-visit-status.s-completed { background: var(--good); }
.dsp-visit-comm { color: var(--accent-2); font-size: 10px; }
.dsp-col-foot { text-align: center; color: var(--text-3); font-size: 11px; padding: 18px 8px; border: 1px dashed var(--line); margin: 8px; border-radius: var(--radius-sm); }

/* ---- week grid ---- */
.dsp-week { flex: 1 1 0; overflow: auto; padding: 16px; min-height: 0; min-width: 0; }
.dsp-week-grid { display: grid; gap: 6px; min-width: 720px; }
.dsp-week-corner, .dsp-week-dh { font-weight: 700; color: var(--text-2); padding: 8px 10px; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; }
.dsp-week-dh { text-align: center; }
.dsp-week-crew { display: flex; align-items: center; font-weight: 700; font-size: 12px; padding: 0 10px; background: var(--panel); border-radius: var(--radius-sm); }
.dsp-week-cell {
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-sm);
    padding: 8px; min-height: 48px; cursor: pointer; display: flex; flex-direction: column; justify-content: space-between;
    transition: border-color .12s ease, transform .1s ease;
}
.dsp-week-cell:hover { border-color: var(--accent); transform: translateY(-1px); }
.dsp-week-cell.cold { opacity: .5; }
.dsp-week-num { font-weight: 800; font-size: 15px; }
.dsp-week-bar { height: 5px; border-radius: 3px; background: var(--panel-3); overflow: hidden; }
.dsp-week-bar > span { display: block; height: 100%; background: var(--good); border-radius: 3px; }
.dsp-week-cell.warm .dsp-week-bar > span { background: var(--warn); }
.dsp-week-cell.hot .dsp-week-bar > span { background: var(--bad); }

/* ---- inspector ---- */
.dsp-inspector { flex: 0 0 320px; background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; min-height: 0; }
.dsp-inspector:not(.open) { display: none; }
.dsp-insp-body { padding: 16px; }
.dsp-insp-head { display: flex; justify-content: space-between; align-items: center; }
.dsp-insp-kind { font-size: 10px; text-transform: uppercase; letter-spacing: .6px; color: var(--accent); font-weight: 800; }
.dsp-insp-close { border: 0; background: transparent; color: var(--text-3); font-size: 14px; }
.dsp-insp-close:hover { color: var(--text); }
.dsp-insp-title { font-weight: 800; font-size: 17px; margin-top: 6px; }
.dsp-insp-sub { color: var(--text-2); font-size: 12px; margin-top: 2px; }
.dsp-insp-rows { margin-top: 14px; }
.dsp-insp-r { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 12px; }
.dsp-insp-r span { color: var(--text-3); }
.dsp-insp-r b { font-weight: 700; text-align: right; }
.dsp-insp-map { margin-top: 14px; height: 120px; border-radius: var(--radius-sm); background: linear-gradient(135deg, #1a2740, #142033); border: 1px solid var(--line); display: grid; place-items: center; position: relative; }
.dsp-map-pin { font-size: 26px; color: var(--accent-2); }
.dsp-map-coords { position: absolute; bottom: 6px; right: 8px; font-size: 9.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.dsp-insp-actions { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.dsp-insp-actions .dsp-btn { width: 100%; text-align: center; }
.dsp-insp-empty { padding: 40px 20px; color: var(--text-3); text-align: center; }

/* ---- toast / loading ---- */
.dsp-toast {
    position: absolute; bottom: 22px; left: 50%; transform: translateX(-50%);
    background: var(--panel-3); color: var(--text); border: 1px solid var(--line-2);
    padding: 11px 18px; border-radius: 10px; font-weight: 600; font-size: 12.5px;
    box-shadow: var(--shadow); z-index: 30; max-width: 70%;
}
.dsp-loading { position: absolute; top: 64px; right: 18px; z-index: 25; }
.dsp-spin { display: inline-block; width: 20px; height: 20px; border: 2.5px solid var(--line-2); border-top-color: var(--accent); border-radius: 50%; animation: dsp-spin .7s linear infinite; }
@keyframes dsp-spin { to { transform: rotate(360deg); } }

.dsp-rail-list::-webkit-scrollbar, .dsp-col-body::-webkit-scrollbar, .dsp-board::-webkit-scrollbar, .dsp-inspector::-webkit-scrollbar { width: 9px; height: 9px; }
.dsp-rail-list::-webkit-scrollbar-thumb, .dsp-col-body::-webkit-scrollbar-thumb, .dsp-board::-webkit-scrollbar-thumb, .dsp-inspector::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 6px; }
