/* ==========================================================
   منصة التدوين والنشر الذكي بالذكاء الاصطناعي
   التصميم العصري الاحترافي (Modern Dark & Emerald Theme)
========================================================== */

:root {
    --bg-main: #0b0f17;
    --bg-secondary: #111827;
    --card-bg: #161f30;
    --card-hover: #1c273c;
    --border-color: rgba(255, 255, 255, 0.08);
    --border-focus: #10b981;
    
    --primary: #10b981;
    --primary-hover: #059669;
    --primary-glow: rgba(16, 185, 129, 0.25);
    
    --secondary: #06b6d4;
    --secondary-hover: #0891b2;
    
    --danger: #ef4444;
    --warning: #f59e0b;
    --success: #10b981;
    
    --text-main: #f3f4f6;
    --text-muted: #9ca3af;
    --text-dim: #6b7280;
    
    --font-main: 'Cairo', system-ui, -apple-system, sans-serif;
    --font-code: 'Fira Code', monospace;
    
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.45);
    
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-full: 9999px;
}

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

body {
    font-family: var(--font-main);
    background-color: var(--bg-main);
    color: var(--text-main);
    min-height: 100vh;
    direction: rtl;
    line-height: 1.6;
}

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

/* Header */
.main-header {
    background: rgba(17, 24, 39, 0.85);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 74px;
    gap: 20px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-logo {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.3rem;
    box-shadow: 0 0 20px var(--primary-glow);
}

.brand-text h1 {
    font-size: 1.15rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    line-height: 1.2;
}

.brand-text .badge {
    font-size: 0.72rem;
    background: rgba(16, 185, 129, 0.15);
    color: var(--primary);
    padding: 2px 8px;
    border-radius: var(--radius-full);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

/* Nav Tabs */
.nav-tabs {
    display: flex;
    gap: 8px;
    background: rgba(0, 0, 0, 0.25);
    padding: 5px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 18px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.92rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
}

.nav-btn:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.05);
}

.nav-btn.active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 2px 10px var(--primary-glow);
}

/* Header Actions & Badges */
.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.25);
    color: var(--primary);
    padding: 6px 14px;
    border-radius: var(--radius-full);
    font-size: 0.88rem;
    font-weight: 600;
}

.btn-logout {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.25);
    color: #f87171;
    padding: 6px 14px;
    border-radius: var(--radius-md);
    font-size: 0.88rem;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s;
}

.btn-logout:hover {
    background: #ef4444;
    color: #fff;
    box-shadow: 0 0 15px rgba(239, 68, 68, 0.35);
}

/* Main Content Area */
.main-content {
    padding-top: 30px;
    padding-bottom: 60px;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease-out;
}

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

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: 460px 1fr;
    gap: 24px;
    align-items: start;
}

.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

/* Card Component */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 26px;
    box-shadow: var(--shadow-md);
    transition: border-color 0.2s ease;
}

.card-header {
    margin-bottom: 22px;
}

.card-header h2 {
    font-size: 1.18rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
}

.card-header .subtitle {
    color: var(--text-muted);
    font-size: 0.86rem;
    margin-top: 4px;
}

.flex-between {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Forms */
.form-group {
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 7px;
    color: var(--text-main);
}

.form-group label i {
    color: var(--primary);
    margin-left: 5px;
}

.required {
    color: var(--danger);
}

.form-control {
    width: 100%;
    padding: 11px 15px;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.95rem;
    transition: all 0.2s ease;
}

.form-control:focus {
    outline: none;
    border-color: var(--border-focus);
    background: rgba(0, 0, 0, 0.4);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

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

.form-row .col {
    flex: 1;
}

.hint {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 6px;
}

/* Toggle Switch */
.form-check {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(255, 255, 255, 0.02);
    padding: 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
    flex-shrink: 0;
}

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

.slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background-color: rgba(255, 255, 255, 0.15);
    transition: .3s;
    border-radius: 34px;
}

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

input:checked + .slider {
    background-color: var(--primary);
}

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

.check-label {
    font-size: 0.88rem;
    color: var(--text-muted);
    cursor: pointer;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    padding: 10px 20px;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
    text-decoration: none;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 4px 15px var(--primary-glow);
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px var(--primary-glow);
}

.btn-secondary {
    background: #374151;
    color: #fff;
}

.btn-secondary:hover {
    background: #4b5563;
}

.btn-success {
    background: linear-gradient(135deg, #f97316, #ea580c);
    color: #fff;
    box-shadow: 0 4px 15px rgba(234, 88, 12, 0.3);
}

.btn-success:hover {
    background: linear-gradient(135deg, #ea580c, #c2410c);
    transform: translateY(-1px);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-main);
}

.btn-outline:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.2);
}

.btn-sm {
    padding: 6px 14px;
    font-size: 0.85rem;
}

.btn-lg {
    width: 100%;
    padding: 14px;
    font-size: 1.05rem;
    margin-top: 10px;
}

.btn-copy-sm {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    padding: 3px 8px;
    cursor: pointer;
    font-size: 0.82rem;
    transition: all 0.2s;
}

.btn-copy-sm:hover {
    background: var(--primary);
    color: #fff;
}

/* Preview States */
.preview-tabs {
    display: flex;
    gap: 4px;
    background: rgba(0, 0, 0, 0.3);
    padding: 3px;
    border-radius: var(--radius-sm);
}

.preview-tab {
    padding: 5px 12px;
    font-size: 0.82rem;
    font-family: inherit;
    font-weight: 600;
    color: var(--text-muted);
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.preview-tab.active {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
}

.preview-placeholder,
.preview-loading {
    text-align: center;
    padding: 70px 20px;
    background: rgba(0, 0, 0, 0.15);
    border-radius: var(--radius-md);
    border: 1px dashed var(--border-color);
}

.placeholder-icon {
    font-size: 3rem;
    color: var(--text-dim);
    margin-bottom: 14px;
}

.preview-placeholder h3,
.preview-loading h3 {
    font-size: 1.15rem;
    margin-bottom: 8px;
}

.preview-placeholder p,
.preview-loading p {
    color: var(--text-muted);
    font-size: 0.9rem;
    max-width: 400px;
    margin: 0 auto;
}

/* Spinner */
.spinner {
    width: 46px;
    height: 46px;
    border: 4px solid rgba(16, 185, 129, 0.15);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 18px;
}

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

/* Result Box */
.meta-box {
    background: rgba(0, 0, 0, 0.3);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    padding: 16px;
    margin-bottom: 18px;
}

.meta-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    font-size: 0.88rem;
}

.meta-row:last-child {
    margin-bottom: 0;
}

.meta-label {
    color: var(--text-muted);
    font-weight: 600;
    min-width: 110px;
}

.action-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.article-content-preview {
    background: #fff;
    color: #222;
    padding: 30px;
    border-radius: var(--radius-md);
    max-height: 540px;
    overflow-y: auto;
    line-height: 1.8;
}

.article-content-preview h2 {
    color: #111;
    margin: 22px 0 10px;
    font-size: 1.35rem;
    border-bottom: 2px solid #e5e7eb;
    padding-bottom: 6px;
}

.article-content-preview h3 {
    color: #2563eb;
    margin: 16px 0 8px;
    font-size: 1.15rem;
}

.article-content-preview p {
    margin-bottom: 14px;
}

.article-content-preview ul {
    margin: 10px 24px 16px;
}

.article-content-preview img {
    max-width: 100%;
    border-radius: 8px;
}

.article-html-preview textarea {
    width: 100%;
    height: 480px;
    background: #0f172a;
    color: #38bdf8;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    font-family: var(--font-code);
    font-size: 0.88rem;
    direction: ltr;
    line-height: 1.5;
    resize: vertical;
}

/* History Table */
.history-container {
    overflow-x: auto;
    margin-top: 10px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}

.data-table th,
.data-table td {
    padding: 14px 16px;
    text-align: right;
    border-bottom: 1px solid var(--border-color);
}

.data-table th {
    background: rgba(0, 0, 0, 0.2);
    color: var(--text-muted);
    font-weight: 600;
}

.data-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

.status-badge {
    padding: 4px 10px;
    border-radius: var(--radius-full);
    font-size: 0.78rem;
    font-weight: 700;
}

.status-ready {
    background: rgba(6, 182, 212, 0.15);
    color: var(--secondary);
    border: 1px solid rgba(6, 182, 212, 0.3);
}

.status-published {
    background: rgba(16, 185, 129, 0.15);
    color: var(--primary);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

/* Database Status Box */
.db-status-box {
    margin-top: 26px;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 18px;
}

.db-status-box h4 {
    font-size: 0.95rem;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--secondary);
}

.db-status-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    font-size: 0.88rem;
}

.db-status-item:last-child {
    border-bottom: none;
}

.badge-success {
    background: rgba(16, 185, 129, 0.15);
    color: var(--primary);
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: 0.8rem;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    left: 24px;
    background: #1f2937;
    color: #fff;
    padding: 14px 22px;
    border-radius: var(--radius-md);
    border-left: 4px solid var(--primary);
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    font-weight: 600;
    animation: slideIn 0.3s ease-out;
}

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

.toast.error {
    border-left-color: var(--danger);
}

.toast.success {
    border-left-color: var(--success);
}

.hidden {
    display: none !important;
}

/* Responsive */
@media (max-width: 1024px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
    .settings-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .header-container {
        height: auto;
        padding: 14px 0;
        flex-direction: column;
        gap: 12px;
    }
    .nav-tabs {
        width: 100%;
        justify-content: space-around;
    }
    .form-row {
        flex-direction: column;
        gap: 0;
    }
    .action-bar {
        flex-direction: column;
    }
    .action-bar .btn {
        width: 100%;
    }
}
