:root {
    --bg-app: #f4f7fe;
    --bg-surface: #ffffff;
    --sidebar-bg: #111c44;
    --sidebar-hover: rgba(255, 255, 255, 0.1);
    --text-main: #2b3674;
    --text-muted: #a3aed1;
    --primary: #4318ff;
    --primary-hover: #3311db;
    --action: #f97316;
    --action-hover: #ea580c;
    --border: #e2e8f0;
    --success: #05cd99;
    --danger: #ee5d50;
    --warning: #ffce20;
    --blue: #3965ff;
}

body.dark-theme {
    --bg-app: #0b1437;
    --bg-surface: #111c44;
    --text-main: #ffffff;
    --text-muted: #8f9bba;
    --border: #1b2559;
}

* { 
    margin: 0; 
    padding: 0; 
    box-sizing: border-box; 
    font-family: 'Inter', sans-serif; 
}

body { 
    display: flex; 
    height: 100vh; 
    background-color: var(--bg-app); 
    color: var(--text-main); 
    overflow: hidden; 
    transition: background-color 0.3s, color 0.3s; 
}

/* Telas Alternáveis */
.screen-view { 
    display: none; 
    animation: fadeIn 0.3s ease-in-out;
}
.screen-view.active { 
    display: block; 
}

@keyframes fadeIn { 
    from { opacity: 0; transform: translateY(5px); } 
    to { opacity: 1; transform: translateY(0); } 
}

/* Sidebar */
.sidebar { 
    width: 260px; 
    background-color: var(--sidebar-bg); 
    color: #fff; 
    display: flex; 
    flex-direction: column; 
    flex-shrink: 0;
}
.sidebar-header { 
    padding: 30px 20px; 
    font-size: 24px; 
    font-weight: 700; 
    display: flex; 
    align-items: center; 
    gap: 12px; 
    border-bottom: 1px solid rgba(255,255,255,0.05); 
}
.sidebar-menu { 
    list-style: none; 
    padding: 20px 10px; 
    flex: 1; 
}
.sidebar-menu li a { 
    display: flex; 
    align-items: center; 
    gap: 12px; 
    padding: 14px 20px; 
    color: var(--text-muted); 
    text-decoration: none; 
    border-radius: 8px; 
    font-weight: 500; 
    transition: 0.2s; 
}
.sidebar-menu li.active a, .sidebar-menu li a:hover { 
    background-color: var(--sidebar-hover); 
    color: #fff; 
}

/* Conteúdo Principal */
.main-content { 
    flex: 1; 
    overflow-y: auto; 
    padding: 30px; 
}
.topbar { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    margin-bottom: 30px; 
    flex-wrap: wrap; 
    gap: 20px;
}
.page-title h2 { 
    font-size: 28px; 
    font-weight: 700; 
    color: var(--text-main);
}
.page-title p { 
    color: var(--text-muted); 
    font-size: 14px; 
    margin-top: 4px; 
}
.controls { 
    display: flex; 
    gap: 12px; 
    align-items: flex-end; 
    flex-wrap: wrap;
}

.input-wrap { 
    display: flex; 
    flex-direction: column; 
    gap: 6px; 
}
.input-wrap label { 
    font-size: 12px; 
    font-weight: 600; 
    color: var(--text-muted); 
    text-transform: uppercase;
}
.input-wrap input { 
    padding: 10px; 
    border: 1px solid var(--border); 
    border-radius: 8px; 
    width: 100px; 
    background: var(--bg-surface); 
    color: var(--text-main); 
    outline: none;
}

.btn-primary, .btn-secondary, .btn-action, .icon-btn { 
    border-radius: 8px; 
    font-weight: 600; 
    cursor: pointer; 
    transition: 0.2s; 
    display: flex; 
    align-items: center; 
    gap: 8px; 
    border: none;
}
.btn-primary { background-color: var(--primary); color: white; padding: 12px 20px; }
.btn-primary:hover { background-color: var(--primary-hover); }
.btn-secondary { background-color: #10b981; color: white; padding: 12px 20px; }
.btn-secondary:hover { background-color: #059669; }
.btn-action { background-color: var(--action); color: white; padding: 12px 20px; }
.btn-action:hover { background-color: var(--action-hover); }
.icon-btn { background: var(--bg-surface); color: var(--text-main); padding: 12px 14px; border: 1px solid var(--border); font-size: 16px;}
.icon-btn:hover { background: var(--border); }

.upload-btn-wrapper { position: relative; overflow: hidden; display: inline-block; }
.upload-btn-wrapper input[type=file] { font-size: 100px; position: absolute; left: 0; top: 0; opacity: 0; cursor: pointer; }

/* KPIs e Gráficos */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 20px; margin-bottom: 30px; }
.kpi-card, .chart-card, .table-section { background: var(--bg-surface); padding: 24px; border-radius: 16px; box-shadow: 0 4px 20px rgba(0,0,0,0.02); }
.kpi-card { display: flex; align-items: center; gap: 16px; }
.kpi-icon { width: 56px; height: 56px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 24px; flex-shrink: 0;}
.kpi-icon.blue { background: rgba(57, 101, 255, 0.1); color: var(--blue); }
.kpi-icon.green { background: rgba(5, 205, 153, 0.1); color: var(--success); }
.kpi-icon.warning { background: rgba(255, 206, 32, 0.1); color: var(--warning); }
.kpi-icon.danger { background: rgba(238, 93, 80, 0.1); color: var(--danger); }
.kpi-info h3 { font-size: 13px; color: var(--text-muted); font-weight: 600; white-space: nowrap; }
.kpi-info p { font-size: 20px; font-weight: 700; color: var(--text-main); margin-top: 4px; }

.charts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(400px, 1fr)); gap: 20px; margin-bottom: 30px; }
.chart-card h3 { font-size: 16px; margin-bottom: 20px; color: var(--text-main); }

/* Tabela e Filtros */
.table-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-wrap: wrap; gap: 15px;}
.filters-row { display: flex; gap: 12px; }
.custom-select, .search-box input { background: var(--bg-app); border: 1px solid var(--border); color: var(--text-main); padding: 10px; border-radius: 8px; outline: none; }
.search-box { position: relative; width: 250px; }
.search-box i { position: absolute; left: 14px; top: 12px; color: var(--text-muted); }
.search-box input { width: 100%; padding-left: 38px; }

.table-responsive { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { background: var(--bg-app); padding: 14px 16px; font-size: 13px; font-weight: 600; color: var(--text-muted); text-align: left; border-bottom: 1px solid var(--border); cursor: pointer; white-space: nowrap;}
th:hover { color: var(--text-main); }
th i { font-size: 10px; margin-left: 4px; }
td { padding: 14px 16px; font-size: 14px; border-bottom: 1px solid var(--border); font-weight: 500; }
tbody tr:hover { background: var(--bg-app); }

.text-right { text-align: right; } .text-center { text-align: center; }
.badge { padding: 6px 12px; border-radius: 20px; font-size: 12px; font-weight: 700; white-space: nowrap;}
.badge.safe { background: rgba(5, 205, 153, 0.1); color: var(--success); }
.badge.warning { background: rgba(255, 206, 32, 0.1); color: #d97706; }
.badge.critical { background: rgba(238, 93, 80, 0.1); color: var(--danger); }
.prod-highlight { color: var(--primary); font-weight: 700; }

/* Paginação */
.pagination { display: flex; justify-content: flex-end; align-items: center; gap: 16px; margin-top: 20px; }
.pagination button { padding: 8px 16px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg-surface); color: var(--text-main); cursor: pointer; transition: 0.2s; font-weight: 600; }
.pagination button:hover:not(:disabled) { background: var(--border); }
.pagination button:disabled { opacity: 0.5; cursor: not-allowed; }
.pagination span { font-size: 14px; font-weight: 500; color: var(--text-muted); }

/* Cards do Corte / Talhação */
.corte-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 20px; }
.corte-card { background: var(--bg-surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; box-shadow: 0 4px 10px rgba(0,0,0,0.03); display: flex; flex-direction: column;}
.corte-header { background: rgba(67, 24, 255, 0.05); padding: 16px 20px; border-bottom: 1px solid var(--border); border-top: 4px solid var(--primary);}
.corte-header h3 { font-size: 16px; color: var(--text-main); line-height: 1.4; margin-bottom: 4px;}
.corte-header p { font-size: 12px; color: var(--text-muted); font-weight: 600; text-transform: uppercase;}
.corte-body { padding: 20px; flex: 1;}
.grade-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed var(--border); font-size: 14px;}
.grade-row:last-child { border-bottom: none; }
.grade-size { font-weight: 700; color: var(--text-main); }
.grade-qty { color: var(--text-muted); font-weight: 600;}
.corte-footer { padding: 16px 20px; background: var(--bg-app); border-top: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center;}
.corte-total-label { font-size: 13px; font-weight: 600; color: var(--text-muted);}
.corte-total-val { font-size: 20px; font-weight: 800; color: var(--primary);}

@media print {
    .sidebar, .topbar .controls { display: none !important; }
    .main-content { padding: 0; }
    .corte-card { page-break-inside: avoid; border: 1px solid #ccc; }
    body.dark-theme { background: #fff; color: #000; }
}