/* ==========================================
   1. DESIGN SYSTEM (Light & Dark Themes)
   ========================================== */
:root {
    --bg-body: #f4f4f5;      
    --bg-card: #ffffff;      
    --text-main: #18181b;    
    --text-muted: #71717a;   
    --border-color: #e4e4e7; 
    --btn-bg: #2563eb;       
    --status-blue: #3b82f6;  
    --status-ok: #16a34a;    
    --status-warn: #d97706;  
    --status-error: #dc2626; 
    --modal-bg: rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] {
    --bg-body: #111114;      
    --bg-card: #1c1c1f;      
    --text-main: #e4e4e7;    
    --text-muted: #a1a1aa;   
    --border-color: #3f3f46; 
    --btn-bg: #3b82f6;       
    --modal-bg: rgba(0, 0, 0, 0.8);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ==========================================
   OCULTAR BARRAS DE ROLAGEM (Scrollbars Invisíveis)
   ========================================== */
*::-webkit-scrollbar {
    display: none; /* Chrome, Safari, Edge, Opera */
}
* {
    -ms-overflow-style: none; /* IE e Edge Antigo */
    scrollbar-width: none; /* Firefox */
}

body {
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.3s, color 0.3s;
}

h1, h2, h3 { font-weight: 600; }

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

.screen { display: none; }
.screen.active { display: block; }

.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 15px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    transition: background-color 0.3s, border-color 0.3s;
}

.card-title {
    font-size: 0.9rem;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    margin-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 5px;
}

.data-row { display: flex; justify-content: space-between; margin-bottom: 10px; font-size: 0.95rem; }

/* ==========================================
   SISTEMA DE BOTÕES PADRONIZADO
   ========================================== */
button {
    background-color: var(--btn-bg);
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
    width: 100%;
    margin-bottom: 10px;
}

/* Variantes de Cor */
.btn-success { background-color: var(--status-ok) !important; color: white !important; border: none !important; }
.btn-danger { background-color: var(--status-error) !important; color: white !important; border: none !important; }
.btn-warn { background-color: var(--status-warn) !important; color: white !important; border: none !important; }
.btn-outline { background-color: transparent !important; border: 1px solid var(--border-color) !important; color: var(--text-main) !important; }

/* Modificadores de Tamanho e Layout */
.btn-sm { padding: 6px 12px !important; font-size: 0.8rem !important; }
.btn-group { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.btn-group button { width: auto; margin-bottom: 0; }

/* File Upload & BT List */
.file-upload-wrapper { position: relative; margin-bottom: 20px; }
.file-upload-wrapper input[type="file"] { position: absolute; left: 0; top: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.file-upload-visual {
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
    background: var(--bg-body);
    transition: 0.3s;
}

.bt-listbox {
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    background: var(--bg-body);
    max-height: 200px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.bt-listbox-item {
    padding: 12px 15px; 
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    font-weight: 500;
    color: var(--text-muted);
    transition: 0.2s;
}
.bt-listbox-item:last-child { border-bottom: none; }
.bt-listbox-item.selected { 
    border-left: 4px solid var(--status-blue); 
    background: rgba(59, 130, 246, 0.1); 
    color: var(--text-main); 
    font-weight: 600; 
}
[data-theme="dark"] .bt-listbox-item.selected { 
    background: rgba(59, 130, 246, 0.2); 
}

/* ==========================================
   MENUS DE NAVEGAÇÃO (Principal e Submenu)
   ========================================== */
.tabs { 
    display: flex; gap: 20px; margin-bottom: 20px; 
    border-bottom: 1px solid var(--border-color); padding-bottom: 8px; overflow-x: auto; 
}
.sub-tabs { 
    display: flex; gap: 40px; /* <- Espaçamento aumentado consideravelmente aqui! */
    margin-bottom: 20px; border-bottom: 1px solid var(--border-color); padding-bottom: 8px; overflow-x: auto; 
}

/* Usando dupla hierarquia (.pai .filho) para esmagar a regra global sem usar !important */
.tabs .tab-btn, 
.sub-tabs .sub-tab-btn { 
    background: transparent; color: var(--text-muted); font-weight: 500; 
    border: none; cursor: pointer; padding: 5px 10px; margin: 0; 
    width: auto; white-space: nowrap; border-radius: 4px; 
}

/* Tamanhos de fonte limpos e hierárquicos */
.tabs .tab-btn { font-size: 1.15rem; }
.sub-tabs .sub-tab-btn { font-size: 1rem; }

.tabs .tab-btn.active, 
.sub-tabs .sub-tab-btn.active { 
    color: var(--status-blue); font-weight: bold; border-bottom: 3px solid var(--status-blue); 
}

.tab-content, .sub-tab-content { display: none; }
.tab-content.active, .sub-tab-content.active { display: block; }

/* Animated Theme Toggle Button (Topo) */
.theme-toggle {
    background: var(--bg-card);
    color: var(--text-main);
    border: 1px solid var(--status-blue); 
    border-radius: 20px;
    display: inline-flex;
    align-items: center;
    width: 38px;
    height: 38px;
    padding: 0;
    overflow: hidden;
    cursor: pointer;
    margin: 0;
    transition: width 0.4s ease, background-color 0.3s;
}
.theme-toggle.expanded {
    width: 100px;
}
.theme-icon {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.1rem;
    margin-top: -2.5px; 
    margin-left: -0.5px; 
}
.theme-toggle-text {
    font-size: 0.85rem;
    font-weight: 600;
    opacity: 0;
    white-space: nowrap;
    transition: opacity 0.3s ease;
}
.theme-toggle.expanded .theme-toggle-text {
    opacity: 1;
}

/* Custom Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--modal-bg);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal-overlay.active { display: flex; }
.modal-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 25px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}
.modal-buttons { display: flex; gap: 10px; margin-top: 20px; margin-bottom: 0; }
.modal-buttons button { margin-bottom: 0; flex: 1; }

/* Log Filters */
.log-controls { display: flex; gap: 15px; margin-bottom: 15px; align-items: center; flex-wrap: wrap; }
.log-filter-label { display: flex; align-items: center; gap: 5px; cursor: pointer; font-size: 0.9rem; font-weight: 500; }
.log-entry { margin-bottom: 5px; }

/* Wrappers */
.login-wrapper {
    max-width: 420px;
    margin: 0 auto;
}

/* Responsiveness */
.grid-layout { display: flex; flex-direction: column; gap: 15px; }

@media (min-width: 768px) {
    .screen { padding: 10px; }
    .grid-layout { display: grid; grid-template-columns: 1fr 1fr; }
    .full-width { grid-column: span 2; }
    .tabs { margin-bottom: 30px; }
    .login-wrapper { margin-top: 60px; }
}

@media (min-width: 1366px) {
    .grid-layout { grid-template-columns: 1fr 1fr 1fr; }
    .full-width { grid-column: span 3; }
}

/* Config Inputs */
.config-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.config-row label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-muted);
}
.config-input {
    background: var(--bg-body);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.9rem;
    width: 60%;
    transition: border-color 0.2s;
}
.config-input:focus {
    outline: none;
    border-color: var(--status-ok);
}

/* Layout Vertical para Formulários Densos (GPIO) */
.config-col {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 10px;
}
.config-col label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
}
.config-col .config-input {
    width: 100%;
}

/* Sub-Tabs for Configuration */
.sub-tabs { display: flex; gap: 15px; margin-bottom: 20px; border-bottom: 1px solid var(--border-color); padding-bottom: 8px; overflow-x: auto; }
.sub-tab-btn { background: transparent; color: var(--text-muted); font-size: 0.85rem; font-weight: 500; border: none; cursor: pointer; padding: 5px 0; white-space: nowrap; }
.sub-tab-btn.active { color: var(--status-blue); font-weight: bold; border-bottom: 2px solid var(--status-blue); }
.sub-tab-content { display: none; }
.sub-tab-content.active { display: block; }

/* Aplica a borda azul na esquerda a TODOS os cartões da aba Config */
#tab-config .card {
    border-left: 4px solid var(--status-blue);
}

/* Modern Global Status Indicator */
.modern-status {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 6px 16px;
    border-radius: 20px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    color: var(--text-main);
    transition: all 0.3s ease;
}

/* Efeito de clique no Status */
.clickable-status {
    cursor: pointer;
}
.clickable-status:hover {
    filter: brightness(1.2);
    transform: scale(1.02);
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: var(--text-muted);
    box-shadow: 0 0 8px var(--text-muted);
    transition: all 0.3s ease;
}

/* Help Modal Styles */
.help-modal-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 25px;
    width: 95%;
    max-width: 700px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    position: relative;
}
.help-close-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    background: transparent;
    color: var(--text-muted);
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    width: auto;
    padding: 5px 10px;
    margin: 0;
}
.help-close-btn:hover { color: var(--status-error); background: transparent; }
.help-section { margin-bottom: 20px; }
.help-section h4 { color: var(--status-blue); border-bottom: 1px solid var(--border-color); padding-bottom: 5px; margin-bottom: 10px; font-size: 1rem; }
.help-section ul { list-style: none; padding-left: 0; }
.help-section li { margin-bottom: 8px; font-size: 0.9rem; color: var(--text-muted); line-height: 1.4; }
.help-section li strong { color: var(--text-main); }

/* ==========================================
   SCHEDULE TAB STYLES (Dynamic List)
   ========================================== */
.schedule-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    background: var(--bg-body);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    margin-bottom: 10px;
    transition: transform 0.2s, box-shadow 0.2s;
}
.schedule-item:hover {
    transform: translateX(4px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.schedule-item-info {
    display: flex;
    gap: 20px;
    align-items: center;
    flex-wrap: wrap;
}
.schedule-badge {
    background: var(--bg-card);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 600;
    border: 1px solid var(--border-color);
}
/* Cores Dinâmicas para os Modos */
.sch-mode-Auto { color: var(--status-ok); }
.sch-mode-Off { color: var(--text-muted); }
.sch-mode-Open { color: var(--status-blue); }
.sch-mode-Close { color: var(--status-warn); }
.sch-mode-Maintenance { color: var(--status-error); }