/*
   CraftGrid One — Phase 2 visual consistency layer
   Scope: dashboard presentation, shared ERP components, and responsive navigation.
   This file changes CSS only. It does not alter routes, data, permissions,
   authentication, calculations, workflows, or database behaviour.
*/

:root {
    --cg-brand-primary: #1769AA;
    --cg-brand-primary-hover: #12548C;
    --cg-brand-sky: #38BDF8;
    --cg-brand-soft: #EEF5FC;
    --cg-brand-border: #D8E3EF;
    --cg-brand-navy: #102B40;
    --cg-brand-yellow: #FFC629;

    /* Keep Bootstrap's primary colour aligned with CraftGrid One. */
    --bs-primary: #1769AA;
    --bs-primary-rgb: 23, 105, 170;
    --bs-link-color: #1769AA;
    --bs-link-hover-color: #12548C;
}

body.craftgrid-authenticated-shell {
    background-color: #F4F8FC;
    color: #29445E;
}

/* ---------------------------------------------------------------
   Shared ERP surfaces and controls
   --------------------------------------------------------------- */

.craftgrid-authenticated-shell .btn-primary,
.craftgrid-authenticated-shell .btn-view {
    color: #FFFFFF;
    background-color: #1769AA;
    border-color: #1769AA;
}

.craftgrid-authenticated-shell .btn-primary:hover,
.craftgrid-authenticated-shell .btn-primary:focus-visible,
.craftgrid-authenticated-shell .btn-view:hover,
.craftgrid-authenticated-shell .btn-view:focus-visible {
    color: #FFFFFF;
    background-color: #12548C;
    border-color: #12548C;
}

.craftgrid-authenticated-shell .btn-outline-primary {
    color: #1769AA;
    border-color: #1769AA;
}

.craftgrid-authenticated-shell .btn-outline-primary:hover,
.craftgrid-authenticated-shell .btn-outline-primary:focus-visible {
    color: #FFFFFF;
    background-color: #1769AA;
    border-color: #1769AA;
}

.craftgrid-authenticated-shell .text-primary,
.craftgrid-authenticated-shell .link-primary {
    color: #1769AA !important;
}

.craftgrid-authenticated-shell .link-primary:hover {
    color: #12548C !important;
}

.craftgrid-authenticated-shell .bg-primary,
.craftgrid-authenticated-shell .page-item.active .page-link,
.craftgrid-authenticated-shell .nav-pills .nav-link.active {
    color: #FFFFFF !important;
    background-color: #1769AA !important;
    border-color: #1769AA !important;
}

.craftgrid-authenticated-shell .form-control:focus,
.craftgrid-authenticated-shell .form-select:focus,
.craftgrid-authenticated-shell .form-check-input:focus {
    border-color: rgba(23, 105, 170, .55);
    box-shadow: 0 0 0 .18rem rgba(23, 105, 170, .12);
}

.craftgrid-authenticated-shell .form-check-input:checked {
    background-color: #1769AA;
    border-color: #1769AA;
}

/* Keep cards neutral; use the same restrained border and shadow system. */
.craftgrid-authenticated-shell .card,
.craftgrid-authenticated-shell .erp-card,
.craftgrid-authenticated-shell .erp-document-card {
    border-color: #D8E3EF;
    background-color: #FFFFFF;
}

.craftgrid-authenticated-shell .card-header {
    border-bottom-color: #E5EDF5;
    background-color: #F8FAFD;
    color: #17324D;
}

.craftgrid-authenticated-shell .erp-section-title,
.craftgrid-authenticated-shell .erp-document-header h1,
.craftgrid-authenticated-shell .erp-document-header h2 {
    color: #102B40;
}

.craftgrid-authenticated-shell .table > :not(caption) > * > * {
    border-bottom-color: #E7EEF5;
}

.craftgrid-authenticated-shell .table:not(.table-dark) > thead > tr > th {
    color: #49647D;
    background-color: #F4F8FC;
    border-bottom-color: #D8E3EF;
}

/* ---------------------------------------------------------------
   Desktop and mobile navigation
   Desktop remains navy. The mobile offcanvas is white/light blue.
   --------------------------------------------------------------- */

@media (min-width: 992px) {
    body.craftgrid-authenticated-shell .desktop-sidebar .erp-sidebar {
        color: #F4F8FC !important;
        background: linear-gradient(180deg, #102B40 0%, #143650 100%) !important;
    }

    body.craftgrid-authenticated-shell .desktop-sidebar .erp-sidebar .sidebar-link.active,
    body.craftgrid-authenticated-shell .desktop-sidebar .erp-sidebar .sidebar-submenu-link.active,
    body.craftgrid-authenticated-shell .desktop-sidebar .erp-sidebar .sidebar-group:has(.sidebar-submenu-link.active) > .sidebar-group-toggle {
        color: #12324D !important;
        background: #DCEEFF !important;
        box-shadow: inset 3px 0 0 #1769AA !important;
    }

    body.craftgrid-authenticated-shell .desktop-sidebar .erp-sidebar .sidebar-link.active .sidebar-link-content > span,
    body.craftgrid-authenticated-shell .desktop-sidebar .erp-sidebar .sidebar-link.active .sidebar-link-content > i,
    body.craftgrid-authenticated-shell .desktop-sidebar .erp-sidebar .sidebar-submenu-link.active .sidebar-link-content > span,
    body.craftgrid-authenticated-shell .desktop-sidebar .erp-sidebar .sidebar-submenu-link.active .sidebar-link-content > i {
        color: #12324D !important;
    }
}

@media (max-width: 991.98px) {
    body.craftgrid-authenticated-shell .craftgrid-mobile-sidebar {
        color: #17324D !important;
        background: #FFFFFF !important;
        border-right: 1px solid #D8E3EF !important;
    }

    body.craftgrid-authenticated-shell .craftgrid-mobile-sidebar .offcanvas-header,
    body.craftgrid-authenticated-shell .craftgrid-mobile-sidebar .craftgrid-mobile-sidebar-header {
        color: #FFFFFF !important;
        background: linear-gradient(110deg, #102B40 0%, #123B5E 100%) !important;
        border-bottom: 1px solid rgba(56, 189, 248, .35) !important;
    }

    body.craftgrid-authenticated-shell .craftgrid-mobile-sidebar .offcanvas-body,
    body.craftgrid-authenticated-shell .craftgrid-mobile-sidebar .erp-sidebar {
        color: #17324D !important;
        background: #FFFFFF !important;
    }

    body.craftgrid-authenticated-shell .craftgrid-mobile-sidebar .sidebar-section-label,
    body.craftgrid-authenticated-shell .craftgrid-mobile-sidebar .sidebar-subsection-label {
        color: #71869A !important;
    }

    body.craftgrid-authenticated-shell .craftgrid-mobile-sidebar .sidebar-dashboard-link,
    body.craftgrid-authenticated-shell .craftgrid-mobile-sidebar .sidebar-group-toggle,
    body.craftgrid-authenticated-shell .craftgrid-mobile-sidebar .sidebar-submenu-link,
    body.craftgrid-authenticated-shell .craftgrid-mobile-sidebar .sidebar-submenu .sidebar-link {
        color: #29445E !important;
        background: transparent !important;
        border-color: #E7EEF5 !important;
    }

    body.craftgrid-authenticated-shell .craftgrid-mobile-sidebar .sidebar-dashboard-link .sidebar-link-content > i,
    body.craftgrid-authenticated-shell .craftgrid-mobile-sidebar .sidebar-group-toggle .sidebar-link-content > i,
    body.craftgrid-authenticated-shell .craftgrid-mobile-sidebar .sidebar-submenu-link .sidebar-link-content > i,
    body.craftgrid-authenticated-shell .craftgrid-mobile-sidebar .sidebar-chevron {
        color: #64809A !important;
    }

    body.craftgrid-authenticated-shell .craftgrid-mobile-sidebar .sidebar-dashboard-link:hover,
    body.craftgrid-authenticated-shell .craftgrid-mobile-sidebar .sidebar-group-toggle:hover,
    body.craftgrid-authenticated-shell .craftgrid-mobile-sidebar .sidebar-submenu-link:hover:not(.active),
    body.craftgrid-authenticated-shell .craftgrid-mobile-sidebar .sidebar-submenu .sidebar-link:hover:not(.active) {
        color: #12548C !important;
        background: #F2F7FD !important;
    }

    body.craftgrid-authenticated-shell .craftgrid-mobile-sidebar .sidebar-dashboard-link.active,
    body.craftgrid-authenticated-shell .craftgrid-mobile-sidebar .sidebar-link.active,
    body.craftgrid-authenticated-shell .craftgrid-mobile-sidebar .sidebar-submenu-link.active,
    body.craftgrid-authenticated-shell .craftgrid-mobile-sidebar .sidebar-submenu .sidebar-link.active,
    body.craftgrid-authenticated-shell .craftgrid-mobile-sidebar .sidebar-group:has(.sidebar-submenu-link.active) > .sidebar-group-toggle {
        color: #12548C !important;
        background: #E5F1FF !important;
        border-color: #D3E6FA !important;
        border-radius: 10px !important;
        box-shadow: inset 3px 0 0 #1769AA !important;
        font-weight: 700 !important;
    }

    body.craftgrid-authenticated-shell .craftgrid-mobile-sidebar .sidebar-link.active .sidebar-link-content > i,
    body.craftgrid-authenticated-shell .craftgrid-mobile-sidebar .sidebar-link.active .sidebar-link-content > span,
    body.craftgrid-authenticated-shell .craftgrid-mobile-sidebar .sidebar-submenu-link.active .sidebar-link-content > i,
    body.craftgrid-authenticated-shell .craftgrid-mobile-sidebar .sidebar-submenu-link.active .sidebar-link-content > span {
        color: #12548C !important;
    }

    body.craftgrid-authenticated-shell .craftgrid-mobile-sidebar .sidebar-favorite-button {
        color: #8295A8 !important;
    }

    body.craftgrid-authenticated-shell .craftgrid-mobile-sidebar .sidebar-favorite-button.is-favorite,
    body.craftgrid-authenticated-shell .craftgrid-mobile-sidebar .sidebar-favorite-button[aria-pressed="true"] {
        color: #C58A18 !important;
        background: #FFF7E6 !important;
    }

    body.craftgrid-authenticated-shell .craftgrid-mobile-sidebar .btn-close,
    body.craftgrid-authenticated-shell .craftgrid-mobile-sidebar .craftgrid-mobile-sidebar-close {
        filter: invert(1) grayscale(100%) brightness(200%) !important;
        opacity: .95 !important;
    }
}

/* ---------------------------------------------------------------
   Tenant Admin Dashboard — colour and surface refinement only.
   Existing layout, chart data, links and breakpoints remain intact.
   --------------------------------------------------------------- */

body.craftgrid-authenticated-shell .cg-admin-v2.cg-admin-v2 {
    --navy: #102B40;
    --navy-2: #173E5F;
    --green: #1769AA;       /* Existing dashboard primary-action token */
    --green-dark: #12548C;  /* Existing dashboard primary-hover token */
    --blue: #38BDF8;
    --purple: #6D5AA6;
    --orange: #C77B2A;
    --red: #C84C55;
    --amber: #C98A1B;
    --ink: #29445E;
    --muted: #6C8093;
    --border: #D8E3EF;
    --page: #F4F8FC;
    background: var(--page);
    color: var(--ink);
}

body.craftgrid-authenticated-shell .cg-admin-v2.cg-admin-v2 .cg-kpi,
body.craftgrid-authenticated-shell .cg-admin-v2.cg-admin-v2 .cg-action,
body.craftgrid-authenticated-shell .cg-admin-v2.cg-admin-v2 .cg-op,
body.craftgrid-authenticated-shell .cg-admin-v2.cg-admin-v2 .cg-panel,
body.craftgrid-authenticated-shell .cg-admin-v2.cg-admin-v2 .cg-foundation-panel {
    border-color: #D8E3EF;
    background-color: #FFFFFF;
    box-shadow: 0 3px 13px rgba(16, 43, 64, .045);
}

body.craftgrid-authenticated-shell .cg-admin-v2.cg-admin-v2 .cg-kpi-link:hover,
body.craftgrid-authenticated-shell .cg-admin-v2.cg-admin-v2 .cg-action:hover,
body.craftgrid-authenticated-shell .cg-admin-v2.cg-admin-v2 .cg-op:hover {
    border-color: #B9D5EF;
    box-shadow: 0 8px 20px rgba(16, 43, 64, .085);
}

body.craftgrid-authenticated-shell .cg-admin-v2.cg-admin-v2 .cg-kicker,
body.craftgrid-authenticated-shell .cg-admin-v2.cg-admin-v2 .cg-period a:hover,
body.craftgrid-authenticated-shell .cg-admin-v2.cg-admin-v2 .cg-range a:hover {
    color: #12548C;
}

body.craftgrid-authenticated-shell .cg-admin-v2.cg-admin-v2 .cg-period a.active,
body.craftgrid-authenticated-shell .cg-admin-v2.cg-admin-v2 .cg-range a.active,
body.craftgrid-authenticated-shell .cg-admin-v2.cg-admin-v2 .cg-custom-form button {
    color: #FFFFFF;
    background: #1769AA;
    border-color: #1769AA;
}

body.craftgrid-authenticated-shell .cg-admin-v2.cg-admin-v2 .cg-section-title {
    color: #102B40;
}

body.craftgrid-authenticated-shell .cg-admin-v2.cg-admin-v2 .cg-section-title::before {
    background: linear-gradient(180deg, #1769AA 0%, #38BDF8 100%);
}

body.craftgrid-authenticated-shell .cg-admin-v2.cg-admin-v2 .cg-panel-link,
body.craftgrid-authenticated-shell .cg-admin-v2.cg-admin-v2 .cg-analysis-link,
body.craftgrid-authenticated-shell .cg-admin-v2.cg-admin-v2 .cg-op-link {
    color: #1769AA;
}

body.craftgrid-authenticated-shell .cg-admin-v2.cg-admin-v2 .cg-chart-sales,
body.craftgrid-authenticated-shell .cg-admin-v2.cg-admin-v2 .cg-chart-dot {
    stroke: #1769AA;
}

body.craftgrid-authenticated-shell .cg-admin-v2.cg-admin-v2 .cg-chart-area {
    fill: rgba(23, 105, 170, .10);
}

body.craftgrid-authenticated-shell .cg-admin-v2.cg-admin-v2 .cg-chart-purchase {
    fill: rgba(109, 90, 166, .22);
    stroke: #6D5AA6;
}

body.craftgrid-authenticated-shell .cg-admin-v2.cg-admin-v2 .cg-chart-tooltip-swatch {
    background: #1769AA;
}

body.craftgrid-authenticated-shell .cg-admin-v2.cg-admin-v2 .cg-chart-tooltip-row.purchase .cg-chart-tooltip-swatch {
    background: #6D5AA6;
}

body.craftgrid-authenticated-shell .cg-admin-v2.cg-admin-v2 .cg-chart-legend .legend-line {
    background: #1769AA;
}

body.craftgrid-authenticated-shell .cg-admin-v2.cg-admin-v2 .cg-chart-legend .legend-bar {
    background: #DCD6F4;
    border-color: #A99BE0;
}

body.craftgrid-authenticated-shell .cg-admin-v2.cg-admin-v2 .cg-chart-metric.sales {
    border-left-color: #1769AA;
}

body.craftgrid-authenticated-shell .cg-admin-v2.cg-admin-v2 .cg-chart-metric.purchase {
    border-left-color: #6D5AA6;
}

/* Preserve semantic health/status colours: green healthy/completed,
   amber low-stock/in-progress, and red out-of-stock/delayed. */

/* ---------------------------------------------------------------
   Platform Dashboard — align its cards, links and controls with
   the same CraftGrid One blue identity. Subscription status pills
   retain their existing semantic colours.
   --------------------------------------------------------------- */

body.craftgrid-authenticated-shell .cg-platform-page {
    background: #F4F8FC;
}

body.craftgrid-authenticated-shell .cg-platform-page .cg-platform-hero {
    border-color: #D8E3EF;
    background: linear-gradient(110deg, #F1F7FD 0%, #FFFFFF 78%);
    box-shadow: 0 5px 20px rgba(16, 43, 64, .045);
}

body.craftgrid-authenticated-shell .cg-platform-page .cg-platform-kicker,
body.craftgrid-authenticated-shell .cg-platform-page .cg-platform-hero-stat small,
body.craftgrid-authenticated-shell .cg-platform-page .cg-platform-card-header a,
body.craftgrid-authenticated-shell .cg-platform-page .cg-action-link {
    color: #1769AA;
}

body.craftgrid-authenticated-shell .cg-platform-page .cg-platform-hero-stat {
    border-color: #D8E3EF;
    background: #FFFFFF;
}

body.craftgrid-authenticated-shell .cg-platform-page .cg-platform-kpi,
body.craftgrid-authenticated-shell .cg-platform-page .cg-platform-card {
    border-color: #D8E3EF;
    box-shadow: 0 4px 15px rgba(16, 43, 64, .045);
}

body.craftgrid-authenticated-shell .cg-platform-page .cg-platform-icon:not(.gold),
body.craftgrid-authenticated-shell .cg-platform-page .cg-activity-icon {
    color: #1769AA;
    background: #EEF5FC;
}

body.craftgrid-authenticated-shell .cg-platform-page .cg-platform-actions a.primary {
    color: #FFFFFF;
    background: #1769AA;
    border-color: #1769AA;
}

body.craftgrid-authenticated-shell .cg-platform-page .cg-platform-actions a.primary:hover {
    background: #12548C;
    border-color: #12548C;
}

body.craftgrid-authenticated-shell .cg-platform-page .cg-progress span {
    background: linear-gradient(90deg, #1769AA, #38BDF8);
}

body.craftgrid-authenticated-shell .cg-platform-page .cg-platform-table th {
    background: #F4F8FC;
}

/* Mobile dashboard retains the existing two-column KPI layout and
   horizontally scrollable operation/chart rails. This only prevents
   cards from forcing the outer content pane wider than the viewport. */
@media (max-width: 767.98px) {
    body.craftgrid-authenticated-shell .cg-admin-v2,
    body.craftgrid-authenticated-shell .cg-platform-page {
        width: 100%;
        min-width: 0;
        max-width: 100%;
    }

    body.craftgrid-authenticated-shell .cg-admin-v2 .cg-wrap,
    body.craftgrid-authenticated-shell .cg-admin-v2 .cg-panel,
    body.craftgrid-authenticated-shell .cg-admin-v2 .cg-two,
    body.craftgrid-authenticated-shell .cg-admin-v2 .cg-bottom {
        min-width: 0;
        max-width: 100%;
    }

    body.craftgrid-authenticated-shell .cg-admin-v2 .cg-kpis,
    body.craftgrid-authenticated-shell .cg-admin-v2 .cg-action-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    body.craftgrid-authenticated-shell .cg-admin-v2 .cg-kpi,
    body.craftgrid-authenticated-shell .cg-admin-v2 .cg-action {
        min-width: 0;
    }

    body.craftgrid-authenticated-shell .cg-admin-v2 .cg-chart-wrap,
    body.craftgrid-authenticated-shell .cg-platform-page .table-responsive {
        max-width: 100%;
    }
}


/* Quick date filters use the primary brand blue; success states elsewhere
   remain semantic green. */
body.craftgrid-authenticated-shell .sa-filters button[name="quickRange"].btn-success {
    color: #FFFFFF;
    background-color: #1769AA;
    border-color: #1769AA;
}

body.craftgrid-authenticated-shell .sa-filters button[name="quickRange"].btn-success:hover,
body.craftgrid-authenticated-shell .sa-filters button[name="quickRange"].btn-success:focus-visible {
    color: #FFFFFF;
    background-color: #12548C;
    border-color: #12548C;
}

/* The Distributor dashboard keeps its own module icon palette, while
   selected date filters follow the shared CraftGrid One primary colour. */
body.craftgrid-authenticated-shell .cg-distributor.dist-dashboard .dist-range-pill.is-active {
    color: #FFFFFF;
    background: #1769AA;
    box-shadow: 0 3px 8px rgba(23, 105, 170, .18);
}

body.craftgrid-authenticated-shell .cg-distributor.dist-dashboard .dist-range-apply {
    color: #1769AA;
    background: #EEF5FC;
    border-color: #D8E3EF;
}

body.craftgrid-authenticated-shell .cg-distributor.dist-dashboard .dist-range-apply:hover,
body.craftgrid-authenticated-shell .cg-distributor.dist-dashboard .dist-range-apply.is-active {
    color: #FFFFFF;
    background: #1769AA;
    border-color: #1769AA;
}
