/* ============================================================
   منحنى المبيعات — بطاقة Modernize مستقلّة (vanilla port لِمكوّن React
   dash-chart-widget). كل القيم من توكنز النظام فيتكيّف مع الثيم والوضع
   الليلي والجوال تلقائياً. لا ألوان حرفية ثابتة: الأسطح --surface-solid،
   الحدود --border-main/--border-light، النص --text-title/--text-secondary،
   والمنحنى يأخذ لون السلسلة عبر currentColor (--primary / --accent).
   ============================================================ */

.sc-card {
    background: var(--surface-solid);
    border-radius: var(--pane-radius);
    box-shadow: var(--shadow-md);
    padding: var(--card-padding);
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-width: 0;
}

/* ===== الرأس: العنوان + شارة مباشر + أدوات ===== */
.sc-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border-light);
}
.sc-head-main { min-width: 0; }
.sc-title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-title);
    letter-spacing: -0.01em;
    display: inline-flex;
    align-items: center;
    gap: 10px;
}
.sc-live {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 700;
    color: var(--ready-text);
    background: var(--ready-bg);
    padding: 4px 9px;
    border-radius: 999px;
    letter-spacing: .02em;
}
.sc-live-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--ready-text);
    position: relative;
}
.sc-live-dot::after {
    content: "";
    position: absolute; inset: -3px;
    border-radius: 50%;
    background: var(--ready-text);
    opacity: .4;
    animation: sc-pulse 1.6s ease-out infinite;
}
@keyframes sc-pulse {
    0% { transform: scale(.6); opacity: .6; }
    100% { transform: scale(2.2); opacity: 0; }
}
.sc-sub {
    margin: 5px 0 0;
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
}
.sc-head-tools {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}

/* ===== مبدّل المقارنة (switch) ===== */
.sc-compare {
    display: flex;
    align-items: center;
    gap: 8px;
}
.sc-cmp-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
}
.sc-switch {
    position: relative;
    width: 38px; height: 22px;
    border: none;
    border-radius: 999px;
    background: color-mix(in srgb, var(--text-main) 22%, transparent);
    cursor: pointer;
    flex: none;
    transition: background .2s ease;
}
.sc-switch.on { background: var(--primary); }
.sc-switch:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.sc-switch-knob {
    position: absolute;
    top: 3px;
    inset-inline-start: 3px;
    width: 16px; height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: var(--shadow-sm);
    transition: transform .2s ease;
}
html:not([dir="rtl"]) .sc-switch.on .sc-switch-knob { transform: translateX(16px); }
html[dir="rtl"] .sc-switch.on .sc-switch-knob { transform: translateX(-16px); }

/* ===== تبويبات المقياس ===== */
.sc-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border-light);
    margin: -2px 0 2px;
}
.sc-tab {
    appearance: none;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 600;
    padding: 8px 14px 12px;
    cursor: pointer;
    position: relative;
    transition: color .16s ease;
}
.sc-tab:hover { color: var(--text-title); }
.sc-tab.is-active { color: var(--text-title); }
.sc-tab.is-active::after {
    content: "";
    position: absolute;
    inset-inline: 10px;
    bottom: -1px;
    height: 2px;
    border-radius: 2px;
    background: var(--primary);
    animation: sc-underline .25s ease;
}
@keyframes sc-underline {
    from { transform: scaleX(0); opacity: 0; }
    to { transform: scaleX(1); opacity: 1; }
}
.sc-tab:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; border-radius: 6px; }

/* ===== لوحة المحتوى ===== */
.sc-panel { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.sc-stats {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px;
}
.sc-val-row { display: inline-flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.sc-val {
    font-size: 30px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-title);
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}
.sc-delta {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    padding: 3px 9px;
    border-radius: 999px;
}
.sc-delta.up { background: var(--ready-bg); color: var(--ready-text); }
.sc-delta.down { background: var(--cancelled-bg, color-mix(in srgb, var(--cancelled-text) 12%, transparent)); color: var(--cancelled-text); }
.sc-delta-ico { width: 13px; height: 13px; }
.sc-delta-ico.down { transform: rotate(180deg); }
.sc-caption {
    margin: 6px 0 0;
    font-size: 12.5px;
    color: var(--text-secondary);
    max-width: 64ch;
}

/* ===== الرسم ===== */
.sc-chart {
    position: relative;
    width: 100%;
    border-radius: var(--pane-radius);
}
.sc-chart:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.sc-svg {
    display: block;
    width: 100%;
    height: auto;
    overflow: visible;
}
.sc-grid { stroke: var(--border-main); stroke-width: 1; }
.sc-axis { fill: var(--text-secondary); font-size: 10px; font-variant-numeric: tabular-nums; }

.sc-area { opacity: 0; animation: sc-fade .55s ease forwards; animation-delay: .15s; }
.sc-prev {
    fill: none;
    stroke: var(--text-secondary);
    stroke-width: 1.75;
    stroke-dasharray: 4 4;
    stroke-linecap: round;
    opacity: 0;
    animation: sc-fade .4s ease forwards;
}
.sc-line {
    fill: none;
    stroke: currentColor;
    stroke-width: 2.5;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-dasharray: 1;
    stroke-dashoffset: 1;
    animation: sc-draw .85s cubic-bezier(.22, 1, .36, 1) forwards;
}
.sc-dot { fill: currentColor; opacity: .7; }

@keyframes sc-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes sc-draw { to { stroke-dashoffset: 0; } }

/* crosshair */
.sc-crosshair { pointer-events: none; }
.sc-xline { stroke: color-mix(in srgb, var(--text-main) 30%, transparent); stroke-width: 1; }
.sc-prev-pt { fill: var(--surface-solid); stroke: var(--text-secondary); stroke-width: 2; }
.sc-halo { fill: currentColor; opacity: .18; }
.sc-cur-pt { fill: currentColor; stroke: var(--surface-solid); stroke-width: 2; }
.sc-hit { fill: transparent; }

/* ===== تلميح ===== */
.sc-tip {
    position: absolute;
    z-index: 5;
    pointer-events: none;
    transform: translate(-50%, calc(-100% - 14px));
    background: var(--surface-solid);
    border: 1px solid var(--border-main);
    border-radius: 10px;
    padding: 8px 12px;
    box-shadow: var(--shadow-lg);
    min-width: 120px;
}
.sc-tip-date { margin: 0; font-size: 11px; font-weight: 600; color: var(--text-secondary); }
.sc-tip-val {
    margin: 4px 0 0;
    font-size: 14px;
    font-weight: 700;
    color: var(--text-title);
    font-variant-numeric: tabular-nums;
    display: flex;
    align-items: center;
    gap: 6px;
}
.sc-tip-prev {
    margin: 3px 0 0;
    font-size: 11.5px;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    display: flex;
    align-items: center;
    gap: 6px;
}
.sc-tip-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--primary)); flex: none; }
.sc-tip-dash { width: 10px; height: 0; border-top: 2px dashed var(--text-secondary); flex: none; }

/* ===== مفتاح الخريطة ===== */
.sc-legend {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 18px;
    font-size: 12px;
    color: var(--text-secondary);
}
.sc-lg-item { display: inline-flex; align-items: center; gap: 6px; }
.sc-lg-cur { width: 14px; height: 3px; border-radius: 2px; background: var(--c, var(--primary)); }
.sc-lg-prev { width: 14px; height: 0; border-top: 2px dashed var(--text-secondary); }
.sc-lg-hint { margin-inline-start: auto; }

/* ===== بطاقات الإحصاء السفلية ===== */
.sc-footer {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1px;
    background: var(--border-main);
    border: 1px solid var(--border-main);
    border-radius: var(--pane-radius);
    overflow: hidden;
    margin: 0;
}
.sc-footer > div { background: var(--surface-solid); padding: 12px 16px; }
.sc-footer dt { font-size: 11.5px; color: var(--text-secondary); margin: 0; }
.sc-footer dd {
    margin: 4px 0 0;
    font-size: 14px;
    font-weight: 700;
    color: var(--text-title);
    font-variant-numeric: tabular-nums;
}
.sc-foot-note { font-size: 11px; font-weight: 500; color: var(--text-secondary); margin-inline-start: 4px; }

.sc-empty {
    padding: 40px 16px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
}

/* ===== الجوال: كثافة مضغوطة عبر التوكنات الموحّدة + تخطيط عمودي ===== */
@media (max-width: 768px) {
    .sc-head { padding-bottom: 10px; gap: 10px; }
    .sc-head-tools { width: 100%; justify-content: space-between; }
    .sc-val { font-size: 24px; }
    .sc-footer { grid-template-columns: 1fr; }
    .sc-lg-hint { display: none; }
}

/* ===== الوصولية: احترام تقليل الحركة ===== */
@media (prefers-reduced-motion: reduce) {
    .sc-line, .sc-area, .sc-prev {
        animation: none !important;
        stroke-dashoffset: 0 !important;
        opacity: 1 !important;
    }
    .sc-live-dot::after,
    .sc-tab.is-active::after { animation: none !important; }
}
