:root {
    /* Pure Light Theme Palette */
    --bg-main: #f8fafc;
    --sidebar-bg: #ffffff;
    --card-bg: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-light: #334155;
    
    /* Wolco Corporate Colors */
    --accent-red: #e11d48;
    --accent-red-hover: #be123c;
    --accent-dark: #0f172a;
    --accent-blue: #2563eb;
    
    --border-color: #cbd5e1;
    --soft-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    --glass-border: 1px solid var(--border-color);
    
    --success: #10b981;
    --error: #ef4444;
}

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

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

/* --- LOGIN SCREEN --- */
.login-wrapper {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: var(--bg-main);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}
.login-wrapper.hidden {
    display: none !important;
}

.login-card {
    background: var(--card-bg);
    padding: 40px;
    border-radius: 16px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.login-logo img {
    max-height: 60px;
    margin-bottom: 20px;
}

.login-card h2 {
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 5px;
}
.login-subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 30px;
}
.login-form {
    text-align: left;
}
.login-error {
    color: var(--error);
    background: rgba(239, 68, 68, 0.1);
    padding: 10px;
    border-radius: 8px;
    margin-top: 15px;
    font-size: 0.85rem;
}

/* --- GLOBAL LOADER (PREMIUM GLASSMORPHISM) --- */
.global-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(248, 250, 252, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.4s ease, visibility 0.4s ease;
}

.global-loader.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.loader-content {
    text-align: center;
    background: rgba(255, 255, 255, 0.6);
    padding: 40px 60px;
    border-radius: 24px;
    border: 1px solid rgba(255, 255, 255, 0.8);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.1), 0 0 0 1px rgba(0, 0, 0, 0.02);
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(37, 99, 235, 0.1);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 1s cubic-bezier(0.4, 0, 0.2, 1) infinite;
    margin: 0 auto 20px;
}

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

.loader-text {
    font-family: 'Montserrat', sans-serif;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 5px;
    letter-spacing: 1px;
}

.loader-sub {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* --- APP SHELL --- */
.app-container {
    display: flex;
    width: 100%;
    height: 100vh;
}
.app-container.hidden {
    display: none !important;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--sidebar-bg);
    border-right: var(--glass-border);
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 10px rgba(0,0,0,0.02);
}

.logo-area {
    padding: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-bottom: var(--glass-border);
}
.sidebar-logo {
    max-height: 40px;
}

.user-profile {
    padding: 20px 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: var(--glass-border);
}
.avatar {
    width: 40px;
    height: 40px;
    background: rgba(225, 29, 72, 0.1);
    color: var(--accent-red);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
}
.user-info {
    display: flex;
    flex-direction: column;
}
.user-name {
    font-weight: 600;
    font-size: 0.95rem;
}
.user-role {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.menu {
    padding: 20px 12px;
    flex: 1;
    overflow-y: auto;
}
.menu-section {
    margin-bottom: 25px;
}
.menu-label {
    display: block;
    padding: 0 12px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-weight: 700;
    margin-bottom: 8px;
    letter-spacing: 0.5px;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 8px;
    transition: all 0.2s ease;
    font-weight: 500;
    font-size: 0.95rem;
}

.menu-item:hover {
    background-color: var(--bg-main);
    color: var(--text-primary);
}

.menu-item.active {
    background-color: rgba(225, 29, 72, 0.1);
    color: var(--accent-red);
    font-weight: 600;
}

.sidebar-footer {
    padding: 20px;
    border-top: var(--glass-border);
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    justify-content: center;
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}
.status-indicator.offline { background-color: var(--text-secondary); }
.status-indicator.online { background-color: var(--success); box-shadow: 0 0 8px var(--success); }

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow-y: auto;
}

.topbar {
    padding: 20px 40px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    position: sticky;
    top: 0;
    z-index: 10;
    border-bottom: var(--glass-border);
}

.topbar h2 {
    font-weight: 600;
    font-size: 1.25rem;
    color: var(--accent-dark);
}

.topbar-actions {
    display: flex;
    gap: 15px;
}
.icon-btn {
    background: var(--bg-main);
    border: var(--glass-border);
    color: var(--text-secondary);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    justify-content: center;
    align-items: center;
}
.icon-btn:hover { color: var(--text-primary); background: #e2e8f0; }

.content-area {
    padding: 30px 40px;
    flex: 1;
}

.hidden {
    display: none !important;
}

.view-panel {
    display: none;
    animation: fadeIn 0.3s ease;
}
.view-panel.active {
    display: block;
}

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

/* Cards & Components */
.glass-card {
    background: var(--card-bg);
    border-radius: 12px;
    border: var(--glass-border);
    box-shadow: var(--soft-shadow);
    padding: 24px;
}

.mt-4 { margin-top: 24px; }
.mt-3 { margin-top: 16px; }
.mt-2 { margin-top: 8px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 16px; }
.w-100 { width: 100%; }

h3 {
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    color: var(--accent-dark);
}
h4 {
    margin: 0;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-primary);
}

.hint-text {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 20px;
}

/* Forms */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    text-align: left;
}

label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 600;
}

input, textarea, select {
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    padding: 10px 14px;
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.95rem;
    outline: none;
    transition: all 0.2s;
}

input:focus, textarea:focus, select:focus {
    border-color: var(--accent-blue);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 0.95rem;
}
.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.primary-btn {
    background-color: var(--accent-red);
    color: white;
}
.primary-btn:hover:not(:disabled) { background-color: var(--accent-red-hover); transform: translateY(-1px); }

.secondary-btn {
    background-color: var(--accent-dark);
    color: white;
}
.secondary-btn:hover:not(:disabled) { background-color: #1e293b; transform: translateY(-1px); }

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

.btn-sm {
    padding: 6px 12px;
    height: auto;
    font-size: 0.85rem;
}

/* Layouts Specific */
.connect-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    align-items: end;
}

/* DB Workspace */
.db-toolbar {
    background: var(--card-bg);
    padding: 20px;
    border-radius: 12px;
    border: var(--glass-border);
    margin-bottom: 20px;
    box-shadow: var(--soft-shadow);
}
.db-connect-bar {
    display: flex;
    gap: 15px;
    align-items: center;
    flex-wrap: wrap;
}
.db-connect-bar input { flex: 1; min-width: 150px; }
.db-selector-bar {
    display: flex;
    gap: 15px;
    align-items: center;
    padding-top: 15px;
    margin-top: 15px;
    border-top: var(--glass-border);
}
.db-selector-bar select { min-width: 300px; }

.db-workspace {
    display: flex;
    gap: 20px;
    height: calc(100vh - 280px);
}
.db-sidebar {
    width: 280px;
    background: var(--card-bg);
    border: var(--glass-border);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    box-shadow: var(--soft-shadow);
}
.db-sidebar-header {
    padding: 15px;
    background: var(--bg-main);
    border-bottom: var(--glass-border);
    border-radius: 12px 12px 0 0;
}
.db-tree {
    list-style: none;
    padding: 10px;
    overflow-y: auto;
    flex: 1;
}
.db-tree li {
    padding: 10px 15px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
    transition: all 0.2s;
}
.db-tree li:hover { background: var(--bg-main); color: var(--text-primary); }
.db-tree li.active { background: rgba(37, 99, 235, 0.1); color: var(--accent-blue); font-weight: 500; }

.db-main {
    flex: 1;
    background: var(--card-bg);
    border: var(--glass-border);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    box-shadow: var(--soft-shadow);
}
.db-main-header {
    padding: 15px 24px;
    background: var(--bg-main);
    border-bottom: var(--glass-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 12px 12px 0 0;
}

/* Terminal */
.terminal-card {
    padding: 0;
    height: 500px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.terminal-header {
    background: var(--bg-main);
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: var(--glass-border);
}
.terminal-header h3 { margin: 0; font-size: 1rem; }
.window-controls { display: flex; gap: 8px; }
.window-controls span { width: 12px; height: 12px; border-radius: 50%; }
.window-controls span:nth-child(1) { background: #ff5f56; }
.window-controls span:nth-child(2) { background: #ffbd2e; }
.window-controls span:nth-child(3) { background: #27c93f; }

.terminal-body {
    flex: 1;
    background: #1e1e1e;
    padding: 20px;
    overflow-y: auto;
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 0.9rem;
}
.log-line.system { color: #888; font-style: italic; }
.log-line.cmd { color: #4af626; }
.log-line.out { color: #eee; white-space: pre-wrap; }
.log-line.err { color: #ff5555; white-space: pre-wrap; }

.cmd-input-area {
    display: flex;
    background: #1e1e1e;
    padding: 15px 20px;
    border-top: 1px solid #333;
    align-items: center;
    gap: 10px;
}
.prompt { color: #4af626; font-family: monospace; font-weight: bold; }
.cmd-input-area input {
    flex: 1; background: transparent; border: none; color: #fff;
    font-family: monospace; padding: 0; box-shadow: none;
}

/* Tables */
.table-container { width: 100%; overflow: auto; flex: 1; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 16px; text-align: left; border-bottom: var(--glass-border); white-space: nowrap; font-size: 0.9rem; }
th { background: var(--bg-main); font-weight: 600; color: var(--text-primary); position: sticky; top: 0; }
tr:hover { background: var(--bg-main); }

.empty-state {
    text-align: center;
    padding: 60px 40px;
    color: var(--text-secondary);
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

/* API Docs */
.api-doc-section p { color: var(--text-secondary); line-height: 1.6; margin-bottom: 15px; font-size: 0.95rem; }
.code-block {
    background: #1e1e1e; border-radius: 8px; position: relative; padding-top: 35px; overflow: hidden;
}
.lang-badge {
    position: absolute; top: 0; left: 0; right: 0; background: #2d2d2d;
    padding: 5px 15px; font-size: 0.75rem; color: #aaa; font-weight: 600;
    text-transform: uppercase; border-bottom: 1px solid #444;
}
.code-block pre { margin: 0; padding: 15px; overflow-x: auto; }
.code-block code { 
    font-family: 'Consolas', 'Courier New', monospace; 
    color: #dcdcdc; 
    font-size: 0.9rem;
    background: transparent;
    padding: 0;
}
code { background: var(--bg-main); padding: 2px 6px; border-radius: 4px; font-family: monospace; color: var(--accent-red); font-size: 0.9em; }

.api-table {
    border-radius: 8px;
    overflow: hidden;
    border: var(--glass-border);
}
.api-table th { background: var(--bg-main); }
.hidden { display: none !important; }

/* --- MES MODULE STYLES --- */
.mes-header {
    display: flex; gap: 15px; margin-bottom: 20px; align-items: stretch;
}
.mes-stat-card {
    background: var(--card-bg); padding: 12px 18px; border-radius: 8px;
    border: var(--glass-border); display: flex; align-items: center; gap: 15px;
    box-shadow: var(--soft-shadow); flex: 1;
}
.card-user {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.05) 0%, rgba(37, 99, 235, 0.1) 100%);
    border-left: 4px solid var(--accent-blue);
}
.card-machine {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.05) 0%, rgba(124, 58, 237, 0.1) 100%);
    border-left: 4px solid var(--accent-purple);
}
.card-timer {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.05) 0%, rgba(217, 119, 6, 0.1) 100%);
    border-left: 4px solid var(--accent-orange);
}
.mes-stat-card i { font-size: 1.8rem; }
.mes-stat-card h5 { margin: 0; color: var(--text-secondary); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.5px;}
.mes-stat-card h3 { margin: 2px 0 0 0; font-size: 1.3rem; color: var(--text-primary); }

.mes-workspace {
    display: grid; grid-template-columns: 350px 1fr; gap: 30px; height: calc(100vh - 220px);
}
.mes-order-list {
    background: var(--card-bg); border-radius: 12px; border: var(--glass-border);
    display: flex; flex-direction: column; overflow: hidden; box-shadow: var(--soft-shadow);
}
.mes-list-header {
    padding: 20px; background: var(--bg-main); border-bottom: var(--glass-border);
}
.mes-search {
    width: 100%; padding: 12px; border-radius: 8px; border: 1px solid var(--border-color);
    margin-top: 15px; font-size: 1rem;
}
.mes-cards-container {
    flex: 1; overflow-y: auto; padding: 15px;
}
.mes-order-card {
    background: #fff; border: 1px solid var(--border-color); padding: 15px;
    border-radius: 10px; margin-bottom: 15px; cursor: pointer; transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}
.mes-order-card:hover { transform: translateY(-2px); border-color: var(--accent-blue); }
.mes-order-card.active { border: 2px solid var(--accent-blue); background: rgba(37, 99, 235, 0.03); }
.mes-order-title { font-weight: 700; color: var(--text-primary); margin-bottom: 5px; font-size: 1.1rem; }
.mes-order-prod { color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 10px; }
.mes-order-qty { display: inline-block; background: var(--bg-main); padding: 4px 10px; border-radius: 20px; font-size: 0.8rem; font-weight: 600;}

.mes-execution-panel {
    background: var(--card-bg); border-radius: 12px; border: var(--glass-border);
    padding: 40px; box-shadow: var(--soft-shadow); display: flex; flex-direction: column;
}
.mes-mo-header {
    display: flex; justify-content: space-between; align-items: center; margin-bottom: 30px;
    padding-bottom: 20px; border-bottom: 1px solid var(--border-color);
}
.mes-mo-header h2 { font-size: 2rem; margin: 0; color: var(--accent-dark); }
.badge { background: var(--accent-dark); color: #fff; padding: 6px 15px; border-radius: 20px; font-size: 0.9rem; font-weight: 600;}

.mes-mo-details { display: flex; gap: 20px; margin-bottom: 40px; }
.detail-box { flex: 1; background: var(--bg-main); padding: 20px; border-radius: 10px; text-align: center; }
.detail-box span { display: block; color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 5px; text-transform: uppercase; font-weight: 600;}
.detail-box strong { font-size: 1.8rem; color: var(--text-primary); }

.mes-timer-display {
    text-align: center; margin-bottom: 40px; padding: 30px; background: #0f172a; border-radius: 16px; color: #fff;
}
#mes-chronometer { font-size: 5rem; font-family: monospace; font-weight: 700; letter-spacing: -2px; line-height: 1;}
.status-label { margin-top: 10px; font-size: 1.2rem; font-weight: 600; letter-spacing: 2px; color: #94a3b8; }
.status-label.running { color: #4ade80; }
.status-label.paused { color: #fbbf24; }

.mes-action-buttons {
    display: flex; gap: 20px; margin-bottom: 40px;
}
.mes-btn-huge {
    flex: 1; height: 80px; font-size: 1.5rem; font-weight: 700; border-radius: 16px;
    text-transform: uppercase; letter-spacing: 1px; transition: all 0.2s;
}
.play-btn { background: var(--success); color: white; }
.play-btn:hover { background: #059669; transform: scale(1.02); }
.pause-btn { background: #f59e0b; color: white; }
.pause-btn:hover { background: #d97706; transform: scale(1.02); }
.stop-btn { background: var(--accent-red); color: white; }
.stop-btn:hover { background: var(--accent-red-hover); transform: scale(1.02); }

.mes-report-section {
    background: var(--bg-main); padding: 30px; border-radius: 12px;
}
.qty-input-group {
    display: flex; gap: 10px; align-items: stretch; margin-top: 15px; height: 60px;
}
.qty-input-group input { flex: 1; text-align: center; font-size: 1.5rem; font-weight: 700; }
.qty-input-group .btn { min-width: 60px; font-size: 1.2rem; }
.qty-input-group #btn-mes-report { flex: 2; font-size: 1.2rem; }

/* =========================================================
   MES STYLE
   ========================================================= */

.mes-workspace-area {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 0;
    margin-top: 10px;
}

.mes-card-area {
    background: var(--card-bg);
    padding: 15px; /* Compact padding */
    border-radius: 12px;
    box-shadow: var(--soft-shadow);
    border: 1px solid var(--border-color);
    width: 100%;
}

.mes-title-area {
    text-align: center;
    color: var(--accent-dark);
    margin-bottom: 8px; /* Extremely compact */
    font-size: 1.1rem;
    font-weight: 700;
}

.mes-form-area .form-section {
    margin-bottom: 6px; /* Extremely compact */
}

.mes-form-area label {
    display: block;
    margin-bottom: 2px;
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.mes-form-area .section-title {
    font-size: 0.8rem;
    color: var(--accent-blue);
    margin-top: 15px;
    margin-bottom: 15px;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 6px;
}

.input-with-icon {
    position: relative;
}

.input-with-icon input,
.input-with-icon select {
    width: 100%;
    padding: 6px 10px; /* Compact padding */
    padding-right: 40px;
    border: 1px solid var(--border-color);
    background: #ffffff;
    color: var(--text-primary);
    border-radius: 6px;
    font-size: 0.9rem; /* Compact font */
    transition: all 0.3s;
    appearance: none;
}

.input-with-icon input:focus,
.input-with-icon select:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
    outline: none;
}

.input-with-icon input:disabled,
.input-with-icon select:disabled {
    background: #f1f5f9;
    color: #94a3b8;
    cursor: not-allowed;
}

.input-with-icon .bg-icon {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    font-size: 1.1rem;
    pointer-events: none;
}

.mes-form-area select {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    background: #ffffff;
    color: var(--text-primary);
    border-radius: 6px;
    font-size: 1rem;
}

.mes-form-area select:disabled {
    background: #f1f5f9;
    color: #94a3b8;
    cursor: not-allowed;
}

.validation-banner {
    margin-top: 10px;
    padding: 10px 14px;
    background: rgba(16, 185, 129, 0.1);
    border-left: 4px solid var(--success-color);
    border-radius: 4px;
    color: var(--success-color);
    font-weight: 500;
    font-size: 0.95rem;
}

.btn-bio-green {
    background-color: var(--success-color);
    color: white;
    font-size: 1.2rem;
    font-weight: 700;
    padding: 16px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: transform 0.2s, background-color 0.3s;
}

.btn-bio-green:hover:not(:disabled) {
    background-color: #059669;
    transform: translateY(-2px);
}

.btn-bio-green:disabled {
    background-color: var(--border-color);
    color: var(--text-muted);
    cursor: not-allowed;
}

.btn-bio-red {
    background-color: var(--error);
    color: white;
    font-size: 1.2rem;
    font-weight: 700;
    padding: 16px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: all 0.3s;
    animation: pulseRed 2s infinite;
}

.btn-bio-red:hover {
    background-color: #dc2626;
}

@keyframes pulseRed {
    0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
    70% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.footer-times {
    display: flex;
    justify-content: space-between;
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.time-col {
    display: flex;
    flex-direction: column;
    gap: 8px;
    color: var(--text-muted);
}

.time-col.text-right {
    text-align: right;
    align-items: flex-end;
}

.timer-display {
    margin-top: 8px;
    font-size: 0.9rem;
}

.timer-display strong {
    font-size: 1.5rem;
    color: var(--primary-color);
    display: block;
    line-height: 1.2;
}

/* =========================================================
   DASHBOARDS STYLE
   ========================================================= */

.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.dashboard-header h2 {
    color: var(--primary-color);
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
}

.kpi-stat-card {
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.03);
    display: flex;
    flex-direction: column;
    justify-content: center;
    transition: all 0.3s ease;
    overflow: hidden;
}

.kpi-stat-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 25px rgba(0,0,0,0.08);
    background: rgba(255, 255, 255, 0.9);
}

.kpi-stat-card h3 {
    font-size: 0.85rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 12px;
    font-weight: 700;
    letter-spacing: 0.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stat-value {
    font-size: 2.2rem;
    font-weight: 800;
    line-height: 1.1;
    color: var(--accent-dark);
    word-break: break-word;
}

.stat-value.text-muted {
    color: #94a3b8;
    font-weight: 500;
}
}

.text-blue { color: #3b82f6; }
.text-green { color: #10b981; }
.text-red { color: #ef4444; }
.text-orange { color: #f59e0b; }

.chart-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    min-height: 300px;
    position: relative;
}

.chart-card h3 {
    font-size: 1.1rem;
    color: var(--text-light);
    margin-bottom: 20px;
    font-weight: 600;
    text-align: center;
}

.chart-card {
    background: var(--card-bg);
    border-radius: 12px;
    border: var(--glass-border);
    box-shadow: var(--soft-shadow);
    padding: 24px;
    display: flex;
    flex-direction: column;
    position: relative;
    min-height: 300px;
    height: 380px; /* Constraints needed for Chart.js */
}
.chart-card h3 {
    margin-bottom: 15px;
    font-size: 1.1rem;
    flex-shrink: 0;
}
.chart-card canvas {
    flex: 1;
    min-height: 0; /* Prevents flex children from growing infinitely */
}

.span-1 { grid-column: span 1; }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }

.gauge-percentage {
    position: absolute;
    top: 60%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 3rem;
    font-weight: 700;
    color: var(--text-light);
}

@media (max-width: 1024px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
    .span-1, .span-2, .span-3 {
        grid-column: span 1;
    }
}

/* MES Modern Form Styling */
.form-section {
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(226, 232, 240, 0.8);
    border-left: 4px solid var(--accent-blue);
    border-radius: 12px;
    padding: 10px 16px; /* Compact padding */
    margin-bottom: 12px; /* Compact margin */
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.03);
    transition: all 0.3s ease;
    position: relative;
    z-index: 1; /* Base z-index */
}

/* Fix for Tom Select rendering behind other absolute/relative elements */
.ts-dropdown {
    z-index: 9999 !important;
    font-size: 1.15rem; /* Make options larger and more readable */
}

/* Make selected text larger as well */
.ts-control {
    font-size: 1.15rem !important;
    padding: 12px 15px !important;
}

.ts-control .item {
    font-size: 1.15rem !important;
}

/* Ensure dropdowns pop over the next sections */
.form-section:focus-within {
    z-index: 99;
}

.form-section:hover {
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.06);
    background: rgba(255, 255, 255, 0.9);
}

.form-section .section-title {
    display: block;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--accent-blue);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px; /* Compact margin */
    border-bottom: 1px dashed rgba(226, 232, 240, 0.8);
    padding-bottom: 4px; /* Compact padding */
}

.form-section > label {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 4px; /* Compact margin */
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Individual Block Accents */
#section-machine { border-left-color: var(--accent-purple); }
#section-machine .section-title { color: var(--accent-purple); }

#section-task { border-left-color: var(--accent-orange); }
#section-task .section-title { color: var(--accent-orange); }

#section-concept { border-left-color: var(--accent-green); }
#section-concept .section-title { color: var(--accent-green); }

/* MES Buttons */
.btn-bio-green {
    background-color: var(--accent-green, #10b981);
    color: white;
    font-size: 1.2rem;
    padding: 15px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-weight: bold;
}
.btn-bio-green:hover { background-color: #059669; }

.btn-bio-red {
    background-color: var(--accent-red, #ef4444);
    color: white;
    font-size: 1.2rem;
    padding: 15px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-weight: bold;
}
.btn-bio-red:hover { background-color: #dc2626; }

/* =========================================================
   MES LOGS TABLE
   ========================================================= */
.mes-logs-table {
    border-collapse: collapse;
}

.mes-logs-table th {
    background-color: var(--card-bg);
    padding: 8px;
    border-bottom: 2px solid var(--border-color);
    position: sticky;
    top: 0;
}

.mes-logs-table td {
    padding: 6px 8px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: top;
    word-break: break-all;
}

.mes-logs-table tr:hover td {
    background-color: rgba(37, 99, 235, 0.05);
}

.log-query-cell {
    max-width: 300px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-family: monospace;
    font-size: 0.8rem;
    color: #475569;
}

.log-query-cell:hover {
    white-space: normal;
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    position: relative;
    z-index: 10;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
    border-radius: 4px;
    padding: 4px;
}

.log-status-ok {
    color: #16a34a;
    font-weight: 600;
}

.log-status-error {
    color: #dc2626;
    font-weight: 600;
}

/* Modal Overlay */
.mes-modal {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}
.mes-modal.hidden {
    display: none !important;
}
.mes-modal-content {
    background: var(--card-bg);
    padding: 30px;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    border: 1px solid var(--border-color);
}
.huge-input {
    font-size: 2rem;
    font-weight: 700;
    text-align: center;
    padding: 15px;
    width: 100%;
    border-radius: 8px;
    border: 2px solid var(--border-color);
}
.huge-input:focus {
    border-color: var(--accent-blue);
    outline: none;
}
.text-danger {
    color: var(--error);
}

/* =========================================
   KPI DASHBOARD (Premium Styling)
   ========================================= */

.kpi-dashboard {
    padding: 24px;
    background: #f8fafc;
    min-height: 100vh;
}

.kpi-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    font-family: 'Montserrat', sans-serif;
}

.kpi-header h2 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent-dark);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 12px;
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
    margin-bottom: 24px;
}

.kpi-card {
    background: linear-gradient(135deg, rgba(255,255,255,0.95), rgba(255,255,255,0.85));
    border-radius: 16px;
    padding: 24px;
    border: 1px solid rgba(255, 255, 255, 0.5);
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.05);
    backdrop-filter: blur(10px);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s ease;
    display: flex;
    flex-direction: column;
}

.kpi-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 20px 40px rgba(15, 23, 42, 0.1);
}

.kpi-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.kpi-card-title {
    font-family: 'Montserrat', sans-serif;
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--text-secondary);
}

.kpi-card-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: white;
}

.icon-blue { background: linear-gradient(135deg, var(--accent-blue), #60a5fa); }
.icon-red { background: linear-gradient(135deg, var(--accent-red), #fb7185); }
.icon-green { background: linear-gradient(135deg, #10b981, #34d399); }
.icon-yellow { background: linear-gradient(135deg, #f59e0b, #fbbf24); }

.kpi-card-value {
    font-family: 'Montserrat', sans-serif;
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--accent-dark);
    margin-bottom: 8px;
}

.kpi-card-target {
    font-size: 0.9rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.kpi-card-target .indicator {
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.8rem;
}

.indicator.up { background: #dcfce7; color: #166534; }
.indicator.down { background: #fee2e2; color: #991b1b; }

.kpi-chart-card {
    background: white;
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    border: var(--glass-border);
    margin-bottom: 24px;
}

.kpi-chart-title {
    font-family: 'Montserrat', sans-serif;
    font-weight: 600;
    font-size: 1.25rem;
    color: var(--accent-dark);
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.kpi-chart-container {
    position: relative;
    height: 300px;
    width: 100%;
}
/* --- OVERVIEW REDISEÑO DENSO (QUIMUNSA STYLE PREMIUM) --- */
.dense-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 24px;
}
.ultra-dense-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}
.dense-card {
    background: linear-gradient(145deg, #ffffff, #f8fafc);
    border-radius: 12px;
    padding: 14px;
    border: 1px solid rgba(226, 232, 240, 0.8);
    box-shadow: 0 10px 25px -5px rgba(15, 23, 42, 0.05), 0 8px 10px -6px rgba(15, 23, 42, 0.01);
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.dense-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 20px 30px -10px rgba(15, 23, 42, 0.1);
}
.dense-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; width: 100%; height: 4px;
    background: linear-gradient(90deg, var(--accent-blue), #60a5fa);
    opacity: 0;
    transition: opacity 0.3s ease;
}
.dense-card:hover::before {
    opacity: 1;
}
.dense-card-title {
    font-size: 0.78rem;
    color: #64748b;
    text-transform: uppercase;
    font-weight: 700;
    margin-bottom: 8px;
    letter-spacing: 0.8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.dense-card-value {
    font-size: 1.5rem;
    font-weight: 800;
    color: #0f172a;
    line-height: 1.2;
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex-wrap: wrap;
}
.kpi-yoy {
    display: inline-flex;
    align-items: center;
    margin-top: 8px;
}
.badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    color: white;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.historical-table {
    width: 100%;
    margin-top: 16px;
    font-size: 0.85rem;
    border-collapse: collapse;
    background: #f8fafc;
    border-radius: 8px;
    overflow: hidden;
}
.historical-table td {
    padding: 6px 12px;
    border-bottom: 1px solid rgba(226, 232, 240, 0.8);
    color: #475569;
}
.historical-table tr:last-child td { border-bottom: none; }
.historical-table td:last-child {
    text-align: right;
    font-weight: 700;
    color: #1e293b;
}
.dense-chart-container {
    background: white;
    border-radius: 12px;
    padding: 14px;
    border: 1px solid rgba(226, 232, 240, 0.8);
    height: 160px;
    position: relative;
    box-shadow: 0 10px 25px -5px rgba(15, 23, 42, 0.05);
}
.dense-chart-container.large {
    height: 200px;
}
.dense-row {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}
.flex-1 { flex: 1; }
.flex-2 { flex: 2; }
.flex-3 { flex: 3; }
.pnc-table-wrapper {
    overflow-x: auto;
    font-size: 0.75rem;
}
.pnc-table th {
    padding: 6px 10px;
}
.pnc-table td {
    padding: 6px 10px;
}

/* ============================================================
   KPI Historical Cards (estilo PDF referencia)
   ============================================================ */
.kpi-hist-card {
    padding: 12px 14px;
}
.kpi-hist-title {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 4px;
}
.kpi-hist-value {
    font-size: 1.65rem;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.03em;
    line-height: 1.1;
    margin-bottom: 6px;
}
.kpi-hist-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 4px;
}
.kpi-hist-table tr td {
    font-size: 0.78rem;
    padding: 2px 0;
    color: var(--text-secondary);
    border: none;
}
.kpi-hist-table tr:last-child td {
    font-weight: 700;
    color: var(--text-primary);
}
.kpi-hist-table tr td:last-child {
    text-align: right;
    font-weight: 600;
}



/* GLOBAL SCALE REDUCTION & LOADER */
.main-content { padding: 1.5rem; }
.kpi-dashboard { transform: scale(1); }

/* Global Loader Overlay */
#global-blur-loader {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(255, 255, 255, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: opacity 0.3s ease;
}
#global-blur-loader.hidden {
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
}
.loader-spinner {
    width: 60px;
    height: 60px;
    border: 5px solid rgba(37, 99, 235, 0.2);
    border-radius: 50%;
    border-top-color: var(--accent-blue);
    animation: spin 1s ease-in-out infinite;
    margin-bottom: 20px;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
.loader-text {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-dark);
    letter-spacing: 2px;
    animation: pulse 1.5s infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}
