/* CSS Variables for Main Colors */
:root {
    --main-color: #002415; /* Dark Green/Black - Your Brand Color */
    --accent-color: #28a745; /* A vibrant green for success/send buttons */
    --primary-light: #e0f2f7; /* Light blue/green for action buttons */
    --primary-dark: #004d33; /* Darker shade of main color */
    --secondary-blue: #007bff; /* Secondary blue for general info */
}

/* General Styling & Mobile Full Screen */
html, body {
    height: 100%; /* Ensure full height */
    width: 100%;  /* Ensure full width */
    margin: 0;
    padding: 0;
    overflow: hidden; /* Hide scrollbars, manage scrolling within components */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f0f2f5;
    color: #333;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

/* Page Management */
.page {
    width: 100vw; /* Take full viewport width */
    height: 100vh; /* Take full viewport height */
    background-color: #fff;
    box-shadow: none; /* No box shadow for full screen */
    border-radius: 0; /* No border-radius for full screen */
    margin: 0;
    overflow: hidden;
    display: none; /* Hidden by default, JS controls visibility */
    flex-direction: column;
}

.page.active {
    display: flex;
}

/* Login Page (Centered on Screen) */
#login-page {
    justify-content: center;
    align-items: center;
    background-color: var(--main-color); /* Match login background to brand color */
    color: white; /* Text color on dark background */
}

.login-container {
    padding: 30px;
    text-align: center;
    width: 100%;
    max-width: 380px;
    background-color: #fff;
    border-radius: 12px; /* Slightly more pronounced radius */
    box-shadow: 0 8px 20px rgba(0,0,0,0.2); /* Deeper shadow */
    color: #333; /* Reset text color for container content */
}

.company-logo {
    max-width: 180px;
    height: auto;
    margin-bottom: 25px;
    /* Optional: If the logo has a light background and clashes, apply filter invert or a specific white version */
    /* filter: brightness(0) invert(1); to make it white (if original is black) */
}

.login-container h2 {
    color: var(--main-color);
    margin-bottom: 25px;
    font-size: 1.8em;
}

.login-container .input-group {
    margin-bottom: 20px;
    text-align: left;
}

.login-container label {
    display: block;
    margin-bottom: 8px;
    font-weight: bold;
    color: #555;
    font-size: 0.95em;
}

.login-container input[type="text"] {
    width: calc(100% - 22px);
    padding: 14px 10px; /* Larger touch target */
    border: 1px solid #ccc;
    border-radius: 8px; /* Slightly more rounded */
    font-size: 1em;
    box-sizing: border-box;
    -webkit-appearance: none; /* For consistent styling on iOS */
}
.login-container input[type="text"]:focus {
    outline: none;
    border-color: var(--secondary-blue);
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.2);
}

.login-container button {
    background-color: var(--main-color);
    color: white;
    padding: 14px 25px; /* Larger touch target */
    border: none;
    border-radius: 8px; /* Slightly more rounded */
    cursor: pointer;
    font-size: 1.1em;
    transition: background-color 0.3s ease, transform 0.1s ease;
    width: 100%;
    margin-top: 10px;
}
.login-container button:hover {
    background-color: var(--primary-dark);
}
.login-container button:active { /* Touch feedback */
    transform: translateY(1px);
    background-color: color-mix(in srgb, var(--primary-dark), black 10%);
}

.login-message {
    margin-top: 15px;
    font-weight: bold;
    color: #dc3545;
}

.hint {
    margin-top: 25px;
    font-size: 0.85em;
    color: #777;
    text-align: left;
    line-height: 1.4;
    background-color: #f8f9fa;
    border-left: 4px solid var(--main-color);
    padding: 10px 15px;
    border-radius: 4px;
}

/* Chatbot Page Layout */
#chatbot-page {
    position: relative; /* For absolutely positioned views */
    flex-direction: column;
}

.chatbot-header {
    background-color: var(--main-color);
    color: white;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    z-index: 10;
    flex-shrink: 0;
    font-size: 0.9em; /* Make user info smaller in header */
    height: 60px; /* Fixed height header */
}

.chatbot-header h1 {
    margin: 0;
    font-size: 1.2em; /* Smaller on mobile */
    flex-grow: 1; /* Allow title to grow */
    text-align: center;
    position: absolute; /* Center title */
    left: 50%;
    transform: translateX(-50%);
}

#user-info {
    font-size: 0.8em;
    opacity: 0.8;
    flex-shrink: 0;
    padding-left: 10px; /* Space for the toggle button */
}

.header-button {
    background: none;
    border: none;
    color: white;
    font-size: 1em; /* Smaller text button */
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 6px;
    transition: background-color 0.2s ease, transform 0.1s ease;
    -webkit-appearance: none; /* For consistent styling on iOS */
    touch-action: manipulation; /* Prevent default touch behavior delay */
}
.header-button:hover {
    background-color: color-mix(in srgb, var(--main-color), white 10%);
}
.header-button:active {
    background-color: color-mix(in srgb, var(--main-color), white 20%);
    transform: translateY(1px);
}
.header-button i { /* Icon buttons get larger icon */
    font-size: 1.2em;
}

#logout-button {
    margin-left: auto; /* Push logout to the right */
    margin-right: 5px; /* Add slight right margin */
}
#toggle-view-button {
    order: -1; /* Place toggle button to the left */
    font-size: 1em;
    font-weight: bold;
}


/* --- App View Container and Sliding Views --- */
#chat-app-wrapper {
    flex-grow: 1; /* Takes all available vertical space */
    position: relative; /* Container for absolute positioned views */
    overflow: hidden; /* Hide views off-screen */
    width: 100%;
}

.app-view {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1); /* Smoother slide transition */
    background-color: #fbfdff; /* Background for views */
    display: flex;
    flex-direction: column; /* Ensure content stacks vertically */
    backface-visibility: hidden; /* Prevent flickering */
    -webkit-backface-visibility: hidden;
}

#chat-view {
    transform: translateX(0); /* Default active */
    z-index: 2;
}

#actions-view {
    transform: translateX(100%); /* Start off-screen to the right */
    z-index: 1;
    background-color: #f8f9fa; /* Slightly different background for actions */
}

/* State when Actions view is active */
#chat-app-wrapper.show-actions #chat-view {
    transform: translateX(-100%); /* Slide chat off to the left */
}
#chat-app-wrapper.show-actions #actions-view {
    transform: translateX(0); /* Slide actions into view */
}

/* Chat View Specifics */
#chat-view .chat-messages {
    flex-grow: 1;
    padding: 15px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-bottom: 70px; /* Space for fixed input area */
}

#chat-view .chat-input-area {
    position: absolute; /* Fixed at bottom of chat view */
    bottom: 0;
    left: 0;
    width: 100%;
    display: flex;
    padding: 10px 15px;
    border-top: 1px solid #eee;
    background-color: #fff;
    gap: 8px;
    box-sizing: border-box; /* Include padding in width */
    z-index: 3; /* Above messages, below header */
    box-shadow: 0 -2px 5px rgba(0,0,0,0.05); /* Slight shadow to lift it */
}

#chat-view #user-input {
    flex-grow: 1;
    padding: 12px 15px; /* Larger for touch */
    border: 1px solid #ddd;
    border-radius: 25px; /* More rounded pill shape */
    font-size: 1em;
    -webkit-appearance: none;
}
#chat-view #user-input:focus {
    outline: none;
    border-color: var(--secondary-blue);
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.2);
}

#chat-view #send-button {
    background-color: var(--accent-color);
    color: white;
    border: none;
    border-radius: 25px;
    padding: 10px 18px; /* Adjusted padding */
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.3s ease, transform 0.1s ease;
    display: flex;
    align-items: center;
    gap: 5px;
}
#chat-view #send-button:hover {
    background-color: #218838;
}
#chat-view #send-button:active {
    transform: translateY(1px);
    background-color: color-mix(in srgb, var(--accent-color), black 10%);
}

.chat-message {
    max-width: 90%; /* Wider for mobile conversation */
    padding: 10px 15px;
    border-radius: 18px;
    line-height: 1.4;
    word-wrap: break-word;
    font-size: 0.95em;
    align-self: flex-start;
}
.user-message {
    background-color: #e6f7ff;
    align-self: flex-end;
    color: #333;
    border-bottom-right-radius: 5px;
}
.bot-message {
    background-color: #f0f0f0;
    align-self: flex-start;
    color: #333;
    border-bottom-left-radius: 5px;
}

/* Actions View Specifics */
#actions-view .quick-actions-content {
    padding: 20px;
    flex-grow: 1;
    overflow-y: auto; /* Scroll for actions content */
}

#actions-view h3 {
    margin-top: 0;
    margin-bottom: 20px;
    color: var(--main-color);
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.4em; /* Larger title for actions view */
}

#actions-view .quick-actions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); /* Adjusted grid for mobile actions */
    gap: 10px; /* Consistent gap */
}

.action-button {
    background-color: var(--primary-light);
    color: var(--main-color);
    border: 1px solid #a7d9ef;
    border-radius: 10px; /* More rounded */
    padding: 12px 10px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 600;
    transition: all 0.2s ease, transform 0.1s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    text-align: center;
    min-height: 75px; /* Larger touch target */
    -webkit-tap-highlight-color: transparent; /* Remove blue highlight on touch */
}

.action-button:hover {
    background-color: #c9e6f2;
    border-color: #8ed0e8;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.action-button:active { /* Touch feedback */
    transform: translateY(1px);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.action-button i {
    font-size: 1.8em; /* Larger icons */
    margin-bottom: 3px;
    color: var(--main-color);
}

.action-button[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: #f0f0f0;
    border-color: #ccc;
    color: #888;
    transform: none; /* No transform on disabled */
    box-shadow: none;
}
.action-button[disabled] i {
    color: #aaa;
}

.qr-mock-button {
    background-color: #ffc107; /* Yellow */
    border-color: #e0a800;
    color: #333;
}
.qr-mock-button:hover {
    background-color: #e0a800;
    border-color: #cc9900;
}
.qr-mock-button i {
    color: #333;
}

.documentation-button {
    background-color: #ADD8E6; /* Light blue for documentation */
    border-color: #87CEEB;
    color: var(--main-color);
}
.documentation-button:hover {
    background-color: #87CEEB;
    border-color: #4682B4;
}

/* --- In-Chat Info Block Styles --- */
.chat-info-block {
    background-color: #ffffff;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    margin-top: 5px; /* Space from the top of the message bubble */
    width: 100%; /* Take full width of its parent chat bubble */
    box-sizing: border-box; /* Include padding and border in width */
}

.chat-info-block h4 {
    margin-top: 0;
    color: var(--secondary-blue);
    border-bottom: 1px solid #eee;
    padding-bottom: 8px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.1em;
}

.chat-info-block h4 span {
    font-size: 0.9em;
    color: #555;
}

.chat-info-block p {
    margin-bottom: 6px;
    line-height: 1.4;
    font-size: 0.9em;
}

.chat-info-block ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.chat-info-block li {
    background-color: #f9f9f9;
    border: 1px solid #eee;
    border-radius: 5px;
    padding: 8px 12px;
    margin-bottom: 6px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    font-size: 0.85em;
    flex-wrap: wrap;
    transition: background-color 0.2s ease; /* For hover/active */
}
/* Touch feedback for list items */
.chat-info-block li:active {
    background-color: #e0e0e0;
}


.chat-info-block li strong {
    color: var(--main-color);
}

.chat-info-block li span.status-paye { color: #28a745; font-weight: bold; }
.chat-info-block li span.status-partiel { color: #ffc107; font-weight: bold; }
.chat-info-block li span.status-impaye, .chat-info-block li span.status-echue { color: #dc3545; font-weight: bold; }

.hidden {
    display: none !important;
}

.error-message {
    color: #dc3545;
    font-weight: bold;
    margin-top: 10px;
}

.alert-message {
    color: #dc3545;
    font-weight: bold;
    background-color: #ffebe6;
    padding: 10px;
    border-radius: 5px;
    border: 1px solid #dc3545;
    margin-top: 10px;
    font-size: 0.9em;
    display: flex;
    align-items: center;
    gap: 8px;
}
.alert-message i {
    font-size: 1.1em;
}

/* FIX for chart height: Added height and width */
.chat-info-block .chart-container {
    margin-top: 15px;
    background-color: #fefefe;
    border: 1px solid #eee;
    border-radius: 5px;
    padding: 10px;
    position: relative; /* Keep this for Chart.js */
    height: 200px; /* <--- THIS IS THE KEY FIX */
    width: 100%; /* Ensure it takes available width */
    box-sizing: border-box; /* Essential */
}
/* Ensure the canvas inside takes 100% of its constrained container */
.chat-info-block .chart-container canvas {
    width: 100% !important; /* Force width */
    height: 100% !important; /* Force height */
    box-sizing: border-box;
}

.chat-info-block .chart-container h5 {
    margin-top: 0;
    font-size: 1em;
    color: #555;
    text-align: center;
    margin-bottom: 10px;
}

/* Remove filters for in-chat view for now, as direct input is less intuitive */
.list-filter {
    display: none;
}


/* Desktop / Tablet View (Min-width 769px) */
@media (min-width: 769px) {
    body {
        justify-content: center;
        align-items: center;
        overflow: auto; /* Allow scroll for full page on desktop if content overflows */
    }

    .page {
        max-width: 1200px; /* Confine desktop layout */
        height: calc(100vh - 40px); /* Leave some margin */
        min-height: 600px; /* Minimum useful height */
        box-shadow: 0 4px 8px rgba(0,0,0,0.1); /* Re-apply shadow */
        border-radius: 8px; /* Re-apply rounded corners */
        margin: 20px;
    }

    /* Reset login page for desktop view */
    #login-page {
        background-color: #f0f2f5; /* Background behind the centered container */
    }
    .login-container {
        max-width: 450px;
        box-shadow: 0 4px 10px rgba(0,0,0,0.1); /* Lighter shadow */
        border-radius: 8px; /* Standard rounding */
    }

    .chatbot-header {
        font-size: 1em;
        height: 70px; /* Slightly taller header for desktop */
    }

    .chatbot-header h1 {
        font-size: 1.5em; /* Larger title for desktop */
        position: static; /* Remove absolute positioning */
        transform: none; /* Remove transform */
    }

    #toggle-view-button {
        display: none; /* Hide toggle button on desktop if both views are shown side-by-side */
    }

    /* Desktop: Both views side-by-side */
    #chat-app-wrapper {
        flex-direction: row; /* Chat and actions side-by-side */
    }

    .app-view {
        position: static; /* No absolute positioning needed */
        width: auto; /* Take flex-grow width */
        height: 100%; /* Take 100% height of parent */
        transition: none; /* No sliding transition needed */
    }
    #chat-app-wrapper.show-actions #chat-view,
    #chat-app-wrapper.show-actions #actions-view {
        transform: none; /* Reset transforms */
    }


    #chat-view {
        flex: 3; /* Chat takes 3 parts of width */
        border-right: 1px solid #eee; /* Separator */
    }

    #actions-view {
        flex: 1.5; /* Actions takes 1.5 parts of width */
        min-width: 280px; /* Minimum width for readability */
        max-width: 350px; /* Max width to prevent it from getting too wide */
    }

    #chat-view .chat-messages {
        padding-bottom: 20px; /* Normal padding for non-fixed input area */
    }
    #chat-view .chat-input-area {
        position: static; /* No longer fixed at bottom of page, part of normal flow */
        box-shadow: none; /* No shadow */
        border-top: 1px solid #eee;
    }
    #actions-view .quick-actions-content {
        padding: 25px; /* Larger padding for desktop */
    }
    #actions-view h3 {
        font-size: 1.6em;
    }
    #actions-view .quick-actions-grid {
        grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); /* Maintain slightly larger buttons */
        gap: 12px;
    }

    /* Revert chart container for desktop to scale dynamically with overall desktop layout, or keep it fixed */
    /* If you want flexible height on desktop: */
    .chat-info-block .chart-container {
        height: 250px; /* Can make it taller for desktop, or unset to allow more dynamic growth if its parent allows */
    }
    /* If you want it to revert to automatic sizing on desktop if possible: */
    /*
    .chat-info-block .chart-container {
        height: auto;
    }
    */
}