/* ---
   SupplyNext Digital Dashboard - Main Stylesheet
   Designed by: Your AI Assistant
   Theme: Modern, Clean, Data-Driven
--- */

/* =========== 1. Global Styles & Variables =========== */
:root {
    /* Color Palette from Blueprint */
    --primary-blue: #16425b;
    --secondary-blue: #2f6690;
    --accent-blue: #3a7ca5;
    --positive-green: #28a745;
    --warning-yellow: #ffc107;
    --critical-red: #dc3545;

    /* UI Neutrals & Text */
    --bg-main: #f4f7fa; /* A cooler, more modern light gray */
    --bg-card: #ffffff;
    --border-color: #e9ecef;
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --text-light: #f8f9fa;

    /* Sizing & Shadows */
    --sidebar-width: 260px;
    --border-radius: 8px;
    --card-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
    --header-height: 70px;
}

/* Base Reset & Font */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    overflow: hidden; /* Prevent scrolling on the body itself */
}

/* =========== 2. Thematic App Loader Animation =========== */
#app-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--primary-blue);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.5s ease-out;
}

.loader-content {
    text-align: center;
}

.supply-chain-animation {
    display: flex;
    align-items: center;
    margin-bottom: 2rem;
}

.supply-chain-animation .fa-solid {
    font-size: 2.5rem;
    color: var(--text-light);
    opacity: 0;
    transform: scale(0.5);
    animation: icon-appear 0.5s forwards;
}

.anim-path {
    height: 3px;
    width: 0;
    background: var(--accent-blue);
    margin: 0 1rem;
    animation: path-grow 0.8s forwards;
}

#anim-factory { animation-delay: 0.2s; }
#path1 { animation-delay: 0.7s; }
#anim-truck { animation-delay: 1.5s; }
#path2 { animation-delay: 2.3s; }
#anim-warehouse { animation-delay: 3.1s; }
#path3 { animation-delay: 3.9s; }
#anim-ship { animation-delay: 4.7s; }
#path4 { animation-delay: 5.5s; }
#anim-globe { animation-delay: 6.3s; }

.loader-title {
    color: var(--text-light);
    font-weight: 300;
    font-size: 2rem;
    letter-spacing: 2px;
}

#loader-status {
    color: var(--accent-blue);
    margin-top: 0.5rem;
    font-size: 1rem;
    min-height: 1.2rem;
}

/* Keyframes for the animation */
@keyframes icon-appear {
    to { opacity: 1; transform: scale(1); }
}

@keyframes path-grow {
    to { width: 60px; }
}


/* =========== 3. Main Application Layout =========== */
.app-container {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    height: 100vh;
}

/* =========== 4. Sidebar Navigation =========== */
.sidebar {
    background: var(--primary-blue);
    color: var(--text-light);
    display: flex;
    flex-direction: column;
    padding: 1.5rem 0;
}

.sidebar-header {
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    margin-bottom: 2rem;
}

.sidebar-header .logo {
    height: 40px;
    width: 40px;
    margin-right: 1rem;
}

.sidebar-header h2 {
    font-weight: 600;
}

.sidebar-menu {
    list-style-type: none;
    flex-grow: 1;
}

.menu-item a {
    display: flex;
    align-items: center;
    padding: 1rem 1.5rem;
    color: var(--text-light);
    text-decoration: none;
    font-weight: 500;
    border-left: 4px solid transparent;
    transition: all 0.2s ease-in-out;
}

.menu-item a:hover {
    background: var(--secondary-blue);
    cursor: pointer;
}

.menu-item.active a {
    background: var(--secondary-blue);
    border-left-color: var(--warning-yellow);
}

.menu-item .fa-fw {
    width: 1.25em; /* Font Awesome fixed width */
    margin-right: 1rem;
    font-size: 1.1rem;
}

.sidebar-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--secondary-blue);
}

.user-profile {
    display: flex;
    align-items: center;
}

.user-profile img {
    height: 40px;
    width: 40px;
    border-radius: 50%;
    margin-right: 1rem;
}

.user-info span {
    display: block;
    font-weight: 600;
}

.user-info small {
    color: var(--border-color);
}

/* =========== 5. Main Content Area =========== */
.main-content {
    background-color: var(--bg-main);
    padding: 2rem;
    overflow-y: auto;
    height: 100vh;
}

.module {
    animation: fadeIn 0.5s ease-in-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.module-header {
    margin-bottom: 2rem;
}

.module-header h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.module-header p {
    font-size: 1rem;
    color: var(--text-secondary);
}


/* =========== 6. Reusable Components =========== */

/* --- KPI Cards --- */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
}

.kpi-card {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--card-shadow);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.kpi-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
}

/* --- Data Tables --- */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-card);
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: var(--card-shadow);
}

.data-table th, .data-table td {
    padding: 1rem;
    text-align: left;
}

.data-table thead {
    background: #f8f9fa; /* Slightly off-white for header */
}

.data-table th {
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 0.5px;
}

.data-table tbody tr {
    border-bottom: 1px solid var(--border-color);
}

.data-table tbody tr:last-child {
    border-bottom: none;
}

.data-table tbody tr:hover {
    background-color: #f1f3f5;
    cursor: pointer;
}

/* --- Tabs --- */
.tabs {
    width: 100%;
}

.tab-nav {
    display: flex;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 1.5rem;
}

.tab-link {
    padding: 0.75rem 1.5rem;
    cursor: pointer;
    background: none;
    border: none;
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-secondary);
    border-bottom: 3px solid transparent;
    transition: all 0.2s ease;
    margin-bottom: -2px; /* Pulls the border up to the line */
}

.tab-link:hover {
    color: var(--text-primary);
}

.tab-link.active {
    color: var(--accent-blue);
    border-bottom-color: var(--accent-blue);
}

.tab-content {
    animation: fadeIn 0.3s ease;
}

/* --- Chart Containers --- */
.chart-container {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--card-shadow);
    min-height: 400px;
    width: 100%;
}

/* =========== 7. Module-Specific Styles =========== */

/* --- Inventory & Ops --- */
.inventory-container {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.5rem;
}
.detail-pane {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    box-shadow: var(--card-shadow);
    padding: 1.5rem;
    /* Initially hidden or styled to slide in */
}

/* --- Settings & Team --- */
.team-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
}

.team-card {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    box-shadow: var(--card-shadow);
    padding: 2rem 1.5rem;
    text-align: center;
    transition: all 0.3s ease;
}

.team-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
}

.team-card img {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 1rem;
    border: 4px solid var(--border-color);
}

.team-card .team-name {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.team-card .team-role {
    font-size: 0.9rem;
    color: var(--accent-blue);
    font-weight: 500;
}
/* --- Spinner Utility --- */
.loading-spinner {
    border: 4px solid rgba(0, 0, 0, 0.1);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border-left-color: var(--accent-blue);
    margin: 40px auto;
    animation: spin 1s ease infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* =========== 8. Widget-Specific & Component Styles =========== */

/* --- KPI Card Components --- */
.kpi-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
}
.kpi-title i {
    margin-right: 0.75rem;
    color: var(--accent-blue);
}

.kpi-value {
    font-size: 3rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.kpi-details {
    font-size: 0.9rem;
    color: var(--text-secondary);
}
.kpi-details span {
    display: block;
}

/* Color utility classes for values */
.color-positive { color: var(--positive-green); }
.color-warning { color: var(--warning-yellow); }
.color-critical { color: var(--critical-red); }
.color-info { color: var(--secondary-blue); }

/* --- Inventory Widget --- */
.chart-wrapper {
    position: relative;
    height: 200px; /* Adjust as needed */
}
.chart-center-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    pointer-events: none;
}
.chart-center-text .total {
    display: block;
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-primary);
}
.chart-center-text .label {
    display: block;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* --- Shipments Widget --- */
.shipment-chart-container {
    height: 40px;
    margin-bottom: 1rem;
}
.shipment-chart-container:last-child {
    margin-bottom: 0;
}

/* --- Alerts Widget --- */
.alerts-list {
    list-style: none;
    max-height: 250px;
    overflow-y: auto;
}
.alert-item {
    display: flex;
    align-items: center;
    padding: 0.75rem 0.25rem;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background-color 0.2s ease;
}
.alert-item:last-child {
    border-bottom: none;
}
.alert-item:hover {
    background-color: #f8f9fa;
}
.alert-icon {
    font-size: 1.2rem;
    margin-right: 1rem;
    width: 20px;
    text-align: center;
}
.alert-message {
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 0.2rem;
}
.alert-timestamp {
    font-size: 0.8rem;
    color: var(--text-secondary);
}
.no-alerts {
    text-align: center;
    padding: 2rem 0;
    color: var(--text-secondary);
}

/* --- Forecasting Module Specific Styles --- */
.forecasting-controls {
    display: flex;
    gap: 1rem;
    align-items: center;
    margin-bottom: 1.5rem;
    background-color: var(--bg-card);
    padding: 1rem;
    border-radius: var(--border-radius);
    box-shadow: var(--card-shadow);
}

.form-control {
    padding: 0.5rem 1rem;
    font-size: 1rem;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    flex-grow: 1; /* Allows selector to take available space */
}

.timeframe-selector .btn-timeframe {
    padding: 0.5rem 1rem;
    font-size: 1rem;
    border: 1px solid var(--border-color);
    background-color: transparent;
    cursor: pointer;
    transition: all 0.2s ease;
}

.timeframe-selector .btn-timeframe:first-of-type {
    border-top-left-radius: var(--border-radius);
    border-bottom-left-radius: var(--border-radius);
}
.timeframe-selector .btn-timeframe:last-of-type {
    border-top-right-radius: var(--border-radius);
    border-bottom-right-radius: var(--border-radius);
    border-left: none;
}
.timeframe-selector .btn-timeframe:not(:first-of-type):not(:last-of-type) {
    border-left: none;
}

.timeframe-selector .btn-timeframe.active,
.timeframe-selector .btn-timeframe:hover {
    background-color: var(--secondary-blue);
    color: var(--text-light);
    border-color: var(--secondary-blue);
}

#decomposition-charts-container canvas {
    margin-bottom: 1rem;
}

.placeholder-message {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 400px;
    color: var(--text-secondary);
    font-size: 1.2rem;
    background-color: var(--bg-card);
    border-radius: var(--border-radius);
    box-shadow: var(--card-shadow);
}
/* --- Inventory Module Specific Styles --- */

/* Table Row Styling */
#inventory-table tbody tr.active {
    background-color: var(--accent-blue) !important;
    color: white;
}
#inventory-table tbody tr.active td {
    color: white;
}

.status-dot {
    height: 10px;
    width: 10px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 0.5rem;
}
.status-dot.green { background-color: var(--positive-green); }
.status-dot.yellow { background-color: var(--warning-yellow); }
.status-dot.red { background-color: var(--critical-red); }

/* Detail Pane Styling */
.detail-pane {
    background: #ffffff;
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--card-shadow);
    position: sticky; /* Sticks to the top on scroll */
    top: 1.5rem;
    height: calc(100vh - 5rem);
    overflow-y: auto;
    transition: transform 0.3s ease-in-out, opacity 0.3s ease-in-out;
}

/* On desktop, the pane is part of the grid. On mobile we can make it slide */
.detail-pane:not(.open) {
    display: none; /* Simple hide/show for desktop grid layout */
}
.detail-pane.open {
    display: block;
}

.detail-pane-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
    margin-bottom: 1rem;
}
.detail-pane-header h3 {
    margin: 0;
    font-size: 1.2rem;
}
.btn-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
}

.detail-section {
    margin-bottom: 1.5rem;
}

.detail-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
}

.buffer-note {
    font-size: 0.8rem;
    color: var(--text-secondary);
    background: var(--bg-main);
    padding: 0.75rem;
    border-radius: var(--border-radius);
    margin-bottom: 1.5rem;
}

.detail-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}
.btn-action {
    padding: 0.75rem;
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: var(--border-radius);
    border: 1px solid var(--accent-blue);
    background: var(--accent-blue);
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
}
.btn-action:hover {
    background: var(--secondary-blue);
    border-color: var(--secondary-blue);
}

/* Ensure the pane has a placeholder when empty and not loading */
.detail-pane .placeholder-message {
    min-height: 0; /* Override default */
    height: 100%;
    background: none;
    box-shadow: none;
}

/* --- Analytics Module Specific Styles --- */
.analytics-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    max-width: 400px;
}

.analytics-controls label {
    font-weight: 600;
    color: var(--text-secondary);
}

.analytics-layout {
    display: grid;
    grid-template-columns: 1fr 2fr; /* 1/3 for chart, 2/3 for table */
    gap: 1.5rem;
    align-items: flex-start;
}

#error-distribution-chart {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--card-shadow);
    height: 450px; /* Give chart a fixed height */
}

#accuracy-summary-table {
    height: 450px; /* Match chart height */
    overflow-y: auto;
    display: block; /* Allows overflow-y to work on a div */
}

/* Styles for forecast bias column */
.color-positive-bias {
    color: var(--warning-yellow); /* Over-forecasting is a warning */
    font-weight: 600;
}
.color-negative-bias {
    color: var(--critical-red); /* Under-forecasting is often more critical */
    font-weight: 600;
}


/* Responsive adjustments for Analytics */
@media (max-width: 1024px) {
    .analytics-layout {
        grid-template-columns: 1fr; /* Stack chart and table on tablets */
    }
    #error-distribution-chart,
    #accuracy-summary-table {
        height: auto; /* Allow height to be determined by content */
        max-height: 400px; /* But limit it to prevent huge scrolling */
    }
}

/* --- Settings Module Specific Styles --- */

.team-card {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    box-shadow: var(--card-shadow);
    padding: 2rem 1.5rem;
    text-align: center;
    transition: all 0.3s ease;
}

.team-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
}

.team-image-wrapper {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    margin: 0 auto 1.5rem auto;
    border: 4px solid var(--border-color);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    background-color: #f0f2f5;
}

.team-image-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.team-image-wrapper .generic-avatar {
    font-size: 4rem;
    color: var(--text-secondary);
}

.team-name {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
    color: var(--text-primary);
}

.team-role {
    font-size: 0.9rem;
    color: var(--accent-blue);
    font-weight: 500;
}