/* ============================================
   بوابة متابعة أولياء الأمور
   تصميم حديث وفخم بأسلوب لوحات التحكم الاحترافية
   ============================================ */

:root {
    --primary: #7367F0;
    --primary-dark: #5A4FD8;
    --primary-light: #EDEBFE;
    --gold: #D4AF37;
    --gold-light: #FBF3DA;
    --success: #28C76F;
    --success-light: #E3FBEE;
    --danger: #EA5455;
    --danger-light: #FBE7E7;
    --warning: #FF9F43;
    --warning-light: #FFF1E3;
    --info: #00CFE8;
    --info-light: #DFFAFD;

    --bg-page: #F5F6FB;
    --bg-card: #FFFFFF;
    --text-primary: #2E263D;
    --text-secondary: #6E6B7B;
    --text-muted: #B9B6C3;
    --border-color: #EDEDF3;

    --shadow-sm: 0 2px 10px rgba(46, 38, 61, 0.06);
    --shadow-md: 0 8px 28px rgba(46, 38, 61, 0.09);
    --shadow-lg: 0 16px 44px rgba(46, 38, 61, 0.14);
    --radius-lg: 18px;
    --radius-md: 14px;
    --radius-sm: 10px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    min-height: 100vh;
    background-color: var(--bg-page);
    color: var(--text-primary);
    font-family: 'Tajawal', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    position: relative;
    display: flex;
    justify-content: center;
    padding: 40px 16px 70px;
    overflow-x: hidden;
}

/* ---------------- خلفية زخرفية ناعمة ---------------- */
.bg-decor {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
}
.orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(70px);
    opacity: 0.35;
}
.orb-1 {
    width: 420px; height: 420px;
    background: radial-gradient(circle, var(--primary) 0%, transparent 70%);
    top: -160px; right: -120px;
}
.orb-2 {
    width: 380px; height: 380px;
    background: radial-gradient(circle, var(--gold) 0%, transparent 70%);
    bottom: -140px; left: -140px;
    opacity: 0.25;
}
.orb-3 {
    width: 260px; height: 260px;
    background: radial-gradient(circle, var(--info) 0%, transparent 70%);
    top: 40%; left: 50%;
    opacity: 0.12;
}

.page {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 620px;
    display: flex;
    flex-direction: column;
    gap: 22px;
    transition: max-width 0.25s ease;
}

/* توسيع الحاوية يصير على أجهزة الديسكتوب (مؤشر دقيق + شاشة واسعة) — تدريجيًا حسب عرض الشاشة
   عشان تستغل عرض الشاشات الكبيرة بدل ما تضل بعرض ثابت وفراغ كبير على الجنبين،
   والهاتف يضل بنفس الشكل العمودي الضيّق القديم دائمًا */
@media (min-width: 900px) and (pointer: fine) {
    .page:has(#step-dashboard:not(.hidden)),
    .page.is-dashboard {
        max-width: 1180px;
    }
}
@media (min-width: 1300px) and (pointer: fine) {
    .page.is-dashboard,
    .page:has(#step-dashboard:not(.hidden)) {
        max-width: min(92vw, 1680px);
    }
}
@media (min-width: 1800px) and (pointer: fine) {
    .page.is-dashboard,
    .page:has(#step-dashboard:not(.hidden)) {
        max-width: min(88vw, 2000px);
    }
}

/* نماذج الدخول/التأكيد تبقى بعرض محدود ومتمركزة حتى لو الحاوية الخارجية واسعة */
.auth-card {
    max-width: 560px;
    width: 100%;
    margin: 0 auto;
}

/* ---------------- الترويسة ---------------- */
.portal-header {
    text-align: center;
    padding: 20px 0 4px;
}

.portal-header h1 {
    font-family: 'Cairo', 'Tajawal', sans-serif;
    font-weight: 800;
    font-size: 28px;
    margin: 0 0 6px;
    background: linear-gradient(90deg, var(--primary) 0%, #9B8CFF 50%, var(--gold) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.3px;
}
.subtitle {
    margin: 0;
    color: var(--text-secondary);
    font-size: 14.5px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.subtitle i { color: var(--gold); font-size: 12px; }

/* ---------------- البطاقات العامة ---------------- */
.card, .dashboard {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 32px 28px;
    animation: rise 0.4s cubic-bezier(0.22, 1, 0.36, 1);
    position: relative;
}
.dashboard { padding: 0; background: transparent; border: none; box-shadow: none; display: flex; flex-direction: column; gap: 20px; }

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

.hidden { display: none !important; }

/* ---------------- مؤشر الخطوات ---------------- */
.step-track {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 18px;
}
.step-dot {
    width: 26px; height: 26px;
    border-radius: 50%;
    background: var(--border-color);
    color: var(--text-muted);
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700;
    flex-shrink: 0;
    transition: all 0.25s ease;
}
.step-dot.active { background: var(--primary); color: #fff; box-shadow: 0 0 0 4px var(--primary-light); }
.step-dot.done { background: var(--success); color: #fff; }
.step-line { flex: 1; height: 3px; background: var(--border-color); border-radius: 3px; }
.step-line.done { background: var(--success); }

.step-eyebrow {
    font-size: 12.5px;
    font-weight: 700;
    color: var(--gold);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.card h2, .dashboard h2 {
    font-family: 'Cairo', 'Tajawal', sans-serif;
    font-size: 22px;
    font-weight: 700;
    margin: 0 0 8px;
    color: var(--text-primary);
}

.hint {
    color: var(--text-secondary);
    font-size: 14px;
    margin: 0 0 24px;
    line-height: 1.7;
}

/* ---------------- الحقول ---------------- */
.field-row {
    display: flex;
    gap: 10px;
}
.input-wrap {
    position: relative;
    flex: 1;
}
.input-icon {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 15px;
    pointer-events: none;
}
.field-row input {
    width: 100%;
    padding: 14px 46px 14px 16px;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-family: inherit;
    background: #FBFBFD;
    color: var(--text-primary);
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.field-row input:focus {
    outline: none;
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 4px var(--primary-light);
}
.field-row input::placeholder { color: var(--text-muted); }

.btn-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    border: none;
    color: white;
    border-radius: var(--radius-sm);
    padding: 14px 24px;
    font-size: 15px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    box-shadow: 0 6px 18px rgba(115, 103, 240, 0.35);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 10px 22px rgba(115, 103, 240, 0.42); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.btn-primary:disabled { opacity: 0.7; cursor: progress; transform: none; }

.btn {
    border-radius: var(--radius-sm);
    font-weight: 700;
    padding: 11px 20px;
    font-family: inherit;
    font-size: 14px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.btn-secondary {
    background-color: #fff;
    border-color: var(--border-color);
    color: var(--text-secondary);
}
.btn-secondary:hover { background-color: var(--danger-light); border-color: var(--danger); color: var(--danger); }

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

/* ---------------- فلتر الفترة الزمنية ---------------- */
.filter-panel { display: flex; flex-direction: column; gap: 14px; }
.filter-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.filter-chip {
    border: 1.5px solid var(--border-color);
    background: #FBFBFD;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 700;
    padding: 9px 16px;
    border-radius: 999px;
    cursor: pointer;
    transition: all 0.18s ease;
}
.filter-chip:hover { border-color: var(--primary); color: var(--primary); }
.filter-chip.active {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    border-color: transparent;
    color: #fff;
    box-shadow: 0 6px 16px rgba(115, 103, 240, 0.3);
}
.filter-presets-months {
    display: contents; /* عشان الأزرار تنضم لنفس صف flex بدون ما تضيف عنصر لفّ إضافي */
}
.filter-range {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.filter-date { flex: 1; min-width: 150px; }
.filter-date input {
    width: 100%;
    padding: 12px 44px 12px 14px;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    background: #FBFBFD;
    color: var(--text-primary);
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.filter-date input:focus {
    outline: none;
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 4px var(--primary-light);
}
.filter-range-sep { color: var(--text-muted); font-weight: 700; font-size: 13px; }
.filter-active-label {
    font-size: 13px;
    font-weight: 700;
    color: var(--primary-dark);
    background: var(--primary-light);
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    display: inline-block;
    width: fit-content;
}

@media (max-width: 640px) {
    .filter-range { flex-direction: column; align-items: stretch; }
    .filter-range-sep { display: none; }
    #filterApplyBtn { justify-content: center; }
}

.btn-link {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 4px;
    margin-top: 18px;
}
.btn-link:hover { color: var(--primary); }
.btn-link:focus-visible { outline: 2px solid var(--gold); }

.error-msg {
    color: var(--danger);
    font-size: 14px;
    font-weight: 700;
    min-height: 20px;
    margin: 14px 0 0;
}

/* ---------------- خانة الاسم المقنّع ---------------- */
.masked-name-box {
    background: linear-gradient(120deg, var(--primary-light) 0%, #F4F2FF 100%);
    border: 1px solid #E4E0FC;
    border-radius: var(--radius-sm);
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    font-size: 19px;
    font-weight: 800;
    color: var(--primary-dark);
    letter-spacing: 1.5px;
}
.masked-name-box i { color: var(--gold); font-size: 20px; }

/* ---------------- بطاقة الملف الشخصي ---------------- */
.profile-card {
    background: linear-gradient(120deg, #2A2140 0%, #382C5C 55%, #4B3B85 100%);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 26px 26px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    position: relative;
    overflow: hidden;
    animation: rise 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}
.profile-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 100% 0%, rgba(212, 175, 55, 0.25) 0%, transparent 45%),
        radial-gradient(circle at 0% 100%, rgba(115, 103, 240, 0.35) 0%, transparent 50%);
    pointer-events: none;
}
.profile-main {
    display: flex;
    align-items: center;
    gap: 16px;
    position: relative;
    z-index: 1;
    min-width: 0;
}
.avatar-ring {
    flex-shrink: 0;
    width: 62px; height: 62px;
    border-radius: 50%;
    padding: 3px;
    background: linear-gradient(135deg, var(--gold) 0%, #F6E7B4 100%);
    display: flex; align-items: center; justify-content: center;
}
.avatar {
    width: 100%; height: 100%;
    border-radius: 50%;
    background: rgba(255,255,255,0.12);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 800;
    font-size: 20px;
    backdrop-filter: blur(4px);
}
.profile-info { min-width: 0; }
.profile-info .step-eyebrow { color: var(--gold); margin-bottom: 4px; }
.profile-info h2 {
    color: #fff;
    margin: 0 0 8px;
    font-size: 20px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.group-badge {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.18);
    color: #EDEAFF;
    padding: 5px 12px;
    border-radius: 30px;
    font-size: 12.5px;
    font-weight: 700;
}
.group-badge i { color: var(--gold); }
.profile-card .btn-secondary {
    position: relative; z-index: 1;
    background: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.2);
    color: #fff;
    flex-shrink: 0;
}
.profile-card .btn-secondary:hover { background: rgba(234, 84, 85, 0.25); border-color: rgba(234, 84, 85, 0.5); color: #fff; }

/* ---------------- بطاقات إحصائية ---------------- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}
.stat-box {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 18px 14px;
    text-align: center;
    transition: box-shadow 0.2s ease, transform 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}
.stat-box:hover { box-shadow: var(--shadow-md); transform: translateY(-3px); }
.stat-icon {
    width: 40px; height: 40px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px;
}
.stat-box .num {
    font-size: 20px;
    font-weight: 800;
    color: var(--text-primary);
    display: block;
    font-family: 'Cairo', sans-serif;
}
.stat-box .label {
    font-size: 11.5px;
    color: var(--text-secondary);
    font-weight: 600;
    line-height: 1.4;
}

.icon-primary { background: var(--primary-light); color: var(--primary); }
.icon-success { background: var(--success-light); color: var(--success); }
.icon-danger { background: var(--danger-light); color: var(--danger); }
.icon-warning { background: var(--warning-light); color: var(--warning); }
.icon-info { background: var(--info-light); color: var(--info); }
.icon-gold { background: var(--gold-light); color: #B8901F; }

/* ---------------- بطاقات الرسوم البيانية / اللوحات ---------------- */
.chart-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 24px 22px;
}
.chart-title {
    font-family: 'Cairo', sans-serif;
    font-size: 16.5px;
    font-weight: 700;
    margin: 0 0 6px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 9px;
}
.chart-title i {
    color: var(--primary);
    font-size: 15px;
    width: 30px; height: 30px;
    background: var(--primary-light);
    border-radius: 9px;
    display: inline-flex; align-items: center; justify-content: center;
}
.panel-sub {
    color: var(--text-secondary);
    font-size: 13px;
    margin: 0 0 16px;
}

.chart-body { display: flex; flex-direction: column; gap: 10px; }
.chart-wrap { position: relative; height: 210px; margin-top: 8px; }
.chart-wrap-wide { height: 230px; }

.legend-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    justify-content: center;
    padding-top: 4px;
    border-top: 1px dashed var(--border-color);
    margin-top: 4px;
}
.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-secondary);
}
.legend-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }

.empty-state {
    text-align: center;
    color: var(--text-muted);
    font-size: 13.5px;
    font-weight: 600;
    padding: 26px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}
.empty-state i { font-size: 22px; opacity: 0.6; }

/* ---------------- الجداول ---------------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); }
table.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
    margin: 0;
    min-width: 420px;
}
table.table thead {
    background: linear-gradient(90deg, var(--primary-light) 0%, #F4F2FF 100%);
    color: var(--primary-dark);
}
table.table th {
    text-align: right;
    padding: 12px 12px;
    font-weight: 700;
    border: none;
    font-size: 12.5px;
    white-space: nowrap;
}
table.table th:first-child { border-radius: 8px 0 0 8px; }
table.table th:last-child { border-radius: 0 8px 8px 0; }
table.table td {
    padding: 11px 12px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
    color: var(--text-primary);
}
table.table tbody tr:hover { background-color: #FAFAFD; }
table.table tbody tr:last-child td { border-bottom: none; }
.cell-muted { color: var(--text-secondary); }
.cell-strong { font-weight: 700; }
.pill {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11.5px;
    font-weight: 700;
    background: var(--primary-light);
    color: var(--primary-dark);
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 11px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
}
.badge-done { background: var(--success-light); color: var(--success); }
.badge-pending { background: var(--warning-light); color: #B8631C; }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-muted { background: var(--bg-page); color: var(--text-muted); }

/* ---------------- خطة الحفظ ---------------- */
.plan-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 12px;
}
.plan-head .badge { font-size: 13px; padding: 6px 14px; }
.progress-track {
    width: 100%;
    height: 10px;
    background: var(--bg-page);
    border-radius: 20px;
    overflow: hidden;
    margin-bottom: 18px;
}
.progress-fill {
    height: 100%;
    border-radius: 20px;
    transition: width 0.4s ease;
}
.plan-meta-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px 10px;
}
.plan-meta-grid .meta-item .meta-label {
    font-size: 11.5px;
    color: var(--text-secondary);
    font-weight: 600;
    margin-bottom: 3px;
}
.plan-meta-grid .meta-item .meta-value {
    font-size: 14.5px;
    color: var(--text-primary);
    font-weight: 800;
    font-family: 'Cairo', sans-serif;
}
.plan-notes {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px dashed var(--border-color);
    font-size: 13px;
    color: var(--text-secondary);
}
@media (max-width: 640px) {
    .plan-meta-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ---------------- الجدول الزمني للإنجازات ---------------- */
.timeline {
    position: relative;
    padding-right: 26px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}
.timeline::before {
    content: '';
    position: absolute;
    right: 9px;
    top: 6px;
    bottom: 6px;
    width: 2px;
    background: linear-gradient(180deg, var(--primary) 0%, var(--border-color) 90%);
    border-radius: 2px;
}
.timeline-item {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.timeline-dot {
    position: absolute;
    right: -26px;
    top: 2px;
    width: 20px; height: 20px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 10px;
    color: #fff;
    box-shadow: 0 0 0 4px var(--bg-card);
}
.timeline-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}
.timeline-title { font-weight: 700; font-size: 14px; color: var(--text-primary); }
.timeline-date { font-size: 12px; color: var(--text-muted); font-weight: 600; white-space: nowrap; }
.timeline-desc { font-size: 13px; color: var(--text-secondary); line-height: 1.6; }

.achievements-panel .timeline { max-height: 420px; overflow-y: auto; padding-left: 4px; }
.achievements-panel .timeline::-webkit-scrollbar { width: 6px; }
.achievements-panel .timeline::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 4px; }

/* ---------------- التذييل ---------------- */
.portal-footer {
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    margin-top: 4px;
    font-weight: 600;
}

/* ---------------- شبكة لوحة البيانات على أجهزة الديسكتوب فقط ---------------- */
@media (min-width: 900px) and (pointer: fine) {
    .dashboard {
        display: grid;
        grid-template-columns: repeat(12, 1fr);
        gap: 22px;
        align-items: start;
    }
    .dashboard > .profile-card,
    .dashboard > .stats-grid {
        grid-column: 1 / -1;
    }
    .stats-grid { grid-template-columns: repeat(6, 1fr); }
    .span-6 { grid-column: span 6; }
    .span-12 { grid-column: 1 / -1; }
}

/* ---------------- الجوال ---------------- */
@media (max-width: 480px) {
    body { padding: 26px 12px 50px; }
    .card, .chart-card { padding: 22px 18px; }
    .profile-card { padding: 20px 18px; flex-wrap: wrap; }
    .profile-card .btn-secondary span { display: none; }
    .field-row { flex-direction: column; }
    .btn-primary { justify-content: center; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .portal-header h1 { font-size: 23px; }
    .profile-info h2 { max-width: 160px; }
}

@media (prefers-reduced-motion: reduce) {
    .card, .dashboard, .profile-card { animation: none; }
}