/* DATAMIND Dash - Corporate Styles (Replica Fedele) */

@import url('https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,500,600,700&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* =============================================================================
   CORPORATE COLORS
   ============================================================================= */
:root {
    --azzurro: #1949ff;
    --arancione: #F7941D;
    --green: #10b981;
    --red: #ef4444;
    --purple: #8b5cf6;
    --pink: #ec4899;
    --gray: #6b7280;
    --orange-warning: #D97706;
    --orange-high: #EA580C;
    --orange-amber: #F59E0B;
    --font-family: 'Source Sans Pro', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* =============================================================================
   GENERAL
   ============================================================================= */
body {
    font-family: var(--font-family) !important;
    background-color: #f8f9fa;
    color: #31333F;
    font-size: 17px;
}

h1, h2, h3, h4 {
    color: var(--azzurro) !important;
    font-weight: 700 !important;
}

/* =============================================================================
   KPI CARDS
   ============================================================================= */
.kpi-card {
    background: white;
    border-radius: 16px;
    padding: 24px;
    border: 1px solid #e5e7eb;
    border-left: 4px solid var(--azzurro);
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    min-height: 120px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    height: 100%;
}

.kpi-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--gray);
    margin-bottom: 8px;
}

.kpi-value {
    font-size: 32px;
    font-weight: 700;
    color: #111827;
}

.kpi-delta {
    display: inline-block;
    font-size: 13px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 20px;
    margin-top: 6px;
}

.kpi-delta.up {
    background: #dcfce7;
    color: #166534;
}

.kpi-delta.down {
    background: #fee2e2;
    color: #991b1b;
}

.kpi-subtitle {
    font-size: 12px;
    color: #9ca3af;
    margin-top: 8px;
}

/* =============================================================================
   SECTION CARDS
   ============================================================================= */
.section-card {
    background: white;
    border-radius: 16px;
    border: 1px solid #e5e7eb;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    margin-bottom: 24px;
}

/* Dropdown menus must escape section-card overflow:hidden */
.section-card .Select-menu-outer,
.section-card .dash-dropdown .Select-menu-outer {
    z-index: 999;
}
.section-card:has(.is-open) {
    overflow: visible;
}

/* =============================================================================
   CHART FULLSCREEN TOGGLE
   ============================================================================= */
.obs-chart-container {
    position: relative;
    transition: all 0.3s ease;
}

.obs-chart-container .obs-fs-btn {
    opacity: 0;
    transition: opacity 0.2s;
}

.obs-chart-container:hover .obs-fs-btn {
    opacity: 0.7;
}

.obs-chart-container:hover .obs-fs-btn:hover {
    opacity: 1;
}

.chart-fullscreen {
    position: fixed !important;
    top: 0;
    left: 0;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 9999;
    background: white;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

.chart-fullscreen .obs-fs-btn {
    opacity: 1 !important;
    position: fixed !important;
    top: 16px;
    right: 16px;
    z-index: 10000;
    font-size: 22px !important;
    padding: 4px 12px !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.section-header {
    padding: 16px 24px;
    border-bottom: 1px solid #f3f4f6;
}

.section-title {
    font-size: 16px;
    font-weight: 600;
    color: #111827;
    margin: 0;
}

.section-subtitle {
    font-size: 13px;
    color: var(--gray);
    margin-top: 4px;
}

.section-content {
    padding: 24px;
}

/* =============================================================================
   BADGES
   ============================================================================= */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.badge-high {
    background: #dcfce7;
    color: #166534;
}

.badge-medium {
    background: #fef3c7;
    color: #92400e;
}

.badge-low {
    background: #fee2e2;
    color: #991b1b;
}

.badge-champion {
    background: #dcfce7;
    color: #166534;
}

.badge-brand-builder {
    background: #dbeafe;
    color: #1e40af;
}

.badge-closer {
    background: #fef3c7;
    color: #92400e;
}

.badge-underperformer {
    background: #fee2e2;
    color: #991b1b;
}

/* =============================================================================
   INSIGHT BOXES
   ============================================================================= */
.insight-box {
    padding: 16px;
    border-radius: 12px;
    border-left: 4px solid;
    margin: 16px 0;
}

.insight-box.info {
    background: #eff6ff;
    border-color: #3b82f6;
}

.insight-box.warning {
    background: #fffbeb;
    border-color: #f59e0b;
}

.insight-box.success {
    background: #ecfdf5;
    border-color: var(--green);
}

.insight-box.error {
    background: #fef2f2;
    border-color: var(--red);
}

.insight-title {
    font-weight: 600;
    margin-bottom: 4px;
}

.insight-box.info .insight-title { color: #1e40af; }
.insight-box.warning .insight-title { color: #92400e; }
.insight-box.success .insight-title { color: #065f46; }
.insight-box.error .insight-title { color: #991b1b; }

.insight-text {
    font-size: 14px;
}

.insight-box.info .insight-text { color: #1e40af; }
.insight-box.warning .insight-text { color: #92400e; }
.insight-box.success .insight-text { color: #065f46; }
.insight-box.error .insight-text { color: #991b1b; }

/* =============================================================================
   PATH STYLING
   ============================================================================= */
.path-row {
    display: flex;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid #f3f4f6;
}

.path-row:hover {
    background: #f9fafb;
}

.channel-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border-radius: 16px;
    font-size: 11px;
    font-weight: 600;
    margin: 0 3px;
    border: 1.5px solid;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    transition: all 0.15s ease;
    white-space: nowrap;
}

.channel-tag:hover {
    transform: translateY(-1px);
    box-shadow: 0 3px 6px rgba(0,0,0,0.1);
}

.channel-tag .pct {
    font-size: 9px;
    font-weight: 500;
    opacity: 0.75;
    padding: 1px 5px;
    border-radius: 8px;
    background: rgba(255,255,255,0.5);
}

.path-arrow {
    color: #9ca3af;
    margin: 0 2px;
    font-size: 10px;
}

.path-start {
    color: #6b7280;
    font-size: 10px;
    font-weight: 500;
    padding: 3px 8px;
    background: #f3f4f6;
    border-radius: 12px;
}

.path-conv {
    color: #166534;
    font-size: 10px;
    font-weight: 600;
    padding: 3px 8px;
    background: #dcfce7;
    border-radius: 12px;
}

/* =============================================================================
   NAVBAR
   ============================================================================= */
.navbar {
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 100100;
    pointer-events: auto;
}

.navbar-brand {
    font-weight: 700;
    font-size: 1.25rem;
}

.navbar .nav-link.active {
    color: var(--azzurro) !important;
    font-weight: 700 !important;
}

/* =============================================================================
   BUTTONS
   ============================================================================= */
.btn-primary {
    background: linear-gradient(135deg, #1949ff 0%, #0a2fd6 100%);
    border: none;
}

.btn-primary:hover {
    background: linear-gradient(135deg, #0a2fd6 0%, #081eb0 100%);
}

/* =============================================================================
   COLLAPSE TOGGLE
   ============================================================================= */
.collapse-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    cursor: pointer;
    margin-bottom: 8px;
    transition: all 0.2s ease;
}

.collapse-toggle:hover {
    background: #f9fafb;
    border-color: var(--azzurro);
}

.collapse-toggle.expanded {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    margin-bottom: 0;
    border-color: var(--azzurro);
}

.collapse-toggle h5 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: #111827;
}

.collapse-icon {
    font-size: 14px;
    color: var(--azzurro);
    transition: transform 0.2s ease;
}

.collapse-toggle.expanded .collapse-icon {
    transform: rotate(180deg);
}

.collapse-content {
    background: white;
    border: 1px solid var(--azzurro);
    border-top: none;
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
    padding: 24px;
    margin-bottom: 16px;
}

/* =============================================================================
   DROPDOWNS
   ============================================================================= */
.Select-control {
    border-radius: 6px !important;
}

/* =============================================================================
   TABLES / AG GRID STYLING
   ============================================================================= */
.ag-theme-alpine {
    --ag-header-background-color: var(--azzurro);
    --ag-header-foreground-color: white;
    --ag-font-family: var(--font-family);
    --ag-font-size: 13px;
    --ag-row-height: 40px;
    --ag-header-height: 44px;
    --ag-borders: solid 1px #e5e7eb;
    --ag-border-color: #e5e7eb;
    --ag-odd-row-background-color: #f9fafb;
    --ag-row-hover-color: #eff6ff;
    --ag-selected-row-background-color: #dbeafe;
    --ag-range-selection-background-color: rgba(25, 73, 255, 0.1);
    --ag-header-column-separator-display: block;
    --ag-header-column-separator-color: rgba(255,255,255,0.3);
    border-radius: 8px;
    overflow: hidden;
}

.ag-theme-alpine .ag-header-cell {
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: left !important;
    color: white !important;
}

.ag-theme-alpine .ag-header-cell-label {
    justify-content: flex-start !important;
    color: white !important;
}

.ag-theme-alpine .ag-cell {
    display: flex;
    align-items: center;
}

.ag-theme-alpine .ag-paging-panel {
    border-top: 1px solid #e5e7eb;
    background: #f9fafb;
    font-size: 12px;
}

.score-neg {
    background-color: #c0392b;
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
}

.score-pos {
    background-color: #20863e;
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
}

/* =============================================================================
   FRESHNESS WIDGET
   ============================================================================= */
.freshness-widget {
    background: #f9fafb;
    border-radius: 8px;
    padding: 12px;
}

.freshness-title {
    font-size: 12px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 8px;
}

.freshness-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    font-size: 12px;
}

.freshness-source {
    color: var(--gray);
}

.freshness-time.ok {
    color: var(--green);
}

.freshness-time.warning {
    color: var(--orange-amber);
}

/* =============================================================================
   FLOATING CHAT
   ============================================================================= */
#floating-chat-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
}

/* =============================================================================
   HEADER
   ============================================================================= */
.page-header {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    margin-bottom: 50px;
}

.page-header img {
    height: 50px;
}

.page-header h1 {
    margin: 0;
    font-size: 2.6rem;
    color: var(--azzurro);
}

/* =============================================================================
   SIDEBAR
   ============================================================================= */
.sidebar-panel {
    position: fixed;
    left: 0;
    top: 70px;
    width: 280px;
    height: calc(100vh - 70px);
    background: white;
    border-right: 1px solid #e5e7eb;
    padding: 20px;
    overflow-y: auto;
    transition: transform 0.3s ease;
    z-index: 100;
    box-shadow: 2px 0 5px rgba(0,0,0,0.05);
    /* Hide scrollbar but keep scroll functional */
    scrollbar-width: none;          /* Firefox */
    -ms-overflow-style: none;       /* IE/Edge */
}
.sidebar-panel::-webkit-scrollbar {
    display: none;                  /* Chrome/Safari */
}

/* When sidebar is translated off-screen, hide overflow + visibility
   to prevent scrollbar ghost at viewport edge (all pages) */
[id$="-sidebar-panel"][style*="translateX(-100%)"] {
    overflow: hidden !important;
    visibility: hidden;
}

.sidebar-open-btn {
    position: fixed;
    left: 10px;
    top: 80px;
    z-index: 99;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 8px 12px;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: all 0.2s ease;
}

/* Align ALL hamburger buttons with page H1 title (overrides inline styles) */
body #main-content #sidebar-open-btn,
body #main-content [id$="-sidebar-open-btn"],
#sidebar-open-btn[style],
[id$="-sidebar-open-btn"][style] {
    top: 80px !important;
    position: fixed !important;
    font-size: 20px !important;
    padding: 8px 12px !important;
    border-radius: 8px !important;
    line-height: 1 !important;
}

.sidebar-open-btn:hover {
    background: #f3f4f6;
    border-color: var(--azzurro);
}

/* Date picker styling */
.DateInput {
    width: 100% !important;
}

.DateInput_input {
    font-size: 14px !important;
    padding: 8px 12px !important;
    border-radius: 6px !important;
}

.SingleDatePicker {
    display: block !important;
}

.SingleDatePickerInput {
    border-radius: 6px !important;
    border-color: #e5e7eb !important;
    width: 100% !important;
}

.dash-date-picker-full .SingleDatePicker,
.dash-date-picker-full .SingleDatePickerInput {
    width: 100% !important;
}

.dash-date-picker-full .DateInput {
    width: 100% !important;
}

.dash-date-picker-full .DateInput_input {
    width: 100% !important;
    padding: 8px 12px !important;
    font-size: 14px !important;
}

/* =============================================================================
   SKELETON LOADER
   ============================================================================= */
@keyframes skeleton-pulse {
    0%   { opacity: 1; }
    50%  { opacity: 0.4; }
    100% { opacity: 1; }
}

.skeleton {
    background: #e5e7eb;
    border-radius: 8px;
    animation: skeleton-pulse 1.5s ease-in-out infinite;
}

.skeleton-kpi {
    height: 120px;
    border-radius: 16px;
    border-left: 4px solid #d1d5db;
}

.skeleton-chart {
    height: 320px;
    border-radius: 16px;
}

.skeleton-table {
    height: 200px;
    border-radius: 16px;
}

.skeleton-text {
    height: 16px;
    width: 60%;
    margin-bottom: 8px;
}

.skeleton-text-short {
    height: 16px;
    width: 35%;
}

/* dcc.Loading spinner custom — no min-height to prevent layout shifts during callback
   cascades (e.g. MMM page fires 15+ callbacks on load, each adding/removing this class
   causes intermittent trembling). Skeleton placeholders handle loading state instead. */
._dash-loading-callback {
    min-height: 0;
}

.dash-spinner.dash-default-spinner {
    border-color: var(--arancione) !important;
    border-top-color: transparent !important;
}

/* =============================================================================
   RESPONSIVE
   ============================================================================= */
/* =============================================================================
   ACCESSIBILITY
   ============================================================================= */
/* Visible focus ring for keyboard navigation */
*:focus-visible {
    outline: 2px solid var(--arancione);
    outline-offset: 2px;
    border-radius: 4px;
}

/* Hide focus ring for mouse clicks */
*:focus:not(:focus-visible) {
    outline: none;
}

/* Skip to main content link (screen readers + keyboard) */
.skip-to-main {
    position: absolute;
    top: -100px;
    left: 0;
    padding: 12px 24px;
    background: var(--arancione);
    color: white;
    font-weight: 600;
    z-index: 9999;
    transition: top 0.2s;
}

.skip-to-main:focus {
    top: 0;
}

/* High contrast mode support */
@media (forced-colors: active) {
    .kpi-card {
        border: 2px solid;
    }
    .badge {
        border: 1px solid;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .skeleton,
    .channel-tag,
    .collapse-icon,
    .sidebar-panel {
        animation: none !important;
        transition: none !important;
    }
}

/* =============================================================================
   RESPONSIVE
   ============================================================================= */
@media (max-width: 768px) {
    .kpi-card {
        padding: 16px;
        min-height: 100px;
    }

    .kpi-value {
        font-size: 24px;
    }

    .page-header h1 {
        font-size: 1.5rem;
    }
}

/* =============================================================================
   FIP / DSL PAGE
   ============================================================================= */

/* OPS card fade-in */
@keyframes ops-fade-in {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.ops-card {
    animation: ops-fade-in 0.4s ease-out;
}

/* STABLE state celebration */
.ops-stable-card {
    background: linear-gradient(90deg, rgba(236,253,245,0.3) 0%, white 40%) !important;
}

/* Risk banner pulse for critical/emergency */
@keyframes risk-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.15); }
    50%      { box-shadow: 0 0 0 8px rgba(220, 38, 38, 0); }
}
.risk-banner-critical {
    animation: risk-pulse 2s ease-in-out infinite;
}

/* Observer agent cards */
.observer-agent-card {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.observer-agent-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

/* Impact chain responsive */
.impact-chain-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
    padding: 10px 0;
}

/* AG-Grid selected row */
.ag-theme-alpine .ag-row-selected {
    background-color: #dbeafe !important;
    border-left: 3px solid var(--azzurro);
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .ops-card,
    .risk-banner-critical,
    .observer-agent-card {
        animation: none !important;
        transition: none !important;
    }
}

/* Lifecycle pipeline */
.lifecycle-pipeline {
    flex-wrap: wrap;
    gap: 4px;
}

/* FIP utility classes */
.fip-section-header {
    font-weight: 600;
    color: #111827;
    margin-bottom: 4px;
}
.fip-badge-status {
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 4px;
    text-transform: uppercase;
}
.fip-timestamp {
    font-size: 11px;
    color: var(--gray);
    font-family: monospace;
}

/* Mobile responsive */
@media (max-width: 768px) {
    .impact-chain-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    .impact-chain-row .impact-arrow {
        transform: rotate(90deg);
    }
    .lifecycle-pipeline {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    .lifecycle-pipeline > div {
        min-width: 48px;
        font-size: 12px;
    }
    .ag-theme-alpine {
        --ag-row-height: 48px;
        --ag-font-size: 14px;
    }
}

/* =============================================================================
   FOOTER
   ============================================================================= */
#app-footer a:hover {
    color: var(--arancione) !important;
}

/* =============================================================================
   PAGE LOAD ANIMATIONS (global - applies to ALL pages)
   ============================================================================= */
@keyframes fadeInPage {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Smooth fade-in for all page content - professional look */
#main-content > div {
    animation: fadeInPage 0.5s ease-out forwards;
}
