/* ===========================
   Reset and Base Styles
   =========================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Color Palette */
    --primary-color: #0078d4;
    --primary-hover: #106ebe;
    --secondary-color: #2b88d8;
    --success-color: #107c10;
    --warning-color: #ff8c00;
    --error-color: #d13438;
    --text-primary: #323130;
    --text-secondary: #605e5c;
    --border-color: #e1dfdd;
    --background-light: #faf9f8;
    --background-white: #ffffff;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.2);
    
    /* Spacing */
    --header-height: 64px;
    --chat-button-size: 60px;
    --chat-window-width: 400px;
    --chat-window-height: 600px;
    
    /* Transitions */
    --transition-fast: 0.2s ease;
    --transition-normal: 0.3s ease;
    --transition-slow: 0.4s ease;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    color: var(--text-primary);
    background-color: var(--background-light);
    overflow-x: hidden;
}

/* ===========================
   Header
   =========================== */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
    box-shadow: var(--shadow-md);
    z-index: 100;
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
}

.header-title {
    font-size: 20px;
    font-weight: 600;
    letter-spacing: -0.2px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-logo {
    height: 24px;
    width: auto;
    object-fit: contain;
    display: block;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-display {
    color: white;
    font-size: 14px;
    font-weight: 500;
    opacity: 0.9;
}

.logout-btn {
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition-fast), transform var(--transition-fast);
    backdrop-filter: blur(10px);
}

.logout-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

.logout-btn:active {
    transform: scale(0.98);
}

.header-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.2);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    backdrop-filter: blur(10px);
    text-decoration: none;
    color: white;
    transition: background var(--transition-fast), transform var(--transition-fast);
    cursor: pointer;
}

.header-badge:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

.header-badge:active {
    transform: scale(0.98);
}

.badge-icon {
    font-size: 18px;
}

.badge-icon-img {
    width: 24px;
    height: 24px;
    object-fit: contain;
    filter: brightness(0) invert(1); /* Make logo white */
}

/* ===========================
   Main Content Area
   =========================== */
.main-content {
    margin-top: var(--header-height);
    height: calc(100vh - var(--header-height));
    position: relative;
    overflow: hidden;
}

.powerbi-container {
    width: 100%;
    height: 100%;
    background: var(--background-white);
}

#powerbi-iframe {
    width: 100%;
    height: 100%;
    border: none;
}

/* ===========================
   Loading States
   =========================== */
.loading-container,
.chat-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 40px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    background: var(--background-white);
    z-index: 10;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-container p,
.chat-loading p {
    color: var(--text-secondary);
    font-size: 14px;
}

/* ===========================
   Error States
   =========================== */
.error-container,
.chat-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 40px;
    text-align: center;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--background-white);
    z-index: 10;
}

.error-icon {
    font-size: 48px;
}

.error-container h3 {
    color: var(--error-color);
    font-size: 20px;
    font-weight: 600;
}

.error-container p,
.chat-error p {
    color: var(--text-secondary);
    font-size: 14px;
    max-width: 400px;
}

.retry-button {
    margin-top: 8px;
    padding: 10px 24px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.retry-button:hover {
    background: var(--primary-hover);
}

/* ===========================
   Chat Interface
   =========================== */
.chat-wrapper {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1000;
}

/* Chat Toggle Button */
.chat-toggle-btn {
    position: relative;
    width: var(--chat-button-size);
    height: var(--chat-button-size);
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--transition-normal), box-shadow var(--transition-normal);
}

.chat-toggle-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 12px 32px rgba(0, 120, 212, 0.3);
}

.chat-toggle-btn:active {
    transform: scale(0.95);
}

.chat-icon {
    font-size: 28px;
}

.chat-icon-img {
    width: 36px;
    height: 36px;
    object-fit: contain;
    filter: brightness(0) invert(1); /* Make logo white */
}

.notification-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 12px;
    height: 12px;
    background: var(--error-color);
    border: 2px solid white;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.7;
        transform: scale(1.1);
    }
}

/* Chat Window */
.chat-window {
    position: absolute;
    bottom: calc(var(--chat-button-size) + 16px);
    right: 0;
    width: var(--chat-window-width);
    height: var(--chat-window-height);
    background: var(--background-white);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2), 
                0 16px 64px rgba(0, 0, 0, 0.15),
                0 0 1px rgba(0.1, 0.1, 0.1, 0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp var(--transition-normal);
    transform-origin: bottom right;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.chat-window.closing {
    animation: slideDown var(--transition-normal);
}

@keyframes slideDown {
    from {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    to {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
}

/* Chat Header */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    cursor: move;
    user-select: none;
}

.chat-header-content {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-header-icon-img {
    width: 28px;
    height: 28px;
    object-fit: contain;
    filter: brightness(0) invert(1); /* Make logo white */
}

.chat-header-title-link {
    text-decoration: none;
    color: white;
    transition: opacity var(--transition-fast);
    cursor: pointer;
    border-radius: 4px;
    padding: 2px 6px;
    margin: -2px -6px;
}

.chat-header-title-link:hover {
    opacity: 0.8;
    background: rgba(255, 255, 255, 0.1);
}

.chat-header-title-link:active {
    opacity: 0.6;
}

.chat-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.chat-status {
    font-size: 12px;
    padding: 2px 8px;
    background: rgba(16, 124, 16, 0.9);
    border-radius: 10px;
    font-weight: 500;
}

.chat-header-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-control-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border-radius: 6px;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-fast);
    font-weight: 300;
}

.chat-control-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

#chat-minimize-btn {
    font-size: 24px;
    line-height: 1;
    padding-bottom: 4px;
}

#chat-maximize-btn {
    font-size: 16px;
}

/* Chat Content */
.chat-content {
    flex: 1;
    position: relative;
    overflow: hidden;
}

#chat-iframe {
    width: 100%;
    height: 100%;
    border: none;
}

/* Resize Handles */
.resize-handle {
    position: absolute;
    z-index: 10;
}

.resize-handle-top,
.resize-handle-bottom {
    left: 0;
    right: 0;
    height: 5px;
    cursor: ns-resize;
}

.resize-handle-left,
.resize-handle-right {
    top: 0;
    bottom: 0;
    width: 5px;
    cursor: ew-resize;
}

.resize-handle-top {
    top: 0;
}

.resize-handle-bottom {
    bottom: 0;
}

.resize-handle-left {
    left: 0;
}

.resize-handle-right {
    right: 0;
}

.resize-handle-top-left,
.resize-handle-top-right,
.resize-handle-bottom-left,
.resize-handle-bottom-right {
    width: 10px;
    height: 10px;
}

.resize-handle-top-left {
    top: 0;
    left: 0;
    cursor: nwse-resize;
}

.resize-handle-top-right {
    top: 0;
    right: 0;
    cursor: nesw-resize;
}

.resize-handle-bottom-left {
    bottom: 0;
    left: 0;
    cursor: nesw-resize;
}

.resize-handle-bottom-right {
    bottom: 0;
    right: 0;
    cursor: nwse-resize;
}

/* Maximized state */
.chat-window.maximized {
    position: fixed !important;
    top: var(--header-height) !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: calc(100vh - var(--header-height)) !important;
    border-radius: 0 !important;
    transform: none !important;
}

.chat-window.maximized .resize-handle {
    display: none;
}

/* Minimized state */
.chat-window.minimized {
    height: auto !important;
}

.chat-window.minimized .chat-content,
.chat-window.minimized .chat-loading,
.chat-window.minimized .chat-error,
.chat-window.minimized .resize-handle {
    display: none !important;
}

/* ===========================
   Responsive Design
   =========================== */
@media (max-width: 768px) {
    :root {
        --header-height: 56px;
        --chat-button-size: 56px;
        --chat-window-width: calc(100vw - 32px);
        --chat-window-height: calc(100vh - 120px);
    }

    .header-title {
        font-size: 18px;
    }

    .header-badge {
        font-size: 12px;
        padding: 6px 12px;
    }

    .badge-icon {
        font-size: 16px;
    }

    .chat-wrapper {
        bottom: 16px;
        right: 16px;
    }

    .chat-window {
        right: 50%;
        transform: translateX(50%);
        bottom: calc(var(--chat-button-size) + 16px);
    }

    @keyframes slideUp {
        from {
            opacity: 0;
            transform: translateX(50%) translateY(20px) scale(0.95);
        }
        to {
            opacity: 1;
            transform: translateX(50%) translateY(0) scale(1);
        }
    }

    @keyframes slideDown {
        from {
            opacity: 1;
            transform: translateX(50%) translateY(0) scale(1);
        }
        to {
            opacity: 0;
            transform: translateX(50%) translateY(20px) scale(0.95);
        }
    }
}

@media (max-width: 480px) {
    .header-badge span:not(.badge-icon) {
        display: none;
    }

    .chat-window {
        --chat-window-width: 100vw;
        --chat-window-height: 100vh;
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
        border-radius: 0;
        transform: none;
    }

    @keyframes slideUp {
        from {
            opacity: 0;
            transform: translateY(100%);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    @keyframes slideDown {
        from {
            opacity: 1;
            transform: translateY(0);
        }
        to {
            opacity: 0;
            transform: translateY(100%);
        }
    }
}

/* ===========================
   Accessibility & Focus States
   =========================== */
.chat-toggle-btn:focus,
.chat-control-btn:focus,
.retry-button:focus,
.header-badge:focus,
.chat-header-title-link:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.header-badge:focus,
.chat-header-title-link:focus {
    outline-color: white;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .chat-toggle-btn,
    .chat-header {
        border: 2px solid currentColor;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
