/*
Theme Name: Ambiental Theme
Theme URI: https://example.com/ambiental-theme
Author: Tu Nombre
Author URI: https://example.com
Description: Tema profesional tipo SaaS/Dashboard con sidebar, dark mode y diseño moderno minimalista.
Version: 2.8.5
Requires at least: 5.0
Tested up to: 6.4
Requires PHP: 7.4
Text Domain: ambiental-theme
*/

/* ========================================
   1. CSS Variables - Premium SaaS Palette
   ======================================== */
:root {
    --color-primary: #10b981;
    /* Emerald 500 */
    --color-primary-dark: #059669;
    /* Emerald 600 */
    --color-primary-light: #d1fae5;
    /* Emerald 100 */

    --color-bg-app: #f3f4f6;
    /* Cool Gray 100 */
    --color-bg-sidebar: #ffffff;
    --color-bg-card: #ffffff;

    --color-text-main: #1f2937;
    /* Gray 800 */
    --color-text-muted: #6b7280;
    /* Gray 500 */
    --color-border: #e5e7eb;
    /* Gray 200 */

    --sidebar-width: 270px;
    --sidebar-collapsed-width: 90px;

    --shadow-subtle: 0 1px 3px 0 rgba(0, 0, 0, 0.05), 0 1px 2px -1px rgba(0, 0, 0, 0.05);
    --shadow-card: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.02);
    --shadow-dropdown: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.04);

    --font-main: 'Inter', system-ui, -apple-system, sans-serif;
    --radius-lg: 0.75rem;
    --radius-md: 0.5rem;
}

[data-theme="dark"] {
    --color-bg-app: #0f172a;
    --color-bg-sidebar: #1e293b;
    --color-bg-card: #1e293b;
    --color-text-main: #f8fafc;
    --color-text-muted: #94a3b8;
    --color-border: #334155;
    --shadow-card: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
}

/* ========================================
   2. Reset & Essentials
   ======================================== */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-main);
    background-color: var(--color-bg-app);
    color: var(--color-text-main);
    font-size: 0.95rem;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Custom Scrollbar for Sidebar */
.sidebar-nav::-webkit-scrollbar {
    width: 5px;
}

.sidebar-nav::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background-color: var(--color-border);
    border-radius: 10px;
}

/* ========================================
   3. Main Layout Architecture
   ======================================== */
.app-container {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

/* Sidebar - Fixed & Premium */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: var(--sidebar-width);
    background: var(--color-bg-sidebar);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    z-index: 999;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-subtle);
}

/* Main Content Wrapper */
.main-content {
    margin-left: var(--sidebar-width);
    /* Push content */
    flex: 1;
    display: flex;
    flex-direction: column;
    /* Sticks footer to bottom */
    min-height: 100vh;
    width: 100%;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    background: var(--color-bg-app);
}

.content-inner {
    padding: 2rem;
    flex: 1;
    /* Takes available space */
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
    flex-wrap: wrap;
    gap: 1rem;
}

/* WhatsApp Support Button */
.support-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background-color: #25D366;
    /* WhatsApp Green */
    color: white;
    padding: 8px 16px;
    border-radius: 9999px;
    /* Pill shape */
    font-weight: 600;
    text-decoration: none;
    font-size: 0.875rem;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 2px 5px rgba(37, 211, 102, 0.3);
}

.support-link:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(37, 211, 102, 0.4);
    color: white;
}

/* Footer - Correctly Placed */
.site-footer {
    background: var(--color-bg-card);
    border-top: 1px solid var(--color-border);
    padding: 1.5rem 2rem;
    margin-top: auto;
    /* Push to bottom */
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1600px;
    margin: 0 auto;
    flex-wrap: wrap;
    gap: 1rem;
}

/* WhatsApp Support Button */
.support-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background-color: #25D366;
    /* WhatsApp Green */
    color: white;
    padding: 8px 16px;
    border-radius: 9999px;
    /* Pill shape */
    font-weight: 600;
    text-decoration: none;
    font-size: 0.875rem;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 2px 5px rgba(37, 211, 102, 0.3);
}

.support-link:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(37, 211, 102, 0.4);
    color: white;
}

/* ========================================
   4. Sidebar Styling (The Premium Look)
   ======================================== */
.sidebar-header {
    height: 72px;
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    border-bottom: 1px solid var(--color-border);
}

.logo-full img {
    height: 38px;
    width: auto;
}

.logo-collapsed {
    display: none;
    text-align: center;
    width: 100%;
    margin-left: 5px;
    margin-right: 5px;
}

.logo-collapsed img {
    height: 32px;
}

.sidebar-toggle-desktop {
    margin-left: auto;
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    color: var(--color-text-muted);
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    margin-right: 5px;
}

.sidebar-toggle-desktop:hover {
    background: var(--color-bg-app);
    color: var(--color-primary);
    border-color: var(--color-primary);
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.sidebar-menu {
    list-style: none;
    margin: 0;
    padding: 0;
}

.sidebar-menu li {
    margin-bottom: 4px;
}

.sidebar-menu a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0.75rem 1rem;
    color: var(--color-text-muted);
    text-decoration: none;
    font-weight: 500;
    border-radius: var(--radius-md);
    transition: all 0.2s ease;
}

.sidebar-menu a:hover {
    background-color: var(--color-bg-app);
    color: var(--color-text-main);
    transform: translateX(4px);
    /* Interactive feel */
}

.sidebar-menu .current-menu-item>a {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.25);
    /* Nice glow */
}

/* Submenus */
.sub-menu {
    padding-left: 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    list-style: none !important;
    margin: 0;
}

.menu-item-has-children.active .sub-menu {
    max-height: 500px;
}


.sub-menu a {
    padding-left: 3.25rem;
    font-size: 0.9rem;
    color: var(--color-text-muted);
    text-align: left;
    justify-content: flex-start;
}

.sub-menu a:hover {
    color: var(--color-primary);
    background: transparent;
}

/* Sidebar Icons Size */
.sidebar-menu a svg,
.sidebar-menu a i,
.sidebar-menu a .dashicons {
    font-size: 1.25rem;
    /* Larger icons */
    width: 1.25rem;
    height: 1.25rem;
}

/* User Details */
.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--color-border);
    position: relative;
}

.user-profile-icon {
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all 0.2s;
    align-items: center;
    justify-content: center;
    padding: auto;
}

.user-profile-icon:hover {
    border-color: var(--color-primary);
    background-color: var(--color-bg-app);
}

.user-profile-trigger {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 0.75rem;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all 0.2s;
}

.user-profile-trigger:hover {
    background: var(--color-bg-app);
    border-color: var(--color-border);
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    object-fit: cover;
}

.user-info {
    flex: 1;
    text-align: left;
    overflow: hidden;
}

.user-name {
    display: block;
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    display: block;
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

/* Dropdown User */
.user-dropdown {
    display: none;
    position: absolute;
    bottom: 100%;
    left: 1rem;
    right: 1rem;
    margin-bottom: 0.5rem;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-dropdown);
    padding: 0.5rem;
    z-index: 100;
}

.user-dropdown.is-active {
    display: block !important;
    animation: slideUp 0.2s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Fix for icons showing both at same time */
.theme-icon-light[hidden],
.theme-icon-dark[hidden] {
    display: none !important;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 0.75rem 1rem;
    border: none;
    background: transparent;
    color: var(--color-text-main);
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: var(--radius-md);
    cursor: pointer;
    text-decoration: none;
}

.dropdown-item:hover {
    background: var(--color-bg-app);
    color: var(--color-primary);
}

.dropdown-item-danger:hover {
    background: #fee2e2;
    color: #ef4444;
}


/* ========================================
   5. Collapsed State
   ======================================== */
@media (min-width: 1024px) {
    body.sidebar-collapsed .sidebar {
        width: var(--sidebar-collapsed-width);
    }

    /* Collapsed User Dropdown */
    body.sidebar-collapsed .user-dropdown {
        left: 100%;
        bottom: 0;
        margin-left: 10px;
        width: 250px;
        right: auto;
        top: auto;
    }

    body.sidebar-collapsed .user-dropdown.is-active {
        display: block !important;
    }

    /* Collapsed Submenus Flyout */
    body.sidebar-collapsed .sidebar-menu li {
        position: relative;
    }

    body.sidebar-collapsed .sidebar-menu li:hover>.sub-menu {
        display: block;
        position: absolute;
        left: 100%;
        top: 0;
        width: 220px;
        background: var(--color-bg-card);
        border: 1px solid var(--color-border);
        box-shadow: var(--shadow-dropdown);
        border-radius: 0 8px 8px 8px;
        padding: 0.5rem 0;
        max-height: none !important;
        overflow: visible;
        z-index: 1000;
    }

    body.sidebar-collapsed .sub-menu a {
        padding-left: 1.5rem;
        /* Reset padding */
        white-space: nowrap;
        /* Prevent wrapping */
    }

    /* CRITICAL FIX: Show text in flyout submenus */
    body.sidebar-collapsed .sidebar-menu li:hover>.sub-menu .nav-text {
        display: inline-block !important;
        position: static !important;
        background: transparent !important;
        color: var(--color-text-muted) !important;
        padding: 0 !important;
        box-shadow: none !important;
        width: auto !important;
    }

    body.sidebar-collapsed .sidebar-menu li:hover>.sub-menu a:hover .nav-text {
        color: var(--color-primary) !important;
    }

    body.sidebar-collapsed .sidebar-menu li:hover>a .nav-text {
        /* Adjust flyout text if needed, or rely on existing */
        border-radius: 0 8px 0 0;
        /* Connect with submenu */
    }

    body.sidebar-collapsed .main-content {
        margin-left: var(--sidebar-collapsed-width);
    }

    /* CRITICAL: Allow flyouts to escape */
    body.sidebar-collapsed .sidebar-nav {
        overflow: visible !important;
    }

    body.sidebar-collapsed .logo-full,
    body.sidebar-collapsed .nav-text,
    body.sidebar-collapsed .user-info,
    body.sidebar-collapsed .menu-item-has-children>a::after {
        display: none;
    }

    body.sidebar-collapsed .logo-collapsed {
        display: block;
    }

    body.sidebar-collapsed .sidebar-header {
        padding: 0;
        justify-content: center;
    }

    body.sidebar-collapsed .sidebar-menu a {
        justify-content: center;
        padding: 1rem 0;
    }

    body.sidebar-collapsed .user-profile-trigger {
        justify-content: center;
        padding: 0.5rem;
    }

    /* Hover Flyout */
    body.sidebar-collapsed .sidebar-menu li:hover>a .nav-text {
        display: block;
        position: absolute;
        left: 100%;
        top: 0;
        background: var(--color-primary-dark);
        color: white;
        padding: 0.75rem 1rem;
        border-radius: 0 8px 8px 0;
        white-space: nowrap;
        z-index: 999;
        box-shadow: 4px 0 10px rgba(0, 0, 0, 0.1);
    }
}

/* ========================================
   6. Mobile Styles
   ======================================== */
.mobile-header {
    display: none;
}

@media (max-width: 1023px) {
    .app-container {
        display: block;
        /* Prevent flex behavior on mobile */
    }

    .mobile-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        height: 64px;
        padding: 0 1.5rem;
        background: var(--color-bg-card);
        border-bottom: 1px solid var(--color-border);
        position: sticky;
        top: 0;
        z-index: 40;
    }

    .mobile-brand {
        font-weight: 700;
        font-size: 1rem;
        color: var(--color-text-main);
    }

    #mobile-menu-toggle {
        order: -1;
        background: transparent;
        border: 1px solid var(--color-border);
        border-radius: 8px;
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        color: var(--color-text-main);
        cursor: pointer;
        -webkit-appearance: none;
        appearance: none;
    }

    .mobile-brand {
        font-weight: 700;
        font-size: 1rem;
        color: var(--color-text-main);
    }

    #mobile-menu-toggle {
        order: -1;
        background: transparent;
        border: 1px solid var(--color-border);
        border-radius: 8px;
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        color: var(--color-text-main);
        cursor: pointer;
        -webkit-appearance: none;
        appearance: none;
    }

    .sidebar {
        transform: translateX(-100%);
        width: 280px;
        z-index: 1000;
        /* Above everything */
    }

    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        padding-top: 0;
        /* Let sticky header handle flow */
    }

    .content-inner {
        padding: 1rem;
        /* Reduce padding for mobile */
    }

    body.sidebar-open .sidebar {
        transform: translateX(0);
        box-shadow: 0 0 50px rgba(0, 0, 0, 0.2);
    }

    /* Overlay */
    body.sidebar-open .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.4);
        backdrop-filter: blur(4px);
        z-index: 900;
        display: block;
    }
}