:root {
    --primary-color: #4A55A2;
    /* Defined from screenshot */
    --secondary-color: #787A91;
    --accent-color: #C5DFF8;
    --bg-color: #F4F7FE;
    --white: #FFFFFF;
    --text-primary: #333333;
    --text-secondary: #666666;
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --font-en: 'Inter', sans-serif;
    --font-ar: 'Cairo', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-en);
    background-color: var(--bg-color);
    color: var(--text-primary);
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    /* Prevent body scroll, handle inside app-container */
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 600px;
    /* Tablet/Mobile optimization */
    margin: 0 auto;
    background-color: var(--bg-color);
    position: relative;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.05);
}

/* Utilities */
.hidden {
    display: none !important;
}

.visible {
    display: block !important;
}

/* Header */
.app-header {
    background-color: var(--primary-color);
    color: var(--white);
    padding: 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 70px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    z-index: 10;
}

.header-left,
.header-right {
    flex: 1;
    display: flex;
    align-items: center;
}

.header-right {
    justify-content: flex-end;
    gap: 10px;
}

.header-center {
    flex: 2;
    text-align: center;
}

#header-logo {
    height: 40px;
    object-fit: contain;
    background: white;
    border-radius: 8px;
    padding: 2px;
}

#header-title {
    font-size: 1rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.icon-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    font-size: 1.2rem;
    cursor: pointer;
    transition: background 0.2s;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

#lang-switch-btn {
    width: auto;
    padding: 0 10px;
    border-radius: 18px;
    font-size: 0.9rem;
}

/* Main Content */
.app-main {
    flex: 1;
    overflow-y: auto;
    position: relative;
    padding: 1rem;
    display: flex;
    flex-direction: column;
}

/* Views */
.view {
    width: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.view.active {
    display: flex;
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Language Selection View */
.lang-selection-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    gap: 2rem;
    background-color: var(--white);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow-md);
    margin: auto 0;
}

.logo-container img {
    max-width: 200px;
    max-height: 100px;
    margin-bottom: 1rem;
}

.welcome-title {
    font-size: 1.8rem;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.welcome-subtitle {
    color: var(--text-secondary);
    margin: 0.2rem 0;
}

.lang-buttons {
    display: flex;
    flex-direction: column;
    width: 100%;
    gap: 1rem;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s, opacity 0.2s;
    width: 100%;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-secondary {
    background-color: #7D70A3;
    /* Muted purple */
    color: white;
}

.btn-outline {
    background-color: transparent;
    border: 1px solid var(--primary-color);
    color: var(--primary-color);
}

.btn-lg {
    padding: 16px;
    font-size: 1.1rem;
}

/* Chat Interface Styles (Shared by Menu, Coupons, Chat) */
.chat-interface {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    /* Increased from 1.5rem */
    padding-bottom: 2rem;
}

.chat-message {
    display: flex;
    gap: 0.8rem;
    /* Increased gap between avatar and bubble */
    max-width: 85%;
    align-items: flex-end;
    margin-bottom: 0.5rem;
    /* Added margin for extra separation */
}

.chat-message.bot {
    align-self: flex-start;
}

.chat-message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-color: var(--white);
    border: 1px solid #ddd;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary-color);
    flex-shrink: 0;
    overflow: hidden;
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    /* Changed to contain to respect padding */
    padding: 6px;
    /* Added padding to make the logo smaller inside the circle */
}

.message-bubble {
    background-color: var(--white);
    padding: 16px 20px;
    /* Increased padding */
    border-radius: 16px;
    border-top-left-radius: 4px;
    box-shadow: var(--shadow-sm);
    color: var(--text-primary);
    font-size: 0.95rem;
    line-height: 1.5;
}

.chat-message.user .message-bubble {
    background-color: var(--primary-color);
    color: white;
    border-radius: 16px;
    border-bottom-right-radius: 4px;
}

/* Menu Options */
.menu-options {
    display: flex;
    flex-direction: row;
    /* Changed to row */
    flex-wrap: wrap;
    /* Allow wrapping */
    gap: 0.5rem;
    /* Reduced gap */
    margin-top: 5px;
    margin-bottom: 1rem;
    /* Added spacing under buttons */
    align-items: center;
    padding-left: 44px;
    /* Align with bubbles, avatar width + gap */
}

.menu-btn {
    background-color: var(--white);
    border: 1px solid var(--primary-color);
    /* Thinner border */
    color: var(--primary-color);
    padding: 8px 14px;
    /* Smaller padding */
    border-radius: 16px;
    /* Pill shape */
    cursor: pointer;
    font-weight: 500;
    /* Slightly lighter weight */
    font-size: 0.9rem;
    /* Smaller font */
    display: flex;
    align-items: center;
    gap: 6px;
    width: auto;
    /* Auto width */
    max-width: none;
    transition: background 0.2s;
}

.menu-btn:hover {
    background-color: #F0F4FF;
}

.menu-btn i {
    font-size: 1.2rem;
}

/* Coupon View */
.coupon-input-container {
    display: flex;
    padding: 0;
    /* Remove padding as iti handles input styling */
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
    margin: 10px 0 20px 0;
}

/* Intl Tel Input customization */
.iti {
    width: 100%;
    direction: ltr !important;
    /* Force LTR for phone input container */
}

.iti__flag {
    box-shadow: none;
}

.iti__country-list {
    z-index: 100;
    /* Ensure dropdown is above other elements */
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border: none;
    font-family: var(--font-en);
    text-align: left !important;
    /* Force Left align */
}

/* Remove RTL override */
/* [dir="rtl"] .iti__country-list { text-align: right; } - REMOVED */

#phone-input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    outline: none;
    transition: border 0.2s;
    direction: ltr !important;
    /* Force LTR for text input */
    text-align: left !important;
}

#phone-input:focus {
    border-color: var(--primary-color);
}

#phone-input {
    border: none;
    outline: none;
    flex: 1;
    font-size: 1rem;
    font-family: inherit;
}

/* Force LTR for Intl Tel Input in RTL Mode */
[dir="rtl"] .iti {
    direction: ltr !important;
    text-align: left !important;
}

[dir="rtl"] .iti__flag-container {
    left: 0 !important;
    right: auto !important;
}

[dir="rtl"] .iti__selected-flag {
    margin-right: 0 !important;
    padding-left: 10px !important;
    /* Standard padding */
}

[dir="rtl"] .iti__country-list {
    text-align: left !important;
    left: 0 !important;
    right: auto !important;
}

/* Override input padding that might be set by library for RTL */
[dir="rtl"] .iti input {
    /* Increased from 90px to 120px to add visual spacing as requested */
    padding-left: 120px !important;
    /* Ensure enough space for flag + code + gap */
    padding-right: 12px !important;
    text-align: left !important;
    direction: ltr !important;
}

.coupon-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.coupon-actions .btn {
    width: auto;
    min-width: 100px;
}

.coupon-result {
    margin-top: 1rem;
    animation: fadeIn 0.3s;
}

/* Chat Input Area */
.chat-input-area {
    padding: 10px 16px;
    background-color: var(--white);
    display: flex;
    align-items: center;
    gap: 10px;
    border-top: 1px solid #eee;
}

#user-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid #ddd;
    border-radius: 24px;
    font-size: 1rem;
    font-family: inherit;
    outline: none;
    transition: border 0.2s;
}

#user-input:focus {
    border-color: var(--primary-color);
}

.send-btn {
    width: 44px;
    height: 44px;
    background-color: #9098CD;
    /* Lighter purple from screenshot */
    color: white;
    border: none;
    border-radius: 12px;
    /* Squircle based on screenshot */
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

/* Static Footer (Copyright) */
.static-footer {
    text-align: center;
    padding: 10px;
    font-size: 0.75rem;
    color: #999;
    background-color: var(--bg-color);
    border-top: 1px solid rgba(0, 0, 0, 0.05);
}

.footer-logo {
    height: 24px;
    vertical-align: middle;
    margin-left: 5px;
}

.footer-link {
    color: inherit;
    text-decoration: none;
    transition: color 0.2s;
}

.footer-link:hover {
    color: var(--primary-color);
}

.footer-copyright {
    margin-top: 2rem;
    font-size: 0.8rem;
    color: #888;
}

/* Markdown Context in Chat */
.markdown-body {
    font-size: 0.95rem;
    line-height: 1.5;
}

.markdown-body p {
    margin-bottom: 0.5rem;
}

.markdown-body ul {
    padding-left: 1.2rem;
}

/* Chat Interface Styles (Shared by Menu, Coupons, Chat) */
.chat-interface {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    /* Increased from 1.5rem */
    padding-bottom: 2rem;
    /* Increased padding bottom */
}

/* ... existing styles ... */

/* RTL Support */
[dir="rtl"] {
    font-family: var(--font-ar);
}

/* Removed flex-direction: row-reverse for .chat-message to allow natural RTL flow (Avatar on Right) */

[dir="rtl"] .message-bubble {
    border-top-left-radius: 16px;
    border-top-right-radius: 4px;
}

[dir="rtl"] .chat-message.user .message-bubble {
    border-bottom-right-radius: 16px;
    border-bottom-left-radius: 4px;
}

[dir="rtl"] .menu-btn {
    text-align: right;
    flex-direction: row-reverse;
    /* Icons on right */
}

[dir="rtl"] .menu-options {
    padding-left: 0;
    padding-right: 44px;
    justify-content: flex-start;
    /* Align start (right) */
}

/* Force LTR for coupon input to keep country code on the left */
.coupon-input-container {
    direction: ltr;
}