/* Custom CSS for Saudi Investment Platform */

/* Import Arabic fonts */
@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@300;400;600;700&display=swap');

/* Root variables for Purple Professional Theme */
:root {
    --primary-purple: #6D5DF6;
    --deep-purple: #4C3BCF;
    --dark-purple: #2E236C;
    --card-white: #FFFFFF;
    --light-surface: #F7F6FF;
    --border-color: #E6E4F5;
    --primary-text: #1E1B4B;
    --secondary-text: #6B7280;
    --muted-text: #9CA3AF;
    --text-on-purple: #FFFFFF;
    --success-green: #166534;
    --success-light: #DCFCE7;
    --warning-orange: #92400E;
    --warning-light: #FEF3C7;
    --danger-red: #7F1D1D;
    --danger-light: #FEE2E2;
    --shadow-sm: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
    --shadow-md: 0 12px 30px rgba(76, 59, 207, 0.18);
    
    /* iOS Safe Area Variables for Notched Devices */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
}

/* Base styles - Mobile First */
body {
    font-family: 'Cairo', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: var(--primary-text);
    background-color: var(--light-surface);
    font-size: 14px;
    margin: 0;
    padding: 0;
    
    /* iOS Smooth Scrolling */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: none;
}

/* Arabic text support */
html[dir="rtl"] {
    text-align: right;
}

/* Mobile-First Responsive Typography */
h1 {
    font-size: 1.75rem;
    line-height: 1.2;
    font-weight: 700;
    margin-bottom: 1rem;
}

h2 {
    font-size: 1.5rem;
    line-height: 1.3;
    font-weight: 600;
    margin-bottom: 0.875rem;
}

h3 {
    font-size: 1.25rem;
    line-height: 1.4;
    font-weight: 600;
    margin-bottom: 0.75rem;
}

h4, h5, h6 {
    font-size: 1.125rem;
    line-height: 1.4;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

p {
    margin-bottom: 1rem;
    line-height: 1.6;
}

/* Responsive text sizes for tablets and desktop */
@media (min-width: 768px) {
    body {
        font-size: 16px;
    }
    
    h1 {
        font-size: 2.25rem;
    }
    
    h2 {
        font-size: 1.875rem;
    }
    
    h3 {
        font-size: 1.5rem;
    }
}

/* Container responsive padding - centered with no gaps */
.container, .container-fluid {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding-left: 15px;
    padding-right: 15px;
}

@media (min-width: 576px) {
    .container, .container-fluid {
        padding-left: 20px;
        padding-right: 20px;
    }
}

/* Stats Box Styling */
.stat-box {
    padding: 0.5rem;
    transition: transform 0.2s ease;
}

.stat-box:hover {
    transform: scale(1.05);
}

.bg-gradient {
    background: linear-gradient(135deg, #6D5DF6 0%, #4C3BCF 50%, #2E236C 100%);
}

/* iOS Touch-Friendly Buttons (44px minimum) */
.btn, .navbar-toggler {
    min-height: 44px;
    min-width: 44px;
    padding: 0.625rem 1.25rem;
}

.navbar-nav .nav-link {
    min-height: 44px;
    display: flex;
    align-items: center;
}

.dropdown-item {
    min-height: 44px;
    padding: 0.625rem 1rem;
    display: flex;
    align-items: center;
}

/* Icon buttons touch targets */
.nav-link i, .btn i {
    pointer-events: none;
}

/* Card interactive areas */
.card-link, .platform-card a {
    min-height: 44px;
    padding: 0.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Mobile-First Navigation */
.navbar {
    padding: 0.5rem 0;
}

.navbar-brand {
    font-size: 1.25rem;
    font-weight: 700;
}

.navbar-nav .nav-link {
    font-weight: 500;
    padding: 0.5rem 0.75rem;
    transition: all 0.3s ease;
}

@media (min-width: 768px) {
    .navbar {
        padding: 1rem 0;
    }
    
    .navbar-brand {
        font-size: 1.5rem;
    }
    
    .navbar-nav .nav-link {
        padding: 0.75rem 1rem;
    }
}

/* Mobile-optimized buttons */
.btn {
    font-size: 0.875rem;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-weight: 600;
}

@media (max-width: 767px) {
    .btn {
        font-size: 0.8rem;
        padding: 0.4rem 0.8rem;
    }
    
    .btn-group .btn, .btn-toolbar .btn {
        margin: 0.2rem;
    }
}

/* Platform card mobile optimization */
.platform-card {
    border: none;
    border-radius: 12px;
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
    transition: all 0.3s ease;
    height: 100%;
    margin-bottom: 1rem;
}

.platform-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
}

.platform-card .card-title {
    color: var(--text-dark);
    font-weight: 700;
    font-size: 1rem;
    margin-bottom: 0.5rem;
    line-height: 1.3;
}

.platform-card .card-text {
    color: var(--text-muted);
    font-size: 0.875rem;
    line-height: 1.5;
}

/* Mobile card improvements */
@media (max-width: 767px) {
    .platform-card .card-body {
        padding: 0.875rem;
    }
    
    .platform-card .card-title {
        font-size: 0.95rem;
    }
    
    .platform-card .card-text {
        font-size: 0.8rem;
    }
    
    .platform-card:hover {
        transform: none;
    }
    
    .col-xl-4, .col-lg-6 {
        padding-left: 5px;
        padding-right: 5px;
        margin-bottom: 0.5rem;
    }
}

/* Form controls mobile optimization */
.form-control, .form-select {
    font-size: 0.875rem;
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
}

@media (max-width: 767px) {
    .form-control, .form-select {
        font-size: 0.8rem;
        padding: 0.4rem 0.6rem;
    }
    
    .input-group {
        margin-bottom: 0.5rem;
    }
}

/* Badge responsive sizing */
.badge {
    font-size: 0.75rem;
    padding: 0.35rem 0.65rem;
    border-radius: 6px;
}

@media (max-width: 767px) {
    .badge {
        font-size: 0.7rem;
        padding: 0.3rem 0.5rem;
    }
}

/* Market data section mobile optimization */
.market-stats {
    padding: 1rem;
    background: white;
    border-radius: 12px;
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
    margin-bottom: 1rem;
}

@media (max-width: 767px) {
    .market-stats {
        padding: 0.75rem;
        margin-bottom: 0.75rem;
    }
    
    .market-stats .row > div {
        margin-bottom: 0.5rem;
    }
}

/* iOS-Specific Optimizations */
@supports (-webkit-touch-callout: none) {
    /* iOS Safari specific styles */
    .btn {
        -webkit-appearance: none;
        border-radius: 12px;
    }
    
    input, select, textarea {
        -webkit-appearance: none;
        border-radius: 12px;
    }
    
    .form-control:focus, .form-select:focus {
        -webkit-tap-highlight-color: transparent;
    }
}

/* iOS Touch Improvements */
.platform-card {
    -webkit-tap-highlight-color: rgba(25, 135, 84, 0.1);
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.btn {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    cursor: pointer;
}

/* iOS-Optimized Typography */
@media screen and (-webkit-min-device-pixel-ratio: 2) {
    body {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
    
    h1, h2, h3, h4, h5, h6 {
        text-rendering: optimizeLegibility;
    }
}

/* Safe Area for iOS Notch */
@media screen and (device-width: 375px) and (device-height: 812px) and (-webkit-device-pixel-ratio: 3) {
    .navbar {
        padding-top: env(safe-area-inset-top);
    }
    
    .container {
        padding-left: max(15px, env(safe-area-inset-left));
        padding-right: max(15px, env(safe-area-inset-right));
    }
}

/* iOS Home Screen App Mode */
@media all and (display-mode: standalone) {
    .navbar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1030;
    }
    
    body {
        padding-top: 60px;
    }
    
    .hero-section {
        padding-top: 2rem;
    }
}

/* iOS Dark Mode Support */
@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: light; /* Force light mode for consistency */
    }
}

/* iOS Performance Optimizations */
.platform-card, .market-stats, .hero-stats {
    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* iOS Scroll Improvements */
.container, .container-fluid {
    -webkit-overflow-scrolling: touch;
}

/* iOS Input Zoom Prevention */
@media screen and (max-width: 767px) {
    input, select, textarea {
        font-size: 16px !important;
        transform: scale(1);
        transition: all 0.2s ease;
    }
}

/* iOS Navigation Improvements */
.navbar-toggler {
    border: none;
    padding: 0.5rem;
    -webkit-tap-highlight-color: transparent;
}

.navbar-toggler:focus {
    box-shadow: none;
    outline: none;
}

/* iOS Badge Optimizations */
.badge {
    border-radius: 8px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

/* Custom Bootstrap overrides */
.btn-primary {
    background-color: var(--primary-green);
    border-color: var(--primary-green);
    font-weight: 600;
}

.btn-primary:hover {
    background-color: #1a6a2e;
    border-color: #1a6a2e;
}

.btn-outline-primary {
    color: var(--primary-green);
    border-color: var(--primary-green);
}

.btn-outline-primary:hover {
    background-color: var(--primary-green);
    border-color: var(--primary-green);
}

.text-primary {
    color: var(--primary-green) !important;
}

.bg-primary {
    background-color: var(--primary-green) !important;
}

.border-primary {
    border-color: var(--primary-green) !important;
}

/* Navigation */
.navbar-brand {
    font-size: 1.5rem;
    font-weight: 700;
}

.navbar-nav .nav-link {
    font-weight: 500;
    padding: 0.75rem 1rem;
    transition: all 0.3s ease;
}

.navbar-nav .nav-link:hover {
    color: var(--saudi-gold) !important;
}

/* Hero section */
.hero-section {
    background: linear-gradient(135deg, var(--primary-green) 0%, var(--secondary-green) 100%);
    min-height: 60vh;
    position: relative;
    overflow: hidden;
}

.hero-section::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.05'%3E%3Ccircle cx='30' cy='30' r='1.5'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E") repeat;
}

.hero-section .container {
    position: relative;
    z-index: 2;
}

/* Cards */
.card {
    border-radius: 0.75rem;
    transition: all 0.3s ease;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.platform-card {
    border: 1px solid var(--border-light);
    overflow: hidden;
}

.platform-card:hover {
    border-color: var(--primary-green);
    box-shadow: 0 0.75rem 1.5rem rgba(30, 126, 52, 0.15);
}

/* Platform cards specific styling */
.platform-logo img {
    object-fit: cover;
    border: 2px solid var(--border-light);
}

/* Badges */
.badge {
    font-weight: 600;
    padding: 0.5em 0.75em;
}

.badge.bg-primary {
    background-color: var(--primary-green) !important;
}

/* Comparison table */
.comparison-table {
    font-size: 0.95rem;
}

.comparison-table th {
    background-color: #f8f9fa;
    font-weight: 600;
    border-bottom: 2px solid var(--primary-green);
}

.comparison-table .section-header {
    background-color: #f8f9fa !important;
}

.comparison-table .section-header td {
    font-weight: 600;
    color: var(--primary-green);
    border-top: 2px solid var(--border-light);
}

/* Compare panel */
.compare-panel {
    max-width: 400px;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        transform: translate(-50%, 100%);
        opacity: 0;
    }
    to {
        transform: translate(-50%, 0);
        opacity: 1;
    }
}

/* Forms */
.form-control, .form-select {
    border-radius: 0.5rem;
    border: 1px solid var(--border-light);
    transition: all 0.3s ease;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary-green);
    box-shadow: 0 0 0 0.2rem rgba(30, 126, 52, 0.25);
}

/* Alerts */
.alert {
    border-radius: 0.75rem;
    border: none;
}

.alert-info {
    background-color: rgba(13, 202, 240, 0.1);
    color: #055160;
}

.alert-warning {
    background-color: rgba(255, 193, 7, 0.1);
    color: #664d03;
}

.alert-success {
    background-color: var(--light-green);
    color: var(--primary-green);
}

/* Feature icons */
.feature-icon {
    display: inline-block;
    padding: 1rem;
    border-radius: 50%;
    background-color: rgba(30, 126, 52, 0.1);
}

/* Footer */
footer {
    background-color: #2c3e50 !important;
}

footer a {
    transition: color 0.3s ease;
}

footer a:hover {
    color: var(--saudi-gold) !important;
}

/* Responsive design */
@media (max-width: 768px) {
    .hero-section {
        min-height: 50vh;
        text-align: center;
    }
    
    .display-4 {
        font-size: 2rem;
    }
    
    .comparison-table {
        font-size: 0.85rem;
    }
    
    .platform-card .card-body {
        padding: 1rem;
    }
    
    .compare-panel {
        max-width: 90%;
        left: 50% !important;
        right: auto !important;
    }
}

@media (max-width: 576px) {
    .btn-group {
        display: flex;
        flex-direction: column;
    }
    
    .btn-group .btn {
        border-radius: 0.375rem !important;
        margin-bottom: 0.5rem;
    }
    
    .btn-group .btn:last-child {
        margin-bottom: 0;
    }
}

/* Loading states */
.spinner-border-sm {
    width: 1rem;
    height: 1rem;
}

/* Custom scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--primary-green);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #1a6a2e;
}

/* Animation utilities */
.fade-in {
    animation: fadeIn 0.5s ease-in;
}

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

.slide-in-right {
    animation: slideInRight 0.5s ease-out;
}

@keyframes slideInRight {
    from {
        transform: translateX(100px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Table responsive improvements */
@media (max-width: 992px) {
    .table-responsive {
        border: none;
    }
    
    .comparison-table th,
    .comparison-table td {
        padding: 0.75rem 0.5rem;
        min-width: 150px;
    }
}

/* Success states */
.bg-success.bg-opacity-10 {
    background-color: rgba(25, 135, 84, 0.1) !important;
}

.bg-warning.bg-opacity-10 {
    background-color: rgba(255, 193, 7, 0.1) !important;
}

/* Opportunities section styling */
.opportunities-section {
    border-top: 1px solid var(--border-light);
    padding-top: 1rem;
    margin-top: 1rem;
}

.opportunity-item {
    transition: all 0.3s ease;
    border: 1px solid transparent;
}

.opportunity-item:hover {
    border-color: var(--primary-green);
    transform: translateY(-1px);
    box-shadow: 0 0.25rem 0.5rem rgba(30, 126, 52, 0.15);
}

/* Risk level badges */
.badge-risk-منخفض-جداً,
.badge-risk-منخفض {
    background-color: #d4edda !important;
    color: #155724 !important;
}

.badge-risk-متوسط {
    background-color: #fff3cd !important;
    color: #856404 !important;
}

.badge-risk-متوسط-إلى-عالي,
.badge-risk-عالي {
    background-color: #f8d7da !important;
    color: #721c24 !important;
}

.badge-risk-منخفض-إلى-متوسط {
    background-color: #d1ecf1 !important;
    color: #0c5460 !important;
}

/* Modal improvements */
.modal-content {
    border-radius: 0.75rem;
    border: none;
    box-shadow: var(--shadow-md);
}

.modal-header {
    border-bottom: 1px solid var(--border-light);
}

/* Empty states styling */
.empty-state {
    padding: 3rem 1rem;
}

.empty-state i {
    color: var(--text-muted);
    opacity: 0.5;
}

/* Button loading state */
.btn.loading {
    position: relative;
    color: transparent !important;
}

.btn.loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin-left: -8px;
    margin-top: -8px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Live Data Updates Styles */
.live-indicator {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.85rem;
    color: #28a745;
    margin-left: 10px;
}

.live-indicator::before {
    content: '';
    width: 8px;
    height: 8px;
    background: #28a745;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(1.2); }
    100% { opacity: 1; transform: scale(1); }
}

.refresh-data-btn {
    border: none;
    background: transparent;
    color: #6c757d;
    font-size: 1rem;
    transition: all 0.3s ease;
}

.refresh-data-btn:hover {
    color: #198754;
    transform: rotate(45deg);
}

.refresh-data-btn.spinning {
    animation: spin 1s linear infinite;
    color: #198754;
}

.value-updated {
    animation: highlight 1s ease-out;
}

@keyframes highlight {
    0% { background-color: rgba(40, 167, 69, 0.3); transform: scale(1.05); }
    100% { background-color: transparent; transform: scale(1); }
}

.animate-fade-in {
    animation: fadeIn 0.5s ease-in;
}

@keyframes fadeIn {
    0% { opacity: 0; transform: translateY(10px); }
    100% { opacity: 1; transform: translateY(0); }
}

.activity-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 6px;
    margin-bottom: 4px;
    background: rgba(255, 255, 255, 0.7);
    transition: all 0.3s ease;
}

.activity-item:hover {
    background: rgba(255, 255, 255, 0.9);
    transform: translateX(5px);
}

.activity-item i {
    width: 16px;
    text-align: center;
}

.updated-indicator {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #28a745;
    color: white;
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 10px;
    opacity: 0;
    transform: scale(0);
    transition: all 0.3s ease;
}

.updated-indicator.show {
    opacity: 1;
    transform: scale(1);
}

.market-stats {
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
}

.market-stat-item {
    text-align: center;
    padding: 15px;
}

.market-stat-value {
    font-size: 1.5rem;
    font-weight: bold;
    color: #198754;
    display: block;
    margin-bottom: 5px;
}

.market-stat-label {
    color: #6c757d;
    font-size: 0.9rem;
}

.live-activities-panel {
    background: rgba(255, 255, 255, 0.9);
    border-radius: 12px;
    padding: 15px;
    max-height: 300px;
    overflow-y: auto;
}

.live-data-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 15px 0;
}

.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: #198754;
}

input:checked + .slider:before {
    transform: translateX(26px);
}

.last-refresh-time {
    font-size: 0.8rem;
    color: #6c757d;
    margin-top: 5px;
}

/* Print styles */
@media print {
    .navbar,
    .modal,
    .compare-panel,
    footer {
        display: none !important;
    }
    
    .container {
        max-width: none !important;
    }
    
    .card {
        break-inside: avoid;
        box-shadow: none !important;
        border: 1px solid #ddd !important;
    }
}
