/* ============================================================
   Mill Integrator IA 360 - Theme System
   Baseado no ERP Millgest IA 360 (style.css / crud_basico.css)
   ============================================================ */

/* --- CSS Variables (Light Mode) --- */
:root {
    --primary: #3b82f6;
    --primary-rgb: 59, 130, 246;
    --primary-light: #eff6ff;
    --bg-body: #f8fafc;
    --bg-card: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --sidebar-bg: #1e293b;
    --sidebar-active: rgba(var(--primary-rgb), 0.2);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 10px 25px -5px rgba(0,0,0,0.15);
    --radius: 8px;
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- CSS Variables (Dark Mode) --- */
.dark-theme {
    --bg-body: #0f172a;
    --bg-card: #1e293b;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border-color: #334155;
    --primary-light: rgba(59, 130, 246, 0.1);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
    --shadow-lg: 0 10px 25px -5px rgba(0,0,0,0.4);
}

/* --- Global Resets --- */
body {
    background-color: var(--bg-body) !important;
    color: var(--text-main);
    font-family: 'Calibri', 'Inter', 'Segoe UI', sans-serif !important;
    transition: background 0.3s, color 0.3s;
    margin: 0;
    overflow-x: hidden;
}

/* --- Page Wrapper --- */
.page-wrapper { min-height: 100vh; }

/* --- Sidebar Vertical Navbar --- */
.navbar-vertical.navbar-expand-lg .navbar-collapse { flex-direction: column; }
.navbar-vertical .nav-link {
    padding: 0.5rem 1rem;
    border-radius: 6px;
    margin: 2px 8px;
    transition: var(--transition);
    font-size: 0.875rem;
    font-weight: 500;
}
.navbar-vertical .nav-link:hover { background: rgba(255,255,255,0.08); }
.navbar-vertical .nav-link.active {
    background: var(--sidebar-active);
    color: #93c5fd !important;
    font-weight: 600;
}

/* --- Cards --- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}
.card:hover { box-shadow: var(--shadow-md); }

.stat-card { transition: transform 0.2s, box-shadow 0.2s; }
.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* --- Tables --- */
.table {
    color: var(--text-main);
}
.table th {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    padding: 12px 16px;
}
.table td {
    padding: 12px 16px;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}
.table tr:hover td {
    background: rgba(59, 130, 246, 0.03);
}
.dark-theme .table tr:hover td {
    background: rgba(255,255,255,0.02);
}

/* --- Premium Badge System (Soft Pill Style) --- */
/* Override Tabler/Bootstrap default badges with readable soft pills */
.badge {
    font-size: 0.72rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 20px;
    letter-spacing: 0.02em;
}

/* Success - Green soft pill */
.badge.bg-success {
    background: rgba(16, 185, 129, 0.12) !important;
    color: #059669 !important;
    border: 1px solid rgba(16, 185, 129, 0.2);
}
.dark-theme .badge.bg-success {
    background: rgba(16, 185, 129, 0.15) !important;
    color: #34d399 !important;
    border-color: rgba(16, 185, 129, 0.3);
}

/* Danger - Red soft pill */
.badge.bg-danger {
    background: rgba(239, 68, 68, 0.12) !important;
    color: #dc2626 !important;
    border: 1px solid rgba(239, 68, 68, 0.2);
}
.dark-theme .badge.bg-danger {
    background: rgba(239, 68, 68, 0.15) !important;
    color: #f87171 !important;
    border-color: rgba(239, 68, 68, 0.3);
}

/* Warning - Amber soft pill */
.badge.bg-warning {
    background: rgba(245, 158, 11, 0.12) !important;
    color: #d97706 !important;
    border: 1px solid rgba(245, 158, 11, 0.2);
}
.dark-theme .badge.bg-warning {
    background: rgba(245, 158, 11, 0.15) !important;
    color: #fbbf24 !important;
    border-color: rgba(245, 158, 11, 0.3);
}

/* Info - Cyan soft pill */
.badge.bg-info {
    background: rgba(6, 182, 212, 0.12) !important;
    color: #0891b2 !important;
    border: 1px solid rgba(6, 182, 212, 0.2);
}
.dark-theme .badge.bg-info {
    background: rgba(6, 182, 212, 0.15) !important;
    color: #22d3ee !important;
    border-color: rgba(6, 182, 212, 0.3);
}

/* Secondary - Slate soft pill */
.badge.bg-secondary {
    background: rgba(100, 116, 139, 0.12) !important;
    color: #475569 !important;
    border: 1px solid rgba(100, 116, 139, 0.2);
}
.dark-theme .badge.bg-secondary {
    background: rgba(100, 116, 139, 0.15) !important;
    color: #94a3b8 !important;
    border-color: rgba(100, 116, 139, 0.3);
}

/* Blue soft pill (for typeBadge: csv, postgresql) */
.badge.bg-blue {
    background: rgba(59, 130, 246, 0.12) !important;
    color: #2563eb !important;
    border: 1px solid rgba(59, 130, 246, 0.2);
}
.dark-theme .badge.bg-blue {
    background: rgba(59, 130, 246, 0.15) !important;
    color: #60a5fa !important;
    border-color: rgba(59, 130, 246, 0.3);
}

/* Red soft pill (for typeBadge: oracle) */
.badge.bg-red {
    background: rgba(239, 68, 68, 0.12) !important;
    color: #dc2626 !important;
    border: 1px solid rgba(239, 68, 68, 0.2);
}
.dark-theme .badge.bg-red {
    background: rgba(239, 68, 68, 0.15) !important;
    color: #f87171 !important;
    border-color: rgba(239, 68, 68, 0.3);
}

/* Green soft pill (for typeBadge: json) */
.badge.bg-green {
    background: rgba(16, 185, 129, 0.12) !important;
    color: #059669 !important;
    border: 1px solid rgba(16, 185, 129, 0.2);
}
.dark-theme .badge.bg-green {
    background: rgba(16, 185, 129, 0.15) !important;
    color: #34d399 !important;
    border-color: rgba(16, 185, 129, 0.3);
}

/* Purple soft pill (for typeBadge: api) */
.badge.bg-purple {
    background: rgba(139, 92, 246, 0.12) !important;
    color: #7c3aed !important;
    border: 1px solid rgba(139, 92, 246, 0.2);
}
.dark-theme .badge.bg-purple {
    background: rgba(139, 92, 246, 0.15) !important;
    color: #a78bfa !important;
    border-color: rgba(139, 92, 246, 0.3);
}

/* Orange soft pill (for typeBadge: mysql) */
.badge.bg-orange {
    background: rgba(249, 115, 22, 0.12) !important;
    color: #ea580c !important;
    border: 1px solid rgba(249, 115, 22, 0.2);
}
.dark-theme .badge.bg-orange {
    background: rgba(249, 115, 22, 0.15) !important;
    color: #fb923c !important;
    border-color: rgba(249, 115, 22, 0.3);
}

/* Primary soft pill */
.badge.bg-primary {
    background: rgba(59, 130, 246, 0.12) !important;
    color: #2563eb !important;
    border: 1px solid rgba(59, 130, 246, 0.2);
}
.dark-theme .badge.bg-primary {
    background: rgba(59, 130, 246, 0.15) !important;
    color: #60a5fa !important;
    border-color: rgba(59, 130, 246, 0.3);
}

/* --- Mapping Row States --- */
.mapping-row.mapped { border-left: 3px solid #10b981; }
.mapping-row.default { border-left: 3px solid #f59e0b; }
.mapping-row.unmapped { border-left: 3px solid #94a3b8; }
.mapping-row:hover { background: rgba(59, 130, 246, 0.04); }
.dark-theme .mapping-row:hover { background: rgba(59, 130, 246, 0.06); }

/* --- Preview Table --- */
.preview-table { font-size: 12px; table-layout: fixed; min-width: 1600px; }
.preview-table td, .preview-table th { padding: 4px 8px; vertical-align: middle; }
.preview-table input, .preview-table select { font-size: 12px; }

/* --- Field Tags --- */
.field-tag { display: inline-block; padding: 2px 8px; margin: 2px; border-radius: 4px; font-size: 11px; }
.field-tag.mapped { background: rgba(16, 185, 129, 0.1); color: #059669; }
.field-tag.unmapped { background: rgba(245, 158, 11, 0.1); color: #d97706; }
.field-tag.default { background: rgba(59, 130, 246, 0.1); color: #2563eb; }
.expression-tag {
    background: rgba(139, 92, 246, 0.1);
    color: #7c3aed;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: monospace;
    font-size: 11px;
}

/* --- Status Colors --- */
.status-success { color: #10b981; }
.status-error { color: #ef4444; }
.status-running { color: #f59e0b; }

/* --- Toasts --- */
.toast { min-width: 300px; }

/* --- Page Section Animation --- */
.page-section { animation: fadeIn 0.25s ease-out; }
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- Disable Tabler.io auto-uppercase on table headers, subtitles, tabs --- */
.subheader,
table th,
.table th,
thead th,
.card-title,
.modal-title,
.nav-link,
.page-title {
    text-transform: none !important;
    letter-spacing: normal !important;
}

/* --- Buttons Premium --- */
.btn {
    font-weight: 600;
    border-radius: 6px;
    transition: var(--transition);
    font-size: 0.85rem;
}
.btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.btn-outline-primary {
    border-color: rgba(59, 130, 246, 0.3);
    color: #3b82f6;
}
.btn-outline-primary:hover {
    background: rgba(59, 130, 246, 0.08);
    border-color: #3b82f6;
    color: #2563eb;
}

.btn-outline-info {
    border-color: rgba(6, 182, 212, 0.3);
    color: #0891b2;
}
.btn-outline-info:hover {
    background: rgba(6, 182, 212, 0.08);
    border-color: #0891b2;
    color: #0e7490;
}

/* --- Dark Mode Adjustments --- */
.dark-theme body,
.dark-theme .page-wrapper {
    background-color: var(--bg-body) !important;
    color: var(--text-main);
}

.dark-theme .card {
    background: var(--bg-card);
    border-color: var(--border-color);
}

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

.dark-theme .form-control,
.dark-theme .form-select {
    background: var(--bg-body);
    border-color: var(--border-color);
    color: var(--text-main);
}

.dark-theme .form-control:focus,
.dark-theme .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.15);
}

.dark-theme .modal-content {
    background: var(--bg-card);
    border-color: var(--border-color);
    color: var(--text-main);
}

.dark-theme .modal-header,
.dark-theme .modal-footer {
    border-color: var(--border-color);
}

.dark-theme .input-group-text {
    background: var(--bg-card);
    border-color: var(--border-color);
    color: var(--text-muted);
}

.dark-theme .text-muted {
    color: var(--text-muted) !important;
}

.dark-theme .nav-tabs .nav-link {
    color: var(--text-muted);
}
.dark-theme .nav-tabs .nav-link.active {
    background: var(--bg-card);
    border-color: var(--border-color);
    color: var(--text-main);
}

.dark-theme code {
    color: #a78bfa;
    background: rgba(139, 92, 246, 0.1);
}

/* --- Theme Toggle Button (injected by JS) --- */
.theme-toggle {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 1050;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    transition: var(--transition);
    font-size: 1.1rem;
}
.theme-toggle:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-lg);
    color: var(--primary);
}

/* --- Scrollbar Styling --- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
.dark-theme ::-webkit-scrollbar-thumb { background: #475569; }
.dark-theme ::-webkit-scrollbar-thumb:hover { background: #64748b; }

/* --- Accordion (Formulas Guide) --- */
.accordion-button:not(.collapsed) {
    color: var(--primary);
    background: transparent;
}

/* --- Responsive Layout Adjustments --- */
@media (max-width: 991.98px) {
    .page-wrapper { margin-left: 0 !important; }
    
    /* Mobile Header container alignment and brand styling */
    .navbar-vertical > .container-fluid {
        flex-wrap: nowrap !important;
        height: 56px;
        padding: 0 1rem !important;
        align-items: center;
    }
    
    .navbar-brand {
        margin: 0 !important;
        padding: 0 !important;
    }
    
    .navbar-brand .brand-text {
        font-size: 0.95rem !important;
        max-width: 140px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        display: inline-block;
    }
    
    /* Ensure the mobile dropdown does not overflow the right edge of screen */
    .dropdown-menu-end {
        right: 0 !important;
        left: auto !important;
    }
}

/* --- Fixed Sidebar Footer & Layout --- */
.navbar-vertical {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1030;
    display: flex;
    flex-direction: column;
}

#sidebar-menu {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 60px; /* Leave space for the fixed footer */
}

/* Custom scrollbar for sidebar menu */
#sidebar-menu::-webkit-scrollbar {
    width: 4px;
}
#sidebar-menu::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}
#sidebar-menu::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

.sidebar-footer {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 12px 20px;
    background: #151e2b; /* Slightly darker than sidebar bg #1e293b */
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    z-index: 10;
}
.sidebar-footer .nav-link {
    padding: 0;
    display: flex;
    align-items: center;
    transition: var(--transition);
}
.sidebar-footer .nav-link:hover {
    color: #ef4444 !important;
    background: transparent !important;
}

/* --- Dropdown Menu Positioning Fixes --- */
.dropdown-menu-end {
    right: 0 !important;
    left: auto !important;
}

/* --- Premium Theme Toggle Buttons --- */
#theme-toggle-btn,
#theme-toggle-btn-mobile {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: var(--transition);
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
    padding: 0 !important;
    cursor: pointer;
}
#theme-toggle-btn:hover,
#theme-toggle-btn-mobile:hover {
    background: rgba(var(--primary-rgb), 0.1) !important;
}
.dark-theme #theme-toggle-btn:hover,
.dark-theme #theme-toggle-btn-mobile:hover {
    background: rgba(255, 255, 255, 0.08) !important;
}

/* --- Color Circle Theme Controls --- */
.color-circle {
    display: inline-block;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s;
    border: 2px solid transparent;
}
.color-circle:hover {
    transform: scale(1.2);
}
.color-circle.active {
    border-color: #ffffff;
    box-shadow: 0 0 0 2px var(--text-main);
}
.color-circle.bg-blue { background-color: #206bc4 !important; }
.color-circle.bg-purple { background-color: #6f42c1 !important; }
.color-circle.bg-green { background-color: #2fb344 !important; }
.color-circle.bg-orange { background-color: #f76707 !important; }
.color-circle.bg-red { background-color: #d63939 !important; }

/* --- Login Page Center --- */
.page-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background-color: var(--bg-body);
}

.avatar-sm {
    width: 2rem;
    height: 2rem;
    font-size: .875rem;
    font-weight: 600;
}

/* --- Sidebar Collapsed State (Desktop only, >= 992px) --- */
@media (min-width: 992px) {
    /* Smooth transition for vertical navbar and page content area */
    .navbar-vertical {
        transition: width 0.2s cubic-bezier(0.4, 0, 0.2, 1) !important;
    }
    .page-wrapper {
        transition: margin-left 0.2s cubic-bezier(0.4, 0, 0.2, 1) !important;
    }

    /* Target state when sidebar is collapsed */
    body.sidebar-collapsed .navbar-vertical {
        width: 70px !important;
    }
    body.sidebar-collapsed .page-wrapper {
        margin-left: 70px !important;
    }

    /* Hide the brand text label, leave only icon */
    body.sidebar-collapsed .navbar-vertical .brand-text {
        display: none !important;
    }
    body.sidebar-collapsed .navbar-vertical .navbar-brand {
        justify-content: center !important;
        margin: 0 !important;
        padding: 1rem 0 !important;
    }

    /* Center and strip text labels of navigation links */
    body.sidebar-collapsed .navbar-vertical .navbar-nav .nav-link {
        justify-content: center !important;
        font-size: 0 !important; /* Hides label text */
        padding: 0.75rem 0 !important;
        margin: 4px 10px !important;
        border-radius: 6px;
    }
    body.sidebar-collapsed .navbar-vertical .navbar-nav .nav-link svg {
        margin: 0 !important;
        width: 20px !important;
        height: 20px !important;
    }

    /* Align footer button in collapsed view */
    body.sidebar-collapsed .sidebar-footer {
        padding: 12px 0 !important;
        display: flex;
        justify-content: center;
    }
    body.sidebar-collapsed .sidebar-footer .nav-link {
        justify-content: center !important;
        width: 100%;
    }
    body.sidebar-collapsed .sidebar-footer .nav-link span {
        display: none !important;
    }
    body.sidebar-collapsed .sidebar-footer .nav-link svg {
        margin: 0 !important;
    }
}
