/* ============================================================
   Track page – live truck tracking (public, broker-facing)
   Fonts: DM Sans (body) + Outfit (headings) · Primary #2563eb
   Desktop: floating left panel · Phones (<=768px): bottom sheet
   ============================================================ */

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-soft: #eff6ff;
    --bg-body: #f1f5f9;
    --bg-white: #ffffff;
    --text-dark: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --success: #059669;
    --success-soft: #ecfdf5;
    --warning: #b45309;
    --warning-soft: #fffbeb;
    --danger: #b91c1c;
    --danger-soft: #fef2f2;
    --neutral: #475569;
    --neutral-soft: #f1f5f9;
    --radius-md: 10px;
    --radius-lg: 16px;
    --shadow-card: 0 10px 30px rgba(15, 23, 42, 0.14), 0 1px 3px rgba(15, 23, 42, 0.08);
    --font-main: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-heading: 'Outfit', 'DM Sans', sans-serif;
    --panel-width: 380px;
    --topbar-height: 64px;
    --ease: 0.2s ease;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    font-family: var(--font-main);
    color: var(--text-dark);
    background: var(--bg-body);
    -webkit-font-smoothing: antialiased;
}

body { overflow: hidden; }

h1, p, dl, dd { margin: 0; }

[hidden] { display: none !important; }

.trk-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

:focus-visible {
    outline: 3px solid rgba(37, 99, 235, 0.55);
    outline-offset: 2px;
}

/* --- Top bar ------------------------------------------------ */
.trk-topbar {
    position: fixed;
    inset: 0 0 auto 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    pointer-events: none;
}

.trk-topbar > * { pointer-events: auto; }

.trk-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    padding: 8px 14px 8px 8px;
    /* Solid background on purpose: backdrop-filter over the WebGL map renders as a black box in Chrome */
    background: var(--bg-white);
    border-radius: 999px;
    box-shadow: var(--shadow-card);
}

.trk-brand-logo { height: 28px; margin-left: 6px; }

.trk-avatar {
    flex-shrink: 0;
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #06b6d4);
    color: #fff;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 0.9rem;
}

.trk-brand-text { display: flex; flex-direction: column; min-width: 0; }

.trk-brand-name {
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.trk-brand-sub { font-size: 0.72rem; color: var(--text-muted); white-space: nowrap; }

.trk-topbar-actions { display: flex; gap: 8px; }

.trk-icon-btn {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 50%;
    background: var(--bg-white);
    color: var(--text-dark);
    font-size: 1.15rem;
    box-shadow: var(--shadow-card);
    cursor: pointer;
    transition: background var(--ease), color var(--ease);
}

.trk-icon-btn.is-active { background: var(--primary); color: #fff; }

/* --- Map ---------------------------------------------------- */
.trk-main { position: fixed; inset: 0; }
.trk-map { position: absolute; inset: 0; }

.trk-map-controls {
    position: absolute;
    top: calc(var(--topbar-height) + 16px);
    right: 16px;
    z-index: 10;
}

.trk-banner {
    position: absolute;
    top: calc(var(--topbar-height) + 16px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 15;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-radius: 999px;
    background: var(--text-dark);
    color: #fff;
    font-size: 0.82rem;
    font-weight: 500;
    box-shadow: var(--shadow-card);
}

/* --- Panel (desktop: left card) ----------------------------- */
.trk-panel {
    position: absolute;
    top: calc(var(--topbar-height) + 16px);
    left: 16px;
    z-index: 10;
    display: flex;
    flex-direction: column;
    width: var(--panel-width);
    max-height: calc(100% - var(--topbar-height) - 32px);
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
}

/* The inner area scrolls, not the card: a scrolling element with a shadow over the
   WebGL map makes Chrome paint a black block around it */
.trk-panel-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    border-radius: inherit;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
    overscroll-behavior: contain;
}

.trk-panel-scroll::-webkit-scrollbar { width: 6px; }
.trk-panel-scroll::-webkit-scrollbar-track { background: transparent; }
.trk-panel-scroll::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 999px; }

.trk-sheet-handle { display: none; }

.trk-summary { padding: 18px 20px 14px; }

.trk-summary-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 10px;
}

.trk-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    background: var(--neutral-soft);
    color: var(--neutral);
}

.trk-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
}

.trk-status.is-moving { background: var(--success-soft); color: var(--success); }
.trk-status.is-moving .trk-status-dot { animation: trk-pulse 1.6s ease-out infinite; }
.trk-status.is-stopped { background: var(--primary-soft); color: var(--primary-dark); }
.trk-status.is-stale { background: var(--warning-soft); color: var(--warning); }
.trk-status.is-offline { background: var(--danger-soft); color: var(--danger); }

@keyframes trk-pulse {
    0% { box-shadow: 0 0 0 0 rgba(5, 150, 105, 0.55); }
    100% { box-shadow: 0 0 0 8px rgba(5, 150, 105, 0); }
}

.trk-updated { font-size: 0.8rem; color: var(--text-muted); white-space: nowrap; }

.trk-truck-name {
    font-family: var(--font-heading);
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.25;
}

.trk-address {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    margin-top: 6px;
    font-size: 0.92rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.trk-address i { color: var(--primary); margin-top: 2px; }
.trk-address > span { flex: 1; }

.trk-stale {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    font-size: 0.8rem;
    line-height: 1.4;
}

.trk-stale.is-stale { background: var(--warning-soft); color: var(--warning); }
.trk-stale.is-offline { background: var(--danger-soft); color: var(--danger); }

.trk-more { padding: 0 20px 18px; }

.trk-quick-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* --- Buttons ------------------------------------------------ */
.trk-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 44px;
    padding: 0 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-white);
    color: var(--text-dark);
    font: 600 0.88rem var(--font-main);
    text-decoration: none;
    cursor: pointer;
    transition: background var(--ease), border-color var(--ease), color var(--ease);
}

.trk-btn:disabled { opacity: 0.6; cursor: default; }
.trk-btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.trk-btn-block { width: 100%; }

.trk-link-btn {
    padding: 0;
    border: 0;
    background: none;
    color: var(--primary);
    font: 600 0.78rem var(--font-main);
    cursor: pointer;
    text-decoration: underline;
}

.trk-link-btn:disabled { color: var(--text-muted); cursor: default; }

/* --- Vehicle details ---------------------------------------- */
.trk-details {
    margin-top: 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.trk-details summary {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 52px;
    padding: 8px 14px;
    cursor: pointer;
    list-style: none;
}

.trk-details summary::-webkit-details-marker { display: none; }

.trk-details-icon {
    flex-shrink: 0;
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 1rem;
}

.trk-details-heading { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.trk-details-title { font-weight: 600; font-size: 0.9rem; }

.trk-details-sub {
    font-size: 0.76rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* The vehicle name is shown in the body when open - only repeat it when collapsed */
.trk-details[open] .trk-details-sub { display: none; }

.trk-details-chevron { color: var(--text-muted); transition: transform var(--ease); }
.trk-details[open] .trk-details-chevron { transform: rotate(180deg); }

.trk-details-body {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 0 14px 14px;
}

.trk-vehicle-title {
    font-family: var(--font-heading);
    font-size: 1.02rem;
    font-weight: 600;
}

.trk-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }

.trk-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: 999px;
    background: var(--bg-body);
    border: 1px solid var(--border-color);
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.trk-chip i { color: var(--text-muted); }

.trk-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.trk-stat {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    background: var(--bg-body);
}

.trk-stat-label {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
}

.trk-stat-value {
    font-family: var(--font-heading);
    font-size: 1rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    line-height: 1.25;
}

.trk-stat.is-wide { grid-column: 1 / -1; }

.trk-stat-unit { font-family: var(--font-main); font-size: 0.74rem; font-weight: 500; color: var(--text-muted); }

.trk-rows { display: flex; flex-direction: column; }

.trk-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 40px;
    padding: 6px 0;
    border-top: 1px solid var(--border-color);
}

.trk-row dt {
    display: flex;
    align-items: center;
    gap: 7px;
    flex-shrink: 0;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.trk-row dd {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    font-size: 0.84rem;
    font-weight: 600;
    text-align: right;
}

.trk-mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.8rem;
    letter-spacing: 0.02em;
    overflow-wrap: anywhere;
}

.trk-copy-btn {
    display: grid;
    place-items: center;
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
}

@media (hover: hover) {
    .trk-copy-btn:hover { background: var(--primary-soft); color: var(--primary); }
    .trk-details summary:hover .trk-details-title { color: var(--primary); }
}

/* --- Carrier card ------------------------------------------- */
.trk-card {
    margin-top: 14px;
    padding: 14px;
    border-radius: var(--radius-md);
    background: var(--bg-body);
}

.trk-card-label {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

.trk-card-title { margin-top: 2px; font-family: var(--font-heading); font-weight: 600; }
.trk-card-sub { margin-top: 2px; font-size: 0.82rem; color: var(--text-secondary); }

.trk-contact-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
    gap: 8px;
    margin-top: 12px;
}

/* --- Link info / footer ------------------------------------- */
.trk-link-info {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 6px 12px;
    margin-top: 14px;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.trk-refresh { display: inline-flex; align-items: center; gap: 8px; }

.trk-powered {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 16px;
    font-size: 0.7rem;
    color: var(--text-muted);
}

.trk-powered img { height: 16px; opacity: 0.8; }

/* --- Loading skeleton --------------------------------------- */
.trk-skeleton {
    display: inline-block;
    height: 0.9em;
    border-radius: 6px;
    background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%);
    background-size: 200% 100%;
    animation: trk-shimmer 1.2s linear infinite;
    vertical-align: middle;
}

.trk-panel.is-loading .trk-more { opacity: 0.5; pointer-events: none; }

@keyframes trk-shimmer {
    from { background-position: 200% 0; }
    to { background-position: -200% 0; }
}

/* --- Map pin: truck + small label above it ------------------ */
.trk-pin {
    position: relative;
    width: 0;
    height: 0;
}

.trk-pin-truck {
    position: absolute;
    left: -20px;
    top: -20px;
    width: 40px;
    height: 40px;
    pointer-events: none;
    filter: drop-shadow(0 2px 3px rgba(15, 23, 42, 0.35));
}

.trk-pin-label {
    position: absolute;
    left: 0;
    bottom: 26px;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 7px;
    max-width: 220px;
    padding: 5px 10px 5px 8px;
    border: 0;
    border-radius: 10px;
    background: var(--bg-white);
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.22), 0 0 0 1px rgba(15, 23, 42, 0.05);
    font-family: var(--font-main);
    text-align: left;
    white-space: nowrap;
    cursor: pointer;
}

/* Little pointer down to the truck */
.trk-pin-label::after {
    content: "";
    position: absolute;
    left: 50%;
    bottom: -5px;
    width: 10px;
    height: 10px;
    background: var(--bg-white);
    transform: translateX(-50%) rotate(45deg);
    box-shadow: 2px 2px 3px rgba(15, 23, 42, 0.08);
}

.trk-pin-dot {
    flex-shrink: 0;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
}

.trk-pin-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }

.trk-pin-name {
    font-family: var(--font-heading);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-dark);
    overflow: hidden;
    text-overflow: ellipsis;
}

.trk-pin-meta { font-size: 0.7rem; font-weight: 500; color: var(--text-muted); }

.trk-pin.is-moving .trk-pin-dot { background: var(--success); animation: trk-pulse 1.6s ease-out infinite; }
.trk-pin.is-moving .trk-pin-meta { color: var(--success); }
.trk-pin.is-stale .trk-pin-dot { background: #f59e0b; }
.trk-pin.is-stale .trk-pin-meta { color: var(--warning); }
.trk-pin.is-offline .trk-pin-dot { background: #ef4444; }
.trk-pin.is-offline .trk-pin-meta { color: var(--danger); }
.trk-pin.is-offline .trk-pin-truck { opacity: 0.55; filter: grayscale(0.6); }

/* --- Dialogs (email check, expired) ------------------------- */
.trk-overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    padding: 20px;
    background: radial-gradient(circle at top, #dbeafe, var(--bg-body) 60%);
    overflow-y: auto;
}

/* Expired while open: dim the live map behind the dialog */
.trk-has-overlay .trk-overlay { background: rgba(15, 23, 42, 0.55); }

.trk-dialog {
    width: 100%;
    max-width: 420px;
    padding: 28px 24px 24px;
    border-radius: var(--radius-lg);
    background: var(--bg-white);
    box-shadow: var(--shadow-card);
    text-align: center;
}

.trk-dialog-icon {
    display: inline-grid;
    place-items: center;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 1.5rem;
}

.trk-dialog-icon.is-muted { background: var(--neutral-soft); color: var(--neutral); }

.trk-dialog-title {
    margin-top: 14px;
    font-family: var(--font-heading);
    font-size: 1.3rem;
    font-weight: 700;
}

.trk-dialog-title:focus { outline: none; }

.trk-dialog-text {
    margin-top: 8px;
    font-size: 0.92rem;
    line-height: 1.5;
    color: var(--text-secondary);
}

.trk-dialog .trk-contact-actions { margin-top: 20px; }

.trk-form { margin-top: 20px; text-align: left; }

.trk-label { display: block; margin-bottom: 6px; font-size: 0.82rem; font-weight: 600; }

.trk-input {
    width: 100%;
    min-height: 46px;
    padding: 0 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font: 400 1rem var(--font-main);
    color: var(--text-dark);
}

.trk-input:focus { border-color: var(--primary); outline: 3px solid rgba(37, 99, 235, 0.2); }
.trk-input[aria-invalid="true"] { border-color: var(--danger); }

.trk-field-error { min-height: 1.4em; margin: 6px 0 10px; font-size: 0.8rem; color: var(--danger); }

.trk-dialog-footer {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
    font-size: 0.82rem;
    color: var(--text-muted);
}

.trk-contact-actions.is-compact { margin-top: 10px; }
.trk-contact-actions.is-compact .trk-btn { min-height: 38px; font-size: 0.8rem; }

/* --- Toast -------------------------------------------------- */
.trk-toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    z-index: 60;
    transform: translateX(-50%);
    padding: 10px 16px;
    border-radius: 999px;
    background: var(--text-dark);
    color: #fff;
    font-size: 0.85rem;
    font-weight: 500;
    box-shadow: var(--shadow-card);
}

/* Hover styles only where there is a real pointer (avoids sticky hover after a tap) */
@media (hover: hover) {
    .trk-icon-btn:hover { background: var(--primary-soft); color: var(--primary); }
    .trk-icon-btn.is-active:hover { background: var(--primary-dark); color: #fff; }
    .trk-btn:hover { border-color: var(--primary); color: var(--primary); }
    .trk-btn-primary:hover { background: var(--primary-dark); color: #fff; }
}

/* --- HERE map UI tweaks ------------------------------------- */
.H_ui { font-family: var(--font-main); }

/* --- Phones: bottom sheet ----------------------------------- */
@media (max-width: 768px) {
    :root { --topbar-height: 60px; }

    .trk-topbar { padding: 10px 12px; }
    .trk-brand-sub { display: none; }

    .trk-panel {
        top: auto;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-height: 82%;
        border-radius: 20px 20px 0 0;
        padding-bottom: env(safe-area-inset-bottom);
        transition: max-height 0.25s ease;
    }

    .trk-sheet-handle {
        flex-shrink: 0;
        display: flex;
        justify-content: center;
        width: 100%;
        padding: 10px 0 2px;
        border: 0;
        background: none;
        cursor: pointer;
        touch-action: none;
    }

    .trk-sheet-grip {
        width: 40px;
        height: 5px;
        border-radius: 999px;
        background: #cbd5e1;
    }

    .trk-summary { padding: 6px 18px 14px; }
    .trk-more { display: none; padding: 0 18px 18px; }
    .trk-panel.is-expanded .trk-more { display: block; }

    .trk-toast { bottom: auto; top: calc(var(--topbar-height) + 12px); }
}

@media (max-width: 360px) {
    .trk-stats { grid-template-columns: 1fr; }
}

/* --- Reduced motion ----------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
