/* app-shell.css — shared tokens, a11y defaults and the sidebar shell.
   Loaded by every page in user/, common/, admin/. Pairs with /static/js/app-shell.js.
   Plain CSS on purpose: several admin pages do not load tailwind. */

:root {
    --ps-primary: #667eea;
    --ps-primary-600: #5568d3;
    --ps-primary-700: #4751b8;
    --ps-primary-50: #f0f4ff;
    --ps-surface: #f9fafb;
    --ps-card: #ffffff;
    --ps-border: #e5e7eb;
    --ps-text: #111827;
    --ps-text-2: #374151;
    --ps-muted: #6b7280;
    /* One colour per meaning, everywhere. */
    --ps-lvl1: #10b981;
    --ps-lvl2: #f59e0b;
    --ps-lvl3: #ef4444;
    --ps-human: #3b82f6;
    --ps-vehicle: #f97316;
    --ps-sidebar-w: 16rem;
    --ps-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* ---- Accessibility defaults ------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
        scroll-behavior: auto !important;
    }
}
/* Many pages strip outlines (outline:none); keyboard focus must stay visible. */
:is(a, button, select, input, textarea, summary, [tabindex]):focus-visible {
    outline: 2px solid var(--ps-primary) !important;
    outline-offset: 2px !important;
}
[onclick]:not(a, button, input, select, textarea) { cursor: pointer; }
.ps-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;
}
.ps-skip {
    position: fixed; left: 8px; top: -48px; z-index: 1000; padding: 8px 14px;
    background: var(--ps-text); color: #fff; border-radius: 6px; font: 600 14px var(--ps-font);
    text-decoration: none;
}
.ps-skip:focus { top: 8px; }

/* ---- Shared page pieces ---------------------------------------------- */
.ps-page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.ps-page-head h1 { margin: 0; font: 700 1.5rem/1.25 var(--ps-font); color: var(--ps-text); }
.ps-page-head p { margin: 4px 0 0; font-size: .875rem; color: var(--ps-muted); }
.ps-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 640px) { .ps-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 1280px) { .ps-stats { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); } }
.ps-skeleton { display: inline-block; min-width: 3ch; height: 1em; border-radius: 4px; background: #e5e7eb; color: transparent !important; animation: ps-pulse 1.4s ease-in-out infinite; }
@keyframes ps-pulse { 50% { opacity: .5; } }

/* ---- Toasts (replace alert()) ----------------------------------------- */
.ps-toasts { position: fixed; right: 16px; bottom: 16px; z-index: 10000; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.ps-toast { padding: 12px 16px; border-radius: 8px; font: 500 14px/1.4 var(--ps-font); color: #fff; background: #1f2937; box-shadow: 0 10px 25px rgba(0,0,0,.15); overflow-wrap: anywhere; white-space: pre-line; }
.ps-toast.error { background: #b91c1c; }
.ps-toast.success { background: #047857; }

/* ---- Sidebar shell ------------------------------------------------------ */
.ps-sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; width: var(--ps-sidebar-w); z-index: 40;
    display: flex; flex-direction: column; background: #fff; border-right: 1px solid var(--ps-border);
    font-family: var(--ps-font); box-sizing: border-box;
}
.ps-sidebar *, .ps-sidebar *::before { box-sizing: border-box; }
.ps-brand { padding: 20px 16px; border-bottom: 1px solid var(--ps-border); display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
.ps-brand img { height: 40px; width: auto; }
.ps-brand-name { margin: 0; font-size: 1rem; font-weight: 700; color: var(--ps-text); overflow-wrap: anywhere; }
.ps-nav { flex: 1; overflow-y: auto; padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; }
.ps-section { padding: 14px 16px 4px; font-size: .75rem; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--ps-muted); }
.ps-link {
    display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 10px 16px; border-radius: 8px;
    border-left: 4px solid transparent; color: var(--ps-text-2); font-size: 15px; font-weight: 500;
    text-decoration: none; transition: background-color .15s, color .15s;
}
.ps-link:hover { background: var(--ps-surface); color: var(--ps-primary-600); }
.ps-link[aria-current="page"] { background: var(--ps-primary-50); color: var(--ps-primary-600); border-left-color: var(--ps-primary); }
.ps-link svg { width: 20px; height: 20px; flex: none; }
.ps-report-link { margin: 0 12px 8px; width: calc(100% - 24px); background: none; border-top: 0; border-right: 0; border-bottom: 0; font: inherit; cursor: pointer; text-align: left; }
.ps-badge { margin-left: auto !important; min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--ps-primary, #4f46e5); color: #fff; font-size: .75rem; font-weight: 700; line-height: 20px; text-align: center; }
.ps-badge.ps-badge-high { background: #dc2626; }
.ps-foot { padding: 12px 16px; border-top: 1px solid var(--ps-border); font-size: .75rem; color: var(--ps-muted); text-align: center; }
.ps-menu-btn, .ps-backdrop { display: none; }

/* Docked sidebar on desktop. html.ps-drawer (set by app-shell.js on phones, or
   on any width for pages with data-shell="drawer") hides it behind the menu button. */
html.ps-shell:not(.ps-drawer) body { margin-left: var(--ps-sidebar-w); }

/* visibility flips instantly on open (so focus() can land) and only after the slide on close. */
html.ps-drawer .ps-sidebar { transform: translateX(-100%); visibility: hidden; transition: transform .2s ease-out, visibility 0s linear .2s; }
html.ps-drawer.ps-shell-open .ps-sidebar { transform: none; visibility: visible; transition: transform .2s ease-out, visibility 0s; box-shadow: 0 10px 30px rgba(0,0,0,.2); }
html.ps-drawer.ps-shell-open .ps-backdrop { display: block; position: fixed; inset: 0; z-index: 39; background: rgba(17,24,39,.45); }
html.ps-drawer .ps-menu-btn {
    display: flex; align-items: center; justify-content: center; position: fixed; top: 10px; left: 10px; z-index: 41;
    width: 44px; height: 44px; padding: 0; background: #fff; color: var(--ps-text-2);
    border: 1px solid var(--ps-border); border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,.12); cursor: pointer;
}
html.ps-drawer .ps-menu-btn svg { width: 24px; height: 24px; }
/* Room for the fixed menu button. */
html.ps-shell.ps-drawer body { margin-top: 64px; }

/* ---- Tables → cards on phones ------------------------------------------
   Add class="ps-cards" to a <table>; app-shell.js copies each <th> text into
   the cells' data-label, so the card rows stay labelled. */
@media (max-width: 640px) {
    table.ps-cards { min-width: 0 !important; width: 100%; border-collapse: separate; }
    table.ps-cards thead { display: none; }
    table.ps-cards, table.ps-cards tbody, table.ps-cards tr, table.ps-cards td { display: block; }
    table.ps-cards tr { margin: 0 0 12px; padding: 8px 12px; border: 1px solid var(--ps-border) !important; border-radius: 10px; background: #fff; }
    table.ps-cards td { display: flex; gap: 12px; align-items: flex-start; padding: 6px 0 !important; border: 0 !important; min-width: 0; max-width: none !important; white-space: normal !important; text-align: left !important; overflow-wrap: anywhere; }
    table.ps-cards td[data-label]::before {
        content: attr(data-label); flex: 0 0 7.5rem; font-size: 12px; font-weight: 600;
        text-transform: uppercase; letter-spacing: .03em; color: var(--ps-muted); padding-top: 2px;
    }
    table.ps-cards td[colspan] { display: block; }
    table.ps-cards td[colspan]::before { content: none; }
}

/* ---- Tailwind v2.2 build gaps ------------------------------------------
   tailwind.min.css was purged before these colours were used in markup, so
   they rendered unstyled (e.g. the dashboard's Vehicle card had no colour).
   Same values as Tailwind's palette. Regenerate tailwind.min.css to drop this. */
.bg-amber-50{background-color:#fffbeb}.bg-orange-50{background-color:#fff7ed}.bg-orange-100{background-color:#ffedd5}
.bg-orange-500{background-color:#f97316}.bg-emerald-500{background-color:#10b981}.bg-rose-100{background-color:#ffe4e6}
.hover\:bg-orange-600:hover{background-color:#ea580c}.hover\:bg-emerald-50:hover{background-color:#ecfdf5}
.text-amber-500{color:#f59e0b}.text-amber-700{color:#b45309}.text-orange-500{color:#f97316}.text-orange-600{color:#ea580c}
.text-orange-700{color:#c2410c}.text-emerald-400{color:#34d399}.text-emerald-600{color:#059669}.text-rose-500{color:#f43f5e}.text-rose-600{color:#e11d48}
.border-amber-300{border-color:#fcd34d}.border-orange-400{border-color:#fb923c}.border-orange-500{border-color:#f97316}
.ring-amber-100{--tw-ring-color:#fef3c7}.ring-orange-100{--tw-ring-color:#ffedd5}
.hover\:ring-amber-300:hover{--tw-ring-color:#fcd34d}.hover\:ring-blue-200:hover{--tw-ring-color:#bfdbfe}
.hover\:ring-emerald-200:hover{--tw-ring-color:#a7f3d0}.hover\:ring-gray-300:hover{--tw-ring-color:#d1d5db}
.hover\:ring-green-300:hover{--tw-ring-color:#6ee7b7}.hover\:ring-indigo-200:hover{--tw-ring-color:#c7d2fe}
.hover\:ring-red-300:hover{--tw-ring-color:#fca5a5}.to-emerald-500{--tw-gradient-to:#10b981}
/* md:max-h-none was purged too, so lists using `max-h-72 sm:max-h-96 md:max-h-none`
   (dealers, dashboard sites, site-analytics) stayed capped at 384px on desktop instead
   of filling the column. !important because this file loads before tailwind.min.css,
   whose sm:max-h-96 would otherwise win. */
.max-h-none{max-height:none!important}
@media (min-width:768px){.md\:max-h-none{max-height:none!important}}

/* ---- Legacy card pages ----
   Opt in with <body class="ps-page">: their purple banner header becomes the plain
   page header the redesigned pages use. !important only where the markup has
   inline white-on-purple styles. */
body.ps-page .container { max-width: 1536px; box-shadow: none; border: 1px solid var(--ps-border); border-radius: 12px; }
body.ps-page .container > .header {
    background: #fff; color: var(--ps-text); text-align: left;
    padding: 20px 24px; border-bottom: 1px solid var(--ps-border);
}
body.ps-page .container > .header h1,
body.ps-page .container > .header .header-title { font-size: 1.5rem; font-weight: 700; line-height: 1.25; margin-bottom: 4px; color: var(--ps-text); }
body.ps-page .container > .header p,
body.ps-page .container > .header .header-sub { font-size: .875rem; color: var(--ps-muted); opacity: 1; }
body.ps-page .container > .header a {
    color: var(--ps-primary-600) !important; background: transparent !important;
    font-size: .875rem !important; font-weight: 600; padding: 0 !important; margin: 10px 16px 0 0 !important;
}
body.ps-page .container > .header a:hover { text-decoration: underline !important; }
body.ps-page .site-info-bar { background: var(--ps-primary-50); border-color: #c7d2fe; color: var(--ps-text-2); }
body.ps-page .site-chip { background: #e0e7ff; color: var(--ps-primary-700); }
body.ps-page .stat-card { box-shadow: none; border: 1px solid var(--ps-border); border-radius: 10px; }
body.ps-page .stat-card h3 { color: var(--ps-text); font-variant-numeric: tabular-nums; }
body.ps-page .stat-card p { color: var(--ps-muted); }
/* Inside the admin dashboard frame the dashboard already draws the card. */
html.ps-embedded body.ps-page { padding: 0; }
html.ps-embedded body.ps-page .container { border: 0; border-radius: 0; max-width: none; }
