@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;700;800&display=swap');

:root {
    --bg-dark: #07090e;
    --surface: rgba(18, 24, 38, 0.65);
    --surface-hover: rgba(28, 38, 60, 0.85);
    --border: rgba(100, 149, 237, 0.15);
    
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    
    --primary: #0ea5e9;
    --primary-glow: rgba(14, 165, 233, 0.4);
    
    --success: #10b981;
    --success-glow: rgba(16, 185, 129, 0.4);
    
    --danger: #f43f5e;
    --danger-glow: rgba(244, 63, 94, 0.4);
    
    --warning: #f59e0b;
    --warning-glow: rgba(245, 158, 11, 0.4);
    
    --info: #8b5cf6;
    --info-glow: rgba(139, 92, 246, 0.4);
    
    --stopped: #475569;
    
    --glass-blur: blur(16px);
    --gradient-bg: linear-gradient(135deg, #07090e 0%, #111827 100%);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
}

body {
    background: var(--gradient-bg);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* TOPBAR */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.7rem 2rem;
    background: var(--surface);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.3);
}

.logo {
    font-size: 1.8rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    background: linear-gradient(90deg, #0ea5e9, #8b5cf6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    display: flex;
    align-items: center;
}

.logo .badge {
    font-size: 0.7rem;
    background: rgba(14, 165, 233, 0.15);
    color: #0ea5e9;
    padding: 0.3rem 0.6rem;
    border-radius: 6px;
    border: 1px solid rgba(14, 165, 233, 0.3);
    margin-left: 0.8rem;
    -webkit-text-fill-color: initial;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.header-info {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.time {
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--primary);
    text-shadow: 0 0 10px var(--primary-glow);
}

/* EXPORT BUTTON */
.btn-export {
    background: linear-gradient(90deg, #0ea5e9, #8b5cf6);
    color: #fff;
    border: none;
    padding: 0.5rem 1.2rem;
    border-radius: 8px;
    font-weight: 700;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(14, 165, 233, 0.3);
}

.btn-export:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(14, 165, 233, 0.5);
    filter: brightness(1.1);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.4rem 1rem 0.4rem 0.4rem;
    background: rgba(255,255,255,0.05);
    border-radius: 30px;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.3s ease;
}

.user-profile:hover {
    background: rgba(255,255,255,0.1);
    box-shadow: 0 0 15px rgba(255,255,255,0.05);
}

.avatar {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, #8b5cf6, #0ea5e9);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    box-shadow: 0 0 10px rgba(139, 92, 246, 0.5);
}

/* DASHBOARD LAYOUT */
.dashboard {
    flex: 1;
    padding: 1.2rem 2rem 2rem 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
}

/* KPI GRID */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.5rem;
}

.kpi-card {
    background: linear-gradient(145deg, var(--surface), rgba(10, 15, 25, 0.8));
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.2rem 1.5rem;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
    overflow: hidden;
}

.kpi-card::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 50%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.05), transparent);
    transform: skewX(-20deg);
    transition: 0.5s;
}

.kpi-card:hover::after {
    left: 150%;
}

.kpi-card:hover {
    transform: translateY(-5px);
    border-color: rgba(14, 165, 233, 0.4);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4), 0 0 15px rgba(14, 165, 233, 0.1);
}

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

.kpi-card .value {
    font-size: 3rem;
    font-weight: 800;
    line-height: 1;
    margin-bottom: 0.5rem;
    background: linear-gradient(to right, #fff, #cbd5e1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.kpi-card .subtext {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

.text-primary { background: linear-gradient(to right, #0ea5e9, #38bdf8) !important; -webkit-background-clip: text !important; -webkit-text-fill-color: transparent !important; }
.text-success { background: linear-gradient(to right, #10b981, #34d399) !important; -webkit-background-clip: text !important; -webkit-text-fill-color: transparent !important; }
.text-danger { background: linear-gradient(to right, #f43f5e, #fb7185) !important; -webkit-background-clip: text !important; -webkit-text-fill-color: transparent !important; }

/* MAIN CONTENT GRID */
.main-content {
    display: grid;
    grid-template-columns: 320px 1fr 400px;
    gap: 2.5rem;
}

h2 {
    font-size: 1.3rem;
    margin-bottom: 1.5rem;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 0.8rem;
    font-weight: 700;
}

h2::before {
    content: '';
    display: block;
    width: 6px;
    height: 24px;
    background: linear-gradient(to bottom, #0ea5e9, #8b5cf6);
    border-radius: 3px;
}

/* LINES SECTION */
.lines-section {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
}

#lines-container {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
}

.line-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    transition: all 0.3s ease;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.2);
}

.line-card:hover {
    border-color: rgba(139, 92, 246, 0.4);
    background: var(--surface-hover);
}

.line-card h4 {
    margin-bottom: 1rem;
    font-size: 1.1rem;
    color: #e2e8f0;
}

.line-stats {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    font-size: 0.95rem;
    color: var(--text-muted);
}

.line-stats span {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0,0,0,0.3);
    padding: 0.5rem 0.8rem;
    border-radius: 6px;
}

/* EVENT LOGS */
.event-log-container {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem;
    height: 320px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    scrollbar-width: thin;
    scrollbar-color: var(--primary) transparent;
}

.event-log-container::-webkit-scrollbar {
    width: 6px;
}

.event-log-container::-webkit-scrollbar-thumb {
    background-color: var(--primary);
    border-radius: 3px;
}

.event-item {
    font-size: 0.8rem;
    padding: 0.6rem 0.8rem;
    border-radius: 6px;
    border-left: 3px solid var(--stopped);
    background: rgba(255,255,255,0.02);
    animation: fadeIn 0.3s ease-out forwards;
}

.event-item.system { border-left-color: var(--info); color: var(--text-main); }
.event-item.produzindo { border-left-color: var(--success); color: #34d399; }
.event-item.falha { border-left-color: var(--danger); color: #fb7185; }
.event-item.manutencao { border-left-color: var(--warning); color: #fbbf24; }
.event-item.setup { border-left-color: var(--primary); color: #38bdf8; }

.event-time {
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-right: 0.5rem;
    font-variant-numeric: tabular-nums;
}

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

/* MACHINES GRID */
.machines-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.8rem;
}

.machine-card {
    background: linear-gradient(145deg, var(--surface), rgba(10, 15, 25, 0.8));
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.8rem;
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    position: relative;
    overflow: hidden;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    cursor: pointer;
}

.machine-card:hover {
    transform: scale(1.02);
}

.machine-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 6px;
    height: 100%;
    background: var(--stopped);
    transition: all 0.4s ease;
}

.machine-card[data-status="PRODUZINDO"] { box-shadow: 0 0 20px rgba(16, 185, 129, 0.05); }
.machine-card[data-status="PRODUZINDO"]::before { background: var(--success); box-shadow: 0 0 15px var(--success-glow); }
.machine-card[data-status="FALHA"] { box-shadow: 0 0 20px rgba(244, 63, 94, 0.05); }
.machine-card[data-status="FALHA"]::before { background: var(--danger); box-shadow: 0 0 15px var(--danger-glow); }
.machine-card[data-status="MANUTENÇÃO"]::before { background: var(--warning); box-shadow: 0 0 15px var(--warning-glow); }
.machine-card[data-status="SETUP"]::before { background: var(--info); box-shadow: 0 0 15px var(--info-glow); }
.machine-card[data-status="PARADA"]::before { background: var(--stopped); }

.machine-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.machine-name {
    font-weight: 700;
    font-size: 1.2rem;
    letter-spacing: 0.5px;
}

.status-badge {
    font-size: 0.75rem;
    padding: 0.3rem 0.8rem;
    border-radius: 20px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    backdrop-filter: blur(4px);
}

.status-badge.produzindo { background: rgba(16, 185, 129, 0.15); color: var(--success); border: 1px solid rgba(16, 185, 129, 0.3); box-shadow: 0 0 10px rgba(16, 185, 129, 0.2); }
.status-badge.falha { background: rgba(244, 63, 94, 0.15); color: var(--danger); border: 1px solid rgba(244, 63, 94, 0.3); animation: neonPulse 2s infinite; }
.status-badge.manutenção { background: rgba(245, 158, 11, 0.15); color: var(--warning); border: 1px solid rgba(245, 158, 11, 0.3); }
.status-badge.setup { background: rgba(139, 92, 246, 0.15); color: var(--info); border: 1px solid rgba(139, 92, 246, 0.3); }
.status-badge.parada { background: rgba(71, 85, 105, 0.15); color: var(--text-muted); border: 1px solid rgba(71, 85, 105, 0.3); }

@keyframes neonPulse {
    0% { box-shadow: 0 0 5px rgba(244, 63, 94, 0.2), inset 0 0 5px rgba(244, 63, 94, 0.2); }
    50% { box-shadow: 0 0 20px rgba(244, 63, 94, 0.6), inset 0 0 10px rgba(244, 63, 94, 0.4); }
    100% { box-shadow: 0 0 5px rgba(244, 63, 94, 0.2), inset 0 0 5px rgba(244, 63, 94, 0.2); }
}

.machine-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    background: rgba(0,0,0,0.4);
    padding: 1.2rem;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.05);
}

.stat-box {
    display: flex;
    flex-direction: column;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.3rem;
}

.stat-val {
    font-size: 1.3rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.oee-bar-container {
    width: 100%;
    height: 8px;
    background: rgba(255,255,255,0.05);
    border-radius: 4px;
    margin-top: 0.8rem;
    overflow: hidden;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.5);
}

.oee-bar {
    height: 100%;
    background: linear-gradient(90deg, #0ea5e9, #8b5cf6);
    border-radius: 4px;
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 0 10px rgba(14, 165, 233, 0.5);
}

.oee-text {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    font-weight: 600;
    margin-top: 0.5rem;
    color: #e2e8f0;
}

/* CHARTS SECTION */
.analytics-section {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.chart-container {
    background: linear-gradient(145deg, var(--surface), rgba(10, 15, 25, 0.8));
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.5rem;
    height: 280px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.mt-2 {
    margin-top: 1.5rem;
}

/* MODAL */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(7, 9, 14, 0.8);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: linear-gradient(145deg, #121826, #07090e);
    border: 1px solid rgba(14, 165, 233, 0.3);
    border-radius: 20px;
    width: 90%;
    max-width: 700px;
    padding: 2.5rem;
    position: relative;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.6), 0 0 30px rgba(14, 165, 233, 0.1);
    animation: modalSlide 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

.modal-close {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    font-size: 1.8rem;
    font-weight: bold;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.2s;
}

.modal-close:hover {
    color: var(--danger);
}

.modal-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    margin-top: 1.5rem;
}

.modal-col {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.modal-meta-box {
    background: rgba(0,0,0,0.3);
    padding: 1.2rem;
    border-radius: 12px;
    border: 1px solid var(--border);
}

.mt-1 {
    margin-top: 0.5rem;
}

.meta-label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.4rem;
}

.meta-value {
    font-size: 1.2rem;
    color: var(--text-main);
}

.modal-chart-wrapper {
    height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

@media (max-width: 1400px) {
    .main-content {
        grid-template-columns: 280px 1fr 350px;
    }
}

@media (max-width: 1100px) {
    .main-content {
        grid-template-columns: 1fr;
    }
    .lines-section {
        flex-direction: row;
        flex-wrap: wrap;
    }
    .line-card {
        flex: 1;
        min-width: 250px;
    }
}

/* TAB NAVIGATION */
.tab-navigation {
    display: flex;
    gap: 1rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.5rem;
    margin-bottom: 1rem;
}

.tab-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.1rem;
    font-weight: 600;
    padding: 0.6rem 1.2rem;
    cursor: pointer;
    transition: all 0.3s ease;
    border-bottom: 3px solid transparent;
}

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

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    text-shadow: 0 0 10px var(--primary-glow);
}

.tab-content {
    display: none;
    animation: tabFade 0.4s ease;
}

.tab-content.active {
    display: block;
}

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

/* FULL LOG VIEW */
.logs-full-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 2rem;
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
}

.logs-header-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

#log-search {
    background: rgba(0,0,0,0.4);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 0.6rem 1.2rem;
    border-radius: 8px;
    width: 300px;
    outline: none;
    font-size: 0.95rem;
    transition: border-color 0.3s;
}

#log-search:focus {
    border-color: var(--primary);
}

.btn-clear-logs {
    background: rgba(244, 63, 94, 0.1);
    border: 1px solid rgba(244, 63, 94, 0.3);
    color: #fb7185;
    padding: 0.6rem 1.2rem;
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-clear-logs:hover {
    background: rgba(244, 63, 94, 0.2);
    transform: translateY(-1px);
}

.event-log-container-full {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    height: 500px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    scrollbar-width: thin;
    scrollbar-color: var(--primary) transparent;
}

.event-log-container-full::-webkit-scrollbar {
    width: 6px;
}

.event-log-container-full::-webkit-scrollbar-thumb {
    background-color: var(--primary);
    border-radius: 3px;
}