/* Global Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #0066cc;
    --secondary-color: #00a651;
    --background: #f5f7fa;
    --surface: #ffffff;
    --text-primary: #1a1a2e;
    --text-secondary: #4a4a5a;
    --border-color: #d1d5db;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-hover: 0 4px 20px rgba(0, 0, 0, 0.12);
    --gradient: linear-gradient(135deg, #0066cc 0%, #0052a3 100%);
    --header-height: 72px;
    --footer-height: 60px;
    --safe-area-inset: env(safe-area-inset-bottom, 0px);
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif, 'Arial';
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.65;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    width: 100%;
}

/* Header - ثابت في الأعلى */
.header {
    background: var(--gradient);
    color: white;
    padding: 16px 0;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
    flex-shrink: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    font-size: 40px;
    line-height: 1;
}

.logo-text h1 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 2px;
    letter-spacing: -0.02em;
}

.logo-text p {
    font-size: 13px;
    opacity: 0.95;
}

/* Main Container */
.main-container {
    flex: 1;
    padding: 24px 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    width: 100%;
}

.main-container .container {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

/* Welcome Section */
.welcome-section {
    background: var(--surface);
    border-radius: 16px;
    padding: 60px 40px;
    box-shadow: var(--shadow);
    text-align: center;
    animation: fadeIn 0.6s ease-in-out;
    align-self: center;
    width: 100%;
    max-width: 800px;
}

.welcome-icon {
    font-size: 80px;
    margin-bottom: 20px;
    animation: bounce 2s infinite;
}

.welcome-content h2 {
    font-size: 32px;
    color: var(--text-primary);
    margin-bottom: 16px;
}

.welcome-content > p {
    font-size: 18px;
    color: var(--text-secondary);
    margin-bottom: 40px;
}

.quick-topics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
    margin-bottom: 40px;
}

/* Main Category Buttons */
.main-categories {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 24px;
    margin-top: 20px;
}

.category-btn {
    -webkit-tap-highlight-color: transparent;
    background: var(--surface);
    border: 2px solid var(--border-color);
    border-radius: 16px;
    padding: 28px 24px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: right;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    min-height: 120px;
}

.category-btn:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-hover);
    border-color: var(--primary-color);
    background: linear-gradient(135deg, #f0f7ff 0%, #fff 100%);
}

.category-icon {
    font-size: 48px;
    display: block;
}

.category-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
}

.category-desc {
    font-size: 14px;
    color: var(--text-secondary);
}

.btn-primary {
    background: var(--gradient);
    color: white;
    border: none;
    padding: 16px 48px;
    font-size: 18px;
    font-weight: 600;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 102, 204, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 102, 204, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

/* Chat Section - ثابت وواضح */
.chat-section {
    background: var(--surface);
    border-radius: 16px;
    box-shadow: var(--shadow);
    overflow: hidden;
    animation: fadeIn 0.6s ease-in-out;
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

/* Chat Header - ثابت */
.chat-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 20px;
    background: var(--background);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.back-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.back-btn:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.chat-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

/* Options Panel - ثابت في الأسفل */
.options-panel {
    padding: 18px 20px;
    padding-bottom: calc(18px + var(--safe-area-inset));
    background: var(--surface);
    border-top: 2px solid var(--border-color);
    flex-shrink: 0;
}

.options-label {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 14px;
    text-align: right;
}

.options-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}

.option-btn {
    -webkit-tap-highlight-color: transparent;
    background: var(--background);
    border: 2px solid var(--border-color);
    padding: 16px 18px;
    border-radius: 12px;
    font-size: 15px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: right;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    min-height: 48px;
}

.option-btn:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    transform: translateY(-2px);
}

.option-btn:active,
.category-btn:active {
    transform: scale(0.98);
}

/* تحسين اللمس على الموبايل */
@media (hover: none) {
    .option-btn:hover,
    .category-btn:hover {
        transform: none;
    }

    .option-btn:active {
        background: var(--primary-color);
        color: white;
    }
}

.option-btn.primary {
    background: var(--gradient);
    color: white;
    border-color: transparent;
}

.option-btn.primary:hover {
    box-shadow: 0 4px 12px rgba(0, 102, 204, 0.3);
}

.option-btn.category-option .option-icon {
    font-size: 24px;
}

/* Chat Messages - منطقة التمرير */
.chat-messages {
    padding: 20px;
    flex: 1;
    min-height: 280px;
    max-height: calc(100vh - 320px);
    overflow-y: auto;
    overflow-x: hidden;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

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

.chat-messages::-webkit-scrollbar-track {
    background: var(--background);
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #999;
}

.message {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    animation: slideIn 0.3s ease-out;
}

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

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.message.bot .message-avatar {
    background: var(--gradient);
    color: white;
}

.message.user .message-avatar {
    background: var(--secondary-color);
    color: white;
}

.message-content {
    max-width: 70%;
    padding: 16px 20px;
    border-radius: 16px;
    position: relative;
}

.message.bot .message-content {
    background: var(--background);
    border-bottom-right-radius: 4px;
}

.message.user .message-content {
    background: var(--primary-color);
    color: white;
    border-bottom-left-radius: 4px;
}

.message-text {
    font-size: 16px;
    line-height: 1.7;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.message-text strong {
    color: inherit;
}

.message-time {
    font-size: 12px;
    opacity: 0.7;
    margin-top: 8px;
    display: block;
}

/* Steps Display */
.steps-container {
    margin-top: 16px;
}

.step-item {
    background: #fff;
    border-right: 4px solid var(--primary-color);
    padding: 14px 18px;
    margin-bottom: 12px;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.step-number {
    display: inline-block;
    background: var(--primary-color);
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    text-align: center;
    line-height: 24px;
    font-size: 12px;
    font-weight: 600;
    margin-left: 8px;
}

.step-title {
    font-weight: 600;
    margin-bottom: 4px;
}

.step-description {
    font-size: 14px;
    color: var(--text-secondary);
}

/* Chat Input */
.chat-input-container {
    padding: 20px 24px;
    background: white;
    border-top: 1px solid var(--border-color);
}

.chat-input {
    display: flex;
    gap: 12px;
    align-items: center;
}

#userInput {
    flex: 1;
    padding: 14px 20px;
    border: 2px solid var(--border-color);
    border-radius: 50px;
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s ease;
}

#userInput:focus {
    border-color: var(--primary-color);
}

.send-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--gradient);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 102, 204, 0.3);
}

.send-btn:active {
    transform: scale(0.95);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.input-hint {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 8px;
    text-align: center;
}

/* Footer - ثابت في الأسفل */
.footer {
    background: var(--surface);
    border-top: 2px solid var(--border-color);
    padding: 16px 0;
    padding-bottom: calc(16px + var(--safe-area-inset));
    margin-top: auto;
    flex-shrink: 0;
}

.footer .container {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px 24px;
}

.footer-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px 20px;
}

.footer-links a {
    color: var(--primary-color);
    text-decoration: none;
    font-size: 15px;
    font-weight: 500;
    padding: 4px 0;
    transition: color 0.2s ease;
}

.footer-links a:hover {
    color: var(--secondary-color);
}

/* Loading Indicator */
.loading-indicator {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1000;
}

.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;
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 16px 20px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

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

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

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

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes bounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-10px);
    }
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

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

/* Responsive Design - متجاوبة مع جميع الشاشات */

/* تابلت وبعض الموبايل الكبير */
@media (max-width: 768px) {
    .container {
        padding: 0 16px;
    }

    .main-container {
        padding: 20px 0;
    }

    .welcome-section {
        padding: 36px 24px;
    }

    .welcome-icon {
        font-size: 64px;
    }

    .welcome-content h2 {
        font-size: 26px;
    }

    .welcome-content > p {
        font-size: 17px;
    }

    .main-categories {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .category-btn {
        padding: 24px 20px;
        min-height: 100px;
    }

    .options-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .option-btn {
        min-height: 52px;
        font-size: 15px;
    }

    .chat-section {
        border-radius: 12px;
    }

    .chat-header {
        padding: 12px 16px;
    }

    .chat-messages {
        padding: 16px;
        min-height: 240px;
        max-height: calc(100vh - 340px);
    }

    .message-content {
        max-width: 88%;
    }

    .message-text {
        font-size: 15px;
    }

    .options-panel {
        padding: 16px;
        padding-bottom: calc(16px + var(--safe-area-inset));
    }

    .logo-text h1 {
        font-size: 18px;
    }

    .logo-text p {
        font-size: 12px;
    }

    .footer-links {
        gap: 10px 16px;
    }

    .footer-links a {
        font-size: 14px;
    }
}

/* موبايل صغير */
@media (max-width: 480px) {
    .container {
        padding: 0 12px;
    }

    .main-container {
        padding: 16px 0;
    }

    .header .container {
        padding: 0 12px;
    }

    .logo-icon {
        font-size: 36px;
    }

    .logo-text h1 {
        font-size: 16px;
    }

    .logo-text p {
        font-size: 11px;
    }

    .welcome-section {
        padding: 28px 16px;
    }

    .welcome-icon {
        font-size: 56px;
    }

    .welcome-content h2 {
        font-size: 22px;
    }

    .welcome-content > p {
        font-size: 15px;
    }

    .category-btn {
        padding: 20px 16px;
    }

    .category-title {
        font-size: 18px;
    }

    .category-desc {
        font-size: 13px;
    }

    .chat-messages {
        padding: 14px;
        min-height: 200px;
    }

    .options-panel {
        padding: 14px 12px;
        padding-bottom: calc(14px + var(--safe-area-inset));
    }

    .back-btn {
        padding: 10px 14px;
        font-size: 13px;
    }

    .chat-title {
        font-size: 16px;
    }
}

/* شاشات كبيرة - تحسين الوضوح */
@media (min-width: 1200px) {
    .chat-section {
        max-width: 920px;
    }

    .message-text {
        font-size: 17px;
    }
}

/* Print Styles */
@media print {
    .header,
    .footer,
    .options-panel,
    .chat-header {
        display: none;
    }

    .chat-messages {
        max-height: none;
    }
}
