/* ==========================================================
   لوحة التحكم الملكية — الإصدار 3.2.0
   المرجع البصري: لوحة مقياس المعتمدة + الذهبي الملكي #D4AF37
========================================================== */
:root{
    --royal-gold:#D4AF37;
    --royal-gold-dark:#A67C00;
    --royal-gold-light:#F2D675;
    --royal-navy:#0b3157;
    --royal-navy-deep:#062746;
    --royal-blue-shadow:rgba(88,144,196,.18);
    --royal-line:#e5eaf0;
    --royal-soft:#f6f9fc;
    --royal-green:#0b8f73;
    --royal-red:#d74949;
    --royal-orange:#d9931f;
}

/* تثبيت الذهبي الملكي في العناصر الذهبية القائمة */
:root{
    --miqyas-sidebar-gold:var(--royal-gold) !important;
    --miqyas-sidebar-gold-hover:var(--royal-gold-light) !important;
}

/* سطح لوحة التحكم */
.royal-dashboard{
    direction:rtl;
    display:grid;
    gap:20px;
    padding-bottom:16px;
}
.royal-dashboard *{box-sizing:border-box}

.royal-summary-head{
    display:flex;
    align-items:flex-end;
    justify-content:space-between;
    gap:12px;
    padding:2px 4px 0;
}
.royal-summary-head h3{
    margin:0;
    color:var(--royal-navy);
    font-size:18px;
    font-weight:900;
}
.royal-summary-head p{
    margin:4px 0 0;
    color:#78879a;
    font-size:10.5px;
    line-height:1.8;
}
.royal-summary-year{
    color:var(--royal-gold-dark);
    font-size:11px;
    font-weight:900;
    white-space:nowrap;
}

.royal-summary-grid{
    display:grid;
    grid-template-columns:repeat(6,minmax(130px,1fr));
    gap:12px;
}

.royal-summary-card,
.royal-metric-card{
    position:relative;
    overflow:hidden;
    border:1px solid var(--royal-gold);
    background:linear-gradient(145deg,#fff 0%,#fff 70%,#fbfdff 100%);
    color:#172a43;
    border-radius:16px;
    box-shadow:
        0 12px 28px var(--royal-blue-shadow),
        0 3px 9px rgba(11,49,87,.06);
    transition:transform .18s ease,box-shadow .18s ease,border-color .18s ease;
}
.royal-summary-card:before,
.royal-metric-card:before{
    content:"";
    position:absolute;
    width:125px;
    height:125px;
    left:-55px;
    bottom:-70px;
    border-radius:50%;
    background:#dcecff;
    filter:blur(28px);
    opacity:.72;
    pointer-events:none;
}
.royal-summary-card:after,
.royal-metric-card:after{
    content:"";
    position:absolute;
    width:95px;
    height:95px;
    right:-55px;
    top:-55px;
    border-radius:50%;
    background:#fff2c6;
    filter:blur(26px);
    opacity:.65;
    pointer-events:none;
}
.royal-summary-card:hover,
.royal-metric-card:hover{
    transform:translateY(-3px);
    border-color:var(--royal-gold-dark);
    box-shadow:
        0 18px 38px rgba(84,145,201,.24),
        0 5px 13px rgba(11,49,87,.08);
}

.royal-summary-card{
    appearance:none;
    width:100%;
    min-height:128px;
    padding:14px 14px 12px;
    text-align:right;
    cursor:pointer;
}
.royal-summary-card .royal-card-top{
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:10px;
    position:relative;
    z-index:1;
}
.royal-summary-card h4{
    margin:0;
    color:var(--royal-navy);
    font-size:11px;
    font-weight:900;
}
.royal-summary-card .royal-value{
    position:relative;
    z-index:1;
    margin-top:10px;
    color:var(--royal-navy);
    font-size:22px;
    font-weight:950;
    line-height:1.15;
}
.royal-summary-card .royal-note{
    position:relative;
    z-index:1;
    min-height:16px;
    margin-top:4px;
    color:#7b899b;
    font-size:9px;
    line-height:1.6;
}
.royal-summary-card .royal-detail-link{
    position:relative;
    z-index:1;
    display:inline-flex;
    align-items:center;
    gap:4px;
    margin-top:8px;
    color:#175b9b;
    font-size:9.5px;
    font-weight:900;
}

.royal-icon{
    width:30px;
    height:30px;
    flex:0 0 auto;
    color:var(--royal-gold);
}
.royal-icon svg{
    width:100%;
    height:100%;
    display:block;
    fill:none;
    stroke:currentColor;
    stroke-width:1.8;
    stroke-linecap:round;
    stroke-linejoin:round;
}
.royal-icon.large{width:46px;height:46px}

.royal-progress{
    position:relative;
    z-index:1;
    height:5px;
    margin-top:9px;
    border-radius:999px;
    background:#e9eef3;
    overflow:hidden;
}
.royal-progress>span{
    display:block;
    height:100%;
    border-radius:inherit;
    background:linear-gradient(90deg,#0b8f83 0%,#2aa7a0 42%,var(--royal-gold-light) 77%,var(--royal-gold) 100%);
}

.royal-dashboard-section{
    display:grid;
    gap:12px;
}
.royal-section-title{
    display:grid;
    grid-template-columns:1fr auto 1fr;
    align-items:center;
    gap:10px;
    min-height:36px;
    color:var(--royal-navy);
}
.royal-section-title:before,
.royal-section-title:after{
    content:"";
    height:1px;
    background:linear-gradient(90deg,transparent,var(--royal-gold),transparent);
}
.royal-section-title>div{
    display:flex;
    align-items:center;
    justify-content:center;
    gap:8px;
    padding:3px 12px;
    border-radius:999px;
    font-weight:950;
    font-size:16px;
    white-space:nowrap;
}
.royal-section-title .royal-icon{width:25px;height:25px}

.royal-card-grid{
    display:grid;
    grid-template-columns:repeat(4,minmax(0,1fr));
    gap:16px;
}
.royal-card-grid.six{grid-template-columns:repeat(6,minmax(0,1fr));gap:12px}
.royal-card-grid.five{grid-template-columns:repeat(5,minmax(0,1fr));gap:13px}

.royal-metric-card{
    min-height:156px;
    padding:18px 18px 14px;
    display:flex;
    flex-direction:column;
    align-items:stretch;
}
.royal-card-grid.six .royal-metric-card{
    min-height:137px;
    padding:14px 13px 12px;
}
.royal-card-grid.five .royal-metric-card{
    min-height:144px;
    padding:15px 14px 12px;
}
.royal-metric-card .royal-card-main{
    position:relative;
    z-index:1;
    display:grid;
    grid-template-columns:1fr auto;
    gap:13px;
    align-items:start;
}
.royal-card-grid.six .royal-metric-card .royal-card-main,
.royal-card-grid.five .royal-metric-card .royal-card-main{
    gap:8px;
}
.royal-metric-card h4{
    margin:0;
    color:var(--royal-navy);
    font-size:14px;
    font-weight:950;
}
.royal-card-grid.six .royal-metric-card h4,
.royal-card-grid.five .royal-metric-card h4{font-size:11px}
.royal-metric-card .royal-value{
    margin-top:7px;
    color:#073d72;
    font-size:25px;
    font-weight:950;
    line-height:1.1;
}
.royal-card-grid.six .royal-metric-card .royal-value,
.royal-card-grid.five .royal-metric-card .royal-value{font-size:20px}
.royal-metric-card .royal-unit{
    margin-top:3px;
    color:#75859a;
    font-size:9px;
    font-weight:700;
}
.royal-metric-card .royal-description{
    position:relative;
    z-index:1;
    flex:1;
    margin:9px 0 0;
    color:#718097;
    font-size:9.5px;
    line-height:1.75;
}
.royal-card-grid.six .royal-metric-card .royal-description,
.royal-card-grid.five .royal-metric-card .royal-description{display:none}
.royal-metric-card .royal-detail-button{
    position:relative;
    z-index:1;
    align-self:flex-start;
    margin-top:10px;
    padding:0;
    border:0;
    background:transparent;
    color:#1768b1;
    font-size:10px;
    font-weight:950;
}
.royal-metric-card .royal-detail-button:hover{color:var(--royal-gold-dark)}

/* ==========================================================
   Popup تحليلي للكروت
========================================================== */
.modal.royal-dashboard-modal{
    background:rgba(4,25,47,.55);
    backdrop-filter:blur(3px);
}
.modal.royal-dashboard-modal .modal-box{
    width:min(1180px,96vw);
    max-height:92vh;
    border:1px solid rgba(212,175,55,.75);
    border-radius:20px;
    box-shadow:0 32px 90px rgba(6,39,70,.28),0 0 0 1px rgba(255,255,255,.65) inset;
    overflow:auto;
}
.modal.royal-dashboard-modal .modal-header{
    color:var(--royal-navy);
    background:rgba(255,255,255,.98);
    border-bottom:1px solid #e6ebf1;
    box-shadow:0 5px 14px rgba(61,112,159,.08);
}
.modal.royal-dashboard-modal .modal-header h3{
    display:flex;
    align-items:center;
    gap:9px;
    font-size:16px;
    font-weight:950;
}
.modal.royal-dashboard-modal .modal-header .royal-icon{width:27px;height:27px}
.modal.royal-dashboard-modal .modal-close{
    color:var(--royal-navy);
    background:#fff;
    border:1px solid #dfe6ed;
}
.modal.royal-dashboard-modal .modal-body{padding:16px 18px 18px;background:#fbfdff}
.modal.royal-dashboard-modal .modal-footer{
    position:sticky;
    bottom:0;
    z-index:3;
    display:flex;
    justify-content:space-between;
    gap:8px;
    padding:11px 18px;
    background:rgba(255,255,255,.97);
    border-top:1px solid #e6ebf1;
}
.royal-popup{
    display:grid;
    gap:14px;
    direction:rtl;
}
.royal-popup-note{
    margin:0;
    color:#6f8096;
    font-size:10px;
    line-height:1.8;
}
.royal-popup-kpis{
    display:grid;
    grid-template-columns:repeat(4,minmax(0,1fr));
    gap:10px;
}
.royal-popup-kpi{
    min-height:78px;
    padding:11px 12px;
    border:1px solid #e1e7ee;
    border-radius:12px;
    background:#fff;
    box-shadow:0 6px 18px rgba(71,126,178,.07);
}
.royal-popup-kpi strong{
    display:block;
    color:#063b70;
    font-size:20px;
    font-weight:950;
}
.royal-popup-kpi span{
    display:block;
    margin-top:3px;
    color:#718097;
    font-size:9.5px;
    font-weight:800;
}
.royal-popup-kpi small{
    display:block;
    margin-top:3px;
    color:#8a98aa;
    font-size:8.5px;
}
.royal-popup-filters{
    display:grid;
    grid-template-columns:repeat(4,minmax(0,1fr));
    gap:9px;
    padding:11px;
    border:1px solid #e1e7ee;
    border-radius:13px;
    background:#fff;
}
.royal-popup-filter label{
    display:block;
    margin-bottom:4px;
    color:#617389;
    font-size:8.5px;
    font-weight:900;
}
.royal-popup-filter select,
.royal-popup-filter input{
    width:100%;
    height:34px;
    padding:6px 9px;
    border:1px solid #dbe4ec;
    border-radius:8px;
    background:#fbfdff;
    color:#233950;
    font-size:9px;
    outline:none;
}
.royal-popup-filter select:focus,
.royal-popup-filter input:focus{
    border-color:var(--royal-gold);
    box-shadow:0 0 0 3px rgba(212,175,55,.12);
}
.royal-popup-section-title{
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:10px;
    color:var(--royal-navy);
    font-size:12px;
    font-weight:950;
}
.royal-popup-section-title:after{
    content:"";
    flex:1;
    height:1px;
    background:linear-gradient(90deg,var(--royal-gold),transparent);
}
.royal-popup-table-wrap{
    overflow:auto;
    border:1px solid #dfe6ed;
    border-radius:12px;
    background:#fff;
}
.royal-popup-table{
    width:100%;
    min-width:760px;
    border-collapse:collapse;
    direction:rtl;
    font-size:9px;
}
.royal-popup-table th{
    padding:9px 8px;
    text-align:right;
    color:#fff;
    background:var(--royal-navy);
    border-left:1px solid rgba(255,255,255,.12);
    font-weight:900;
    white-space:nowrap;
}
.royal-popup-table td{
    padding:8px;
    vertical-align:middle;
    border-top:1px solid #e7edf2;
    color:#334b63;
    line-height:1.6;
}
.royal-popup-table tr:nth-child(even) td{background:#fbfdff}
.royal-popup-table .empty{text-align:center;color:#8290a2;padding:22px}
.royal-mini-progress{
    min-width:96px;
    display:flex;
    align-items:center;
    gap:6px;
}
.royal-mini-progress>i{
    flex:1;
    height:5px;
    overflow:hidden;
    border-radius:999px;
    background:#e8edf2;
    font-style:normal;
}
.royal-mini-progress>i>span{
    display:block;
    height:100%;
    border-radius:inherit;
    background:linear-gradient(90deg,#0b8f83,var(--royal-gold));
}
.royal-mini-progress>b{min-width:34px;color:#0c5c83;font-size:8.5px}
.royal-status{
    display:inline-flex;
    align-items:center;
    justify-content:center;
    min-width:64px;
    padding:4px 7px;
    border-radius:999px;
    font-size:8px;
    font-weight:900;
    white-space:nowrap;
}
.royal-status.good{color:#0a7f63;background:#e9f7f2}
.royal-status.warn{color:#9a6500;background:#fff6d9}
.royal-status.bad{color:#bd3434;background:#fdecec}
.royal-status.info{color:#1d619d;background:#edf5fd}

.royal-popup-bars{
    display:grid;
    gap:9px;
    padding:12px;
    border:1px solid #e1e7ee;
    border-radius:12px;
    background:#fff;
}
.royal-popup-bar-row{
    display:grid;
    grid-template-columns:minmax(130px,1fr) 2fr 50px;
    gap:10px;
    align-items:center;
    font-size:9px;
    color:#405871;
}
.royal-popup-bar-row>i{
    height:7px;
    border-radius:999px;
    background:#e9eef3;
    overflow:hidden;
    font-style:normal;
}
.royal-popup-bar-row>i>span{
    display:block;
    height:100%;
    background:linear-gradient(90deg,#1b6eb0,var(--royal-gold));
}
.royal-popup-bar-row>b{color:#0b4c7e;font-size:8.5px}

.royal-popup-btn{
    border:1px solid var(--royal-gold);
    border-radius:9px;
    padding:8px 12px;
    color:#fff;
    background:var(--royal-navy);
    font-size:10px;
    font-weight:900;
}
.royal-popup-btn.secondary{
    color:var(--royal-navy);
    background:#fff;
    border-color:#dce5ec;
}

/* تحسين نافذة الصفحة الرئيسية فقط دون المساس ببقية المودالات */
.royal-dashboard .page-header{margin-bottom:0}

@media(max-width:1260px){
    .royal-summary-grid{grid-template-columns:repeat(3,minmax(0,1fr))}
    .royal-card-grid,.royal-card-grid.five{grid-template-columns:repeat(2,minmax(0,1fr))}
    .royal-card-grid.six{grid-template-columns:repeat(3,minmax(0,1fr))}
}
@media(max-width:820px){
    .royal-summary-grid{grid-template-columns:repeat(2,minmax(0,1fr))}
    .royal-card-grid,.royal-card-grid.five,.royal-card-grid.six{grid-template-columns:1fr 1fr}
    .royal-popup-kpis,.royal-popup-filters{grid-template-columns:1fr 1fr}
}
@media(max-width:560px){
    .royal-summary-grid,.royal-card-grid,.royal-card-grid.five,.royal-card-grid.six{grid-template-columns:1fr}
    .royal-popup-kpis,.royal-popup-filters{grid-template-columns:1fr}
    .royal-section-title{grid-template-columns:22px auto 22px}
    .royal-popup-bar-row{grid-template-columns:1fr;gap:4px}
}
