/* 
   Ads Optimizer Theme - Glassmorphic Dark UI
   Font: Vazirmatn (RTL)
*/

:root {
    --bg-gradient: linear-gradient(135deg, #0b0f19 0%, #111827 50%, #1e1b4b 100%);
    --panel-bg: rgba(17, 24, 39, 0.7);
    --panel-border: rgba(255, 255, 255, 0.08);
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --primary-glow: rgba(99, 102, 241, 0.4);
    
    --accent-color: #a855f7;
    --accent-hover: #9333ea;
    
    --bot-bubble-bg: rgba(30, 41, 59, 0.85);
    --bot-bubble-border: rgba(255, 255, 255, 0.05);
    --user-bubble-bg: linear-gradient(135deg, #4f46e5 0%, #3730a3 100%);
    --user-bubble-border: rgba(99, 102, 241, 0.3);
    
    --input-bg: rgba(15, 23, 42, 0.8);
    --input-border: rgba(255, 255, 255, 0.1);
    
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    
    --transition-fast: 0.2s ease;
    --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --border-radius-lg: 16px;
    --border-radius-md: 12px;
    --border-radius-sm: 8px;
    
    --shadow-premium: 0 10px 30px -10px rgba(0, 0, 0, 0.7);
    --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.15);
}

/* Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Vazirmatn', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg-gradient);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    line-height: 1.6;
}

/* App Layout */
.app-container {
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: rgba(10, 15, 30, 0.3);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

@media (min-width: 1024px) {
    .app-container {
        width: 95vw;
        max-width: 1400px;
        height: 90vh;
        border-radius: var(--border-radius-lg);
        border: 1px solid var(--panel-border);
        box-shadow: var(--shadow-premium);
        overflow: hidden;
    }
}

/* Header Styles */
.app-header {
    background: var(--panel-bg);
    border-bottom: 1px solid var(--panel-border);
    padding: 16px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    z-index: 100;
}

@media (min-width: 768px) {
    .app-header {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        padding: 20px 32px;
    }
}

.brand {
    display: flex;
    align-items: center;
    gap: 16px;
}

.brand-logo {
    width: 48px;
    height: 48px;
    border-radius: var(--border-radius-md);
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    color: white;
    box-shadow: 0 0 15px var(--primary-glow);
    animation: pulse-glow 3s infinite alternate;
}

.brand-text h1 {
    font-size: 18px;
    font-weight: 800;
    letter-spacing: -0.5px;
    color: var(--text-primary);
}

.brand-text span {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Config Panel inside Header */
.config-panel {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
}

@media (min-width: 768px) {
    .config-panel {
        flex-direction: row;
        justify-content: flex-end;
        align-items: center;
        width: auto;
        flex: 1;
        max-width: 70%;
    }
}

.config-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

@media (min-width: 768px) {
    .config-group {
        max-width: 320px;
    }
}

.config-label {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Toggle Switch Button Container */
.toggle-container {
    display: flex;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--border-radius-md);
    padding: 4px;
    height: 48px;
}

.toggle-btn {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    border-radius: var(--border-radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: var(--transition-fast);
}

.toggle-btn i {
    font-size: 14px;
}

.toggle-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.03);
}

.toggle-btn.active {
    color: white;
    background: var(--user-bubble-bg);
    box-shadow: 0 4px 10px rgba(79, 70, 229, 0.3);
}

/* Custom Dropdown Styles (Searchable dropdown) */
.custom-dropdown {
    position: relative;
    width: 100%;
}

.trigger-delete-btn {
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--border-radius-sm);
    display: none; /* controlled by JS */
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
    z-index: 10;
    margin-left: 8px;
}

.trigger-delete-btn:hover {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.15);
}

.dropdown-trigger {
    display: flex;
    align-items: center;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--border-radius-md);
    padding: 0 16px;
    height: 48px;
    cursor: pointer;
    transition: var(--transition-fast);
}

.dropdown-trigger:hover, .dropdown-trigger.focused {
    border-color: var(--primary-color);
    box-shadow: var(--shadow-glow);
}

.dropdown-trigger .icon-right {
    color: var(--text-secondary);
    margin-left: 12px;
}

.dropdown-trigger .icon-left {
    color: var(--text-secondary);
    margin-right: auto;
    transition: var(--transition-fast);
}

.dropdown-trigger.open .icon-left {
    transform: rotate(180deg);
    color: var(--primary-color);
}

.dropdown-trigger input {
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    width: 100%;
    height: 100%;
    cursor: pointer;
}

.dropdown-trigger input::placeholder {
    color: var(--text-muted);
}

.dropdown-menu {
    position: absolute;
    top: 54px;
    left: 0;
    right: 0;
    background: rgba(17, 24, 39, 0.95);
    border: 1px solid var(--panel-border);
    border-radius: var(--border-radius-md);
    box-shadow: var(--shadow-premium);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    max-height: 250px;
    overflow-y: auto;
    z-index: 200;
    opacity: 0;
    transform: translateY(-10px) scale(0.98);
    pointer-events: none;
    transition: var(--transition-normal);
}

.custom-dropdown.open .dropdown-menu {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.dropdown-list {
    list-style: none;
    padding: 6px;
}

.dropdown-item {
    padding: 10px 14px;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    transition: var(--transition-fast);
}

.dropdown-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.dropdown-item.selected {
    background: rgba(99, 102, 241, 0.15);
    color: var(--primary-color);
    font-weight: 700;
}

.item-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.item-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.delete-account-btn {
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: var(--border-radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
    opacity: 1;
}

.delete-account-btn:hover {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.15);
}

.select-check-icon {
    color: var(--primary-color);
    font-size: 12px;
}

.dropdown-add-account {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-top: 1px solid var(--panel-border);
    background: rgba(15, 23, 42, 0.95);
    position: sticky;
    bottom: 0;
}

.dropdown-add-account input {
    flex: 1;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--input-border);
    border-radius: var(--border-radius-sm);
    padding: 6px 10px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 13px;
    outline: none;
    transition: var(--transition-fast);
}

.dropdown-add-account input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.2);
}

.dropdown-add-account button {
    background: var(--user-bubble-bg);
    border: none;
    outline: none;
    width: 32px;
    height: 32px;
    border-radius: var(--border-radius-sm);
    color: white;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
    box-shadow: 0 2px 6px rgba(79, 70, 229, 0.2);
}

.dropdown-add-account button:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(79, 70, 229, 0.35);
}

.dropdown-add-account button:active {
    transform: translateY(0);
}

.dropdown-no-results {
    padding: 16px;
    color: var(--text-muted);
    font-size: 14px;
    text-align: center;
}

/* Chat Main Layout */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    background: rgba(15, 23, 42, 0.2);
}

/* Chat Message History */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Chat Bubbles */
.message {
    display: flex;
    gap: 16px;
    max-width: 85%;
    opacity: 0;
    transform: translateY(15px);
    animation: message-fade-in 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

@media (min-width: 768px) {
    .message {
        max-width: 75%;
    }
}

/* Bot Alignments (Right / Start) */
.bot-message {
    align-self: flex-start; /* in RTL, flex-start is the right side */
    flex-direction: row;
}

/* User Alignments (Left / End) */
.user-message {
    align-self: flex-end; /* in RTL, flex-end is the left side */
    flex-direction: row-reverse;
}

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 18px;
    color: white;
}

.bot-message .message-avatar {
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    box-shadow: 0 0 10px var(--primary-glow);
}

.user-message .message-avatar {
    background: linear-gradient(135deg, #10b981, #059669);
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.2);
}

.message-content {
    border-radius: var(--border-radius-lg);
    padding: 14px 18px;
    font-size: 15px;
    position: relative;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
}

.bot-message .message-content {
    background: var(--bot-bubble-bg);
    border: 1px solid var(--bot-bubble-border);
    color: var(--text-primary);
    border-top-right-radius: 2px;
}

.user-message .message-content {
    background: var(--user-bubble-bg);
    border: 1px solid var(--user-bubble-border);
    color: white;
    border-top-left-radius: 2px;
}

/* System error messages */
.error-message .message-content {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #fca5a5;
}

.error-message .message-avatar {
    background: var(--danger);
    box-shadow: 0 0 10px rgba(239, 68, 68, 0.3);
}

/* Welcome Message layout */
.welcome-message {
    align-self: center;
    max-width: 600px;
    width: 100%;
}

.welcome-message .message-content {
    background: linear-gradient(135deg, rgba(30, 27, 75, 0.5) 0%, rgba(17, 24, 39, 0.6) 100%);
    border: 1px solid rgba(99, 102, 241, 0.2);
    padding: 24px;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-glow);
}

.welcome-header {
    font-size: 18px;
    font-weight: 800;
    margin-bottom: 12px;
    background: linear-gradient(90deg, var(--text-primary), var(--primary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.welcome-message p {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 12px;
}

.welcome-steps {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 16px;
    padding-right: 0;
}

.welcome-steps li {
    font-size: 14px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
}

.welcome-steps li i {
    color: var(--primary-color);
    font-size: 16px;
}

/* Typing / Loading Indicators */
.typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-right: 8px;
}

.typing-dots .dot {
    width: 6px;
    height: 6px;
    background-color: var(--text-primary);
    border-radius: 50%;
    animation: dot-bounce 1.4s infinite ease-in-out both;
}

.typing-dots .dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dots .dot:nth-child(2) { animation-delay: -0.16s; }

.typing-content {
    display: flex;
    align-items: center;
    font-size: 14px;
    color: var(--text-secondary);
}

/* Chat Input Bar */
.chat-input-bar {
    padding: 16px 24px;
    background: var(--panel-bg);
    border-top: 1px solid var(--panel-border);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.chat-form {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    max-width: 1000px;
    margin: 0 auto;
}

.clear-chat-btn {
    background: transparent;
    border: 1px solid var(--input-border);
    width: 48px;
    height: 48px;
    border-radius: var(--border-radius-md);
    color: var(--text-secondary);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
    flex-shrink: 0;
}

.clear-chat-btn:hover {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.08);
    border-color: rgba(239, 68, 68, 0.2);
}

.input-wrapper {
    flex: 1;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--border-radius-md);
    padding: 10px 16px;
    display: flex;
    align-items: center;
    transition: var(--transition-fast);
}

.input-wrapper:focus-within {
    border-color: var(--primary-color);
    box-shadow: var(--shadow-glow);
}

.input-wrapper textarea {
    width: 100%;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 15px;
    resize: none;
    max-height: 120px;
    line-height: 1.5;
}

.input-wrapper textarea::placeholder {
    color: var(--text-muted);
}

.send-btn {
    background: var(--user-bubble-bg);
    border: none;
    outline: none;
    width: 48px;
    height: 48px;
    border-radius: var(--border-radius-md);
    color: white;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
    flex-shrink: 0;
}

.send-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(79, 70, 229, 0.4);
}

.send-btn:active {
    transform: translateY(0);
}

/* Styled Markdown Output components */
.message-content p {
    margin-bottom: 10px;
}
.message-content p:last-child {
    margin-bottom: 0;
}

.message-content strong {
    color: white;
    font-weight: 700;
}

.bot-message .message-content strong {
    color: #e0e7ff;
}

.message-content a {
    color: #818cf8;
    text-decoration: underline;
}

.message-content ul, .message-content ol {
    margin: 10px 0;
    padding-right: 20px;
}

.message-content li {
    margin-bottom: 6px;
}

.message-content code {
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 13px;
    color: #fda4af;
    direction: ltr;
    display: inline-block;
}

.message-content pre {
    background: rgba(0, 0, 0, 0.4);
    padding: 12px;
    border-radius: var(--border-radius-sm);
    overflow-x: auto;
    margin: 12px 0;
    direction: ltr;
}

.message-content pre code {
    background: transparent;
    padding: 0;
    color: #f3f4f6;
    display: block;
}

/* Tables style in markdown output (Critical for Google Ads stats) */
.message-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
    font-size: 14px;
    text-align: right;
    border-radius: var(--border-radius-md);
    overflow: hidden;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.message-content th, .message-content td {
    padding: 10px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.message-content th {
    background-color: rgba(99, 102, 241, 0.15);
    color: #c7d2fe;
    font-weight: 700;
}

.message-content tr:last-child td {
    border-bottom: none;
}

.message-content tr:nth-child(even) {
    background-color: rgba(255, 255, 255, 0.02);
}

.message-content tr:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.message-content blockquote {
    border-right: 4px solid var(--primary-color);
    padding-right: 12px;
    margin: 12px 0;
    color: var(--text-secondary);
    font-style: italic;
}

/* Webkit Scrollbars */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
    transition: var(--transition-fast);
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Custom styles for select layout on mobile */
@media (max-width: 767px) {
    .app-header {
        padding: 12px 16px;
    }
    
    .brand-logo {
        width: 36px;
        height: 36px;
        font-size: 16px;
    }

    .brand-text h1 {
        font-size: 15px;
    }

    .config-panel {
        gap: 10px;
    }

    .toggle-container, .dropdown-trigger {
        height: 40px;
    }

    .toggle-btn {
        font-size: 12px;
    }

    .dropdown-trigger input {
        font-size: 13px;
    }
    
    .chat-messages {
        padding: 16px;
        gap: 16px;
    }

    .message {
        max-width: 90%;
        gap: 10px;
    }

    .message-avatar {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }

    .message-content {
        padding: 10px 14px;
        font-size: 14px;
    }
    
    .chat-input-bar {
        padding: 12px;
    }

    .clear-chat-btn, .send-btn {
        width: 42px;
        height: 42px;
        font-size: 16px;
    }
    
    .input-wrapper {
        padding: 8px 12px;
    }

    .input-wrapper textarea {
        font-size: 14px;
    }
}

.dropdown-item.add-account-trigger {
    border-top: 1px solid var(--panel-border);
    color: var(--primary-color);
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(99, 102, 241, 0.04);
}

.dropdown-item.add-account-trigger:hover {
    background: rgba(99, 102, 241, 0.12);
    color: white;
}

/* Animations */
@keyframes message-fade-in {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse-glow {
    0% {
        box-shadow: 0 0 10px rgba(99, 102, 241, 0.3);
    }
    100% {
        box-shadow: 0 0 25px rgba(99, 102, 241, 0.6), 0 0 15px rgba(168, 85, 247, 0.4);
    }
}

@keyframes dot-bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1.0); }
}
