/**
 * Advertisement System CSS
 * Styling for advertisement management and display
 */

/* Advertisement Cards */
.advertisement {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 20px;
    transition: all 0.3s ease;
}

.advertisement:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

.ad-shell {
    background: #fff;
    border: 1px solid #e5e7eb;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.08);
    display: grid;
    grid-template-columns: minmax(0, 1fr);
}

.ad-shell:hover {
    transform: none;
}

.ad-shell-creative {
    position: relative;
    min-width: 0;
}

.ad-shell-meta {
    display: grid;
    gap: 6px;
    min-height: 92px;
    padding: 12px 14px 14px;
    background: #fff;
    align-content: start;
}

.ad-shell-label {
    color: #6b7280;
    font-size: 11px;
    line-height: 1.2;
}

.ad-shell-title {
    color: #111827;
    font-size: 16px;
    font-weight: 700;
    line-height: 1.35;
    margin: 0;
}

.ad-shell-description {
    color: #4b5563;
    font-size: 13px;
    line-height: 1.55;
    margin: 0;
}

.ad-shell-cta {
    justify-self: start;
    margin-top: 4px;
    min-height: 34px;
    padding: 7px 14px;
}

.ad-shell-controls {
    position: absolute;
    inset-block-start: 10px;
    inset-inline-end: 10px;
    z-index: 20;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.ad-dismiss,
.ad-skip {
    border: 0;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.18);
    cursor: pointer;
}

.ad-dismiss {
    width: 32px;
    height: 32px;
    border-radius: 999px;
    background: rgba(17, 24, 39, 0.78);
    color: #fff;
    font-size: 22px;
    line-height: 1;
}

.ad-skip {
    min-height: 32px;
    border-radius: 999px;
    background: rgba(17, 24, 39, 0.78);
    color: #fff;
    font-size: 12px;
    padding: 6px 12px;
}

.ad-skip:disabled {
    cursor: default;
    opacity: 0.72;
}

.ad-dismiss:focus-visible,
.ad-skip:focus-visible {
    outline: 2px solid #20ad8c;
    outline-offset: 2px;
}

.ad-shell-banner,
.ad-shell-inline {
    width: 100%;
}

.ad-shell-sticky {
    grid-template-columns: minmax(0, 1fr) minmax(220px, 340px);
    align-items: stretch;
    margin-bottom: 0;
}

.ad-shell-sticky .ad-shell-meta {
    min-height: 0;
    padding-inline-end: 54px;
}

.ad-shell-interstitial {
    max-width: 760px;
    margin: 0 auto;
}

.ad-shell-sidebar .ad-shell-meta {
    min-height: 112px;
}

.ad-text-panel {
    display: grid;
    gap: 10px;
    min-height: 160px;
    align-content: center;
    padding: 24px;
    background: linear-gradient(135deg, #0f766e 0%, #1f2937 100%);
    color: #fff;
}

.ad-text-panel .ad-rich-text,
.ad-text-panel p {
    color: inherit;
    margin: 0;
}

/* Advertisement Zones */
.advertisement-zone {
    width: min(100%, 1120px);
    margin: 18px auto;
    padding-inline: 12px;
    min-height: 0;
}

.advertisement-zone.loading {
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Zone Types */
.zone-header {
    padding: 10px 0;
    background: #f8f9fa;
}

.zone-sidebar {
    position: sticky;
    top: 80px;
    max-height: calc(100vh - 100px);
    overflow-y: auto;
}

.zone-footer {
    padding: 20px 0;
    background: #f8f9fa;
    margin-top: 40px;
}

.zone-in-feed {
    margin: 30px 0;
}

.zone-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 9999;
    max-width: 600px;
    width: 90%;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}

.zone-sticky-bottom {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 999;
    background: white;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    padding: 10px 0;
}

/* Banner Ads */
.advertisement-banner {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
}

.advertisement-banner img {
    width: 100%;
    height: auto;
    display: block;
}

.advertisement .ad-media-link {
    display: block;
    color: inherit;
    text-decoration: none;
}

.advertisement .ad-media-frame {
    position: relative;
    width: 100%;
    height: clamp(140px, 26vw, 320px);
    background: #f8fafc;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    overflow: hidden;
}

.ad-shell .ad-media-frame {
    border: 0;
    border-radius: 0;
}

.advertisement-zone[data-ad-zone*="header"] .ad-media-frame,
.advertisement-zone[data-ad-zone="global_header"] .ad-media-frame {
    height: clamp(120px, 22vw, 260px);
}

.advertisement-zone[data-ad-zone*="sidebar"] .ad-media-frame {
    height: clamp(180px, 34vw, 300px);
}

.advertisement-zone[data-ad-zone="sticky_bottom"] {
    margin-block: 10px;
}

.advertisement-zone[data-ad-zone="sticky_bottom"] .ad-media-frame {
    height: clamp(86px, 14vw, 140px);
}

.role-sidebar-ad,
.shipping-sidebar-ad {
    border-top: 1px solid rgba(148, 163, 184, 0.22);
    margin-top: 14px;
    padding: 12px;
}

.role-sidebar-ad .advertisement-zone,
.shipping-sidebar-ad .advertisement-zone {
    width: 100%;
    margin: 0;
    padding-inline: 0;
}

.role-sidebar-ad .ad-shell,
.shipping-sidebar-ad .ad-shell {
    border-radius: 8px;
}

.role-sidebar-ad .ad-shell-meta,
.shipping-sidebar-ad .ad-shell-meta {
    min-height: 0;
    padding: 10px;
}

.role-sidebar-ad .ad-shell-title,
.shipping-sidebar-ad .ad-shell-title {
    font-size: 13px;
}

.role-sidebar-ad .ad-shell-description,
.shipping-sidebar-ad .ad-shell-description {
    font-size: 12px;
}

.role-sidebar-ad .ad-media-frame,
.shipping-sidebar-ad .ad-media-frame,
.advertisement-zone[data-ad-zone$="_dashboard_sidebar"] .ad-media-frame {
    height: clamp(120px, 18vw, 190px);
}

.advertisement-zone[data-ad-zone="popup_modal"] .ad-media-frame,
.ad-shell-interstitial .ad-media-frame {
    height: clamp(240px, 52vw, 430px);
}

.advertisement .ad-media-frame .ad-image {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
    opacity: 0;
    transition: opacity 0.45s ease;
}

.advertisement .ad-media-frame .ad-image.is-active {
    opacity: 1;
    z-index: 1;
}

.advertisement .ad-slide-dots {
    position: absolute;
    left: 50%;
    bottom: 10px;
    z-index: 2;
    display: flex;
    gap: 6px;
    transform: translateX(-50%);
}

.advertisement .ad-slide-dot {
    width: 7px;
    height: 7px;
    border-radius: 999px;
    background: rgba(17, 24, 39, 0.28);
    box-shadow: 0 1px 2px rgba(255, 255, 255, 0.6);
}

.advertisement .ad-slide-dot.is-active {
    width: 18px;
    background: #20ad8c;
}

.advertisement-banner .ad-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);
    padding: 20px;
    color: white;
}

.advertisement-banner .ad-title {
    margin: 0 0 10px 0;
    font-size: 20px;
    font-weight: bold;
}

.advertisement-banner .btn {
    margin-top: 10px;
}

/* Text Ads */
.advertisement-text {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 8px;
    padding: 25px;
    color: white;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.advertisement-text .ad-text-title {
    margin: 0 0 15px 0;
    font-size: 22px;
    font-weight: bold;
}

.advertisement-text .ad-text-description {
    margin-bottom: 15px;
    opacity: 0.95;
    line-height: 1.6;
}

.advertisement-text .ad-text-cta {
    background: rgba(255,255,255,0.2);
    border: 2px solid rgba(255,255,255,0.3);
    color: white;
    padding: 10px 20px;
    border-radius: 6px;
    text-decoration: none;
    display: inline-block;
    transition: all 0.3s;
}

.advertisement-text .ad-text-cta:hover {
    background: white;
    color: #667eea;
    transform: translateY(-2px);
}

/* Video Ads */
.advertisement-video {
    border-radius: 8px;
    overflow: hidden;
    background: #000;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.advertisement-video .video-wrapper {
    position: relative;
    padding-bottom: 56.25%; /* 16:9 aspect ratio */
    height: 0;
    overflow: hidden;
}

.advertisement-video .ad-video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.advertisement-video .video-ad-footer {
    padding: 20px;
    background: #f8f9fa;
}

.advertisement-video .ad-title {
    margin: 0 0 10px 0;
    font-size: 18px;
    color: #333;
}

.advertisement .video-caption-overlay {
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: 18px;
    color: #fff;
    background: rgba(0,0,0,0.55);
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 13px;
    line-height: 1.6;
}

.advertisement .ad-video-meta {
    margin-top: 12px;
    font-size: 13px;
    color: #6b7280;
    font-weight: 600;
}

.advertisement .ad-rich-text {
    line-height: 1.7;
    color: #374151;
}

.advertisement .ad-rich-text p:last-child {
    margin-bottom: 0;
}

/* Carousel Ads */
.advertisement-carousel {
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.advertisement-carousel .carousel-item img {
    border-radius: 8px;
    width: 100%;
    height: auto;
}

.advertisement-carousel .carousel-caption {
    background: rgba(0,0,0,0.6);
    padding: 15px;
    border-radius: 6px;
    backdrop-filter: blur(5px);
}

.advertisement-carousel .carousel-control-prev,
.advertisement-carousel .carousel-control-next {
    width: 5%;
}

/* Ad Close Button */
.ad-close {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0,0,0,0.5);
    color: white;
    border: none;
    border-radius: 50%;
    width: 35px;
    height: 35px;
    cursor: pointer;
    z-index: 10;
    font-size: 20px;
    transition: all 0.3s;
}

.ad-close:hover {
    background: rgba(0,0,0,0.8);
    transform: rotate(90deg);
}

/* Loading State */
.advertisement-zone .spinner-border {
    margin: 20px auto;
    display: block;
}

.advertisement-zone.loading::after {
    content: 'جاري تحميل الإعلانات...';
    display: block;
    text-align: center;
    color: #999;
    font-size: 14px;
    margin-top: 10px;
}

/* Responsive */
@media (max-width: 768px) {
    .zone-sidebar {
        position: relative;
        top: auto;
        max-height: none;
    }

    .advertisement-text {
        padding: 15px;
    }

    .advertisement-banner .ad-overlay {
        padding: 15px;
    }

    .ad-close {
        width: 30px;
        height: 30px;
        font-size: 18px;
    }

    .ad-shell-sticky {
        grid-template-columns: 1fr;
    }

    .ad-shell-meta {
        min-height: 88px;
        padding: 10px 12px 12px;
    }

    .ad-shell-title {
        font-size: 14px;
    }

    .ad-shell-description {
        font-size: 12px;
    }

    .ad-shell-controls {
        inset-block-start: 8px;
        inset-inline-end: 8px;
    }
}

/* Admin Specific Styles */
.admin-ad-preview {
    border: 2px dashed #ddd;
    padding: 20px;
    border-radius: 8px;
    background: #f8f9fa;
}

.admin-ad-preview .preview-label {
    position: absolute;
    top: 10px;
    left: 10px;
    background: #ffc107;
    color: #000;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: bold;
}

/* Zone Management */
.zone-card {
    border: 2px solid #e9ecef;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 15px;
    transition: all 0.3s;
}

.zone-card:hover {
    border-color: #6777ef;
    box-shadow: 0 4px 10px rgba(103, 119, 239, 0.1);
}

.zone-card.active {
    border-color: #28a745;
    background: #f0f9f4;
}

.zone-card.inactive {
    border-color: #dc3545;
    background: #fff5f5;
    opacity: 0.7;
}

/* Analytics Charts */
.analytics-chart-container {
    position: relative;
    height: 300px;
    margin: 20px 0;
}

.analytics-stat-card {
    text-align: center;
    padding: 20px;
    border-radius: 8px;
    background: white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.analytics-stat-card h3 {
    margin: 0;
    font-size: 32px;
    font-weight: bold;
}

.analytics-stat-card p {
    margin: 10px 0 0 0;
    color: #666;
    font-size: 14px;
}

/* Budget Progress Bar */
.budget-progress {
    height: 25px;
    border-radius: 12px;
    overflow: hidden;
    background: #e9ecef;
    position: relative;
}

.budget-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #28a745, #20c997);
    transition: width 0.5s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 12px;
}

.budget-progress-bar.warning {
    background: linear-gradient(90deg, #ffc107, #fd7e14);
}

.budget-progress-bar.danger {
    background: linear-gradient(90deg, #dc3545, #c82333);
}

/* Status Badges */
.status-badge {
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
}

.status-badge.active {
    background: #d4edda;
    color: #155724;
}

.status-badge.pending {
    background: #fff3cd;
    color: #856404;
}

.status-badge.paused {
    background: #d1ecf1;
    color: #0c5460;
}

.status-badge.rejected {
    background: #f8d7da;
    color: #721c24;
}

/* Media Upload Preview */
.media-preview {
    position: relative;
    display: inline-block;
    margin: 10px;
}

.media-preview img,
.media-preview video {
    max-width: 200px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.media-preview .remove-media {
    position: absolute;
    top: 5px;
    right: 5px;
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 50%;
    width: 25px;
    height: 25px;
    cursor: pointer;
}

/* Targeting Selector */
.targeting-option {
    padding: 15px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: all 0.3s;
}

.targeting-option:hover {
    border-color: #6777ef;
    background: #f8f9ff;
}

.targeting-option.selected {
    border-color: #28a745;
    background: #f0f9f4;
}

/* Print Styles */
@media print {
    .advertisement,
    .advertisement-zone {
        display: none !important;
    }
}

/* Accessibility */
.advertisement:focus-within {
    outline: 2px solid #6777ef;
    outline-offset: 2px;
}

.ad-link:focus {
    outline: 2px solid #ffc107;
    outline-offset: 2px;
}

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

.advertisement {
    animation: fadeInUp 0.5s ease;
}

/* Advertisement Badge */
.ad-badge {
    position: absolute;
    top: 10px;
    left: 10px;
    background: rgba(0,0,0,0.6);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 10px;
    text-transform: uppercase;
}

/* Responsive Grid for Ads */
.ads-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
    margin: 20px 0;
}

@media (max-width: 768px) {
    .ads-grid {
        grid-template-columns: 1fr;
    }
}
