/* ============================================================
   ChatOS Widget — Fully Responsive CSS
   Priority: HIGHEST — Mobile-first approach
   ============================================================ */

/* ---- Base Widget Container ---- */
#chatos-widget-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 999999;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ---- Launcher Button ---- */
#chatos-launcher {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6028ff, #4c1d95);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(96, 40, 255, 0.4);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    min-width: 60px;
    min-height: 60px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

#chatos-launcher:hover {
    transform: scale(1.1) translateY(-4px);
    box-shadow: 0 15px 35px rgba(96, 40, 255, 0.6);
}

#chatos-launcher:active {
    transform: scale(0.96);
}

/* ---- Widget Panel ---- */
#chatos-widget {
    position: fixed;
    bottom: 96px;
    right: 24px;
    width: min(420px, calc(100vw - 40px));
    height: min(680px, calc(100vh - 120px));
    max-height: calc(100vh - 120px);
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 22px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.12), 0 0 0 1px rgba(255, 255, 255, 0.5) inset;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    transform-origin: bottom right;
}

#chatos-widget.active {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* ---- Header ---- */
.chatos-header {
    background: linear-gradient(135deg, #6028ff, #4c1d95);
    padding: clamp(16px, 3vw, 24px) clamp(16px, 3vw, 24px) clamp(20px, 3vw, 30px);
    color: white;
    border-radius: 22px 22px 0 0;
    position: relative;
    clip-path: polygon(0 0, 100% 0, 100% calc(100% - 15px), 0 100%);
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.chatos-header-info {
    flex: 1;
    overflow: hidden;
    padding-right: 12px;
}

.chatos-header h3 {
    margin: 0;
    font-size: clamp(16px, 2vw, 20px);
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chatos-header p {
    margin: 6px 0 0 0;
    font-size: clamp(11px, 1.5vw, 13px);
    opacity: 0.85;
}

/* ---- Language Selector ---- */
.chatos-lang-select {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    max-width: 80px;
}
.chatos-lang-select option { color: #0f172a; }

/* ---- Messages Area ---- */
.chatos-messages {
    flex: 1;
    padding: clamp(12px, 2vw, 20px);
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.chatos-messages::-webkit-scrollbar { width: 4px; }
.chatos-messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.1); border-radius: 10px; }

/* ---- Message Bubbles ---- */
.msg-bubble {
    max-width: 85%;
    padding: clamp(10px, 1.5vw, 14px) clamp(12px, 2vw, 18px);
    font-size: clamp(13px, 1.5vw, 14px);
    line-height: 1.55;
    position: relative;
    animation: slideUp 0.3s ease forwards;
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
    hyphens: auto;
}

.msg-ai {
    background: white;
    color: #1e293b;
    border-radius: 0 18px 18px 18px;
    align-self: flex-start;
    box-shadow: 0 4px 15px rgba(0,0,0,0.04);
    border: 1px solid rgba(0,0,0,0.04);
}

.msg-user {
    background: linear-gradient(135deg, #6028ff, #4c1d95);
    color: white;
    border-radius: 18px 0 18px 18px;
    align-self: flex-end;
    box-shadow: 0 4px 15px rgba(96, 40, 255, 0.2);
}

.msg-time {
    font-size: 10px;
    opacity: 0.6;
    margin-top: 6px;
    display: block;
    text-align: right;
}

.msg-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    opacity: 0;
    transition: opacity 0.2s;
    flex-wrap: wrap;
}
.msg-ai:hover .msg-actions { opacity: 1; }
.msg-action-btn {
    background: #f1f5f9;
    border: none;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 12px;
    color: #64748b;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 28px;
}
.msg-action-btn:hover { background: #e2e8f0; color: #0f172a; }

/* Overflow fix for code, pre, long URLs */
.msg-ai pre {
    background: #0f172a;
    color: #e2e8f0;
    padding: 12px;
    border-radius: 10px;
    overflow-x: auto;
    font-size: 12px;
    max-width: 100%;
    white-space: pre-wrap;
    word-break: break-all;
}
.msg-ai code { font-family: monospace; word-break: break-all; }
.msg-ai a { color: #6028ff; word-break: break-all; }
.msg-ai p { margin: 0 0 8px 0; }
.msg-ai p:last-child { margin: 0; }
.msg-ai img { max-width: 100%; height: auto; border-radius: 8px; }
.msg-ai table { width: 100%; border-collapse: collapse; overflow-x: auto; display: block; font-size: 12px; }
.msg-ai table td, .msg-ai table th { padding: 6px 8px; border: 1px solid #e2e8f0; }

/* ---- Quick Action Chips ---- */
.chatos-chips {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    padding: 0 clamp(12px, 2vw, 20px) 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.chatos-chips::-webkit-scrollbar { display: none; }

.chip {
    background: #f1f5f9;
    color: #334155;
    border: 1px solid #e2e8f0;
    padding: 8px 14px;
    border-radius: 20px;
    font-size: clamp(11px, 1.5vw, 12px);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
    min-height: 36px;
    display: flex;
    align-items: center;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
.chip:hover, .chip:active {
    background: #eff6ff;
    color: #3b82f6;
    border-color: #bfdbfe;
}

/* ---- Input Area ---- */
.chatos-input-area {
    padding: clamp(10px, 1.5vw, 15px) clamp(12px, 2vw, 20px) clamp(12px, 2vw, 20px);
    background: rgba(255, 255, 255, 0.95);
    border-top: 1px solid rgba(0,0,0,0.06);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.chatos-input {
    flex: 1;
    min-width: 0;
    background: #f1f5f9;
    border: 1px solid transparent;
    padding: clamp(10px, 1.5vw, 14px) clamp(14px, 2vw, 20px);
    border-radius: 24px;
    font-size: clamp(13px, 1.5vw, 14px);
    font-family: inherit;
    color: #0f172a;
    transition: all 0.3s;
    resize: none;
    min-height: 48px;
    max-height: 120px;
    overflow-y: auto;
}
.chatos-input:focus {
    outline: none;
    background: white;
    border-color: #6028ff;
    box-shadow: 0 0 0 3px rgba(96, 40, 255, 0.1);
}

.chatos-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.btn-mic { background: #f1f5f9; color: #64748b; }
.btn-mic.recording { background: #fee2e2; color: #ef4444; animation: pulse 1.5s infinite; }
.btn-send {
    background: linear-gradient(135deg, #6028ff, #4c1d95);
    color: white;
    box-shadow: 0 4px 10px rgba(96, 40, 255, 0.3);
}
.btn-send:hover { transform: scale(1.05); }
.btn-send:active { transform: scale(0.96); }

/* ---- Typing Indicator ---- */
.chatos-typing {
    display: none;
    gap: 4px;
    padding: 10px 14px;
    background: white;
    border-radius: 18px;
    width: fit-content;
    align-self: flex-start;
    box-shadow: 0 4px 15px rgba(0,0,0,0.04);
    margin-bottom: 10px;
}
.chatos-typing .dot {
    width: 6px;
    height: 6px;
    background: #cbd5e1;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}
.chatos-typing .dot:nth-child(1) { animation-delay: -0.32s; }
.chatos-typing .dot:nth-child(2) { animation-delay: -0.16s; }

/* ============================================================
   RESPONSIVE BREAKPOINTS
   ============================================================ */

/* ---- Tablet (≤768px) ---- */
@media (max-width: 768px) {
    #chatos-widget-container {
        bottom: 16px;
        right: 16px;
    }

    #chatos-widget {
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
        border: none;
        transform-origin: bottom center;
        box-shadow: none;
        z-index: 9999999;
    }

    #chatos-widget.active {
        transform: translateY(0) scale(1);
    }

    .chatos-header {
        border-radius: 0;
        padding: 20px 16px 20px;
    }

    .chatos-header h3 {
        font-size: 17px;
    }

    #chatos-close-btn {
        display: flex !important;
    }
}

/* ---- Large Mobile (≤576px) ---- */
@media (max-width: 576px) {
    #chatos-launcher {
        width: 54px;
        height: 54px;
        font-size: 24px;
    }

    .chatos-header p {
        display: none; /* Hide subtitle to save space */
    }

    .msg-bubble {
        max-width: 90%;
        font-size: 13px;
    }

    .chatos-input-area {
        gap: 6px;
    }

    .chatos-btn {
        width: 42px;
        height: 42px;
        min-width: 42px;
        font-size: 18px;
    }
}

/* ---- Small Mobile (≤414px) ---- */
@media (max-width: 414px) {
    .chatos-lang-select {
        font-size: 10px;
        padding: 3px 8px;
        max-width: 60px;
    }

    .chatos-chips {
        padding-left: 12px;
        padding-right: 12px;
    }

    .chip {
        font-size: 11px;
        padding: 7px 12px;
    }
}

/* ---- Tiny Mobile (≤360px) ---- */
@media (max-width: 360px) {
    .chatos-header h3 {
        font-size: 15px;
    }

    .btn-mic {
        display: none; /* Hide mic on tiny screens to save space */
    }

    .chatos-input {
        font-size: 13px;
    }
}

/* ---- Landscape mode on mobile ---- */
@media (max-height: 500px) and (max-width: 900px) {
    #chatos-widget {
        height: 100dvh;
        max-height: 100dvh;
    }

    .chatos-header {
        padding: 12px 16px 18px;
    }

    .chatos-header p {
        display: none;
    }

    .chatos-messages {
        padding: 10px 16px;
        gap: 8px;
    }

    .chatos-input-area {
        padding: 8px 12px;
    }
}

/* ---- Keyframe Animations ---- */
@keyframes slideUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes typing {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); background: #6028ff; }
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
    70% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}
