/**
 * app.css — Estilos compartilhados do Sistema MRP/PCP
 * Variáveis de cor, sidebar, navegação, KPI cards, scrollbar, animações.
 * Incluir em todas as páginas: <link rel="stylesheet" href="/app.css">
 */

/* ─── Tailwind CDN v3 ──────────────────────────────────────────────────────── */
/* Carregado separadamente via <script src="https://cdn.tailwindcss.com"> */

/* ─── Design Tokens ────────────────────────────────────────────────────────── */

:root {
    --color-bg-dark: #1a2332;
    --color-bg-light: #2d3f5c;
    --color-text-main: #e2e8f0;
    --color-text-secondary: #94a3b8;
    --color-accent: #3b82f6;
    --color-accent-dark: #2563eb;
    --color-success: #10b981;
    --color-success-dark: #059669;
    --color-warning: #f59e0b;
    --color-error: #ef4444;
    --color-error-dark: #dc2626;
    --color-gantt-order: #3b82f6;
    --color-gantt-stock: #10b981;
    --color-gantt-old: #F39C12;
    --color-gantt-new: #ef4444;
}

/* ─── Base ──────────────────────────────────────────────────────────────────── */

body {
    background-color: var(--color-bg-dark);
    color: var(--color-text-main);
}

/* ─── Utility classes (CSS var-based, complementam Tailwind) ───────────────── */

.bg-primary-light,
.bg-panel {
    background-color: var(--color-bg-light);
}

.text-main {
    color: var(--color-text-main);
}

.text-secondary {
    color: var(--color-text-secondary);
}

.text-accent {
    color: var(--color-accent);
}

.border-accent {
    border-color: var(--color-accent);
}

.bg-accent {
    background-color: var(--color-accent);
}

.hover\:bg-accent-dark:hover {
    background-color: var(--color-accent-dark);
}

.bg-success {
    background-color: var(--color-success);
}

.hover\:bg-success-dark:hover {
    background-color: var(--color-success-dark);
}

.bg-error {
    background-color: var(--color-error);
}

.hover\:bg-error-dark:hover {
    background-color: var(--color-error-dark);
}

.bg-warning {
    background-color: var(--color-warning);
}

/* ─── Sidebar ──────────────────────────────────────────────────────────────── */

.sidebar {
    transition: transform 0.3s ease-in-out;
    background: linear-gradient(180deg, #0f172a 0%, #1a2332 40%, #0f172a 100%);
    border-right: 1px solid rgba(59, 130, 246, 0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-collapsed {
    transform: translateX(-100%);
}

/* ─── Sidebar Toggle Button ────────────────────────────────────────────────── */

.sidebar-toggle-btn {
    position: fixed;
    top: 16px;
    left: 248px; /* w-64 = 256px, button centered on edge */
    z-index: 50;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid rgba(59, 130, 246, 0.2);
    background: #1e293b;
    color: rgba(148, 163, 184, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.65rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.sidebar-toggle-btn:hover {
    background: var(--color-accent);
    color: white;
    border-color: var(--color-accent);
    transform: scale(1.1);
    box-shadow: 0 2px 12px rgba(59, 130, 246, 0.3);
}

.sidebar-collapsed ~ .sidebar-toggle-btn,
.sidebar-toggle-btn.collapsed {
    left: 8px;
    background: rgba(30, 41, 59, 0.95);
    border-color: rgba(59, 130, 246, 0.15);
}

/* Sidebar Header / Brand */
.sidebar-header {
    padding: 20px 20px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: linear-gradient(135deg, #3b82f6 0%, #6366f1 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    color: white;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
    flex-shrink: 0;
}

.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.brand-name {
    font-size: 1.05rem;
    font-weight: 800;
    color: white;
    letter-spacing: 0.5px;
}

.brand-sub {
    font-size: 0.65rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    letter-spacing: 1.5px;
    text-transform: uppercase;
}

/* Sidebar Navigation Container */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
    scrollbar-width: thin;
    scrollbar-color: rgba(59, 130, 246, 0.15) transparent;
}

.sidebar-nav::-webkit-scrollbar { width: 3px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(59, 130, 246, 0.2); border-radius: 10px; }

/* Nav Groups */
.nav-group {
    margin-bottom: 6px;
}

.nav-group-label {
    display: block;
    font-size: 0.6rem;
    font-weight: 700;
    color: rgba(148, 163, 184, 0.5);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    padding: 12px 12px 6px;
    user-select: none;
}

/* ─── Navigation Items ─────────────────────────────────────────────────────── */

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 8px;
    color: rgba(203, 213, 225, 0.75);
    font-size: 0.82rem;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.15s ease;
    position: relative;
    margin-bottom: 1px;
}

.nav-item i {
    width: 18px;
    text-align: center;
    font-size: 0.8rem;
    opacity: 0.7;
    flex-shrink: 0;
    transition: opacity 0.15s ease;
}

.nav-item span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-item:hover {
    background: rgba(59, 130, 246, 0.08);
    color: rgba(219, 234, 254, 0.95);
}

.nav-item:hover i {
    opacity: 1;
}

.nav-item.active {
    background: rgba(59, 130, 246, 0.12);
    color: white;
    font-weight: 600;
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 20px;
    border-radius: 0 3px 3px 0;
    background: var(--color-accent);
}

.nav-item.active i {
    opacity: 1;
    color: var(--color-accent);
}

/* AI special nav item */
.nav-item-ai {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.08) 0%, rgba(59, 130, 246, 0.08) 100%);
    border: 1px solid rgba(99, 102, 241, 0.1);
}

.nav-item-ai:hover {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.15) 0%, rgba(59, 130, 246, 0.15) 100%);
    border-color: rgba(99, 102, 241, 0.2);
}

.nav-item-ai i {
    color: #a78bfa;
    opacity: 1;
}

.nav-badge {
    font-size: 0.55rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(99, 102, 241, 0.2);
    color: #a78bfa;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    margin-left: auto;
    flex-shrink: 0;
}

/* Sidebar Footer / User */
.sidebar-footer {
    padding: 10px 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.04);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    border-radius: 10px;
    transition: background 0.15s;
}

.sidebar-user:hover {
    background: rgba(255, 255, 255, 0.03);
}

.sidebar-user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: #64748b;
    font-size: 0.7rem;
}

.sidebar-user-details {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.sidebar-user-name {
    font-size: 0.75rem;
    font-weight: 600;
    color: #cbd5e1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-version {
    font-size: 0.6rem;
    color: rgba(148, 163, 184, 0.35);
    letter-spacing: 0.5px;
}

.sidebar-logout-btn {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: #475569;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s;
    flex-shrink: 0;
    font-size: 0.75rem;
}

.sidebar-logout-btn:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

/* ─── KPI Cards ────────────────────────────────────────────────────────────── */

.kpi-card,
.kpi-card-blue {
    background: var(--color-accent);
}

.kpi-card-green {
    background: var(--color-success);
}

.kpi-card-red {
    background: var(--color-error);
}

.kpi-card-yellow {
    background: var(--color-warning);
}

.kpi-card-teal {
    background: #1ABC9C;
}

/* ─── Tabs & Steps ─────────────────────────────────────────────────────────── */

.tab-button {
    transition: all 0.3s ease;
}

.tab-button.active {
    background-color: var(--color-accent);
    color: white;
}

.step-indicator {
    transition: all 0.3s ease;
}

.step-indicator.active {
    background-color: var(--color-accent);
    color: white;
}

.step-indicator.completed {
    background-color: var(--color-success);
    color: white;
}

/* ─── Gantt Chart (dark theme overrides) ───────────────────────────────────── */

.gantt-container {
    overflow-x: auto;
    max-height: 500px;
}

.gantt .bar-order .bar {
    fill: var(--color-gantt-order);
}

.gantt .bar-stock .bar {
    fill: var(--color-gantt-stock);
}

.gantt .bar-comparison-old .bar {
    fill: var(--color-gantt-old);
}

.gantt .bar-comparison-new .bar {
    fill: var(--color-gantt-new);
}

.gantt .bar-order .bar-progress,
.gantt .bar-stock .bar-progress,
.gantt .bar-comparison-old .bar-progress,
.gantt .bar-comparison-new .bar-progress {
    fill: rgba(0, 0, 0, 0.25);
}

.gantt .grid-header text {
    fill: var(--color-text-main) !important;
    font-weight: 500;
}

.gantt .grid-header .upper-text {
    fill: var(--color-text-main) !important;
    font-size: 14px;
}

.gantt .grid-header .lower-text {
    fill: var(--color-text-secondary) !important;
    font-size: 12px;
}

.gantt .grid-background {
    fill: rgba(0, 0, 0, 0.5) !important;
}

.gantt .tick,
.gantt .grid-horizontal-line {
    stroke: #4a4a4a;
}

.gantt .grid-row {
    fill: transparent !important;
}

.gantt .bar-label {
    fill: #ffffff !important;
    font-weight: 500;
}

/* ─── Scrollbar (custom) ───────────────────────────────────────────────────── */

.gantt-container::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.gantt-container::-webkit-scrollbar-track {
    background: transparent;
}

.gantt-container::-webkit-scrollbar-thumb {
    background-color: rgba(74, 74, 74, 0.7);
    border-radius: 10px;
}

.gantt-container::-webkit-scrollbar-thumb:hover {
    background-color: rgba(120, 120, 120, 0.8);
}

#ai-chat-messages::-webkit-scrollbar {
    width: 6px;
}

#ai-chat-messages::-webkit-scrollbar-track {
    background: var(--color-bg-light);
    border-radius: 10px;
}

#ai-chat-messages::-webkit-scrollbar-thumb {
    background-color: var(--color-accent);
    border-radius: 10px;
}

#ai-chat-messages::-webkit-scrollbar-thumb:hover {
    background-color: var(--color-accent-dark);
}

/* ─── Highlight & Drag ─────────────────────────────────────────────────────── */

.highlight-produto {
    background-color: rgba(52, 152, 219, 0.3) !important;
}

.mold-row[draggable="true"] {
    cursor: grab;
}

.mold-row.dragging {
    opacity: 0.4;
    background: var(--color-accent-dark);
}

.arm-card.drag-over {
    border: 2px dashed var(--color-accent);
    background-color: rgba(52, 152, 219, 0.1);
}

/* ─── Loading Bar ──────────────────────────────────────────────────────────── */

#top-loading-bar {
    background-color: rgba(46, 204, 113, 0.2);
    overflow: hidden;
}

.loading-bar-progress {
    height: 100%;
    width: 100%;
    background: linear-gradient(to right, transparent, var(--color-success), transparent);
    animation: loading-animation 1.5s linear infinite;
}

@keyframes loading-animation {
    from {
        transform: translateX(-100%);
    }

    to {
        transform: translateX(100%);
    }
}

/* ─── Focus visible (acessibilidade) ───────────────────────────────────────── */

:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

/* ─── Skip to content (acessibilidade) ─────────────────────────────────────── */

.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--color-accent);
    color: white;
    padding: 8px 16px;
    z-index: 100;
    transition: top 0.3s;
}

.skip-link:focus {
    top: 0;
}

/* ─── Page Transition Overlay ──────────────────────────────────────────────── */

#page-transition-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(15, 23, 42, 0.92);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease, visibility 0.15s ease;
    pointer-events: none;
}

#page-transition-overlay.active {
    opacity: 1;
    visibility: visible;
    pointer-events: all;
}

.transition-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.spinner-ring {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(59, 130, 246, 0.15);
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin-ring 0.8s linear infinite;
}

@keyframes spin-ring {
    to { transform: rotate(360deg); }
}

.spinner-text {
    color: rgba(148, 163, 184, 0.7);
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.5px;
}
