* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

:root {
    --primary-teal: #067377;
    --secondary-teal: #20b2aa;
    --light-teal: #b3dcdf;
    --ultra-light-teal: #e8f5f6;
    --dark-bg: #0a1a1b;
    --surface: #ffffff;
    --surface-elevated: #f8fafc;
    --text-primary: #1a202c;
    --text-secondary: #718096;
    --border-color: #e2e8f0;
    --shadow-lg: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    --shadow-xl: 0 35px 60px -12px rgba(0, 0, 0, 0.3);
    --radius-lg: 24px;
    --radius-xl: 32px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(145deg, #f0fdff 0%, var(--light-teal) 50%, var(--primary-teal) 100%);
    min-height: 100vh;
    min-height: 100dvh; /* Dynamic viewport height for mobile */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: env(safe-area-inset-top, 8px) env(safe-area-inset-right, 8px) env(safe-area-inset-bottom, 8px) env(safe-area-inset-left, 8px);
    overflow: hidden;
}

.chat-container {
    width: 100%;
    max-width: 380px;
    height: 100vh;
    height: 100dvh;
    background: var(--surface);
    border-radius: 0;
    box-shadow: var(--shadow-xl);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    position: relative;
}

@media (min-width: 480px) {
    .chat-container {
        max-width: 400px;
        height: 95vh;
        height: 95dvh;
        border-radius: var(--radius-xl);
        border: 1px solid var(--border-color);
    }
}

@media (min-width: 768px) {
    .chat-container {
        max-width: 900px;
        height: 90vh;
        height: 90dvh;
    }
}

@media (min-width: 1024px) {
    .chat-container {
        max-width: 1000px;
        height: 95vh;
    }
    
    .brand-title {
        font-size: 19px;
    }
    
    .restart-chat-btn {
        padding: 8px 16px;
        height: 36px;
    }
}

/* OpenAI-Style Compact Navbar */
.chat-header {
    background: linear-gradient(135deg, var(--primary-teal) 0%, var(--secondary-teal) 100%);
    box-shadow: 0 2px 12px rgba(6, 115, 119, 0.15);
    position: relative;
    overflow: hidden;
    z-index: 10;
    padding: 0;
}

.chat-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, transparent 40%, rgba(255, 255, 255, 0.1) 50%, transparent 60%);
    animation: shimmer 3s ease-in-out infinite;
    pointer-events: none;
}

@keyframes shimmer {
    0%, 100% { transform: translateX(-100%); }
    50% { transform: translateX(100%); }
}

.navbar-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    position: relative;
    z-index: 1;
    min-height: 16px;
}

.brand-title {
    color: white;
    font-size: 18px;
    font-weight: 600;
    margin: 0;
    letter-spacing: -0.02em;
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: calc(100% - 120px);
}

.restart-chat-btn {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: white;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.15s ease;
    backdrop-filter: blur(10px);
    flex-shrink: 0;
    height: 32px;
}

.restart-chat-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.4);
    transform: translateY(-1px);
}

.restart-chat-btn:active {
    transform: translateY(0);
    background: rgba(255, 255, 255, 0.2);
}

.restart-chat-btn i {
    font-size: 12px;
}

/* Mobile-first responsive design */
@media (max-width: 640px) {
    .navbar-container {
        padding: 9px 16px;
    }
    
    .brand-title {
        font-size: 16px;
        max-width: calc(100% - 100px);
    }
    
    .restart-chat-btn {
        padding: 6px 12px;
        font-size: 12px;
        gap: 5px;
    }
    
    .btn-text {
        display: none;
    }
}

@media (max-width: 360px) {
    .navbar-container {
        padding: 7px 12px;
    }
    
    .brand-title {
        font-size: 15px;
        max-width: calc(100% - 80px);
    }
    
    .restart-chat-btn {
        padding: 6px 10px;
        min-width: 36px;
    }
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 16px;
    background: linear-gradient(180deg, var(--ultra-light-teal) 0%, var(--surface-elevated) 100%);
    scroll-behavior: smooth;
    position: relative;
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(6, 115, 119, 0.2);
    border-radius: 10px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(6, 115, 119, 0.3);
}

.message-container {
    margin-bottom: 16px;
    opacity: 0;
    animation: slideInUp 0.5s ease-out forwards;
}

.message {
    display: flex;
    gap: 8px;
    max-width: 85%;
}

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

.user-message {
    flex-direction: row-reverse;
    margin-left: auto;
}

.agent-message {
    flex-direction: row;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.8);
    transition: all 0.3s ease;
}

.agent-message .message-avatar {
    background: linear-gradient(135deg, var(--primary-teal) 0%, var(--secondary-teal) 100%);
    color: white;
    padding: 3px;
}

.user-message .message-avatar {
    background: linear-gradient(135deg, var(--light-teal) 0%, #a0d4d7 100%);
    color: var(--primary-teal);
    font-weight: 600;
}

.message-content {
    flex: 1;
}

.message-text {
    padding: 12px 16px;
    border-radius: 20px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
    font-size: 13px;
    font-weight: 400;
    position: relative;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.message-text.rtl {
    direction: rtl;
    text-align: right;
}

.user-message .message-text {
    background: var(--light-teal);
    color: #000000;
    border-bottom-right-radius: 8px;
    box-shadow: 0 6px 25px rgba(179, 220, 223, 0.25);
}

.agent-message .message-text {
    background: rgba(255, 255, 255, 0.95);
    color: var(--text-primary);
    border-bottom-left-radius: 8px;
    border: 1px solid rgba(6, 115, 119, 0.1);
}

.message-time {
    font-size: 10px;
    color: #6b7280;
    margin-top: 2px;
    padding: 0 12px;
}

.user-message .message-time {
    text-align: right;
}

.chat-input-container {
    padding: 16px 16px 18px 16px;
    background: rgba(255, 255, 255, 0.95);
    border-top: 1px solid rgba(6, 115, 119, 0.1);
    backdrop-filter: blur(20px);
    position: relative;
}

.chat-input-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 20px;
    right: 20px;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--primary-teal), transparent);
}

.input-wrapper {
    display: flex;
    gap: 8px;
    align-items: center;
    position: relative;
}

#messageInput {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: 24px;
    outline: none;
    font-size: 14px;
    font-weight: 400;
    background: rgba(255, 255, 255, 0.9);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
    backdrop-filter: blur(10px);
}

#messageInput:focus {
    border-color: var(--primary-teal);
    box-shadow: 0 8px 30px rgba(6, 115, 119, 0.15);
    background: rgba(255, 255, 255, 1);
    transform: translateY(-1px);
}

#messageInput::placeholder {
    color: var(--text-secondary);
    font-weight: 400;
}

.send-btn {
    width: 42px;
    height: 42px;
    background: linear-gradient(135deg, var(--primary-teal) 0%, var(--secondary-teal) 100%);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 8px 25px rgba(6, 115, 119, 0.3);
    position: relative;
    overflow: hidden;
}

.send-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    transition: all 0.6s ease;
    transform: translate(-50%, -50%);
}

.send-btn:hover::before {
    width: 100%;
    height: 100%;
}

.send-btn:hover:not(:disabled) {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 12px 35px rgba(6, 115, 119, 0.4);
}

.send-btn:active {
    transform: translateY(-1px) scale(1.02);
}

.send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
    box-shadow: 0 4px 15px rgba(6, 115, 119, 0.15);
}

.input-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 4px;
    padding: 0 16px 4px 16px;
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 9px;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.3s ease;
}

.connection-status i {
    font-size: 8px;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.connection-status.connected {
    color: var(--primary-teal);
}

.connection-status.connected i {
    animation: none;
}

.connection-status.disconnected {
    color: #EF4444;
}

.character-count {
    font-size: 8px;
    color: var(--text-secondary);
    font-weight: 500;
    opacity: 0.8;
}

.typing-indicator {
    display: none;
    padding: 0 16px 8px;
    animation: fadeIn 0.3s ease;
}

.typing-bubble {
    background: rgba(255, 255, 255, 0.95);
    color: var(--text-primary);
    border-bottom-left-radius: 8px;
    border: 1px solid rgba(6, 115, 119, 0.1);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
}

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

.typing-dots span {
    width: 8px;
    height: 8px;
    background: #067377;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

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

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

.typing-text {
    font-size: 12px;
    color: #6b7280;
    font-style: italic;
    margin: 0;
}

.error-message {
    color: #EF4444;
    background: #FEF2F2;
    border: 1px solid #FECACA;
    padding: 12px;
    border-radius: 8px;
    margin: 10px 0;
    font-size: 14px;
}

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

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-10px);
    }
}

/* Enhanced Mobile Responsive Design */
@media (max-width: 480px) {
    body {
        padding: 0;
        background: linear-gradient(145deg, #f0fdff 0%, var(--light-teal) 50%, var(--primary-teal) 100%);
    }
    
    .chat-container {
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
        max-width: 100%;
        border: none;
    }
    
    .chat-header {
        padding: 8px 16px 10px 16px;
        padding-top: calc(8px + env(safe-area-inset-top, 0px));
    }
    
    .logo {
        font-size: 16px;
        gap: 10px;
    }
    
    .sirdab-logo {
        width: 24px;
        height: 24px;
    }
    
    .logo i {
        font-size: 18px;
    }
    
    .restart-btn {
        padding: 8px 14px;
        font-size: 12px;
        gap: 4px;
        align-self: flex-end;
    }
    
    .restart-text {
        display: none;
    }
    
    .header-content {
        flex-direction: column;
        gap: 8px;
    }
    
    .chat-messages {
        padding: 16px 16px 20px 16px;
    }
    
    .message {
        max-width: 90%;
    }
    
    .message-avatar {
        width: 38px;
        height: 38px;
    }
    
    .message-text {
        padding: 14px 16px;
        font-size: 14px;
        border-radius: 20px;
    }
    
    .chat-input-container {
        padding: 16px;
        padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    }
    
    #messageInput {
        padding: 14px 18px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .send-btn {
        width: 48px;
        height: 48px;
        font-size: 16px;
    }
    
    .input-footer {
        padding: 0 16px 2px 16px;
        margin-top: 4px;
    }
}

@media (max-width: 768px) and (min-width: 481px) {
    body {
        padding: 8px;
    }
    
    .chat-container {
        height: 95vh;
        height: 95dvh;
        border-radius: var(--radius-lg);
        max-width: 100%;
    }
    
    .chat-header {
        padding: 8px 18px 10px 18px;
    }
    
    .header-content {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        gap: 12px;
    }
    
    .logo {
        font-size: 16px;
    }
    
    .restart-btn {
        font-size: 11px;
        padding: 6px 10px;
    }
    
    .chat-messages {
        padding: 15px;
    }
    
    .message {
        max-width: 95%;
    }
    
    .message-avatar {
        width: 35px;
        height: 35px;
        font-size: 16px;
    }
    
    .message-text {
        font-size: 14px;
        padding: 10px 14px;
    }
    
    .chat-input-container {
        padding: 15px;
    }
    
    #messageInput {
        font-size: 14px;
        padding: 10px 14px;
    }
    
    .send-btn {
        width: 40px;
        height: 40px;
        font-size: 14px;
    }
}

/* Enhanced Touch Interactions for Mobile */
@media (hover: none) and (pointer: coarse) {
    .send-btn:hover {
        transform: none;
        box-shadow: 0 8px 25px rgba(6, 115, 119, 0.3);
    }
    
    .restart-btn:hover {
        transform: none;
        background: rgba(255, 255, 255, 0.15);
    }
}

/* High DPI Displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .message-avatar img {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}
