/* لوحة الإدارة — تصميم خاص */

/* إصلاح: ضمان عمل خاصية hidden لكل العناصر */
[hidden] { display: none !important; }

.admin-header-actions { display: flex; gap: .5rem; align-items: center; margin-inline-start: auto; }

.admin-login { min-height: calc(100vh - var(--header-height) - 100px); display: grid; place-items: center; padding: 3rem 1rem; }
.login-card { width: 100%; max-width: 420px; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 2.5rem 2rem; box-shadow: var(--shadow-lg); text-align: center; animation: fadeUp .5s var(--transition-slow); }
.login-icon { display: inline-grid; place-items: center; width: 64px; height: 64px; border-radius: 50%; background: var(--grad-hero); color: #fff; font-size: 2rem; margin-bottom: 1rem; box-shadow: 0 8px 20px rgba(13,148,136,.3); }
.login-card h1 { margin: 0 0 .5rem; font-family: 'Amiri', 'Cairo', serif; font-size: 1.6rem; }
.login-card > p { color: var(--text-muted); margin: 0 0 1.5rem; font-size: .95rem; }
.login-error { color: var(--rose); background: rgba(244,63,94,.1); border: 1px solid rgba(244,63,94,.3); padding: .65rem 1rem; border-radius: var(--radius-sm); margin: 0 0 1rem; font-size: .9rem; }
.login-hint { margin-top: 1.5rem; font-size: .8rem; color: var(--text-soft); }
.login-hint code { background: var(--bg-subtle); padding: .1rem .4rem; border-radius: 4px; font-size: .85em; }

.field { display: flex; flex-direction: column; gap: .35rem; margin-bottom: 1rem; }
.field label { font-size: .9rem; font-weight: 600; color: var(--text); }
.field input[type="text"], .field input[type="number"], .field input[type="password"], .field input[type="url"], .field input[type="search"], .field textarea, .field select {
    width: 100%; padding: .7rem 1rem; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
    background: var(--bg); color: var(--text); font-family: inherit; font-size: .95rem; transition: all var(--transition);
}
.field input:focus, .field textarea:focus, .field select:focus { outline: 0; border-color: var(--primary); background: var(--bg-elevated); box-shadow: 0 0 0 3px var(--primary-soft); }
.field textarea { resize: vertical; min-height: 80px; font-family: inherit; line-height: 1.7; }
.field-hint { color: var(--text-muted); font-size: .8rem; margin: .15rem 0; }
.field-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
.field-full { grid-column: 1 / -1; }
.checkbox { display: inline-flex; align-items: center; gap: .55rem; cursor: pointer; user-select: none; font-weight: 600; color: var(--text); padding: .65rem 1rem; background: var(--bg-subtle); border-radius: var(--radius-sm); border: 1.5px solid var(--border); }
.checkbox input { width: 18px; height: 18px; accent-color: var(--primary); }
.btn-full { width: 100%; }

.admin-dashboard { padding: 2rem 1.25rem 4rem; }
.admin-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.admin-stat-card { display: flex; align-items: center; gap: 1rem; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; transition: all var(--transition); }
.admin-stat-card:hover { border-color: var(--primary); box-shadow: var(--shadow-md); transform: translateY(-2px); }
.admin-stat-card .stat-icon { width: 48px; height: 48px; display: grid; place-items: center; background: var(--primary-soft); border-radius: 12px; font-size: 1.5rem; }
.admin-stat-card b { display: block; font-size: 1.5rem; font-weight: 800; color: var(--text); }
.admin-stat-card span { color: var(--text-muted); font-size: .85rem; }

.admin-toolbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.admin-toolbar h2 { margin: 0 0 .15rem; }
.toolbar-actions { display: flex; gap: .65rem; flex-wrap: wrap; }
.admin-search { padding: .65rem 1rem; border: 1.5px solid var(--border); border-radius: var(--radius-full); background: var(--bg-elevated); color: var(--text); font-family: inherit; font-size: .9rem; min-width: 240px; }
.admin-search:focus { outline: 0; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

.admin-notice { background: var(--accent-soft); border: 1px solid var(--accent); border-radius: var(--radius); padding: 1rem 1.25rem; margin-bottom: 1.5rem; color: var(--text); font-size: .9rem; }
.admin-notice code { background: var(--bg-elevated); padding: .1rem .35rem; border-radius: 4px; font-size: .85em; }
.admin-notice a { color: var(--primary); font-weight: 700; margin-inline-start: .35rem; }

.admin-books-table { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; overflow-x: auto; }
.admin-books-table table { width: 100%; border-collapse: collapse; min-width: 720px; }
.admin-books-table th, .admin-books-table td { text-align: start; padding: .85rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.admin-books-table th { background: var(--bg-subtle); font-size: .85rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.admin-books-table tbody tr { transition: background var(--transition); }
.admin-books-table tbody tr:hover { background: var(--bg-subtle); }
.admin-books-table .row-cover { width: 40px; height: 56px; object-fit: cover; border-radius: 6px; background: var(--bg-subtle); }
.admin-books-table .row-actions { display: flex; gap: .35rem; }
.btn-icon { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text-muted); cursor: pointer; transition: all var(--transition); }
.btn-icon:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.btn-icon.danger:hover { border-color: var(--rose); color: var(--rose); background: rgba(244,63,94,.1); }
.row-stats { font-size: .85rem; color: var(--text-muted); display: flex; gap: .85rem; }

.admin-modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 1rem; animation: fadeIn .2s; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.admin-modal-backdrop { position: absolute; inset: 0; background: rgba(15,23,42,.6); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.admin-modal-card { position: relative; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-lg); width: 100%; max-width: 800px; max-height: 90vh; display: flex; flex-direction: column; box-shadow: var(--shadow-xl); animation: fadeUp .3s var(--transition-slow); overflow: hidden; }
.admin-modal-head { display: flex; align-items: center; justify-content: space-between; padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border); }
.admin-modal-head h2 { margin: 0; font-size: 1.2rem; }
.modal-close { width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text-muted); font-size: 1.1rem; transition: all var(--transition); }
.modal-close:hover { color: var(--rose); border-color: var(--rose); }
.admin-modal-body { flex: 1; overflow-y: auto; padding: 1.5rem; }
.admin-modal-foot { display: flex; align-items: center; gap: .5rem; padding: 1rem 1.5rem; border-top: 1px solid var(--border); background: var(--bg-subtle); }
.modal-foot-spacer { flex: 1; }

.admin-stepper { list-style: none; display: flex; gap: .5rem; margin: 0 0 2rem; padding: 0; counter-reset: step; }
.step { flex: 1; display: flex; align-items: center; gap: .5rem; padding: .7rem 1rem; border: 1.5px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-subtle); color: var(--text-muted); font-size: .9rem; font-weight: 600; transition: all var(--transition); }
.step.active { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-hover); }
.step span { width: 22px; height: 22px; border-radius: 50%; background: var(--text-soft); color: #fff; display: grid; place-items: center; font-size: .8rem; font-weight: 800; flex-shrink: 0; }
.step.active span { background: var(--primary); }
.step-panel { display: none; animation: fadeUp .3s var(--transition-slow); }
.step-panel.active { display: block; }

.upload-zone { position: relative; border: 2px dashed var(--border-strong); border-radius: var(--radius); padding: 2rem 1rem; text-align: center; cursor: pointer; transition: all var(--transition); background: var(--bg-subtle); overflow: hidden; }
.upload-zone:hover, .upload-zone.dragover { border-color: var(--primary); background: var(--primary-soft); }
.upload-zone img { max-width: 200px; max-height: 280px; margin: 0 auto; border-radius: var(--radius-sm); box-shadow: var(--shadow-md); }
.upload-placeholder { color: var(--text-muted); }
.upload-icon { display: block; font-size: 2.5rem; margin-bottom: .5rem; }
.upload-placeholder p { margin: .35rem 0; color: var(--text); }
.upload-placeholder small { color: var(--text-soft); }

.upload-tabs { display: flex; gap: .35rem; margin-bottom: .75rem; background: var(--bg-subtle); padding: .3rem; border-radius: var(--radius-sm); }
.tab-btn { flex: 1; padding: .55rem .75rem; background: transparent; border: 0; border-radius: calc(var(--radius-sm) - 2px); color: var(--text-muted); font-family: inherit; font-size: .9rem; font-weight: 600; transition: all var(--transition); }
.tab-btn.active { background: var(--bg-elevated); color: var(--primary); box-shadow: var(--shadow-sm); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ===== AI Magic Buttons (Pollinations.ai) ===== */
.btn-ai {
    display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
    padding: .7rem 1.25rem;
    margin-top: .65rem;
    border: 0; border-radius: var(--radius-sm);
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #a855f7 100%);
    color: #fff; font-family: inherit; font-weight: 700; font-size: .9rem;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(139, 92, 246, .35);
    transition: transform .15s, box-shadow .15s, opacity .2s;
    position: relative; overflow: hidden;
}
.btn-ai:hover { transform: translateY(-1px); box-shadow: 0 8px 22px rgba(139, 92, 246, .5); }
.btn-ai:active { transform: translateY(0); }
.btn-ai:disabled { opacity: .65; cursor: wait; background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%); box-shadow: none; transform: none; }
.btn-ai::before {
    content: '';
    position: absolute; inset: 0;
    background: linear-gradient(105deg, transparent 30%, rgba(255,255,255,.25) 50%, transparent 70%);
    transform: translateX(-100%); transition: transform .6s;
}
.btn-ai:hover::before { transform: translateX(100%); }
.ai-icon { font-size: 1.1em; }
.ai-buttons-row { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .65rem; }
.ai-buttons-row .btn-ai { margin-top: 0; flex: 1; min-width: 200px; }

.docx-preview-wrap { margin-top: 1rem; animation: fadeUp .4s; }
.docx-preview.book-preview { background: #fefdf7; color: #1f2937; border: 1px solid var(--border); border-radius: var(--radius); padding: 2.5rem 3rem; max-height: 500px; overflow-y: auto; line-height: 1.85; font-family: 'Amiri', 'Cairo', serif; font-size: 1.05rem; box-shadow: inset 0 0 30px rgba(0,0,0,.04); text-align: justify; }
[data-theme="dark"] .docx-preview.book-preview { background: #1f2937; color: #f1f5f9; }
.docx-preview h1, .docx-preview h2, .docx-preview h3 { color: var(--primary-hover); margin: 1.25rem 0 .5rem; font-family: 'Amiri', serif; }
[data-theme="dark"] .docx-preview h1, [data-theme="dark"] .docx-preview h2, [data-theme="dark"] .docx-preview h3 { color: var(--primary); }
.docx-preview p { margin: .85rem 0; text-indent: 1.5rem; }
.docx-preview img { max-width: 100%; height: auto; margin: 1rem 0; border-radius: 8px; }
.preview-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 1rem; }

.toast-container { position: fixed; top: 80px; inset-inline-end: 1rem; z-index: 200; display: flex; flex-direction: column; gap: .5rem; pointer-events: none; }
.toast { background: var(--bg-elevated); border: 1px solid var(--border); border-inline-start: 4px solid var(--primary); border-radius: var(--radius-sm); padding: .85rem 1.25rem; box-shadow: var(--shadow-lg); min-width: 240px; max-width: 380px; font-size: .9rem; color: var(--text); pointer-events: auto; animation: toastIn .3s, toastOut .3s 3s forwards; }
.toast.success { border-inline-start-color: var(--primary); }
.toast.error { border-inline-start-color: var(--rose); }
.toast.warning { border-inline-start-color: var(--accent); }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateX(20px); } }

@media (max-width: 700px) {
    .admin-dashboard { padding: 1rem .75rem 3rem; }
    .admin-toolbar { align-items: stretch; }
    .toolbar-actions { flex-direction: column; }
    .admin-search { min-width: 0; }
    .field-grid { grid-template-columns: 1fr; }
    .admin-modal-card { max-height: 95vh; }
    .admin-modal-body { padding: 1rem; }
    .admin-modal-foot { padding: .85rem 1rem; flex-wrap: wrap; }
    .admin-stepper { flex-direction: column; gap: .35rem; margin-bottom: 1.25rem; }
    .step { padding: .55rem .85rem; font-size: .85rem; }
    .docx-preview.book-preview { padding: 1.5rem 1.25rem; font-size: .95rem; }
    .login-card { padding: 2rem 1.5rem; }
    .ai-buttons-row .btn-ai { min-width: 100%; }
}
