:root {
    --bg-color: #1a1a1a;
    --glass-bg: rgba(30, 30, 30, 0.95);
    --glass-bg-fallback: #1e1e1e;
    --glass-border: rgba(255, 255, 255, 0.15);
    --primary-color: #00f2fe;
    --secondary-color: #4facfe;
    --text-color: #ffffff;
    --text-dim: #b0b0b0;
    --font-primary: 'Outfit', 'Prompt', -apple-system, BlinkMacSystemFont, sans-serif;
    
    /* Fluid typography scale */
    --fluid-min-width: 320;
    --fluid-max-width: 1440;
    --fluid-screen: 100vw;
    --fluid-bp: calc(
        (var(--fluid-screen) - var(--fluid-min-width) / 16 * 1rem) /
        (var(--fluid-max-width) - var(--fluid-min-width))
    );
    
    /* Responsive font sizes */
    --step-0: clamp(0.875rem, 0.8rem + 0.375vw, 1rem);
    --step-1: clamp(1rem, 0.925rem + 0.375vw, 1.125rem);
    --step-2: clamp(1.125rem, 1rem + 0.625vw, 1.25rem);
    --step-3: clamp(1.25rem, 1.1rem + 0.75vw, 1.375rem);
    --step-4: clamp(1.375rem, 1.175rem + 1vw, 1.5rem);
    --step-5: clamp(1.5rem, 1.25rem + 1.25vw, 1.75rem);
    
    /* Responsive spacing */
    --space-xs: clamp(0.25rem, 0.2rem + 0.25vw, 0.5rem);
    --space-sm: clamp(0.5rem, 0.4rem + 0.5vw, 0.75rem);
    --space-md: clamp(0.75rem, 0.6rem + 0.75vw, 1rem);
    --space-lg: clamp(1rem, 0.8rem + 1vw, 1.5rem);
    --space-xl: clamp(1.5rem, 1.2rem + 1.5vw, 2rem);
    --space-2xl: clamp(2rem, 1.6rem + 2vw, 3rem);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box !important;
}

html, body {
    all: initial;
    font-family: var(--font-primary) !important;
    background-color: var(--glass-bg-fallback) !important;
    height: 100vh;
    width: 100%;
    overflow: hidden;
}


.launcher {
    position: fixed !important;
    bottom: 30px !important;
    left: 30px !important;
    right: auto !important;
    width: 65px !important;
    height: 65px !important;
    min-width: 65px !important;
    min-height: 65px !important;
    border-radius: 50% !important;
    background: linear-gradient(135deg, var(--secondary-color), var(--primary-color)) !important;
    background-color: var(--primary-color) !important;
    border: none !important;
    cursor: pointer !important;
    box-shadow: 0 10px 30px rgba(79, 172, 254, 0.4) !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    font-size: 1.8rem !important;
    z-index: 9999 !important;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) !important;
    font-family: var(--font-primary) !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
    /* Touch improvements */
    -webkit-tap-highlight-color: transparent !important;
    touch-action: manipulation !important;
    user-select: none !important;
    -webkit-user-select: none !important;
    /* Accessibility */
    outline: none !important;
    will-change: transform, box-shadow !important;
}

.launcher .icon {
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    width: auto !important;
    height: auto !important;
    line-height: 1 !important;
    margin: 0 !important;
    padding: 0 !important;
}

.launcher:hover {
    transform: scale(1.1) rotate(5deg);
    box-shadow: 0 15px 40px rgba(79, 172, 254, 0.6);
}

.launcher:focus {
    transform: scale(1.05) rotate(2deg);
    box-shadow: 0 12px 35px rgba(79, 172, 254, 0.5), 0 0 0 3px rgba(0, 242, 254, 0.3) !important;
}

.launcher:active {
    transform: scale(0.95) rotate(-2deg);
    transition: all 0.1s ease !important;
}

.launcher.active-chat {
    opacity: 0;
    transform: scale(0) rotate(-20deg);
    pointer-events: none;
}


.chat-widget {
    position: fixed !important;
    bottom: 25px !important;
    left: 25px !important;
    right: auto !important;
    width: 400px !important;
    height: 650px !important;
    max-height: calc(100vh - 50px) !important;
    z-index: 9998 !important;
    transition: all 0.4s cubic-bezier(0.165, 0.84, 0.44, 1) !important;
    transform-origin: bottom left !important;
    font-family: var(--font-primary) !important;
    overflow: visible !important;
    border-radius: 24px !important;
}

.chat-widget.hidden {
    opacity: 0;
    transform: scale(0.8) translateY(20px);
    pointer-events: none;
}

.container {
    width: calc(100% - 4px) !important;
    height: calc(100% - 4px) !important;
    margin: 2px !important;
    background-color: #1e1e1e !important;
    border-radius: 22px !important;
    display: flex !important;
    flex-direction: column !important;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.8) !important;
    overflow: hidden !important;
    font-family: var(--font-primary) !important;
}

header {
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #252525 !important;
}

.logo h1 {
    font-size: 1.2rem;
    font-weight: 800;
    background: linear-gradient(to right, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

#clear-chat {
    background: transparent;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: all 0.2s;
    padding: 5px;
    border-radius: 8px;
}

#clear-chat:hover {
    color: #ff4b2b;
    background: rgba(255, 75, 43, 0.1);
}

.close-btn {
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-size: 1.8rem;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
}

.close-btn:hover {
    color: white;
}

main {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

main::-webkit-scrollbar { width: 4px; }
main::-webkit-scrollbar-thumb { background: var(--glass-border); border-radius: 10px; }

.message {
    max-width: 85%;
    padding: var(--space-sm) var(--space-md);
    border-radius: 16px;
    font-size: var(--step-0);
    line-height: 1.5;
    animation: fadeIn 0.3s ease-out forwards;
    word-wrap: break-word;
    overflow-wrap: break-word;
    margin-bottom: var(--space-sm);
}

.message strong { color: var(--primary-color); font-weight: 700; }

.ai-message {
    align-self: flex-start;
    background-color: #2a2a2a !important;
    border-bottom-left-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #eee;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

.user-message {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--secondary-color), var(--primary-color));
    color: #000;
    font-weight: 600;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 15px rgba(0, 242, 254, 0.2);
}

.hidden {
    display: none !important;
}

footer { 
    padding: var(--space-md) var(--space-lg) var(--space-lg);
    background-color: transparent;
}

.input-area {
    display: flex;
    background-color: #2a2a2a !important;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 14px;
    padding: var(--space-xs) var(--space-sm);
    gap: var(--space-xs);
    align-items: center;
    min-height: 50px;
    transition: all 0.2s ease;
}

.input-area:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(0, 242, 254, 0.2);
}

input {
    flex: 1;
    background: transparent;
    border: none;
    color: white;
    font-size: var(--step-0);
    padding: var(--space-sm);
    outline: none;
    min-height: 40px;
    font-family: var(--font-primary);
    resize: none;
    -webkit-appearance: none;
    appearance: none;
}

input::placeholder {
    color: var(--text-dim);
    opacity: 0.7;
}

#send-btn {
    background: var(--primary-color);
    color: black;
    border: none;
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: var(--step-1);
    font-weight: 600;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

#send-btn:hover {
    background: var(--secondary-color);
    transform: translateY(-1px);
}

#send-btn:active {
    transform: translateY(0);
}

#send-btn:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}


.message ul, .message ol {
    margin-left: 20px;
    margin-top: 8px;
    margin-bottom: 8px;
}

.message ul ul, .message ol ol,
.message ul ol, .message ol ul {
    margin-top: 4px;
    margin-bottom: 4px;
}

.message li {
    margin-bottom: 4px;
}

.message p {
    margin-bottom: 10px;
}

.message p:last-child {
    margin-bottom: 0;
}

.message pre {
    background: rgba(0,0,0,0.5);
    padding: 12px;
    border-radius: 10px;
    margin: 10px 0;
    max-width: 100%;
    border: 1px solid rgba(255,255,255,0.1);
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-x: hidden;
}

.message pre code {
    background: transparent;
    padding: 0;
    border-radius: 0;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.85rem;
    line-height: 1.4;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.message code {
    background: rgba(255,255,255,0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.9em;
}

.message table {
    width: 100%;
    margin: 15px 0;
    font-size: 0.9rem;
    display: block;
    border: none;
}

.message thead {
    display: none;
}

.message tbody {
    display: block;
}

.message tr {
    display: block;
    margin-bottom: 15px;
    padding: 12px 15px;
    background: rgba(255,255,255,0.05);
    border-radius: 10px;
    border-left: 3px solid var(--primary-color);
}

.message tr:last-child {
    margin-bottom: 0;
}

.message th, .message td {
    display: block;
    padding: 4px 0;
    text-align: left;
    border: none;
}

.message th {
    font-weight: 700;
    color: var(--primary-color);
    font-size: 1rem;
    margin-bottom: 5px;
}

.message td {
    color: var(--text-dim);
    line-height: 1.5;
}

.message td strong {
    color: var(--text-color);
    font-weight: 600;
}

.message blockquote {
    border-left: 3px solid var(--primary-color);
    padding-left: 12px;
    margin: 10px 0;
    color: var(--text-dim);
    font-style: italic;
}

.message h1, .message h2, .message h3,
.message h4, .message h5, .message h6 {
    margin-top: var(--space-lg);
    margin-bottom: var(--space-sm);
    font-weight: 600;
    color: var(--text-color);
    line-height: 1.3;
}

.message h1 { font-size: var(--step-4); }
.message h2 { font-size: var(--step-3); }
.message h3 { font-size: var(--step-2); }
.message h4 { font-size: var(--step-1); }
.message h5 { font-size: var(--step-1); }
.message h6 { font-size: var(--step-0); }

.message a {
    color: var(--primary-color);
    text-decoration: none;
    border-bottom: 1px dotted var(--primary-color);
}

.message a:hover {
    border-bottom: 1px solid var(--primary-color);
}

.message img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 10px 0;
}

.message hr {
    border: none;
    border-top: 1px solid var(--glass-border);
    margin: 15px 0;
}

.message .hljs {
    background: transparent;
}

.typing-dots {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    background: var(--text-dim);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out both;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1.0); }
}

@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }


.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    transition: all 0.3s ease;
    padding: var(--space-md);
    box-sizing: border-box;
}

.modal-content {
    background-color: #1e1e1e !important;
    border: 1px solid rgba(255, 255, 255, 0.15);
    padding: var(--space-xl);
    border-radius: 24px;
    width: 100%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
    animation: modalPop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    max-height: 90vh;
    overflow-y: auto;
    margin: auto;
}

@keyframes modalPop {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.modal-content h3 {
    margin-bottom: 10px;
    color: var(--primary-color);
}

.modal-content p {
    color: var(--text-dim);
    font-size: 0.9rem;
    margin-bottom: 25px;
}

.modal-actions {
    display: flex;
    gap: 10px;
}

.modal-actions button {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.btn-danger {
    background: linear-gradient(135deg, #ff416c, #ff4b2b);
    color: white;
}

.btn-secondary:hover { background: rgba(255, 255, 255, 0.2); }
.btn-danger:hover { transform: translateY(-2px); box-shadow: 0 5px 15px rgba(255, 75, 43, 0.4); }


/* Mobile Devices - Small phones (320px - 480px) */
@media (max-width: 480px) {
    .chat-widget {
        width: 100vw !important;
        height: 100vh !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        border-radius: 0 !important;
        max-height: 100vh !important;
    }
    
    .container {
        border-radius: 0 !important;
        height: 100vh !important;
        margin: 0 !important;
    }
    
    .launcher {
        bottom: 20px !important;
        right: 20px !important;
        left: auto !important;
        width: 60px !important;
        height: 60px !important;
        min-width: 60px !important;
        min-height: 60px !important;
        font-size: 1.5rem !important;
    }
    
    header {
        padding: 12px 15px !important;
    }
    
    .logo h1 {
        font-size: 1.1rem !important;
    }
    
    main {
        padding: 15px !important;
        gap: 12px !important;
    }
    
    .message {
        max-width: 95% !important;
        padding: 10px 14px !important;
        font-size: 0.9rem !important;
    }
    
    footer {
        padding: 12px 15px 15px !important;
    }
    
    .input-area {
        padding: 4px 8px !important;
    }
    
    input {
        font-size: 16px !important; /* Prevents zoom on iOS */
        padding: 10px !important;
    }
    
    #send-btn {
        width: 40px !important;
        height: 40px !important;
    }
    
    .modal-content {
        width: 95% !important;
        padding: 20px !important;
        margin: 20px !important;
    }
}

/* Mobile Devices - Large phones (481px - 768px) */
@media (min-width: 481px) and (max-width: 768px) {
    .chat-widget {
        width: 90vw !important;
        height: 85vh !important;
        max-width: 450px !important;
        max-height: 700px !important;
        bottom: 20px !important;
        left: 20px !important;
        right: auto !important;
    }
    
    .launcher {
        width: 65px !important;
        height: 65px !important;
        bottom: 25px !important;
        left: 25px !important;
    }
    
    main {
        padding: 18px !important;
    }
    
    .message {
        max-width: 90% !important;
        font-size: 0.95rem !important;
    }
    
    input {
        font-size: 16px !important;
    }
}

/* Tablet Devices (769px - 1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
    .chat-widget {
        width: 420px !important;
        height: 680px !important;
        max-height: 80vh !important;
        bottom: 30px !important;
        left: 30px !important;
    }
    
    .launcher {
        width: 70px !important;
        height: 70px !important;
        bottom: 35px !important;
        left: 35px !important;
        font-size: 2rem !important;
    }
    
    main {
        padding: 20px !important;
    }
    
    .message {
        max-width: 88% !important;
        font-size: 1rem !important;
    }
}

/* Large Desktop Devices (1025px - 1440px) */
@media (min-width: 1025px) and (max-width: 1440px) {
    .chat-widget {
        width: 440px !important;
        height: 700px !important;
        max-height: 85vh !important;
    }
    
    .launcher {
        width: 70px !important;
        height: 70px !important;
        font-size: 2rem !important;
    }
}

/* Extra Large Desktop Devices (1441px and up) */
@media (min-width: 1441px) {
    .chat-widget {
        width: 460px !important;
        height: 720px !important;
        max-height: 85vh !important;
    }
    
    .launcher {
        width: 75px !important;
        height: 75px !important;
        font-size: 2.2rem !important;
    }
    
    main {
        padding: 25px !important;
    }
    
    .message {
        font-size: 1.05rem !important;
        line-height: 1.6 !important;
    }
}

/* Landscape orientation adjustments */
@media (max-height: 600px) and (orientation: landscape) {
    .chat-widget {
        height: 95vh !important;
        max-height: 95vh !important;
    }
    
    header {
        padding: 8px 15px !important;
    }
    
    .logo h1 {
        font-size: 1rem !important;
    }
    
    main {
        padding: 10px 15px !important;
        gap: 8px !important;
    }
    
    .message {
        padding: 8px 12px !important;
        font-size: 0.85rem !important;
    }
    
    footer {
        padding: 8px 15px 10px !important;
    }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .launcher {
        box-shadow: 0 10px 30px rgba(79, 172, 254, 0.5) !important;
    }
    
    .message {
        border-width: 0.5px !important;
    }
}
