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

:root {
    --primary: #0066cc;
    --primary-dark: #004d99;
    --primary-light: #e6f0ff;
    --secondary: #475569;
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

/* Login */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0066cc 0%, #004d99 100%);
    padding: 16px;
}

.login-box {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-header h1 {
    font-size: 28px;
    color: var(--primary);
    margin-bottom: 4px;
}

.login-header p {
    color: var(--text-muted);
    font-size: 14px;
}

/* Form */
.form-group {
    margin-bottom: 16px;
    flex: 1;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--secondary);
    margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.form-group input[type="color"] {
    height: 42px;
    padding: 4px;
    cursor: pointer;
}

.form-row {
    display: flex;
    gap: 16px;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 14px;
}

.checkbox-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

/* Image Upload */
.image-upload-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.image-upload-row .image-url-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
}

.image-upload-row .image-url-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.btn-upload {
    cursor: pointer;
    white-space: nowrap;
}

.image-preview {
    margin-top: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    max-width: 300px;
}

.image-preview img {
    width: 100%;
    height: auto;
    display: block;
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn-secondary { background: var(--bg); color: var(--secondary); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-outline { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,0.5); }
.btn-outline:hover { background: rgba(255,255,255,0.1); }
.btn-full { width: 100%; justify-content: center; }
.btn-small { padding: 6px 12px; font-size: 12px; }
.btn-danger { background: var(--error); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-success { background: var(--success); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }

/* Header */
.header {
    background: linear-gradient(135deg, #0066cc 0%, #004d99 100%);
    color: #fff;
    padding: 20px 0;
    box-shadow: var(--shadow);
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-content h1 { font-size: 22px; }

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

.badge {
    background: rgba(255,255,255,0.2);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 13px;
}

/* Main Content */
.main-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Cards */
.card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 24px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.card h2 { font-size: 18px; margin-bottom: 16px; color: var(--text); }

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 12px;
}

.card-header h2 { margin-bottom: 0; }

.filter-group { display: flex; gap: 8px; }
.filter-group select {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
}

/* Ads List */
.ads-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Gallery Section */
.gallery-section { padding-bottom: 24px; }

.gallery-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.gallery-toolbar {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
    padding: 16px;
    background: var(--bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.search-box {
    flex: 1;
    min-width: 200px;
}

.search-box input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    background: var(--card-bg);
    transition: border-color 0.2s;
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1);
}

.gallery-results-info {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 16px;
    padding: 0 4px;
}

/* Gallery Groups */
.gallery-group {
    margin-bottom: 24px;
}

.gallery-group-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    border-radius: 8px;
    margin-bottom: 12px;
}

.gallery-group-header.active-header {
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
}

.gallery-group-header.stopped-header {
    background: #fef2f2;
    border: 1px solid #fecaca;
}

.gallery-group-header h3 {
    font-size: 14px;
    font-weight: 700;
    flex: 1;
}

.group-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.group-dot.active { background: var(--success); }
.group-dot.stopped { background: var(--error); }

.group-count {
    font-size: 12px;
    font-weight: 700;
    background: rgba(0,0,0,0.06);
    padding: 3px 10px;
    border-radius: 12px;
}

/* Gallery Grid */
.ads-gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 14px;
}

.ad-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    transition: box-shadow 0.2s, transform 0.15s;
}

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

.ad-card.stopped-card {
    opacity: 0.75;
    border-color: #fecaca;
}

.ad-card-thumb {
    width: 100%;
    height: 80px;
    background: var(--primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.ad-card-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ad-card-thumb .slot-label {
    font-size: 12px;
    font-weight: 700;
    color: var(--primary);
}

.ad-card-status-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    font-size: 10px;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 10px;
    color: #fff;
}

.ad-card-status-badge.active { background: var(--success); }
.ad-card-status-badge.stopped { background: var(--error); }
.ad-card-status-badge.expired { background: #6b7280; }
.ad-card-status-badge.limit { background: var(--warning); }

.ad-card-body {
    padding: 12px 14px;
}

.ad-card-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ad-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}

.ad-card-meta-item {
    font-size: 11px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 3px;
    background: var(--bg);
    padding: 3px 8px;
    border-radius: 10px;
}

.ad-card-stop-reason {
    font-size: 11px;
    color: var(--error);
    background: #fef2f2;
    padding: 5px 10px;
    border-radius: 6px;
    margin-bottom: 10px;
    font-weight: 600;
}

.ad-card-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

.ad-card-actions .btn { font-size: 11px; padding: 5px 10px; }

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 16px 0;
}

.pagination .page-btn {
    min-width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    background: var(--card-bg);
    color: var(--text);
    transition: all 0.15s;
}

.pagination .page-btn:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}

.pagination .page-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.pagination .page-btn.disabled {
    opacity: 0.4;
    cursor: default;
    pointer-events: none;
}

.ad-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    background: var(--bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    transition: box-shadow 0.2s;
}

.ad-item:hover { box-shadow: var(--shadow); }
.ad-item.expired { opacity: 0.6; border-color: var(--error); }

.ad-item-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.ad-item-thumb {
    width: 60px;
    height: 48px;
    border-radius: 6px;
    background: var(--primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    color: var(--primary);
    flex-shrink: 0;
    overflow: hidden;
    text-align: center;
}

.ad-item-thumb img { width: 100%; height: 100%; object-fit: cover; }

.ad-item-details h3 {
    font-size: 15px;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ad-item-meta {
    display: flex;
    gap: 10px;
    font-size: 12px;
    color: var(--text-muted);
    flex-wrap: wrap;
}

.ad-item-meta span { display: flex; align-items: center; gap: 4px; }

.ad-item-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.status-dot.active { background: var(--success); }
.status-dot.inactive { background: var(--error); }
.status-dot.expired { background: #999; }

.empty-state {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
    font-size: 14px;
}

/* Code Block */
.code-block {
    background: #1e293b;
    color: #e2e8f0;
    padding: 12px 16px;
    border-radius: var(--radius);
    font-family: 'Courier New', monospace;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.code-block code { flex: 1; word-break: break-all; }

.btn-copy {
    background: rgba(255,255,255,0.1);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.2);
    flex-shrink: 0;
}

.btn-copy:hover { background: rgba(255,255,255,0.2); }

.embed-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
}

.embed-item h4 { font-size: 13px; color: var(--secondary); margin-bottom: 8px; }

.hint { font-size: 13px; color: var(--text-muted); margin-bottom: 12px; }
.error-msg { color: var(--error); font-size: 13px; margin-top: 12px; text-align: center; }
.form-actions { display: flex; gap: 12px; margin-top: 8px; }

/* Brands Section */
.brands-section {
    margin-bottom: 16px;
    padding: 16px;
    background: var(--bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.brands-section > label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--secondary);
    margin-bottom: 4px;
}

.brand-row {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
    align-items: center;
}

.brand-row input {
    flex: 1;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
}

.brand-row input:focus { outline: none; border-color: var(--primary); }
.brand-row button {
    padding: 6px 10px;
    background: var(--error);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
}

.brands-dimensions {
    background: var(--primary-light);
    border: 1px solid #b3d4ff;
    border-radius: 6px;
    padding: 10px 14px;
    margin-bottom: 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    color: var(--primary-dark);
}

.brands-dimensions strong {
    color: var(--primary);
}

.brands-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 8px;
}

.brands-counter {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 600;
}

/* Live Preview */
.preview-section {
    margin-top: 24px;
    padding-top: 24px;
    border-top: 2px solid var(--border);
}

.preview-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 6px;
}

.preview-container {
    background: #f0f2f5;
    border-radius: 10px;
    padding: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 120px;
    border: 1px dashed var(--border);
}

.ad-preview-box {
    transition: all 0.2s ease;
    max-width: 100%;
}

.ad-preview-box:empty::before {
    content: 'ابدأ بملء الحقول لمشاهدة المعاينة';
    color: #aaa;
    font-size: 14px;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #1e293b;
    color: #fff;
    padding: 12px 24px;
    border-radius: var(--radius);
    font-size: 14px;
    z-index: 9999;
    transition: transform 0.3s ease;
    box-shadow: var(--shadow-lg);
}

.toast.show { transform: translateX(-50%) translateY(0); }
.toast.success { background: var(--success); }
.toast.error { background: var(--error); }

/* Tabs */
.tabs-nav {
    max-width: 1200px;
    margin: 0 auto;
    padding: 12px 24px 0;
    display: flex;
    gap: 4px;
}

.tab-btn {
    padding: 10px 24px;
    background: rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.7);
    border: none;
    border-radius: 8px 8px 0 0;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.tab-btn:hover { background: rgba(255,255,255,0.15); color: #fff; }
.tab-btn.active { background: var(--bg); color: var(--primary); }

.tab-content { display: none; flex-direction: column; gap: 24px; }
.tab-content.active { display: flex; }

/* Statistics */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

.stat-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 20px;
    text-align: center;
    transition: box-shadow 0.2s;
}

.stat-card:hover { box-shadow: var(--shadow); }

.stat-number {
    display: block;
    font-size: 28px;
    font-weight: 800;
    color: var(--primary);
    margin-bottom: 4px;
}

.stat-label {
    display: block;
    font-size: 13px;
    color: var(--text-muted);
}

/* Domains List */
.domains-list { margin-top: 12px; }

.domain-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
}

.domain-item:hover { background: var(--bg); }
.domain-item:last-child { border-bottom: none; }

.domain-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    direction: ltr;
    text-align: left;
}

.domain-count {
    font-size: 13px;
    color: var(--text-muted);
    background: var(--bg);
    padding: 4px 12px;
    border-radius: 12px;
    font-weight: 600;
}

/* Ads Stats List */
.ads-stats-list { display: flex; flex-direction: column; gap: 12px; }

.ad-stat-item {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
    transition: box-shadow 0.2s;
}

.ad-stat-item:hover { box-shadow: var(--shadow); }

.ad-stat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    flex-wrap: wrap;
    gap: 8px;
}

.ad-stat-header h3 { font-size: 15px; color: var(--text); }
.ad-stat-header .slot-badge {
    font-size: 11px;
    background: var(--primary-light);
    color: var(--primary);
    padding: 3px 10px;
    border-radius: 12px;
    font-weight: 600;
}

.ad-stat-numbers {
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.ad-stat-num {
    text-align: center;
}

.ad-stat-num .num {
    display: block;
    font-size: 20px;
    font-weight: 700;
    color: var(--primary);
}

.ad-stat-num .lbl {
    font-size: 11px;
    color: var(--text-muted);
}

.ad-stat-domains {
    border-top: 1px solid var(--border);
    padding-top: 10px;
}

.ad-stat-domains h4 {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.ad-stat-domains-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.domain-tag {
    font-size: 11px;
    background: #fff;
    border: 1px solid var(--border);
    padding: 3px 10px;
    border-radius: 12px;
    color: var(--secondary);
    direction: ltr;
}

.ad-stat-actions {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

/* Progress Bar */
.ctr-bar {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 8px;
}

.ctr-bar-fill {
    height: 100%;
    background: var(--success);
    border-radius: 3px;
    transition: width 0.3s;
}

/* Responsive */
@media (max-width: 768px) {
    .form-row { flex-direction: column; gap: 0; }
    .header-content { flex-direction: column; gap: 12px; text-align: center; }
    .ad-item { flex-direction: column; align-items: flex-start; gap: 12px; }
    .ad-item-actions { width: 100%; justify-content: flex-end; }
    .card-header { flex-direction: column; align-items: flex-start; }
    .embed-grid { grid-template-columns: 1fr; }
    .image-upload-row { flex-wrap: wrap; }
    .tabs-nav { padding: 12px 16px 0; }
    .tab-btn { padding: 8px 16px; font-size: 13px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .ad-stat-numbers { gap: 16px; }
    .gallery-toolbar { flex-direction: column; }
    .ads-gallery-grid { grid-template-columns: 1fr; }
    .ad-card-actions { flex-wrap: wrap; }
    .filter-group { width: 100%; flex-direction: column; }
    .filter-group select { width: 100%; }
}
