/* ═══════════════════════════════════════════════════════════════════
   YSnapp — Client Dashboard Design System (Mobile-First)
   نظام تصميم موحّد للوحة العميل: متوافق مع الموبايل والشاشات الصغيرة
   ═══════════════════════════════════════════════════════════════════ */

/* ── 1. Design Tokens ─────────────────────────────────────────── */
:root {
    --ys-text: #1a2035;
    --ys-text-muted: #64748b;
    --ys-text-soft: #94a3b8;
    --ys-card-bg: rgba(255, 255, 255, 0.72);
    --ys-card-border: rgba(255, 255, 255, 0.85);
    --ys-shadow: 0 4px 20px rgba(0, 0, 0, 0.04);
    --ys-shadow-hover: 0 10px 28px rgba(33, 150, 243, 0.14);
    --ys-radius-lg: 18px;
    --ys-radius: 16px;
    --ys-radius-sm: 12px;
    --ys-success: #10b981;
    --ys-success-dark: #059669;
    --ys-danger: #ef4444;
    --ys-danger-dark: #dc2626;
    --ys-warning: #f59e0b;
    --ys-warning-dark: #d97706;
    --ys-surface: rgba(0, 0, 0, 0.035);
    --ys-surface-strong: rgba(0, 0, 0, 0.06);
}

body.dark-theme {
    --ys-text: #f1f5f9;
    --ys-text-muted: #94a3b8;
    --ys-text-soft: #64748b;
    --ys-card-bg: rgba(30, 41, 59, 0.72);
    --ys-card-border: rgba(255, 255, 255, 0.08);
    --ys-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    --ys-shadow-hover: 0 10px 28px rgba(0, 0, 0, 0.35);
    --ys-surface: rgba(255, 255, 255, 0.05);
    --ys-surface-strong: rgba(255, 255, 255, 0.09);
}

/* ── 2. Shell: Topbar / Sidebar / Main / Toast (Mobile-First) ─── */
html, body { overflow-x: clip; }
@supports not (overflow: clip) {
    html, body { overflow-x: hidden; }
}

#topbar { height: 52px; padding: 0 12px; gap: 8px; }
#topbar .page-title { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1; }
#topbar .topbar-menu-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; padding: 0; border-radius: 10px; flex-shrink: 0;
}
#topbar .topbar-logout { font-size: 11.5px; border-radius: 9px; font-weight: 700; padding: 6px 10px; flex-shrink: 0; white-space: nowrap; }
#topbar .topbar-logout i { font-size: 11px; }

.topbar-user-pill { padding: 3px 8px 3px 4px; gap: 6px; }
.topbar-user-pill .user-avatar-circle { width: 28px; height: 28px; font-size: 13px; }
.user-pill-name { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#sidebar { width: min(282px, 84vw); }
#sidebar .brand { padding: 16px 16px 14px; }
#sidebar nav { padding: 10px 10px; }
#sidebar .nav-section { padding: 12px 14px 6px; }
#sidebar .nav-link { padding: 10px 14px; font-size: 13.5px; }

body #main { margin-right: 0; margin-top: 52px; padding: 14px 12px 40px !important; min-height: calc(100vh - 52px); }

#toast-container { left: 12px; right: 12px; min-width: 0 !important; }

/* ── 3. Shared Content Components (scoped for guaranteed override) ── */

/* Containers: توحيد المسافات */
#main .cd-container, #main .cs-container, #main .cp-container, #main .co-container,
#main .ck-container, #main .cw-container, #main .cr-container, #main .cc-container,
#main .cpc-container, #main .cos-container, #main .cyd-container, #main .cpd-container {
    gap: 16px;
}

/* Cards: توحيد الشكل والمسافات */
#main .cd-card, #main .cs-card-main, #main .co-card, #main .ck-card, #main .ck-guide-card,
#main .cw-card, #main .cr-card, #main .cc-panel, #main .cpc-card,
#main .cos-card, #main .cyd-card, #main .cpd-card {
    padding: 18px;
    border-radius: var(--ys-radius);
    background: var(--ys-card-bg);
    border: 1px solid var(--ys-card-border);
    box-shadow: var(--ys-shadow);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}

/* Page headers: توحيد */
#main .cs-header, #main .co-header, #main .ck-header, #main .cc-header,
#main .cos-header, #main .cyd-header, #main .cpd-header, #main .cr-header {
    flex-wrap: wrap;
    gap: 10px;
}
#main .cs-title, #main .co-title, #main .ck-title, #main .cc-title,
#main .cos-title, #main .cyd-title, #main .cpd-title, #main .cr-title {
    font-size: 18px;
    color: var(--ys-text);
}
#main .cs-subtitle, #main .co-subtitle, #main .ck-subtitle, #main .cc-subtitle,
#main .cos-subtitle, #main .cyd-subtitle, #main .cpd-subtitle, #main .cr-subtitle {
    font-size: 12px;
    color: var(--ys-text-muted);
}

/* CTA buttons: ملء كامل على الجوال */
#main .cs-btn-new, #main .co-btn-new {
    width: 100%;
    justify-content: center;
    min-height: 44px;
}

/* Heroes: مدمجة ومنسقة */
#main .cd-hero, #main .cp-hero, #main .cpc-hero {
    padding: 18px 16px;
    border-radius: var(--ys-radius);
    gap: 12px;
    box-shadow: var(--ys-shadow);
}
#main .cd-welcome-title, #main .cp-hero-title, #main .cpc-hero-title { font-size: 17px; color: var(--ys-text); }
#main .cd-welcome-sub, #main .cp-hero-sub, #main .cpc-hero-sub { font-size: 12.5px; color: var(--ys-text-muted); }
#main .cd-hero-badge, #main .cp-hero-badge, #main .cpc-hero-badge { font-size: 11px; padding: 4px 10px; }
#main .cd-hero-actions { width: 100%; gap: 8px; }
#main .cd-hero-actions .cd-btn-hero { flex: 1 1 auto; justify-content: center; padding: 10px 12px; font-size: 12.5px; }

/* Stats: بطاقات إحصائية متناسقة */
#main .cd-stats, #main .co-stats, #main .cs-stats { gap: 10px; }
#main .cd-stat-card, #main .co-stat-item, #main .cs-stat-item, #main .cr-stat-card {
    padding: 14px;
    gap: 10px;
    border-radius: var(--ys-radius-sm);
    background: var(--ys-card-bg);
    border: 1px solid var(--ys-card-border);
    box-shadow: var(--ys-shadow);
}
#main .cd-stat-icon, #main .co-stat-icon, #main .cs-stat-icon, #main .cr-stat-icon {
    width: 38px; height: 38px; font-size: 17px; border-radius: 11px; flex-shrink: 0;
}
#main .cd-stat-num, #main .co-stat-val, #main .cs-stat-val, #main .cr-stat-val {
    font-size: 17px; color: var(--ys-text);
}
#main .cd-stat-label, #main .co-stat-lbl, #main .cs-stat-lbl, #main .cr-stat-lbl {
    font-size: 10.5px; color: var(--ys-text-muted);
}

/* Filter tabs: شريط تصفية يلتف ولا يفيض (العرض الكامل في كتلة الجوال) */
#main .cs-filter-tabs, #main .co-filter-tabs, #main .cw-filter-tabs {
    flex-wrap: wrap;
    gap: 6px;
}
#main .cs-filter-btn, #main .co-filter-btn, #main .cw-filter-btn {
    padding: 7px 12px;
    font-size: 11.5px;
    border-radius: 9px;
    white-space: nowrap;
}
#main .cs-card-head, #main .co-card-head, #main .cw-card-header { gap: 10px; }

/* Tables: خلايا مدمجة */
#main .cd-table th, #main .cw-table th, #main .cr-table th {
    font-size: 10.5px;
    padding: 9px 10px;
    color: var(--ys-text-soft);
}
#main .cd-table td, #main .cw-table td, #main .cr-table td {
    padding: 11px 10px;
    font-size: 12.5px;
    color: var(--ys-text);
}

/* ── 4. Mobile Compact (≤767px): الحجم الأنيق الكامل ──────────── */
@media (max-width: 767.98px) {
    /* Stats: عمودان على الجوال */
    #main .cd-stats, #main .co-stats, #main .cs-stats, #main .cr-stats { grid-template-columns: repeat(2, 1fr); gap: 10px; }

    /* Filter tabs: عرض كامل يلتف */
    #main .cs-filter-tabs, #main .co-filter-tabs, #main .cw-filter-tabs { width: 100%; }

    /* Cards padding موحّد */
    #main .cd-card, #main .cs-card-main, #main .co-card, #main .ck-card, #main .ck-guide-card,
    #main .cw-card, #main .cr-card, #main .cc-panel, #main .cpc-card,
    #main .cos-card, #main .cyd-card, #main .cpd-card { padding: 16px; }

    /* Hero أصغر */
    #main .cd-hero, #main .cp-hero, #main .cpc-hero { padding: 16px; }

    /* Subscriptions cards */
    #main .cs-grid { gap: 14px; }
    #main .cs-sub-card-top { flex-wrap: wrap; gap: 8px; }
    #main .cs-badge-active, #main .cs-badge-expired { white-space: nowrap; }
    #main .cs-plan-title { font-size: 16px; }

    /* Plans cards */
    #main .cp-grid { gap: 14px; }
    #main .cp-plan-card { padding: 18px; }
    #main .cp-plan-name { font-size: 17px; }
    #main .cp-plan-price { font-size: 28px; }
    #main .cp-price-currency { font-size: 12.5px; }
    #main .cp-usd-badge { padding: 5px 12px; font-size: 13.5px; gap: 6px; }
    #main .cp-usd-icon { width: 20px; height: 20px; font-size: 12px; }
    #main .cp-plan-desc { font-size: 12.5px; }
    #main .cp-feature-item { font-size: 12px; }
    #main .cp-btn-order, #main .cp-btn-details { min-height: 44px; }
    #main .cp-trust-card { padding: 15px; gap: 10px; }
    #main .cp-trust-icon { width: 38px; height: 38px; font-size: 17px; }
    #main .cp-trust-title { font-size: 13.5px; }
    #main .cp-trust-desc { font-size: 11.5px; }

    /* Orders cards */
    #main .co-orders-list { gap: 12px; }
    #main .co-order-card { padding: 16px; }
    #main .co-order-main { gap: 10px; }
    #main .co-order-plan-name { font-size: 15px; }
    #main .co-order-price { font-size: 17px; }
    #main .co-order-footer { gap: 10px; }
    #main .co-order-actions { width: 100%; }
    #main .co-btn-action { flex: 1; justify-content: center; min-height: 42px; }

    /* Keys */
    #main .ck-key-item { padding: 15px; gap: 12px; }
    #main .ck-key-code { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    #main .ck-top-nav-tabs, #main .ck-guide-tabs { flex-wrap: wrap; gap: 6px; }
    #main .ck-top-nav-btn, #main .ck-guide-tab { flex: 1 1 auto; justify-content: center; padding: 8px 12px; font-size: 12px; }
    #main .ck-guide-box { font-size: 11px; padding: 12px; overflow-x: auto; white-space: pre-wrap; word-break: break-all; }
    #main .ck-info-box { padding: 12px 14px; font-size: 12.5px; }

    /* Wallet */
    #main .cw-card-digital { padding: 20px; min-height: 185px; border-radius: 20px; }
    #main .cw-balance-amount { font-size: 30px; }
    #main .cw-balance-currency { font-size: 14px; }
    #main .cw-card-bottom { flex-wrap: wrap; gap: 12px; }
    #main .cw-recharge-btn { padding: 9px 16px; font-size: 12.5px; }
    #main .cw-stats-col { gap: 12px; }
    #main .cw-stat-card { padding: 16px; gap: 12px; }
    #main .cw-stat-icon { width: 40px; height: 40px; font-size: 17px; }
    #main .cw-stat-num { font-size: 19px; }
    #main .cw-key-row { flex-wrap: wrap; gap: 8px; }

    /* Reports filters */
    #main .cr-filter-box { padding: 14px; gap: 10px; }
    #main .cr-filter-group { width: 100%; }
    #main .cr-select, #main .cr-search-input { width: 100%; flex: 1 1 auto; min-width: 0; }
    #main .cr-filter-btn-submit { flex-shrink: 0; }

    /* Contact */
    #main .cc-cards-grid { gap: 12px; }
    #main .cc-info-card { padding: 16px; }
    #main .cc-card-icon { width: 42px; height: 42px; font-size: 18px; }
    #main .cc-card-val { font-size: 14px; }
    #main .cc-open-banner { flex-wrap: wrap; gap: 10px; }
    #main .cc-ticket { padding: 14px; }
    #main .cc-admin-reply { padding: 12px; font-size: 12.5px; }

    /* Confirm page */
    #main .cpc-summary-box { padding: 15px; }
    #main .cpc-price-tag { font-size: 24px; }
    #main .cpc-row { font-size: 13px; gap: 8px; }
    #main .cpc-btn-submit { min-height: 46px; }

    /* Order show */
    #main .cos-meta-item { padding: 10px; }
    #main .cos-meta-val { font-size: 14px; }

    /* Deposits */
    #main .cyd-step-item, #main .cpd-desc-box { padding: 13px; font-size: 12.5px; }
    #main .cyd-step-num, #main .cpd-paypal-icon { width: 36px; height: 36px; font-size: 15px; }

    /* Modals */
    .my-account-modal-overlay .my-account-modal-card { padding: 20px; }
    .my-account-modal-overlay .account-tabs { flex-wrap: wrap; }
    .my-account-modal-overlay .account-tab-btn { font-size: 12px; padding: 8px 10px; white-space: nowrap; }

    /* General text coherence */
    #main .cd-card-title, #main .cr-card-title, #main .cw-card-title, #main .cc-panel-title { font-size: 15px; }
}

/* ── 5. Ultra Narrow (≤420px) ────────────────────────────────── */
@media (max-width: 420px) {
    .topbar-user-pill .user-pill-info,
    .topbar-user-pill .user-pill-arrow { display: none; }
    .topbar-user-pill { padding: 3px; }
    #topbar .topbar-logout {
        width: 34px; height: 34px; padding: 0;
        display: inline-flex; align-items: center; justify-content: center; font-size: 0;
    }
    #topbar .topbar-logout i { font-size: 13px; margin: 0; }
    #topbar .topbar-logout .logout-label { display: none; }

    #main .cd-stats, #main .co-stats { gap: 8px; }
    #main .cd-stat-card, #main .co-stat-item { padding: 12px 10px; }
    #main .cd-stat-num, #main .co-stat-val { font-size: 15.5px; }
    #main .cd-stat-label, #main .co-stat-lbl { font-size: 10px; }
}

/* ── 6. Desktop Harmony (≥768px): تناسق موحّد ────────────────── */
@media (min-width: 768px) {
    /* Shell desktop */
    #topbar { height: 56px; padding: 0 20px; }
    #topbar .page-title { font-size: 15px; }
    #topbar .topbar-logout { font-size: 12px; padding: 4px 10px; }
    #topbar .topbar-logout i { font-size: 12px; }
    #sidebar { width: var(--sidebar-width, 250px); }
    #sidebar .brand { padding: 20px 20px 16px; }
    #sidebar nav { padding: 12px 10px; }
    body #main { margin-right: var(--sidebar-width, 250px); margin-top: 56px; padding: 24px 20px 40px !important; min-height: calc(100vh - 56px); }
    #toast-container { left: auto; right: 20px; min-width: 340px !important; }

    #main .cd-card, #main .cs-card-main, #main .co-card, #main .ck-card, #main .ck-guide-card,
    #main .cw-card, #main .cr-card, #main .cc-panel, #main .cpc-card,
    #main .cos-card, #main .cyd-card, #main .cpd-card { padding: 22px; }

    #main .cd-hero, #main .cp-hero, #main .cpc-hero { padding: 26px 30px; }
    #main .cd-welcome-title, #main .cp-hero-title, #main .cpc-hero-title { font-size: 21px; }
    #main .cs-title, #main .co-title, #main .ck-title, #main .cc-title,
    #main .cos-title, #main .cyd-title, #main .cpd-title, #main .cr-title { font-size: 20px; }

    #main .cs-btn-new, #main .co-btn-new { width: auto; min-height: 0; }
    #main .cd-hero-actions { width: auto; }
    #main .cd-hero-actions .cd-btn-hero { flex: 0 0 auto; padding: 11px 20px; font-size: 13px; }

    #main .cd-stat-card, #main .co-stat-item, #main .cs-stat-item, #main .cr-stat-card { padding: 16px; }
    #main .cd-stat-icon, #main .co-stat-icon, #main .cs-stat-icon, #main .cr-stat-icon {
        width: 44px; height: 44px; font-size: 19px;
    }
    #main .cd-stat-num, #main .co-stat-val, #main .cs-stat-val, #main .cr-stat-val { font-size: 20px; }
    #main .cd-stat-label, #main .co-stat-lbl, #main .cs-stat-lbl, #main .cr-stat-lbl { font-size: 11.5px; }

    #main .cp-grid { gap: 20px; }
    #main .cp-plan-price { font-size: 32px; }
    #main .cw-card-digital { padding: 28px; }
    #main .cw-balance-amount { font-size: 36px; }
    .my-account-modal-overlay .my-account-modal-card { padding: 26px; }
}

/* ── 7. Dark Theme Coherence ─────────────────────────────────── */
body.dark-theme #topbar { background: #1e293b; border-bottom-color: rgba(255,255,255,0.08); }
body.dark-theme #topbar .page-title { color: #f1f5f9; }
body.dark-theme #topbar > .btn-outline-danger { border-color: rgba(248,113,113,0.4); color: #f87171; }
body.dark-theme #topbar > .btn-outline-danger:hover { background: #ef4444; color: #fff; }

body.dark-theme #main .cd-card, body.dark-theme #main .cs-card-main, body.dark-theme #main .co-card,
body.dark-theme #main .ck-card, body.dark-theme #main .ck-guide-card, body.dark-theme #main .cw-card,
body.dark-theme #main .cr-card, body.dark-theme #main .cc-panel, body.dark-theme #main .cpc-card,
body.dark-theme #main .cos-card, body.dark-theme #main .cyd-card, body.dark-theme #main .cpd-card,
body.dark-theme #main .cd-stat-card, body.dark-theme #main .co-stat-item,
body.dark-theme #main .cs-stat-item, body.dark-theme #main .cr-stat-card {
    background: var(--ys-card-bg);
    border-color: var(--ys-card-border);
}

body.dark-theme #main .cd-plan-card, body.dark-theme #main .cp-plan-card,
body.dark-theme #main .cs-sub-card, body.dark-theme #main .co-order-card,
body.dark-theme #main .ck-key-item, body.dark-theme #main .cc-info-card,
body.dark-theme #main .cc-ticket { background: var(--ys-card-bg); border-color: var(--ys-card-border); }

body.dark-theme #main .cd-table td, body.dark-theme #main .cw-table td, body.dark-theme #main .cr-table td {
    color: #cbd5e1;
    border-bottom-color: rgba(255,255,255,0.06);
}
body.dark-theme #main .cd-table th, body.dark-theme #main .cw-table th, body.dark-theme #main .cr-table th {
    color: #64748b;
}

body.dark-theme #main .cs-filter-tabs, body.dark-theme #main .co-filter-tabs, body.dark-theme #main .cw-filter-tabs {
    background: rgba(255,255,255,0.06);
}

body.dark-theme #main .cd-welcome-title, body.dark-theme #main .cp-hero-title,
body.dark-theme #main .cpc-hero-title, body.dark-theme #main .cs-title,
body.dark-theme #main .co-title, body.dark-theme #main .ck-title, body.dark-theme #main .cc-title,
body.dark-theme #main .cos-title, body.dark-theme #main .cyd-title, body.dark-theme #main .cpd-title,
body.dark-theme #main .cr-title, body.dark-theme #main .cd-card-title, body.dark-theme #main .cr-card-title,
body.dark-theme #main .cw-card-title, body.dark-theme #main .cc-panel-title,
body.dark-theme #main .cd-stat-num, body.dark-theme #main .co-stat-val,
body.dark-theme #main .cs-stat-val, body.dark-theme #main .cr-stat-val { color: #f1f5f9; }

body.dark-theme #main .cd-welcome-sub, body.dark-theme #main .cp-hero-sub,
body.dark-theme #main .cpc-hero-sub, body.dark-theme #main .cs-subtitle,
body.dark-theme #main .co-subtitle, body.dark-theme #main .ck-subtitle, body.dark-theme #main .cc-subtitle,
body.dark-theme #main .cos-subtitle, body.dark-theme #main .cyd-subtitle, body.dark-theme #main .cpd-subtitle,
body.dark-theme #main .cr-subtitle, body.dark-theme #main .cd-stat-label,
body.dark-theme #main .co-stat-lbl, body.dark-theme #main .cs-stat-lbl, body.dark-theme #main .cr-stat-lbl { color: #94a3b8; }
