/* Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Roboto+Flex:opsz,wght@8..144,100..1000&family=Roboto:wght@300;400;500;700&display=swap');

/* Class-based theme overrides (for WebView and manual control) - these override media query */
.light,
html.light,
body.light {
    --background-color: #ffffff;
    --dm-border-color: #e5e5e5;
    --color: #212121;
    --sub-color: #bbb;
    --hover-color: #ffffff;
    --hover-background: #f9f9f9;
    --active-color: #212121;
    --sub-active-color: #4b4b4b;
    --message-background: #efefef;
    --status-background: var(--e-global-color-accent);
    --online-background: #e8f5e9;
    --online-color: #28a745;
    --accent-color: var(--e-global-color-primary);
    --message-other-bg: #f5f5f5;
    --message-self-bg: #675e72;
    --pending-color: #c7980e;
    --pending-bg: #fff0c2;
    --completed-color: #66a875;
    --completed-bg: rgba(40, 167, 69, 0.1);
    --running-color: #3e84d0;
    --running-hover: #007dff36;
    --running-bg: #007dff1c;
    --failed-color: #d28289;
    --failed-bg: rgba(220, 53, 69, 0.1);
    --second-btn: #f0f0f0;
    --second-btn-hover: #e7e7e7;
}

.dark,
html.dark,
body.dark {
    --background-color: #212121;
    --dm-border-color: #4a4a4a;
    --color: #ffffff;
    --sub-color: #9b9b9b;
    --hover-color: #ffffff;
    --hover-background: #2f2f2f;
    --active-color: #212121;
    --sub-active-color: #4b4b4b;
    --message-background: #2c2c2c;
    --status-background: var(--hover-background);
    --online-background: #8afe93;
    --online-color: #28a745;
    --accent-color: var(--e-global-color-accent);
    --message-other-bg: #2a2a2a;
    --message-self-bg: #145f31;
    --not-started-color: #986cb9;
    --not-started-hover: #af90c947;
    --not-started-bg: #af90c933;
    --pending-color: #d2b151;
    --pending-bg: #fff3cd1f;
    --completed-color: #66a875;
    --completed-bg: rgba(40, 167, 69, 0.1);
    --running-color: #3e84d0;
    --running-hover: #007dff36;
    --running-bg: #007dff1c;
    --failed-color: #d28289;
    --failed-bg: rgba(220, 53, 69, 0.1);
    --second-btn: #444444;
    --second-btn-hover: var(--dm-border-color);
}

:root {
    --header-height: 75px;
    --input-font-size: 14px;
    --input-padding: 10px;
    --container-padding: 15px;
    
    /* Default light theme variables - applied immediately, no JavaScript needed */
    --background-color: #ffffff;
    --dm-border-color: #e5e5e5;
    --color: #212121;
    --sub-color: #bbb;
    --hover-color: #ffffff;
    --hover-background: #f9f9f9;
    --active-color: #212121;
    --sub-active-color: #4b4b4b;
    --message-background: #efefef;
    --status-background: var(--e-global-color-accent);
    --online-background: #e8f5e9;
    --online-color: #28a745;
    --accent-color: var(--e-global-color-primary);
    --message-other-bg: #f5f5f5;
    --message-self-bg: #675e72;
    --pending-color: #c7980e;
    --pending-bg: #fff0c2;
    --completed-color: #66a875;
    --completed-bg: rgba(40, 167, 69, 0.1);
    --running-color: #3e84d0;
    --running-hover: #007dff36;
    --running-bg: #007dff1c;
    --failed-color: #d28289;
    --failed-bg: rgba(220, 53, 69, 0.1);
    --second-btn: #f0f0f0;
    --second-btn-hover: #e7e7e7;
    --danger: rgba(220, 53, 69);
}

/* === Dashboard: Chat unread dot (sidebar .dash-menus) ================================ */
.dash-menus a.dm-chat-menu-link {
    position: relative;
}

.dash-menus a.dm-chat-menu-link .dm-chat-unread-dot {
    position: absolute;
    top: 9px;
    left: 18px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #f44336;
    border: 2px solid #ffffff;
    display: none;
    pointer-events: none;
    box-sizing: border-box;
}

.dash-menus a.dm-chat-menu-link.dm-chat-has-unread .dm-chat-unread-dot {
    display: block;
}

/* === Mobile Bottom Nav: Chat unread dot ================================ */
.mobile-bottom-nav .mobile-nav-item.dm-chat-menu-link {
    position: relative;
}

.mobile-bottom-nav .mobile-nav-item.dm-chat-menu-link .dm-chat-unread-dot {
    position: absolute;
    top: 10px;
    right: calc(50% + 5px); /* Position relative to icon center */
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #f44336;
    border: 2px solid var(--background-color);
    display: none;
    pointer-events: none;
    box-sizing: border-box;
    z-index: 10;
}

.mobile-bottom-nav .mobile-nav-item.dm-chat-menu-link.dm-chat-has-unread .dm-chat-unread-dot {
    display: block;
}

/* Apply dark theme automatically via CSS media query - NO FLASH! */
@media (prefers-color-scheme: dark) {
    :root {
        --background-color: #212121;
        --dm-border-color: #4a4a4a;
        --color: #ffffff;
        --sub-color: #9b9b9b;
        --hover-color: #ffffff;
        --hover-background: #2f2f2f;
        --active-color: #212121;
        --sub-active-color: #4b4b4b;
        --message-background: #2c2c2c;
        --status-background: var(--hover-background);
        --online-background: #8afe93;
        --online-color: #28a745;
        --accent-color: var(--e-global-color-accent);
        --message-other-bg: #2a2a2a;
        --message-self-bg: #145f31;
        --not-started-color: #986cb9;
        --not-started-hover: #af90c947;
        --not-started-bg: #af90c933;
        --pending-color: #d2b151;
        --pending-bg: #fff3cd1f;
        --completed-color: #66a875;
        --completed-bg: rgba(40, 167, 69, 0.1);
        --running-color: #3e84d0;
        --running-hover: #007dff36;
        --running-bg: #007dff1c;
        --failed-color: #d28289;
        --failed-bg: rgba(220, 53, 69, 0.1);
        --second-btn: #444444;
        --second-btn-hover: var(--dm-border-color);
    }
}


* {
    /*
    --e-global-color-primary: #453750;
    --e-global-color-secondary: #0C0910;
    --e-global-color-text: #2C2A29;
    --e-global-color-accent: #B7FB49;
    --e-global-color-ec09438: #F0F0F0;
    */
    --btn-hover: #ce3152;
    padding: 0;
    margin: 0;
}

/* Global body font */
body {
    font-family: 'Roboto', -apple-system, BlinkMacSystemFont, "Segoe UI", Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}

.climanage-main-container {
    background: var(--background-color);
    display: flex;
    justify-content: center;
    align-items: center;
}

.climanage-dash-container {
    display: flex;
    flex-direction: row;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    max-width: 1475px;
}

.sidebar {
    width: 300px;
    height: 100vh;
    background-color: var(--background-color);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    border-right: 1px solid var(--dm-border-color);
}

.sidebar-footer {
    gap: 0px !important;
}

.page-body {
    width: calc(100vw - 300px);
    overflow-y: auto;
    background-color: var(--background-color);
    color: var(--color);
    font-family: 'Roboto', -apple-system, BlinkMacSystemFont, "Segoe UI", Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}

.sidebar>div {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.dash-menus ul,
.sidebar-footer ul {
    /*margin: 0 -20px;*/
    overflow: hidden;
    position: relative;
    z-index: 1;
}

.dash-menus li,
.sidebar-footer li {
    text-decoration: none;
    list-style: none;
    margin-bottom: 10px;
    transition: all 0.5s;
}

.dash-menus li:after,
.sidebar-footer li {
    transition: all 0.5s;
}

/*.dash-menus li:hover:after,
.dash-menus li.active:after {
    content: "";
    width: 6px;
    height: 70%;
    background: #9b1818;
    position: relative;
    right: 0;
    left: unset;
    top: unset;
    bottom: unset;
}*/

.dash-menus li:hover,
.dash-menus li.active,
.sidebar-footer li:hover {
    background-color: var(--e-global-color-primary);
}

.dash-menus li svg,
.sidebar-footer li svg {
    width: 24px;
}

.dash-menus li path,
.sidebar-footer li path {
    fill: var(--color);
}

.dash-menus li a,
.sidebar-footer li a {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--color);
    padding: 10px 20px !important;
}

.dash-menus li a:hover, .dash-menus li:hover path,
.sidebar-footer li:hover path, .sidebar-footer li a:hover{
    color: var(--hover-color);
    fill: var(--hover-color);
}

.dash-menus li.active a, .dash-menus li.active path,
.sidebar-footer li.active path, .sidebar-footer li.active a {
color: #fff;
fill: #fff;
}

.theme-switch {
    font-size: 16px;
    position: relative;
    display: inline-block;
    width: 60px;
    height: 30px;
}

.theme-toggle {
    padding: 20px;
    padding-top: 0;
}

.theme-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    transition: .4s;
    border-radius: 30px;
    background-color: #675e72;
}

.slider:before {
    position: absolute;
    content: "";
    height: 24px;
    width: 24px;
    border-radius: 20px;
    left: 4px;
    bottom: 3px;
    z-index: 2;
    background-color: var(--e-global-color-secondary);
    transition: .4s;
}

.sun svg {
    fill: var(--e-global-color-ec09438);
    position: absolute;
    top: 6px;
    left: 36px;
    z-index: 1;
    width: 20px;
    height: 20px;
}

.moon svg {
    fill: var(--e-global-color-ec09438);
    ;
    position: absolute;
    top: 5px;
    left: 5px;
    z-index: 1;
    width: 20px;
    height: 20px;
}

/* .switch:hover */
.sun svg {
    animation: rotate 15s linear infinite;
}

@keyframes rotate {

    0% {
        transform: rotate(0);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* .switch:hover */
.moon svg {
    animation: tilt 5s linear infinite;
}

@keyframes tilt {

    0% {
        transform: rotate(0deg);
    }

    25% {
        transform: rotate(-10deg);
    }

    75% {
        transform: rotate(10deg);
    }

    100% {
        transform: rotate(0deg);
    }
}

.input:checked+.slider {
    background-color: var(--e-global-color-primary);
}

.input:focus+.slider {
    box-shadow: 0 0 1px var(--e-global-color-primary);
}

.input:checked+.slider:before {
    transform: translateX(28px);
}

@media (min-width: 1475px) {
    .climanage-main-container {
        padding: 20px;
    }

    .climanage-dash-container {
        height: calc(100vh - 40px);
    }

    .sidebar {
        height: calc(100vh - 40px);
    }
}

/* Header*/
.page-header {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 20px;
    height: var(--header-height);
    border-bottom: 1px solid var(--dm-border-color);
    position: sticky;
    top: 0;
    background-color: var(--background-color);
    z-index: 100;
}

.page-header a{
    display: flex;
    align-items: center;
}

.notifications svg {
    width: 30px;
    height: auto;
    fill: var(--color);
}

.header-profile-link {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    min-width: 0; /* Allow flex item to shrink */
}

.header-profile-image {
    width: 40px;
    height: 40px;
    border-radius: 4px;
    flex-shrink: 0; /* Prevent image from shrinking */
}

.header-user-info {
    display: flex;
    flex-direction: column;
    min-width: 0; /* Allow text truncation */
    flex: 1;
}

.header-user-name {
    font-size: 20px;
    font-weight: 600;
    color: var(--color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

.header-user-status {
    font-size: 12px;
    color: var(--sub-color);
    line-height: 1.2;
}

.header-user-status .completion-percentage {
    color: var(--sub-color);
}

.header-user-status .membership-plan-name {
    color: var(--sub-color, #9b9b9b);
    font-weight: 400;
}

.sidebar .logo {
    padding: 20px;
    border-bottom: 1px solid var(--dm-border-color);
    height: var(--header-height);
    display: flex;
    align-items: center;
}

.sidebar .logo img {
    height: 45px;
    width: auto;
}

.page-content {
    background-color: var(--background-color);
    color: var(--color);
    min-height: 100%;
    font-family: 'Roboto', -apple-system, BlinkMacSystemFont, "Segoe UI", Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}

/* Headings use Roboto Flex */
.page-content h1,
.page-content h2,
.page-content h3,
.page-content h4,
.page-content h5,
.page-content h6,
h1, h2, h3, h4, h5, h6 {
    font-family: 'Roboto Flex', 'Roboto', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-weight: 600;
}

.page-content .climanage-form{
    padding: 20px 0;
}

.climanage-project-tabs{
    padding: 20px;
    overflow: hidden;
}

.currency-switcher {
    margin-bottom: 10px;
    padding: 0 15px;
}

/* Responsive Styles */
@media (max-width: 1024px) {
    .climanage-dash-container {
        position: relative;
        border: none;
    }
    
    .sidebar {
        position: fixed;
        left: -300px;
        transition: left 0.3s ease;
        z-index: 1000;
        height: 100%;
    }
    
    .sidebar.active {
        left: 0;
    }
    
    .page-body {
        width: 100%;
    }
    
    /* Hide hamburger on mobile/tablet; profile image toggles the sidebar */
    .menu-toggle { display: none; }
    
    .menu-toggle svg {
        width: 24px;
        height: 24px;
        fill: var(--color);
    }
    
    /* Overlay when sidebar is open */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
    }
    
    .sidebar-overlay.active {
        display: block;
    }

    /* Mobile bottom navigation */
    .mobile-bottom-nav {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        height: 60px;
        background: var(--background-color);
        border-top: none;
        border-radius: 20px 20px 0 0;
        display: flex;
        align-items: center;
        justify-content: space-around;
        z-index: 1001;
        padding-bottom: env(safe-area-inset-bottom);
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    }

    .mobile-bottom-nav .mobile-safe-area {
        display: none;
    }

    .mobile-bottom-nav .mobile-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        text-decoration: none;
        color: var(--sub-color);
        gap: 4px;
        height: 100%;
        position: relative;
        transition: color 0.2s ease;
    }

    .mobile-bottom-nav .mobile-nav-item .indicator {
        position: absolute;
        top: 0;
        left: 50%;
        transform: translateX(-50%);
        width: 30px;
        height: 3px;
        background: transparent;
        border-radius: 0 0 2px 2px;
        transition: background 0.2s ease;
    }

    .mobile-bottom-nav .mobile-nav-item.active .indicator {
        background: var(--e-global-color-primary);
    }

    .mobile-bottom-nav .mobile-nav-item .icon {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .mobile-bottom-nav .mobile-nav-item .icon svg {
        width: 24px;
        height: 24px;
    }

    .mobile-bottom-nav .mobile-nav-item .icon svg path {
        fill: var(--sub-color);
        transition: fill 0.2s ease;
    }

    .mobile-bottom-nav .mobile-nav-item .label {
        font-size: 11px;
        line-height: 1;
        font-weight: 400;
    }
    
    .mobile-bottom-nav .mobile-nav-item:hover {
        color: var(--sub-color);
        background: transparent;
    }

    .mobile-bottom-nav .mobile-nav-item.active {
        color: var(--e-global-color-primary);
        background: transparent;
    }

    .mobile-bottom-nav .mobile-nav-item.active .icon svg path {
        fill: var(--e-global-color-primary);
    }

    /* Ensure content not hidden under bottom bar */
    .page-content {
        padding-bottom: 90px;
    }
    
    .chat-header, .menu-desktop-only {
        display: none;
    }
}

@media (min-width: 1025px) {
    .menu-toggle, .dash-menus li, .mobile-bottom-nav{
        display: none;
    }
    
    .menu-desktop-only, .menu-desktop-mobile{
        display: block !important;
    }
    .page-header {
        flex-direction: row-reverse;
        justify-content: flex-start !important;
        gap: 15px;
    }
    
    /* Ensure menu toggle doesn't interfere (it's hidden but just in case) */
    .page-header .menu-toggle {
        display: none !important;
    }
    
    /* Group notifications and profile together on the right */
    .page-header .notifications {
        margin-left: 0;
        flex-shrink: 0;
    }
    
    .page-header .header-profile-link {
        margin-left: 0;
        flex-shrink: 0;
        flex: 0 0 auto;
    }
    
    /* Hide user info on desktop, show only image */
    .header-user-info {
        display: none;
    }
}

/* Sidebar should appear above bottom nav */
.sidebar { z-index: 1100; }