/* =========================================================================
   Delegation → SolveAll360 shared 3D layer adapter
   Loaded right after shared/solveall-3d.css. Maps delegation's own class
   names (card-3d, btn-primary-gradient, input-3d, #mainSidebar, ...) onto the
   same look and colours as the Checklist app. Visual only: no layout logic
   the JS depends on is changed here.
   Tailwind's CDN injects its utilities after this file, so rules that must beat
   a utility (bg-white, border-*, shadow-*) are scoped under body.sa3d and/or
   use !important.
   ========================================================================= */

/* ── Canvas ────────────────────────────────────────────────────────────── */
html { background-color: var(--sa-bg, #E9E9EE); }
body.sa3d {
    background: var(--sa-bg, #E9E9EE) !important;
    color: var(--sa-text, #1D1D1F);
}
body.sa3d main { background: transparent !important; }

/* ── Cards: white gradient, inset top highlight, layered soft shadow ───── */
body.sa3d .card-3d:not(.bg-slate-900),
body.sa3d .table-container {
    background: var(--sa-card-bg) !important;
    border: 1px solid var(--sa-border) !important;
    border-radius: var(--sa-radius-card, 16px);
    box-shadow: var(--sa-card-shadow) !important;
}
body.sa3d .card-3d:not(.bg-slate-900):hover {
    box-shadow: var(--sa-card-shadow-hover) !important;
}
/* Inner bordered panels (task table wrapper, empty states) stay flat but crisp */
body.sa3d #tasksDesktopTableContainer {
    background: #fff !important;
    border-color: rgba(0, 0, 0, 0.07) !important;
    box-shadow: inset 0 1px 0 #fff, 0 1px 2px rgba(0, 0, 0, 0.04) !important;
}

/* Modal sheets: same surface, deeper drop (they float above the page) */
body.sa3d div[id$="Modal"].fixed.inset-0 > .card-3d:not(.bg-slate-900):first-child,
body.sa3d div[id$="Modal"].fixed.inset-0 > div:first-child > .card-3d:not(.bg-slate-900) {
    background: linear-gradient(180deg, #FFFFFF 0%, #FAFAFC 100%) !important;
    box-shadow: inset 0 1px 0 #fff, 0 32px 80px -20px rgba(0, 0, 0, 0.35), 0 0 0 0.5px rgba(0, 0, 0, 0.08) !important;
}

/* ── Buttons ───────────────────────────────────────────────────────────── */
body.sa3d .btn-primary-gradient {
    background: var(--sa-btn-primary-bg) !important;
    color: #fff !important;
    border: 1px solid #0066D6 !important;
    box-shadow: var(--sa-btn-primary-shadow) !important;
}
body.sa3d .btn-primary-gradient:hover { filter: brightness(1.05); transform: none; }
body.sa3d .btn-primary-gradient:active {
    transform: translateY(1px) !important;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2) !important;
}
body.sa3d .btn-primary-gradient:disabled { filter: saturate(0.6) brightness(1.05); opacity: 0.75; }

/* Quiet secondary buttons (refresh / neutral chips) get the raised white key */
body.sa3d button.bg-slate-100,
body.sa3d a.bg-white.border,
body.sa3d button.bg-white.border {
    background: var(--sa-btn-bg) !important;
    box-shadow: var(--sa-btn-shadow) !important;
}

/* ── Inputs: recessed ──────────────────────────────────────────────────── */
body.sa3d .input-3d,
body.sa3d input[type="text"]:not([hidden]), body.sa3d input[type="email"], body.sa3d input[type="password"],
body.sa3d input[type="search"], body.sa3d input[type="tel"], body.sa3d input[type="number"],
body.sa3d input[type="date"], body.sa3d select, body.sa3d textarea {
    box-shadow: var(--sa-input-shadow) !important;
}
body.sa3d .input-3d {
    background-color: #fff;
    border: 1px solid rgba(60, 60, 67, 0.18) !important;
    border-radius: 10px;
}
body.sa3d .input-3d:disabled, body.sa3d .input-3d.bg-slate-100 { background-color: #F2F2F5 !important; }
body.sa3d .input-3d:focus,
body.sa3d input:focus-visible, body.sa3d select:focus-visible, body.sa3d textarea:focus-visible {
    border-color: var(--sa-primary) !important;
    box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.16) !important;
    outline: none !important;
}
/* Inputs that live inside a bare search strip (no own border) stay flat */
body.sa3d input.bg-transparent { box-shadow: none !important; }

/* ── Sidebar: solid white with a soft right shadow ─────────────────────── */
body.sa3d #mainSidebar {
    background: #FFFFFF !important;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    border-right: 1px solid rgba(0, 0, 0, 0.06) !important;
    box-shadow: 1px 0 0 rgba(0, 0, 0, 0.02), 6px 0 24px -16px rgba(0, 0, 0, 0.25) !important;
}
body.sa3d #mainSidebar .sidebar-footer { background: #FAFAFC !important; border-top-color: rgba(0, 0, 0, 0.06) !important; }
body.sa3d .sidebar-item { color: var(--sa-text-2); }
body.sa3d .sidebar-item:hover { background: rgba(0, 0, 0, 0.04) !important; }
body.sa3d .sidebar-item.sidebar-item-active,
body.sa3d .sidebar-item-active {
    background: rgba(0, 122, 255, 0.12) !important;
    color: var(--sa-primary) !important;
    border-color: transparent !important;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6), 0 1px 3px rgba(0, 122, 255, 0.18) !important;
}
body.sa3d .sidebar-item-active svg { color: var(--sa-primary) !important; }

/* Brand lockup: [logo tile] SolveAll360 (DELEGATION) → main site */
body.sa3d .dl-brand { text-decoration: none; }
.dl-brand-mark {
    width: 34px !important; height: 34px !important; min-width: 34px; border-radius: 10px !important;
    display: inline-flex; align-items: center; justify-content: center;
    background: linear-gradient(180deg, #1A84FF 0%, #0066D6 100%) !important;
    color: #fff !important; border: 0 !important;
    box-shadow: 0 2px 6px rgba(0, 102, 214, 0.28) !important;
    overflow: hidden;
}
.dl-brand-mark svg { width: 19px !important; height: 19px !important; }
.dl-brand-mark img { width: 34px !important; height: 34px !important; max-width: 34px !important; object-fit: contain; }
.dl-brand .sa3d-brand-name { font: 700 15px/1 var(--sa-font-display); color: var(--sa-text); letter-spacing: -0.02em; }
.dl-brand .sa3d-brand-tag { font: 700 9.5px/1 var(--sa-font); letter-spacing: .08em; text-transform: uppercase; color: var(--sa-primary);
    background: rgba(0, 122, 255, .10); padding: 4px 8px; border-radius: 999px; }
.dl-brand:hover .sa3d-brand-name { color: var(--sa-primary); }
body.sa3d #mainSidebar .sidebar-brand {
    height: 66px; min-height: 66px; padding: 0 16px !important;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06) !important;
}
#mainSidebar.is-rail .dl-brand { gap: 0 !important; }
#mainSidebar.is-rail .dl-brand-text { display: none !important; }

/* ── Header: light frosted with soft drop ──────────────────────────────── */
body.sa3d main > header,
body.sa3d header.sticky {
    background: rgba(255, 255, 255, 0.78) !important;
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    backdrop-filter: blur(20px) saturate(180%);
    border-bottom: 1px solid rgba(0, 0, 0, 0.05) !important;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.04), 0 8px 20px -16px rgba(0, 0, 0, 0.25) !important;
}

/* ── Tables ────────────────────────────────────────────────────────────── */
body.sa3d table thead th,
body.sa3d .table-header-sticky th { background-color: #F7F7FA; color: var(--sa-text-3); }

/* ── Mobile bottom navigation ──────────────────────────────────────────── */
body.sa3d #mobileBottomNav {
    background: rgba(255, 255, 255, 0.94) !important;
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    backdrop-filter: blur(20px) saturate(180%);
    border-top: 1px solid rgba(0, 0, 0, 0.06) !important;
    box-shadow: 0 -8px 24px -16px rgba(0, 0, 0, 0.25) !important;
    padding-top: 6px !important;
    padding-bottom: max(6px, env(safe-area-inset-bottom)) !important;
}
body.sa3d #mobileBottomNav .mobile-nav-btn {
    min-width: 56px; min-height: 44px;
    justify-content: center;
    padding: 4px 8px;
    border-radius: 12px;
    transition: background-color .2s ease, color .2s ease;
}
body.sa3d #mobileBottomNav .mobile-nav-btn.text-sky-600,
body.sa3d #mobileBottomNav .mobile-nav-btn.text-purple-600 {
    color: var(--sa-primary) !important;
    background: rgba(0, 122, 255, 0.10);
}
body.sa3d #mobileBottomNav .mobile-nav-btn span.text-\[10px\] { font-size: 10.5px; font-weight: 600; letter-spacing: 0; }
/* Centre "New Task" key: raised primary disc */
body.sa3d #mobileBottomNav > button:not(.mobile-nav-btn) > div {
    background: var(--sa-btn-primary-bg) !important;
    border: 3px solid #fff !important;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 6px 14px -4px rgba(0, 102, 214, 0.55), 0 0 0 1px rgba(0, 0, 0, 0.04) !important;
}
body.sa3d #mobileBottomNav > button:not(.mobile-nav-btn) > span { color: var(--sa-primary) !important; font-weight: 600; }

/* ── PWA install prompt: card surface ──────────────────────────────────── */
body.sa3d #pwaInstallPromptBanner {
    background: var(--sa-card-bg) !important;
    border: 1px solid var(--sa-border) !important;
    box-shadow: var(--sa-card-shadow-hover) !important;
}

/* ======================================================================
   Mobile (≤ 768px)
   ====================================================================== */
@media (max-width: 768px) {
    html, body.sa3d { overflow-x: hidden; max-width: 100%; }
    body.sa3d { width: 100% !important; }

    /* readable micro text */
    body.sa3d .text-\[9px\] { font-size: 10px !important; }
    body.sa3d .text-\[10px\] { font-size: 11px !important; }

    /* header: comfortable 40px keys, nothing pushes past the edge */
    body.sa3d main > header { padding-left: 10px !important; padding-right: 10px !important; }
    body.sa3d main > header button,
    body.sa3d main > header a { min-height: 40px; min-width: 40px; display: inline-flex; align-items: center; justify-content: center; }
    body.sa3d main > header .font-display { font-size: 16px !important; }

    /* sidebar drawer: full-height white sheet */
    body.sa3d #mainSidebar { box-shadow: 12px 0 40px -12px rgba(0, 0, 0, 0.35) !important; max-width: 86vw; }
    body.sa3d .sidebar-item { min-height: 44px; }
    body.sa3d #mainSidebar .sidebar-brand button { min-width: 40px; min-height: 40px; display: inline-flex; align-items: center; justify-content: center; }

    /* cards slightly tighter radius */
    body.sa3d .card-3d:not(.bg-slate-900), body.sa3d .table-container { border-radius: 14px; }

    /* tables scroll inside their card instead of widening the page */
    body.sa3d div:has(> table) { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
    body.sa3d div:has(> table) > table { min-width: 100%; }
    body.sa3d .card-3d.overflow-hidden:has(> table) { overflow-x: auto !important; }

    /* small icon keys that sit inside inputs keep their size */
    body.sa3d .relative > button.absolute { min-height: 0 !important; }

    /* modals fit the screen */
    body.sa3d div[id$="Modal"].fixed.inset-0 > div:first-child {
        max-width: 100vw !important;
        max-height: 94vh;
        min-height: 0 !important;
    }
    body.sa3d div[id$="Modal"].fixed.inset-0 > div:first-child.h-\[94vh\],
    body.sa3d div[id$="Modal"].fixed.inset-0 > div:first-child.h-\[88vh\] { height: 92vh !important; }

    /* fixed popups stay inside the viewport */
    body.sa3d #pwaInstallPromptBanner { left: 12px !important; right: 12px !important; max-width: none !important; bottom: calc(76px + env(safe-area-inset-bottom)) !important; }
    body.sa3d #pwaInstallPromptBanner > div { min-width: 0; }

    /* leave room above the bottom nav */
    body.sa3d #mainScrollContainer { padding-bottom: calc(88px + env(safe-area-inset-bottom)) !important; }
}

@media (max-width: 420px) {
    body.sa3d #mainScrollContainer { padding-left: 10px !important; padding-right: 10px !important; }
}

/* ── Mobile fixes for specific delegation chrome ───────────────────────── */
@media (max-width: 767px) {
    /* drawer wide enough for the brand lockup + close key */
    body.sa3d #mainSidebar { width: min(300px, 86vw) !important; }
    body.sa3d #mainSidebar .dl-brand .sa3d-brand-name { overflow: visible; text-overflow: clip; }
}
@media (max-width: 480px) {
    /* header: Compass link collapses to an icon key so the title has room */
    body.sa3d main > header a[title="Switch to Compass ERP"] { padding: 0 !important; width: 40px; border-radius: 999px; white-space: nowrap; margin-left: 0 !important; }
    body.sa3d main > header a[title="Switch to Compass ERP"] > span { display: none; }
    body.sa3d main > header a[title="Switch to Compass ERP"] > svg { width: 18px; height: 18px; }
}
@media (max-width: 768px) {
    /* mobile task cards: action keys wrap instead of running off the card */
    body.sa3d #tasksMobileGridContainer > * { min-width: 0; overflow: hidden; }
    body.sa3d #tasksMobileGridContainer .flex.items-center.gap-2.pt-1 { flex-wrap: wrap; }
    body.sa3d #tasksMobileGridContainer .flex.items-center.gap-2.pt-1 > * { flex: 1 1 auto; white-space: nowrap; min-height: 40px; }
    body.sa3d #tasksMobileGridContainer .flex.items-center.gap-1\.5 > * { min-width: 0; flex-shrink: 1; }
    body.sa3d #tasksMobileGridContainer .flex.items-center.gap-1\.5 > svg { flex-shrink: 0; }
}
