/* Mileage & Demo Commission — every rule is scoped under .md-shell (or the
   preview dialog, which lives on <body>), so nothing here touches another module.
   Colours are the Hub's own tokens from styles.css plus the approved mock-up's. */

.module-view-body:has(> .md-shell) { grid-template-columns: minmax(0, 1fr); }

.md-shell, .md-scrim {
  --md-card-2: #f6f9fc;
  --md-ink: #1e5799;
  --md-ok: #0f9f6e;  --md-ok-soft: rgba(16,185,129,.12);
  --md-warn: #b45309; --md-warn-soft: rgba(245,158,11,.14);
  --md-bad: #c0352b; --md-bad-soft: rgba(239,68,68,.10);
  --md-shadow: 0 1px 2px rgba(15,42,78,.06), 0 10px 28px rgba(15,42,78,.08);
  --md-glass: rgba(255,255,255,.78);
  --md-mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}
.md-shell { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.md-shell [hidden] { display: none !important; }      /* .log-wrap and .md-runbox set display */
.md-loading { padding: 32px; text-align: center; color: var(--text-3); }
.md-hint { font-size: 12px; color: var(--text-3); }
.md-warn { color: var(--md-warn); font-weight: 600; }
.md-num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* tabs */
.md-topline { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.md-tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.md-tab { padding: 8px 16px; border-radius: 9px; font-size: 12.5px; font-weight: 600; cursor: pointer;
          border: 1px solid var(--border); background: var(--card); color: var(--text-2); transition: all .15s; }
.md-tab:hover { border-color: var(--accent); color: var(--md-ink); }
.md-tab.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.md-lock { font-size: 10.5px; font-weight: 700; opacity: .8; margin-left: 6px; letter-spacing: .02em; }
.md-test { font-size: 11.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
           padding: 6px 12px; border-radius: 999px; background: var(--md-warn-soft); color: var(--md-warn); }

/* panels */
.md-panel { background: var(--card); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--md-shadow); min-width: 0; }
.md-panel-h { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; justify-content: space-between;
              padding: 14px 18px; border-bottom: 1px solid var(--border); }
.md-panel-h h2 { margin: 0; font-size: 14.5px; }
.md-panel-b { padding: 16px 18px; }
.md-grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.md-kv { display: grid; gap: 12px; }
.md-empty { display: grid; justify-items: center; gap: 6px; padding: 36px 18px; text-align: center; }
.md-empty-ic { font-size: 30px; }

/* batch bar */
.md-batchbar { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; padding: 16px 18px; align-items: end; }
.md-field label { display: block; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
                  color: var(--text-2); margin-bottom: 6px; }
.md-field .hub-input { width: 100%; }
.md-pair { display: flex; gap: 8px; align-items: center; }
.md-pair .hub-input { min-width: 0; }
.md-time { max-width: 120px; }
.md-pullnote { align-self: center; }
.md-savedline { display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: center; padding: 0 18px 14px; }
.md-saved { display: inline-flex; gap: 7px; align-items: center; font-size: 12px; color: var(--md-ok); font-weight: 600; }
.md-saved::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--md-ok); box-shadow: 0 0 0 4px var(--md-ok-soft); }

/* run box — the Hub's own run button and log, kept outside the re-drawn panel */
.md-runbox { display: grid; gap: 10px; }
.md-runrow { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.md-runrow .btn-run-module { width: auto; flex: 0 1 280px; margin: 0; }
.md-runrow .btn-stop { margin: 0; }
.md-log .log-body { max-height: 220px; }

/* buttons */
.md-btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 9px; border: 1px solid var(--border);
          background: var(--card); color: var(--text); font-size: 12.5px; font-weight: 600; cursor: pointer; transition: all .15s; white-space: nowrap; }
.md-btn:hover:not([disabled]) { border-color: var(--accent); color: var(--md-ink); }
.md-btn.solid { background: var(--accent); border-color: var(--accent); color: #fff; }
.md-btn.solid:hover:not([disabled]) { filter: brightness(1.07); color: #fff; box-shadow: 0 6px 16px rgba(59,158,218,.3); }
.md-btn.sm { padding: 5px 10px; font-size: 12px; }
.md-ico { width: 16px; height: 16px; flex: none; color: var(--accent); transition: color .15s; }
.md-btn:hover:not([disabled]) .md-ico { color: var(--md-ink); }
.md-btn[disabled] .md-ico { color: inherit; }
.md-btn[disabled] { opacity: .45; cursor: not-allowed; }
.md-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* tiles */
.md-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.md-tile { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; box-shadow: var(--md-shadow); }
.md-tile .k { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-2); }
.md-tile .v { font-size: 22px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.md-tile .s { font-size: 12px; color: var(--text-3); }
.md-tile.ok .v { color: var(--md-ok); } .md-tile.bad .v { color: var(--md-bad); } .md-tile.idle .v { color: var(--text-3); }

/* table */
.md-scroll { overflow-x: auto; }
.md-table { width: 100%; border-collapse: collapse; }
.md-table th { font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--text-2);
               text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--md-card-2); white-space: nowrap; }
.md-table th.md-num { text-align: right; }
.md-table td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.md-table tfoot td { font-weight: 700; background: var(--md-card-2); border-bottom: 0; }
tr.md-rep { cursor: pointer; transition: background .12s; }
tr.md-rep:hover, tr.md-rep.open { background: var(--accent-soft); }
tr.md-rep.idle td { color: var(--text-3); }
tr.md-current td { background: var(--accent-soft); }
.md-rname { font-weight: 700; }
.md-lpname { font-size: 11.5px; color: var(--text-3); font-family: var(--md-mono); }
.md-caret { color: var(--text-3); transition: transform .15s; display: inline-block; }
tr.md-rep.open .md-caret { transform: rotate(90deg); }
.md-tick { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }
.md-tick[disabled] { cursor: not-allowed; opacity: .4; }
.md-sentmark { color: var(--md-ok); font-weight: 800; }

.md-pill { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.md-pill.ok { background: var(--md-ok-soft); color: var(--md-ok); }
.md-pill.bad { background: var(--md-bad-soft); color: var(--md-bad); }
.md-pill.warn { background: var(--md-warn-soft); color: var(--md-warn); }
.md-pill.idle { background: var(--md-card-2); color: var(--text-3); border: 1px solid var(--border); }
.md-pill.info { background: var(--accent-soft); color: var(--md-ink); }

/* one rep's detail */
tr.md-detail > td { background: var(--md-card-2); padding: 0; }
/* Never stretched edge to edge; on a phone the table scrolls sideways, so the panel
   stays pinned to the visible part instead of running off with it. */
tr.md-detail .in { padding: 16px 18px 18px; display: grid; gap: 14px; max-width: min(980px, calc(100vw - 40px));
                   position: sticky; left: 0; box-sizing: border-box; }
.md-split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(220px, 290px); gap: 14px 18px; align-items: start; }
.md-split.solo { grid-template-columns: minmax(0, 1fr); }
.md-left { display: grid; gap: 12px; min-width: 0; }
.md-side { display: grid; gap: 12px; align-content: start; min-width: 0; font-size: 12.5px;
           background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.md-split.solo .md-side { max-width: 560px; }
.md-checksum summary { list-style: none; cursor: pointer; display: flex; gap: 7px; align-items: center; font-weight: 600; color: var(--md-ok); }
.md-checksum summary::-webkit-details-marker { display: none; }
.md-checksum summary::after { content: 'Details'; margin-left: auto; font-weight: 500; font-size: 11.5px; color: var(--text-3); }
.md-checksum[open] summary::after { content: 'Hide'; }
.md-checksum summary .m { font-weight: 800; }
.md-checksum .md-checks { margin-top: 8px; }
.md-side .md-checks { grid-template-columns: minmax(0, 1fr); }
.md-docs { display: grid; gap: 6px; }
.md-docrow { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.md-doc { display: inline-flex; gap: 8px; align-items: center; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px;
          background: var(--card); font-size: 12.5px; font-weight: 600; color: var(--text-1, inherit); cursor: pointer; transition: border-color .15s; }
.md-doc:hover { border-color: var(--accent); }
.md-doc .ic { font-size: 10px; font-weight: 800; color: #fff; background: var(--md-bad); border-radius: 4px; padding: 2px 5px; }
.md-to { color: var(--text-2); overflow-wrap: anywhere; }
.md-to .md-ico { width: 14px; height: 14px; vertical-align: -2px; margin-right: 6px; }
.md-to.ok { color: var(--md-ok); }
.md-to b { color: var(--text-1, inherit); }
@media (max-width: 860px) { .md-split { grid-template-columns: minmax(0, 1fr); } }
.md-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.md-lines { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.md-lines td { padding: 9px 12px; border-bottom: 1px solid var(--border); }
.md-lines tr.md-total td { border-bottom: 0; font-weight: 700; font-size: 15px; background: rgba(16,185,129,.07); }
.md-src { font-size: 12px; color: var(--text-2); }
.md-files { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.md-file { display: inline-flex; gap: 8px; align-items: center; padding: 7px 11px; border: 1px solid var(--border); border-radius: 9px;
           background: var(--card); font-size: 12px; cursor: pointer; min-width: 0; transition: border-color .15s; text-align: left; }
.md-file:hover { border-color: var(--accent); }
.md-file .ic { font-size: 10px; font-weight: 800; color: #fff; background: var(--md-bad); border-radius: 4px; padding: 2px 5px; }
.md-file span { overflow-wrap: anywhere; }
.md-checks { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 6px 16px; font-size: 12.5px; }
.md-chk { display: flex; gap: 7px; align-items: baseline; }
.md-chk .m { font-weight: 800; }
.md-chk.ok .m { color: var(--md-ok); } .md-chk.bad { color: var(--md-bad); font-weight: 600; }

/* adjustments */
.md-adjbox { display: grid; gap: 10px; background: var(--card); border: 1px dashed var(--accent); border-radius: 10px; padding: 12px; }
.md-adj { display: grid; grid-template-columns: auto minmax(0, 1fr) 110px auto; gap: 8px; align-items: center; }
.md-adj-amt { text-align: right; }
.md-seg { display: inline-flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; }
.md-seg button { border: 0; background: var(--card); padding: 7px 10px; font-size: 12px; font-weight: 700; color: var(--text-2); cursor: pointer; white-space: nowrap; }
.md-seg button.on { background: var(--md-ok-soft); color: var(--md-ok); }
.md-seg button.on.bad { background: var(--md-bad-soft); color: var(--md-bad); }
@media (max-width: 640px) { .md-adj { grid-template-columns: minmax(0, 1fr) auto; }
  .md-adj .md-seg, .md-adj-desc { grid-column: 1 / -1; } .md-adj .md-seg { justify-self: start; } }

/* alerts */
.md-alert { border-radius: 10px; padding: 11px 14px; font-size: 13px; display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center; }
.md-alert ul { margin: 6px 0; padding-left: 18px; }
.md-alert.bad { background: var(--md-bad-soft); color: var(--md-bad); }
.md-alert.warn { background: var(--md-warn-soft); color: var(--md-warn); }
.md-alert.ok { background: var(--md-ok-soft); color: var(--md-ok); }
.md-alert.info { background: var(--accent-soft); color: var(--md-ink); }

/* send bar — glass, sticks to the bottom while the table scrolls */
.md-dock { position: sticky; bottom: 12px; z-index: 5; }
.md-dock:empty { display: none; }
@media (max-width: 640px) { .md-dock { position: static; } }
.md-dockcard { background: var(--md-glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
               border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--md-shadow);
               padding: 12px 16px; display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; justify-content: space-between; }
.md-sum { font-size: 13px; color: var(--text-2); }
.md-sum b { color: var(--text); font-variant-numeric: tabular-nums; }
.md-confirm { display: grid; gap: 8px; font-size: 13px; width: 100%; }
.md-confirm ul { margin: 0; padding-left: 18px; color: var(--text-2); display: grid; gap: 3px; }
.md-confirm ul b { color: var(--text); }

/* settings */
.md-path { font-family: var(--md-mono); font-size: 12px; background: var(--md-card-2); border: 1px solid var(--border);
           border-radius: 8px; padding: 8px 10px; overflow-wrap: anywhere; margin-bottom: 6px; }
.md-textarea { width: 100%; resize: vertical; font: inherit; }
.md-code { font-family: var(--md-mono); font-size: 12px; line-height: 1.6; }
.md-ph { font-family: var(--md-mono); font-size: 12px; color: var(--md-ink); background: var(--accent-soft); padding: 1px 5px; border-radius: 4px; display: inline-block; margin: 2px 0; }
.md-linksel { min-width: 180px; }
.md-check { display: inline-flex; gap: 6px; align-items: center; font-size: 12.5px; white-space: nowrap; cursor: pointer; }
.md-presets { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin-bottom: 8px; }
.md-preset { text-align: left; border: 1px solid var(--border); border-radius: 12px; background: var(--card); padding: 12px 14px;
             cursor: pointer; display: grid; gap: 4px; transition: all .15s; }
.md-preset:hover { border-color: var(--accent); }
.md-preset[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.md-preset span { font-size: 12px; color: var(--text-2); }

/* batches */
.md-year { font-variant-numeric: tabular-nums; min-width: 44px; text-align: center; }
.md-spcard { display: grid; gap: 8px; align-content: start; }
.md-months { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.md-months li { display: flex; justify-content: space-between; gap: 10px; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; }
.md-months a { color: var(--md-ink); font-weight: 600; text-decoration: none; }
.md-months a:hover { text-decoration: underline; }

/* email preview */
.md-scrim { position: fixed; inset: 0; background: rgba(8,17,30,.55); backdrop-filter: blur(3px); z-index: 1000;
            display: grid; place-items: center; padding: 16px; }
.md-modal { background: var(--card); border-radius: 16px; box-shadow: var(--md-shadow); width: min(720px, 100%);
            max-height: calc(100% - 32px); display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--border); }
.md-modal-h { display: flex; gap: 8px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.md-pvname { min-width: 0; flex: 1; display: grid; }
.md-pvname b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.md-modal-b { overflow-y: auto; padding: 16px; display: grid; gap: 12px; transition: opacity .15s; }
.md-meta { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; font-size: 12.5px; margin: 0; }
.md-meta dt { color: var(--text-3); font-weight: 600; }
.md-meta dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.md-email { width: 100%; min-height: 420px; border: 1px solid var(--border); border-radius: 10px; background: #fff; }

@media (prefers-reduced-motion: reduce) { .md-shell *, .md-scrim * { transition: none !important; } }
