/* 
============================================================
   OTIF DASHBOARD — Design System
   Aesthetics: Premium, Dark Mode, Glassmorphism
============================================================
*/

:root {
    color-scheme: dark;
    --bg-dark: #090d16;
    --card-bg: rgba(15, 23, 42, 0.72);
    --card-border: rgba(255, 255, 255, 0.08);
    --card-hover-border: rgba(56, 189, 248, 0.3);
    --primary: #38bdf8;
    --primary-glow: rgba(56, 189, 248, 0.15);
    --secondary: #818cf8;
    --accent: #f472b6;
    --success: #4ade80;
    --warning: #fbbf24;
    --danger: #f87171;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --glass-border: rgba(255, 255, 255, 0.08);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.05);
    --shadow-elevated: 0 20px 40px -15px rgba(0, 0, 0, 0.7), 0 0 20px rgba(56, 189, 248, 0.15);
}

body.light-mode {
    color-scheme: light;
    --bg-dark: #f8fafc;
    --card-bg: rgba(255, 255, 255, 0.88);
    --card-border: rgba(0, 0, 0, 0.08);
    --card-hover-border: rgba(2, 132, 199, 0.3);
    --text-main: #0f172a;
    --text-muted: #64748b;
    --glass-border: rgba(0, 0, 0, 0.08);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04);
    --shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.08), 0 0 0 1px rgba(0, 0, 0, 0.05);
    --shadow-elevated: 0 20px 35px -10px rgba(0, 0, 0, 0.12);
    --primary: #0284c7;
    --secondary: #4f46e5;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    hyphens: none;
    -webkit-hyphens: none;
    word-break: normal;
    overflow-wrap: break-word;
    transition: background-color 0.25s ease, color 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

body {
    background-color: var(--bg-dark);
    background-image: 
        radial-gradient(ellipse 80% 50% at 50% -20%, rgba(56, 189, 248, 0.12), transparent),
        radial-gradient(ellipse 60% 40% at 100% 100%, rgba(129, 140, 248, 0.08), transparent),
        linear-gradient(to right, rgba(255, 255, 255, 0.02) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
    background-size: 100% 100%, 100% 100%, 48px 48px, 48px 48px;
    background-position: 0 0, 0 0, -1px -1px, -1px -1px;
    color: var(--text-main);
    min-height: 100vh;
}

body.light-mode {
    background-image: 
        radial-gradient(ellipse 80% 50% at 50% -20%, rgba(2, 132, 199, 0.08), transparent),
        linear-gradient(to right, rgba(0, 0, 0, 0.03) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(0, 0, 0, 0.03) 1px, transparent 1px);
    background-size: 100% 100%, 48px 48px, 48px 48px;
}

/* ── Layout ── */
.container {
    max-width: 100%;
    width: 100%;
    margin: 0 auto;
    padding: 1.25rem 1.5rem;
}

/* ── Sticky Header Area ── */
.sticky-top-area {
    position: sticky;
    top: 0;
    z-index: 999;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    margin: -1.5rem -1rem 1rem -1rem;
    padding: 1.5rem 1rem 1rem 1rem;
    border-bottom: 1px solid var(--glass-border);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

body.light-mode .sticky-top-area {
    background: rgba(241, 245, 249, 0.95);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    animation: fadeInDown 0.8s ease-out;
}

.logo-area h1 {
    font-size: 2rem;
    font-weight: 800;
    background: linear-gradient(to right, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -1px;
}

.logo-area p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* ── KPI Cards ── */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.25rem;
    margin-bottom: 2.5rem;
}

.kpi-card {
    background: var(--card-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--card-border);
    border-radius: 18px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.25s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.25s ease;
    position: relative;
    overflow: visible;
    animation: fadeInUpStagger 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    opacity: 0;
}

.kpi-card:nth-child(1) { animation-delay: 0.05s; }
.kpi-card:nth-child(2) { animation-delay: 0.12s; }
.kpi-card:nth-child(3) { animation-delay: 0.19s; }
.kpi-card:nth-child(4) { animation-delay: 0.26s; }

.kpi-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-elevated);
    border-color: var(--card-hover-border);
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: linear-gradient(to bottom, var(--primary), var(--secondary));
    border-top-left-radius: 18px;
    border-bottom-left-radius: 18px;
}

.kpi-icon {
    font-size: 1.4rem;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: rgba(56, 189, 248, 0.1);
    color: var(--primary);
    border: 1px solid rgba(56, 189, 248, 0.2);
}

.kpi-label {
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 0.25rem;
}

.kpi-value {
    font-size: clamp(1.8rem, 2.2vw, 2.4rem);
    font-weight: 800;
    letter-spacing: -0.02em;
    margin-top: 0.25rem;
    line-height: 1.1;
}

/* ── Data Table Area ── */
.data-section {
    background: var(--card-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--card-border);
    border-radius: 20px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    animation: fadeInUpStagger 0.6s cubic-bezier(0.16, 1, 0.3, 1) 0.3s forwards;
    opacity: 0;
    transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.data-section:hover {
    border-color: rgba(255, 255, 255, 0.12);
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--glass-border);
}

.section-title h2 {
    font-size: 1.25rem;
    font-weight: 700;
}

.table-container {
    overflow-x: auto;
    max-height: 600px;
    overflow-y: auto;
}

table {
    width: 100%;
    border-collapse: separate; /* Required for sticky borders */
    border-spacing: 0;
    text-align: left;
}

th {
    position: sticky;
    top: 0;
    z-index: 100;
    background-color: #1e293b; /* Fallback solid color */
    background: var(--bg-dark);
    padding: 0.75rem 0.5rem;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
    border-bottom: 2px solid var(--glass-border);
}

/* Sticky adjustment for the CATEGORY row (first row) */
thead tr:first-child th {
    top: 0;
    z-index: 101;
    font-size: 0.8rem;
    letter-spacing: 2px;
    padding: 10px;
}

/* Sticky adjustment for the COLUMN NAME row (second row) */
thead tr:last-child th {
    top: 41px; /* Height of the first row */
    z-index: 100;
    border-bottom: 1px solid var(--glass-border);
    background: var(--bg-dark);
}

td {
    padding: 0.75rem 0.6rem;
    border-bottom: 1px solid var(--glass-border);
    font-size: 0.85rem;
    hyphens: none;
    -webkit-hyphens: none;
    word-break: normal;
    white-space: nowrap;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background: rgba(255, 255, 255, 0.04);
}

/* ── Badges ── */
.badge {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-telecontro { background: rgba(56, 189, 248, 0.2); color: var(--primary); }
.badge-sap { background: rgba(129, 140, 248, 0.2); color: var(--secondary); }
.badge-expedicao { background: rgba(74, 222, 128, 0.2); color: var(--success); }
.badge-warning { background: rgba(251, 191, 36, 0.2); color: var(--warning); }
.badge-bonif { background: rgba(244, 114, 182, 0.2); color: var(--accent); border: 1px solid rgba(244, 114, 182, 0.3); }

/* ── Buttons ── */
.btn {
    padding: 10px 20px;
    border-radius: 12px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(to right, var(--primary), var(--secondary));
    color: white;
}

.btn-primary:hover {
    transform: scale(1.05);
    box-shadow: 0 0 20px rgba(56, 189, 248, 0.4);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--glass-border);
    color: var(--text-main);
}

.btn-outline:hover {
    background: var(--glass-border);
}

/* ── Animations ── */
@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-16px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInUpStagger {
    from { 
        opacity: 0; 
        transform: translateY(20px) scale(0.99); 
    }
    to { 
        opacity: 1; 
        transform: translateY(0) scale(1); 
    }
}

/* ── Respeito a prefers-reduced-motion ── */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    .kpi-card,
    .data-section,
    header {
        animation: none !important;
        opacity: 1 !important;
        transform: none !important;
    }
    .kpi-card:hover,
    .sector-card:hover,
    .calendar-day-pill:hover,
    .btn-primary:hover {
        transform: none !important;
    }
}

/* ── Loading State ── */
.loader {
    width: 24px;
    height: 24px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top: 3px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ── Responsive ── */
@media (max-width: 768px) {
    .container { padding: 1rem; }
    header { flex-direction: column; align-items: flex-start; gap: 1rem; }
    .kpi-grid { grid-template-columns: 1fr; }
}

/* ── Premium Tooltips ── */
[data-tooltip] {
    position: relative;
}

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%) translateY(6px);
    background: rgba(10, 15, 29, 0.96);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #f8fafc;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 0.75rem;
    line-height: 1.45;
    font-weight: 500;
    width: 280px;
    text-align: left;
    white-space: normal;
    hyphens: none;
    word-break: normal;
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.7), 0 0 1px rgba(255, 255, 255, 0.2);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s cubic-bezier(0.16, 1, 0.3, 1), transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 9999;
}

[data-tooltip]:hover::after {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Tooltip arrow */
[data-tooltip]::before {
    content: '';
    position: absolute;
    bottom: 115%;
    left: 50%;
    transform: translateX(-50%) translateY(8px);
    border-width: 6px 6px 0;
    border-style: solid;
    border-color: rgba(15, 23, 42, 0.95) transparent transparent;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s cubic-bezier(0.4, 0, 0.2, 1), transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 9999;
}

[data-tooltip]:hover::before {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Premium Tooltip Adjustments for Right Edge Elements */
.tooltip-right-edge[data-tooltip]::after {
    left: auto;
    right: -10px;
    transform: translateY(8px);
}

.tooltip-right-edge[data-tooltip]:hover::after {
    transform: translateY(0);
}

.tooltip-right-edge[data-tooltip]::before {
    left: auto;
    right: 2px;
    transform: translateY(8px);
}

.tooltip-right-edge[data-tooltip]:hover::before {
    transform: translateY(0);
}

/* ── Painel de Performance dos Setores (Option A - Grouped Flow) ── */
.process-flow-container {
    display: flex;
    align-items: stretch;
    gap: 0.5rem;
    width: 100%;
}

.flow-group {
    background: rgba(15, 23, 42, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: 20px;
    padding: 0.8rem 1rem 1rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    transition: all 0.3s ease;
}

.flow-group:hover {
    background: rgba(15, 23, 42, 0.35);
    border-color: rgba(255, 255, 255, 0.08);
}

.group-approvals {
    flex: 3;
}

.group-logistics {
    flex: 1;
}

.group-result {
    flex: 1;
}

.flow-group-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 6px;
}

.flow-group-cards {
    display: grid;
    gap: 0.8rem;
    height: 100%;
}

.group-approvals .flow-group-cards {
    grid-template-columns: repeat(5, 1fr);
}

.flow-connector {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 0.2rem;
}

@media (max-width: 1200px) {
    .process-flow-container {
        flex-direction: column;
        gap: 1rem;
    }
    .flow-connector {
        transform: rotate(90deg);
        padding: 0.5rem 0;
    }
    .group-approvals .flow-group-cards {
        grid-template-columns: 1fr;
    }
}

.sector-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 1.2rem;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.25s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.25s ease;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: var(--shadow-sm);
}

.sector-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    opacity: 0.9;
}

.sector-card.color-comercial::before {
    background: linear-gradient(90deg, #0ea5e9, #0284c7);
}
.sector-card.color-diretoria::before {
    background: linear-gradient(90deg, #fbbf24, #d97706);
}
.sector-card.color-financeiro::before {
    background: linear-gradient(90deg, #f97316, #ea580c);
}
.sector-card.color-faturamento::before {
    background: linear-gradient(90deg, #22c55e, #16a34a);
}

.sector-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-elevated);
    border-color: var(--card-hover-border);
}

.sector-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.sector-title {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-main);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.sector-sla-badge {
    font-size: 0.6rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 20px;
    text-transform: uppercase;
}

.sector-sla-badge.sla-ok {
    background: rgba(34, 197, 94, 0.15);
    color: #4ade80;
    border: 1px solid rgba(34, 197, 94, 0.3);
}

.sector-sla-badge.sla-warning {
    background: rgba(251, 191, 36, 0.15);
    color: #fbbf24;
    border: 1px solid rgba(251, 191, 36, 0.3);
}

.sector-sla-badge.sla-danger {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.sector-time {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--text-main);
    letter-spacing: -0.5px;
    margin: 0.2rem 0;
    transition: all 0.3s ease;
}

.sector-progress-bg {
    width: 100%;
    height: 8px;
    background: rgba(15, 23, 42, 0.6);
    border-radius: 10px;
    overflow: hidden;
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.sector-progress-bar {
    height: 100%;
    width: 0%;
    border-radius: 10px;
    transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

.bar-comercial {
    background: linear-gradient(90deg, #0ea5e9, #0284c7);
    box-shadow: 0 0 8px rgba(14, 165, 233, 0.5);
}

.bar-gerente {
    background: linear-gradient(90deg, #a855f7, #7c3aed);
    box-shadow: 0 0 8px rgba(168, 85, 247, 0.5);
}

.bar-diretoria {
    background: linear-gradient(90deg, #fbbf24, #d97706);
    box-shadow: 0 0 8px rgba(251, 191, 36, 0.5);
}

.bar-financeiro {
    background: linear-gradient(90deg, #f97316, #ea580c);
    box-shadow: 0 0 8px rgba(249, 115, 22, 0.5);
}

.bar-faturamento {
    background: linear-gradient(90deg, #22c55e, #16a34a);
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.5);
}

.sector-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.65rem;
    color: var(--text-muted);
}

.sector-status {
    font-weight: 600;
}

.legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.color-comercial .legend-dot {
    background: #0ea5e9;
    box-shadow: 0 0 6px #0ea5e9;
}

.color-gerente .legend-dot {
    background: #a855f7;
    box-shadow: 0 0 6px #a855f7;
}

.color-diretoria .legend-dot {
    background: #fbbf24;
    box-shadow: 0 0 6px #fbbf24;
}

.color-financeiro .legend-dot {
    background: #f97316;
    box-shadow: 0 0 6px #f97316;
}

.color-faturamento .legend-dot {
    background: #22c55e;
    box-shadow: 0 0 6px #22c55e;
}

/* ── Calendário Diário OTIF ── */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(75px, 1fr));
    gap: 10px;
    width: 100%;
}

.calendar-day-pill {
    background: rgba(30, 41, 59, 0.45);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 10px 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.15);
}

.calendar-day-pill:hover {
    transform: translateY(-4px) scale(1.05);
    box-shadow: 0 10px 15px rgba(0, 0, 0, 0.35);
    border-color: rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.05);
}

.calendar-day-num {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 700;
}

.calendar-day-dot {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: 800;
    color: #0f172a;
    box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.2);
}

.calendar-day-dot.status-excellent {
    background: #4ade80;
    box-shadow: 0 0 10px rgba(74, 222, 128, 0.6), inset 0 2px 4px rgba(255, 255, 255, 0.2);
    color: #0f172a;
}

.calendar-day-dot.status-warning {
    background: #fbbf24;
    box-shadow: 0 0 10px rgba(251, 191, 36, 0.6), inset 0 2px 4px rgba(255, 255, 255, 0.2);
    color: #0f172a;
}

.calendar-day-dot.status-critical {
    background: #f87171;
    box-shadow: 0 0 10px rgba(248, 113, 113, 0.6), inset 0 2px 4px rgba(255, 255, 255, 0.2);
    color: #ffffff;
}

.calendar-day-dot.status-nodata {
    background: #475569;
    box-shadow: none;
    color: #94a3b8;
}

/* Premium Card hover style adjust */
.premium-card:hover {
    box-shadow: 0 12px 40px 0 rgba(251, 191, 36, 0.25) !important;
}

/* Responsive Main Charts Row */
@media (max-width: 1024px) {
    .main-charts-row {
        grid-template-columns: 1fr !important;
    }
}
/* ── Dropdown / Select Fixes ── */
select.btn-outline option {
    background-color: var(--bg-dark);
    color: var(--text-main);
}

body.light-mode select.btn-outline option {
    background-color: #ffffff;
    color: #0f172a;
}