/* =====================================================================
   Dealer portal — page BODY design system (tokens + components)

   Opt-in per page: <body class="mt-body"> + this stylesheet, linked AFTER
   dealer-dark-mode.css. Scoped to <main> and the page's modals/toasts only —
   the shared header, nav and footer are untouched.

   Restrained, neutral, enterprise look: Inter, neutral grays, 1px borders,
   6 / 8 / 10 / 12px radii, no shadows on static surfaces. Values match the
   Team Portal's token set (css/team-theme.css); the accent is the dealer
   portal's own brand blue (#006897, as in the dealer header).

   In use on: dealer-billing.html, dealer-invoice-detail.html
   ===================================================================== */

/* ── Tokens ─────────────────────────────────────────────────────────── */
body.mt-body {
    --mt-font: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --mt-font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

    --mt-bg: #ffffff;              /* surfaces: cards, panels, modals, inputs */
    --mt-bg-subtle: #f7f7f8;       /* page body, table headers, quiet fills */
    --mt-bg-hover: #f1f1f1;
    --mt-bg-selected: #ececec;

    --mt-text: #0d0d0d;
    --mt-text-2: #676767;          /* secondary */
    --mt-text-3: #8a8a8a;          /* muted / labels */

    --mt-border: #e5e5e5;
    --mt-border-strong: #d5d5d5;
    --mt-border-input: #dadada;

    --mt-accent: #006897;          /* links, icons, active indicators */
    --mt-accent-solid: #006897;    /* primary button fill */
    --mt-accent-solid-hover: #00587f;
    --mt-accent-soft: #e8f1f6;
    --mt-accent-border: #b9d4e3;
    --mt-on-accent: #ffffff;
    --mt-focus-ring: 0 0 0 3px rgba(0, 104, 151, 0.18);

    --mt-success: #1d7a4c;  --mt-success-bg: #eaf5ef;  --mt-success-border: #c6e3d2;
    --mt-danger: #b42318;   --mt-danger-bg: #fdeeec;   --mt-danger-border: #f3c9c4;
    --mt-danger-solid: #b42318; --mt-danger-solid-hover: #962018;
    --mt-warning: #8a5300;  --mt-warning-bg: #fdf5e6;  --mt-warning-border: #f0dcb0;
    --mt-info: #2a5aa6;     --mt-info-bg: #eef3fb;     --mt-info-border: #cddbf1;

    --mt-radius-sm: 6px;           /* controls, badges */
    --mt-radius-md: 8px;           /* buttons, inputs */
    --mt-radius-lg: 10px;          /* cards, panels */
    --mt-radius-xl: 12px;          /* dialogs */

    --mt-shadow-float: 0 4px 14px rgba(0, 0, 0, 0.06);
    --mt-shadow-modal: 0 12px 32px rgba(0, 0, 0, 0.12);
    --mt-transition: 150ms ease;
}

body.dark-mode.mt-body {
    --mt-bg: #1a1a1a;
    --mt-bg-subtle: #141414;
    --mt-bg-hover: #242424;
    --mt-bg-selected: #2b2b2b;
    --mt-text: #ededed;
    --mt-text-2: #a9a9a9;
    --mt-text-3: #8c8c8c;
    --mt-border: #2c2c2c;
    --mt-border-strong: #3a3a3a;
    --mt-border-input: #404040;
    --mt-accent: #6cb8e6;
    --mt-accent-solid: #0b77ad;
    --mt-accent-solid-hover: #0a6a9a;
    --mt-accent-soft: rgba(108, 184, 230, 0.12);
    --mt-accent-border: rgba(108, 184, 230, 0.32);
    --mt-on-accent: #ffffff;
    --mt-focus-ring: 0 0 0 3px rgba(108, 184, 230, 0.25);
    --mt-success: #6fcf97;  --mt-success-bg: rgba(111, 207, 151, 0.12); --mt-success-border: rgba(111, 207, 151, 0.3);
    --mt-danger: #f28b82;   --mt-danger-bg: rgba(242, 139, 130, 0.12);  --mt-danger-border: rgba(242, 139, 130, 0.3);
    --mt-danger-solid: #c5372c; --mt-danger-solid-hover: #ad2f25;
    --mt-warning: #f2c46b;  --mt-warning-bg: rgba(242, 196, 107, 0.12); --mt-warning-border: rgba(242, 196, 107, 0.3);
    --mt-info: #8ab4f8;     --mt-info-bg: rgba(138, 180, 248, 0.12);    --mt-info-border: rgba(138, 180, 248, 0.3);
    --mt-shadow-float: 0 4px 14px rgba(0, 0, 0, 0.35);
    --mt-shadow-modal: 0 12px 32px rgba(0, 0, 0, 0.5);
}

/* ── Scope: page body + dialogs ─────────────────────────────────────────
   Legacy page variables are re-pointed at the tokens here, so each page's
   existing rules re-skin without renaming anything the JS depends on. */
body.mt-body main,
body.mt-body .modal-overlay,
body.mt-body .mt-toast {
    --primary-blue: var(--mt-accent-solid);
    --primary-dark: var(--mt-accent-solid-hover);
    --white: var(--mt-bg);
    --light-gray: var(--mt-border);
    --navy: var(--mt-text);
    --gray: var(--mt-text);
    --font-heading: var(--mt-font);
    --font-body: var(--mt-font);
    --radius-sm: var(--mt-radius-sm);
    --radius-md: var(--mt-radius-lg);
    font-family: var(--mt-font);
    color: var(--mt-text);
    -webkit-font-smoothing: antialiased;
}
body.mt-body main { background: var(--mt-bg-subtle); }
body.mt-body main :is(h1, h2, h3, h4, p) { font-family: var(--mt-font); }
body.mt-body main a:not(.mt-btn) { color: var(--mt-accent); }
body.mt-body main a:not(.mt-btn):hover { color: var(--mt-accent-solid-hover); }
body.dark-mode.mt-body main a:not(.mt-btn):hover { color: #8fcbef; }

/* ── Page header ────────────────────────────────────────────────────── */
.mt-page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin: 0 0 24px; }
.mt-page-title { font-size: 24px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.25; color: var(--mt-text); margin: 0; }
.mt-page-desc { font-size: 14px; color: var(--mt-text-2); margin: 4px 0 0; line-height: 1.5; }

/* ── Cards ──────────────────────────────────────────────────────────── */
.mt-card { background: var(--mt-bg); border: 1px solid var(--mt-border); border-radius: var(--mt-radius-lg); overflow: hidden; }
.mt-card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--mt-border); background: var(--mt-bg); min-height: 56px; }
.mt-card-title { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 600; letter-spacing: -0.005em; color: var(--mt-text); margin: 0; }
.mt-card-title svg { width: 16px; height: 16px; color: var(--mt-text-3); flex-shrink: 0; }
.mt-card-sub { font-size: 13px; font-weight: 400; color: var(--mt-text-2); margin: 2px 0 0; }
.mt-card-count { font-size: 13px; font-weight: 400; color: var(--mt-text-3); }
.mt-card-body { padding: 16px 20px; }

/* ── Buttons ────────────────────────────────────────────────────────── */
.mt-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    height: 36px; padding: 0 14px; border-radius: var(--mt-radius-md);
    border: 1px solid transparent; background: transparent; color: var(--mt-text);
    font: 500 14px/1 var(--mt-font); white-space: nowrap; cursor: pointer; text-decoration: none;
    transition: background-color var(--mt-transition), border-color var(--mt-transition), color var(--mt-transition), opacity var(--mt-transition);
}
.mt-btn svg { width: 15px; height: 15px; flex-shrink: 0; }
.mt-btn:focus-visible { outline: none; box-shadow: var(--mt-focus-ring); }
.mt-btn:disabled, .mt-btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
.mt-btn--primary { background: var(--mt-accent-solid); border-color: var(--mt-accent-solid); color: var(--mt-on-accent); }
.mt-btn--primary:hover:not(:disabled) { background: var(--mt-accent-solid-hover); border-color: var(--mt-accent-solid-hover); color: var(--mt-on-accent); }
.mt-btn--secondary { background: var(--mt-bg); border-color: var(--mt-border-strong); color: var(--mt-text); }
.mt-btn--secondary:hover:not(:disabled) { background: var(--mt-bg-hover); color: var(--mt-text); }
.mt-btn--ghost { color: var(--mt-text-2); }
.mt-btn--ghost:hover:not(:disabled) { background: var(--mt-bg-hover); color: var(--mt-text); }
.mt-btn--danger { background: var(--mt-danger-solid); border-color: var(--mt-danger-solid); color: #ffffff; }
.mt-btn--danger:hover:not(:disabled) { background: var(--mt-danger-solid-hover); border-color: var(--mt-danger-solid-hover); color: #ffffff; }
.mt-btn--sm { height: 30px; padding: 0 10px; font-size: 13px; }
.mt-btn--lg { height: 42px; padding: 0 18px; font-size: 15px; }
.mt-btn--block { width: 100%; }
.mt-btn--icon { width: 32px; height: 32px; padding: 0; color: var(--mt-text-2); }
.mt-btn--icon:hover:not(:disabled) { background: var(--mt-bg-hover); color: var(--mt-text); }
.mt-btn--icon.mt-btn--danger-hover:hover:not(:disabled) { color: var(--mt-danger); background: var(--mt-danger-bg); }
.mt-btn--icon svg { width: 16px; height: 16px; }

/* ── Form controls ──────────────────────────────────────────────────── */
.mt-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; min-width: 0; }
.mt-field:last-child { margin-bottom: 0; }
.mt-field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; margin-bottom: 14px; }
.mt-field-row > .mt-field { margin-bottom: 0; }
.mt-label { font-size: 13px; font-weight: 500; color: var(--mt-text); }
.mt-help { font-size: 12px; color: var(--mt-text-3); line-height: 1.45; }
.mt-input, .mt-select, .mt-textarea {
    width: 100%; height: 40px; padding: 0 12px; box-sizing: border-box;
    background: var(--mt-bg); color: var(--mt-text);
    border: 1px solid var(--mt-border-input); border-radius: var(--mt-radius-md);
    font: 400 14px var(--mt-font);
    transition: border-color var(--mt-transition), box-shadow var(--mt-transition);
}
.mt-textarea { height: auto; min-height: 88px; padding: 10px 12px; line-height: 1.5; resize: vertical; }
.mt-input::placeholder, .mt-textarea::placeholder { color: var(--mt-text-3); }
.mt-input:hover, .mt-select:hover, .mt-textarea:hover { border-color: var(--mt-border-strong); }
.mt-input:focus, .mt-select:focus, .mt-textarea:focus { outline: none; border-color: var(--mt-accent); box-shadow: var(--mt-focus-ring); }
.mt-select { appearance: none; -webkit-appearance: none; padding-right: 34px; cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a8a8a' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 12px center; }
.mt-error { padding: 9px 12px; border-radius: var(--mt-radius-md); background: var(--mt-danger-bg); border: 1px solid var(--mt-danger-border); color: var(--mt-danger); font-size: 13px; line-height: 1.45; }

/* segmented control (e.g. card / bank tabs) */
.mt-segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--mt-bg-subtle); border: 1px solid var(--mt-border); border-radius: var(--mt-radius-md); margin-bottom: 16px; }
.mt-segmented button { height: 30px; padding: 0 12px; border: none; border-radius: var(--mt-radius-sm); background: transparent; color: var(--mt-text-2); font: 500 13px var(--mt-font); cursor: pointer; }
.mt-segmented button[aria-pressed="true"] { background: var(--mt-bg); color: var(--mt-text); box-shadow: 0 0 0 1px var(--mt-border); }

/* choice rows (radio cards) — the checked row carries the selected state */
.mt-choice { display: flex; align-items: center; gap: 12px; padding: 12px; margin-bottom: 8px; background: var(--mt-bg); border: 1px solid var(--mt-border); border-radius: var(--mt-radius-md); cursor: pointer; transition: background-color var(--mt-transition), border-color var(--mt-transition); }
.mt-choice:hover { background: var(--mt-bg-hover); }
.mt-choice:has(input:checked) { background: var(--mt-bg-selected); border-color: var(--mt-border-strong); }
.mt-choice input { flex-shrink: 0; margin: 0; accent-color: var(--mt-accent-solid); }

/* ── Badges ─────────────────────────────────────────────────────────── */
.mt-badge {
    display: inline-flex; align-items: center; gap: 6px; padding: 3px 8px; border-radius: var(--mt-radius-sm);
    font: 500 12px/1.4 var(--mt-font); white-space: nowrap;
    background: var(--mt-bg-hover); color: var(--mt-text-2); border: 1px solid transparent;
}
.mt-badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.mt-badge--success { background: var(--mt-success-bg); color: var(--mt-success); }
.mt-badge--danger  { background: var(--mt-danger-bg);  color: var(--mt-danger); }
.mt-badge--warning { background: var(--mt-warning-bg); color: var(--mt-warning); }
.mt-badge--info    { background: var(--mt-info-bg);    color: var(--mt-info); }
.mt-badge--accent  { background: var(--mt-accent-soft); color: var(--mt-accent); }

/* ── Key / value grid ───────────────────────────────────────────────── */
.mt-kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px 24px; margin: 0; }
.mt-kv dt, .mt-kv-label { font-size: 12px; font-weight: 500; color: var(--mt-text-2); margin: 0; }
.mt-kv dd, .mt-kv-value { font-size: 14px; font-weight: 500; color: var(--mt-text); margin: 2px 0 0; overflow-wrap: anywhere; }

/* ── Lists (address / payment-method rows) ──────────────────────────── */
.mt-list { list-style: none; margin: 0; padding: 0; }
.mt-list-item { display: flex; align-items: center; gap: 14px; padding: 14px 20px; border-top: 1px solid var(--mt-border); }
.mt-list-item:first-child { border-top: none; }
.mt-list-body { flex: 1; min-width: 0; }
.mt-list-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 14px; font-weight: 500; color: var(--mt-text); }
.mt-list-meta { font-size: 13px; color: var(--mt-text-2); line-height: 1.5; margin-top: 2px; }
.mt-list-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }

/* ── Tables ─────────────────────────────────────────────────────────── */
.mt-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.mt-table thead th {
    text-align: left; font-size: 12px; font-weight: 500; color: var(--mt-text-2);
    background: var(--mt-bg-subtle); padding: 9px 12px; border-bottom: 1px solid var(--mt-border); white-space: nowrap;
}
.mt-table tbody td { padding: 11px 12px; border-bottom: 1px solid var(--mt-border); color: var(--mt-text); vertical-align: middle; }
.mt-table tbody tr:last-child > td { border-bottom: none; }
.mt-table tbody tr:hover > td { background: var(--mt-bg-subtle); }
.mt-table .mt-num, .mt-num { text-align: right; font-variant-numeric: tabular-nums; }

/* ── Empty / loading / error ────────────────────────────────────────── */
.mt-empty { display: flex; align-items: center; gap: 12px; padding: 20px; color: var(--mt-text-2); font-size: 13px; }
.mt-empty svg { width: 18px; height: 18px; color: var(--mt-text-3); flex-shrink: 0; }
.mt-empty strong { display: block; color: var(--mt-text); font-weight: 500; font-size: 14px; }
.mt-loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 28px 20px; color: var(--mt-text-3); font-size: 13px; }
.mt-spinner { width: 16px; height: 16px; border: 2px solid var(--mt-border-strong); border-top-color: var(--mt-text-2); border-radius: 50%; animation: mt-spin 0.7s linear infinite; flex-shrink: 0; }
@keyframes mt-spin { to { transform: rotate(360deg); } }

/* ── Notes / callouts ───────────────────────────────────────────────── */
.mt-note { padding: 10px 12px; border-radius: var(--mt-radius-md); background: var(--mt-bg-subtle); border: 1px solid var(--mt-border); color: var(--mt-text-2); font-size: 13px; line-height: 1.5; }
.mt-note--info { background: var(--mt-info-bg); border-color: var(--mt-info-border); color: var(--mt-info); }
.mt-note--success { background: var(--mt-success-bg); border-color: var(--mt-success-border); color: var(--mt-success); }
.mt-note--danger { background: var(--mt-danger-bg); border-color: var(--mt-danger-border); color: var(--mt-danger); }

/* ── Modals ─────────────────────────────────────────────────────────── */
body.mt-body .modal-overlay { background: rgba(13, 13, 13, 0.45); }
body.dark-mode.mt-body .modal-overlay { background: rgba(0, 0, 0, 0.6); }
.mt-modal {
    background: var(--mt-bg); color: var(--mt-text); border: 1px solid var(--mt-border);
    border-radius: var(--mt-radius-xl); box-shadow: var(--mt-shadow-modal);
    width: 100%; max-width: 520px; max-height: 90vh; display: flex; flex-direction: column; overflow: hidden;
}
.mt-modal-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--mt-border); flex-shrink: 0; }
.mt-modal-title { font-size: 16px; font-weight: 600; color: var(--mt-text); margin: 0; }
.mt-modal-desc { font-size: 13px; color: var(--mt-text-2); margin: 0 0 14px; line-height: 1.5; }
.mt-modal-close {
    width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center;
    border: none; border-radius: var(--mt-radius-md); background: transparent; color: var(--mt-text-2);
    font-size: 20px; line-height: 1; cursor: pointer; transition: background-color var(--mt-transition), color var(--mt-transition);
}
.mt-modal-close:hover { background: var(--mt-bg-hover); color: var(--mt-text); }
.mt-modal-close:focus-visible { outline: none; box-shadow: var(--mt-focus-ring); }
.mt-modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.mt-modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--mt-border); flex-shrink: 0; }

/* ── Toast ──────────────────────────────────────────────────────────── */
.mt-toast { font: 500 13px var(--mt-font); border-radius: var(--mt-radius-md); box-shadow: var(--mt-shadow-float); }

/* ── Dark mode vs dealer-dark-mode.css ────────────────────────────────
   That file restyles every input/select/textarea with element+attribute
   selectors (body.dark-mode input[type="text"] …). These win for the controls
   here, so they follow the tokens like everything else. */
body.dark-mode.mt-body :is(.mt-input, .mt-select, .mt-textarea, .modal-input, .modal-select) {
    background-color: var(--mt-bg); border-color: var(--mt-border-input); color: var(--mt-text); box-shadow: none;
}
body.dark-mode.mt-body :is(.mt-input, .mt-select, .mt-textarea, .modal-input, .modal-select):focus {
    background-color: var(--mt-bg); border-color: var(--mt-accent); box-shadow: var(--mt-focus-ring); outline: none;
}
/* its `background:` shorthand also wipes the dropdown arrow — put it back */
body.dark-mode.mt-body :is(.mt-select, .modal-select) {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238c8c8c' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 12px center;
}

/* ── Utilities ──────────────────────────────────────────────────────── */
.mt-muted { color: var(--mt-text-2); }
.mt-mono { font-family: var(--mt-font-mono); }
.mt-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
