/* ===== إعادة ترتيب صفحة الإعدادات + التخصيص العائم للألوان =====
   الهدف: تبويبات معنونة واضحة + رأس صفحة أنيق + لوحة تخصيص عائمة
   اختيارية تظهر في كل صفحات البرنامج عند تفعيل المستخدم لها من
   تبويب "عام" > "زر الألوان العائم". كل القيم من توكنز Meadows
   فتتكيف مع الوضع الليلي تلقائياً. */

/* ============================================================
   1) رأس صفحة الإعدادات (عنوان + وصف ديناميكي)
   ============================================================ */
.settings-page-head {
    margin: 4px 0 22px;
    padding: 0;
}

.settings-page-title {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.01em;
    color: var(--text-title);
    margin: 0;
    line-height: 1.2;
}

.settings-page-sub {
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-muted);
    margin: 6px 0 0;
    max-width: 640px;
    font-weight: 500;
}

/* ============================================================
   2) شريط التبويبات العلوي (sub-nav) — معنون بدل الأيقونات فقط
   يُلغى تأثير .stat-tab الافتراضي ضمن هذا النطاق فقط.
   ============================================================ */
.settings-subnav {
    position: sticky;
    top: 0;
    z-index: 30;
    margin: 0 0 22px;
    background: color-mix(in srgb, var(--bg-main) 86%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-main);
    /* يسمح للشريط بأن يتمدّد بعرض المحتوى ويُلصق تحت الترويسة */
    border-radius: 0;
}

.settings-subnav-inner {
    display: flex;
    gap: 2px;
    overflow-x: auto;
    scrollbar-width: none;
    padding: 4px 0;
}

.settings-subnav-inner::-webkit-scrollbar { display: none; }

/* تجاوز مظهر .stat-tab داخل الـ sub-nav فقط (لا يمسّ صفحة الطلبات) */
.settings-subnav .stat-tab {
    flex-direction: row;
    gap: 8px;
    padding: 11px 15px;
    min-width: 0;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--control-radius);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
    box-shadow: none;
    position: relative;
    transition: color .18s ease, background-color .18s ease;
}

.settings-subnav .stat-tab:hover {
    color: var(--text-title);
    background: color-mix(in srgb, var(--primary) 6%, transparent);
    border-color: transparent;
}

.settings-subnav .stat-tab.active {
    /* مؤشّر سفلي بدل خلفية متدرّجة كاملة */
    background: transparent;
    color: var(--primary) !important;
    border-color: transparent;
    box-shadow: none;
}

.settings-subnav .stat-tab.active::after {
    content: '';
    position: absolute;
    bottom: -5px;
    inset-inline-start: 14px;
    inset-inline-end: 14px;
    height: 3px;
    border-radius: 3px 3px 0 0;
    background: linear-gradient(90deg, var(--primary), var(--primary-soft));
}

.snt-ico {
    width: 17px;
    height: 17px;
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: .85;
}

.settings-subnav .stat-tab.active .snt-ico { opacity: 1; }

.snt-label { line-height: 1; }

@media (max-width: 600px) {
    .settings-subnav .stat-tab { padding: 10px 12px; }
    .snt-label { font-size: 12.5px; }
}

/* ============================================================
   3) التخصيص العائم — زر (FAB) + لوحة (panel)
   عناصر عامّة في الـ body (تُحقن مرة واحدة في _body.html).
   تُخفى افتراضياً عبر [hidden]، ويُفعّلها المستخدم من
   إعدادات "عام" > "زر الألوان العائم". الموضع: يسار-أسفل.
   ============================================================ */

/* --- الزر العائم --- */
.color-fab:not([hidden]) {
    position: fixed;
    bottom: 24px;
    left: 24px;
    z-index: var(--z-tool-fab);
    width: 54px;
    height: 54px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    background: linear-gradient(135deg, var(--primary-soft) 0%, var(--primary) 55%, var(--primary-hover) 100%);
    box-shadow: var(--shadow-primary), 0 0 0 4px color-mix(in srgb, var(--primary) 14%, transparent);
    transition: transform .2s cubic-bezier(.16,1,.3,1), box-shadow .2s ease;
    animation: cpFabIn .35s cubic-bezier(.16,1,.3,1) both;
}

.color-fab:hover {
    transform: scale(1.07) rotate(-6deg);
    box-shadow: 0 14px 30px color-mix(in srgb, var(--primary) 45%, transparent),
                0 0 0 5px color-mix(in srgb, var(--primary) 16%, transparent);
}

.color-fab:active { transform: scale(.95); }

.color-fab-pulse {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: var(--primary);
    opacity: .45;
    animation: cpPulse 2.4s ease-out infinite;
    pointer-events: none;
}

.color-fab.is-open .color-fab-pulse { animation: none; opacity: 0; }

@keyframes cpFabIn {
    from { transform: scale(.4); opacity: 0; }
    to   { transform: scale(1); opacity: 1; }
}

@keyframes cpPulse {
    0%   { transform: scale(1); opacity: .45; }
    70%  { transform: scale(1.7); opacity: 0; }
    100% { transform: scale(1.7); opacity: 0; }
}

/* --- اللوحة --- */
.color-panel {
    position: fixed;
    bottom: 88px;
    left: 24px;
    z-index: var(--z-tool-panel);
    width: 372px;
    max-width: calc(100vw - 32px);
    max-height: min(680px, calc(100vh - 120px));
    display: none;
    flex-direction: column;
    overflow: hidden;
    background: var(--surface-solid);
    color: var(--text-main);
    border: 1px solid var(--border-main);
    border-radius: var(--pane-radius);
    box-shadow: var(--shadow-lg);
    font-family: inherit;
}

.color-panel.is-open:not([hidden]) {
    display: flex;
    animation: cpPanelIn .3s cubic-bezier(.16,1,.3,1) both;
}

@keyframes cpPanelIn {
    from { transform: translateY(14px) scale(.98); opacity: 0; }
    to   { transform: translateY(0) scale(1); opacity: 1; }
}

/* رأس اللوحة (قابل للسحب) */
.cp-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 14px 16px;
    cursor: grab;
    user-select: none;
    background: linear-gradient(135deg,
        color-mix(in srgb, var(--text-title) 5%, var(--surface-solid)) 0%,
        var(--surface-solid) 100%);
    border-bottom: 1px solid var(--border-main);
}

.cp-head:active { cursor: grabbing; }

.cp-head-left { display: flex; align-items: center; gap: 10px; min-width: 0; }

.cp-icon {
    width: 34px;
    height: 34px;
    flex: none;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    background: var(--text-title);
    box-shadow: 0 4px 12px color-mix(in srgb, var(--text-title) 35%, transparent);
}

.cp-title { font-size: 14.5px; font-weight: 800; color: var(--text-title); line-height: 1.2; letter-spacing: -0.01em; }
.cp-subtitle { font-size: 10.5px; color: var(--text-secondary); margin-top: 3px; font-weight: 600; }

.cp-actions { display: flex; gap: 4px; flex: none; }

.cp-action {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s ease, color .15s ease;
}

.cp-action:hover { background: color-mix(in srgb, var(--text-title) 10%, transparent); color: var(--text-title); }
.cp-action.cp-danger:hover { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }

/* جسم اللوحة */
.cp-body {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 14px;
    -webkit-overflow-scrolling: touch;
}

.cp-body::-webkit-scrollbar { width: 6px; }
.cp-body::-webkit-scrollbar-thumb { background: var(--border-main); border-radius: 3px; }
.cp-body::-webkit-scrollbar-thumb:hover { background: var(--placeholder); }

.cp-section { margin-bottom: 16px; }
.cp-section:last-child { margin-bottom: 0; }

.cp-section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    font-weight: 800;
    color: var(--text-title);
    text-transform: uppercase;
    letter-spacing: .08em;
    margin-bottom: 10px;
}

.cp-section-title .num {
    width: 19px;
    height: 19px;
    flex: none;
    border-radius: 6px;
    background: var(--text-title);
    color: #ffffff;
    font-size: 10px;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* --- الثيمات الجاهزة --- */
.cp-presets {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
    gap: 8px;
}

.cp-preset {
    position: relative;
    border: 1.5px solid var(--border-main);
    border-radius: 10px;
    cursor: pointer;
    overflow: hidden;
    transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
    background: var(--surface-solid);
    padding: 0;
}

.cp-preset:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); }

.cp-preset.is-active {
    border-color: var(--text-title);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--text-title) 12%, transparent);
}

.cp-preset-swatch {
    height: 36px;
    width: 100%;
    display: block;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06);
}

.cp-preset-name {
    font-size: 10.5px;
    font-weight: 800;
    color: var(--text-title);
    text-align: center;
    padding: 5px 3px 6px;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* --- حقل اللون (swatch + hex) --- */
.cp-color-field {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface-main);
    border: 1px solid var(--border-main);
    border-radius: 9px;
    padding: 4px 8px 4px 4px;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.cp-color-field:hover {
    border-color: color-mix(in srgb, var(--text-title) 25%, var(--border-main));
}

.cp-swatch {
    position: relative;
    width: 34px;
    height: 34px;
    flex: none;
    border-radius: 8px;
    border: 1px solid rgba(0,0,0,.12);
    cursor: pointer;
    overflow: hidden;
    box-shadow: inset 0 0 0 2px rgba(255,255,255,.5), 0 1px 2px rgba(0,0,0,.08);
    transition: transform .12s ease, box-shadow .12s ease;
}
.cp-swatch:hover {
    transform: scale(1.05);
    box-shadow: inset 0 0 0 2px rgba(255,255,255,.6), 0 2px 6px rgba(0,0,0,.14);
}

.cp-swatch input[type=color] {
    position: absolute;
    inset: -6px;
    width: calc(100% + 12px);
    height: calc(100% + 12px);
    border: none;
    padding: 0;
    background: none;
    cursor: pointer;
    opacity: 0;
}

.cp-hex {
    flex: 1;
    min-width: 0;
    border: none;
    outline: none;
    background: none;
    color: var(--text-title);
    font-family: var(--app-mono-family, ui-monospace, monospace);
    font-size: 11.5px;
    font-weight: 700;
    text-transform: uppercase;
    direction: ltr;
    text-align: left;
}

/* صف اللون الأساسي */
.cp-primary-row { display: flex; align-items: center; gap: 8px; }
.cp-primary-row .cp-color-field { flex: 1; }
.cp-primary-label {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-main);
    white-space: nowrap;
}

/* --- حقل بحث الألوان --- */
.cp-search-wrap {
    position: relative;
    margin-bottom: 14px;
}
.cp-search-ico {
    position: absolute;
    top: 50%;
    inset-inline-start: 10px;
    transform: translateY(-50%);
    width: 15px;
    height: 15px;
    color: var(--text-secondary);
    pointer-events: none;
}
.cp-search-input {
    width: 100%;
    box-sizing: border-box;
    padding: 10px 12px 10px 34px;
    border: 1px solid var(--border-main);
    border-radius: 10px;
    background: var(--surface-main);
    color: var(--text-title);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}
[dir="rtl"] .cp-search-input { padding: 10px 34px 10px 12px; }
.cp-search-input:focus {
    border-color: var(--text-title);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--text-title) 10%, transparent);
}
.cp-search-input::placeholder { color: var(--text-secondary); }

/* --- مجموعات الألوان القابلة للطي --- */
.cp-all-groups {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.cp-group {
    border: 1px solid var(--border-main);
    border-radius: 10px;
    overflow: hidden;
    background: var(--surface-main);
}

.cp-group-head {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 10px 12px;
    border: none;
    background: transparent;
    color: var(--text-title);
    font: inherit;
    font-size: 12.5px;
    font-weight: 800;
    cursor: pointer;
    text-align: start;
    transition: background-color .15s ease;
}
.cp-group-head:hover { background: color-mix(in srgb, var(--text-title) 5%, transparent); }

.cp-group-name { flex: 1; min-width: 0; }

.cp-group-count {
    flex: none;
    min-width: 22px;
    height: 19px;
    padding: 0 6px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--text-title) 8%, transparent);
    color: var(--text-title);
    font-size: 10.5px;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.cp-group-chev {
    width: 14px;
    height: 14px;
    flex: none;
    color: var(--text-secondary);
    transition: transform .2s ease;
}
.cp-group:not(.is-collapsed) .cp-group-chev { transform: rotate(180deg); }

.cp-group-body {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 4px 9px 10px;
}
.cp-group.is-collapsed .cp-group-body { display: none; }

/* --- صف لون واحد (تسمية + حقل) --- */
.cp-color-row {
    display: grid;
    grid-template-columns: 1fr 124px;
    gap: 10px;
    align-items: center;
    padding: 6px 4px;
    border-radius: 8px;
    transition: background-color .12s ease;
}
.cp-color-row:hover {
    background: color-mix(in srgb, var(--text-title) 4%, transparent);
}

.cp-color-label {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-title);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cp-color-row .cp-color-field { padding: 3px 6px 3px 3px; }
.cp-color-row .cp-swatch { width: 28px; height: 28px; }
.cp-color-row .cp-hex { font-size: 11px; }

/* --- تذييل اللوحة --- */
.cp-foot {
    display: flex;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid var(--border-main);
    background: color-mix(in srgb, var(--text-title) 4%, var(--surface-main));
}

.cp-btn {
    flex: 1;
    padding: 10px 14px;
    border-radius: 999px;
    border: 1px solid var(--border-main);
    background: var(--surface-solid);
    color: var(--text-title);
    font: inherit;
    font-size: 12.5px;
    font-weight: 800;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: background-color .15s ease, border-color .15s ease, color .15s ease, transform .12s ease;
}

.cp-btn:hover {
    background: color-mix(in srgb, var(--text-title) 8%, var(--surface-solid));
    border-color: var(--text-title);
    color: var(--text-title);
}
.cp-btn:active { transform: scale(.97); }

.cp-btn-primary {
    background: var(--text-title);
    color: #ffffff;
    border-color: var(--text-title);
    box-shadow: 0 6px 14px color-mix(in srgb, var(--text-title) 25%, transparent);
}

.cp-btn-primary:hover {
    background: color-mix(in srgb, #000 25%, var(--text-title));
    border-color: transparent;
    color: #ffffff;
}

/* --- Toast صغير --- */
.cp-toast {
    position: fixed;
    bottom: 26px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    z-index: 95;
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 10px 18px;
    border-radius: 999px;
    background: var(--text-title);
    color: #fff;
    font-size: 12.5px;
    font-weight: 700;
    box-shadow: var(--shadow-lg);
    pointer-events: none;
    opacity: 0;
    transition: transform .3s cubic-bezier(.16,1,.3,1), opacity .3s ease;
}

.cp-toast.is-shown {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* --- الجوال: الزر واللوحة --- */
@media (max-width: 600px) {
    .color-fab { bottom: 18px; left: 18px; width: 50px; height: 50px; }
    .color-panel {
        left: 16px;
        right: 16px;
        width: auto;
        max-width: none;
        bottom: 80px;
    }
}

/* === كثافة صفحة الإعدادات على الجوال (≤768px) ===
   صفحة الإعدادات أكثر الصفحات طولاً (تبويبات + مجموعات + حقول ألوان)
   فأثر الـpadding يتراكم بسرعة. التقليص يركّز على:
   - .settings-page-head margin-bottom 22 → 14
   - .settings-page-title 22 → 18
   - .cp-section margin-bottom 16 → 12
   - .cp-group-body padding 4 9 10 → 3 8 8
   - .te-section-body padding 4 18 18 → 3 14 14
   - .theme-group-body padding 16 → 12 (مأخوذ من --card-padding الجديد أصلاً)
   الهدف: تحرير ~50px عمودياً + 8px أفقياً في كل قسم، أي ما يعادل
   رؤية 3-4 صفوف إضافية من المحتوى قبل الحاجة للتمرير. */
@media (max-width: 768px) {
    .settings-page-head { margin: 2px 0 14px; }
    .settings-page-title { font-size: 18px; }
    .settings-page-sub { font-size: 12px; }
    .cp-section { margin-bottom: 12px; }
    .cp-group-body { padding: 3px 8px 8px; }
    #settingsThemeTab .te-section-body { padding: 3px 14px 14px; }
    #settingsThemeTab .theme-color-pickers { padding-right: 6px; padding-left: 2px; }
}
@media (max-width: 420px) {
    .settings-page-head { margin: 0 0 10px; }
}

/* ============================================================
   4) محرّر الثيم (تبويب «الثيم والألوان») — أسلوب calm
   بطاقات أقسام مسطّحة برؤوس رمادية محايدة + صفوف ألوان بسيطة
   (نقطة ملوّنة + اسم + حقل hex) + بطاقات ثيم بمعاينة 6 ألوان.
   كل القيم من توكنز Meadows. مُحدَّدة بـ #settingsThemeTab.
   ============================================================ */

/* الحاوية العامة: شبكة بعمودين على الشاشات العريضة لعرض مجموعات الألوان جنباً
   لجنب بدل التكديس الطويل. على الموبايل يعود لعمود واحد. */
#settingsThemeTab.settings-tab-content {
    display: block;
    gap: 0;
}

#settingsThemeTab .theme-color-pickers {
    overflow: visible;
    padding: 0;
    flex: none;
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
    gap: 12px;
    align-items: start;
}

/* الثيمات الجاهزة تبقى بطاقتها ممتدة على عرض العمودين للحفاظ على المعاينة */
#settingsThemeTab #themePresetsSection,
#settingsThemeTab #themeCustomSection {
    grid-column: 1 / -1;
}

/* بطاقة الثيمات الجاهزة ثابتة في الأعلى تحت شريط الأدوات — تماماً مثل المثال
   المرجعي — كي تبقى معاينة الثيمات في المتناول أثناء التمرير بين مجموعات
   الألوان. z-index أعلى من بطاقات الألوان كي تبقى فوقها. قيمة `top` تُحدَّد
   من JS بقياس ارتفاع شريط الأدوات وتُحقن في --theme-toolbar-h على التبويب. */
#settingsThemeTab #themePresetsSection {
    position: sticky;
    top: var(--theme-toolbar-h, 64px);
    z-index: 4;
    backdrop-filter: blur(8px);
    background: color-mix(in srgb, var(--surface-solid) 94%, transparent);
}

/* --- شريط الأدوات (بحث + فتح/طي) --- */
#settingsThemeTab .theme-editor-toolbar {
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 14px;
    border: 1px solid var(--border-main);
    border-radius: var(--pane-radius);
    box-shadow: var(--shadow-sm);
    /* ثابت في الأعلى أثناء التمرير داخل تبويب الثيم — يظل البحث وأزرار
       الفتح/طي في المتناول دائماً. z-index فوق البطاقات. */
    position: sticky;
    top: 0;
    z-index: 5;
    backdrop-filter: blur(8px);
    background: color-mix(in srgb, var(--surface-solid) 92%, transparent);
}

.te-search-wrap {
    position: relative;
    flex: 1 1 220px;
    min-width: 180px;
}

.te-search-ico {
    position: absolute;
    top: 50%;
    inset-inline-start: 12px;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    pointer-events: none;
}

#settingsThemeTab .theme-search-input {
    width: 100%;
    padding: 10px 14px 10px 14px;
    padding-inline-start: 38px;
    font-size: 13px;
    background: var(--surface-main);
    border: 1px solid var(--border-main);
    border-radius: 10px;
    color: var(--text-title);
    font-weight: 500;
    font-family: inherit;
    transition: border-color .15s ease, box-shadow .15s ease;
}

#settingsThemeTab .theme-search-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 12%, transparent);
}

#settingsThemeTab .theme-editor-actions { flex: none; }

#settingsThemeTab .theme-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 12px;
    font-size: 12.5px;
    font-weight: 700;
    border-radius: 10px;
    background: var(--surface-main);
    border: 1px solid var(--border-main);
    color: var(--text-main);
    cursor: pointer;
    transition: background .15s ease, border-color .15s ease, color .15s ease;
}
#settingsThemeTab .theme-action-btn:hover {
    background: var(--surface-hover);
    border-color: color-mix(in srgb, var(--primary) 30%, var(--border-main));
    color: var(--primary);
}

#settingsThemeTab .theme-action-btn svg { width: 14px; height: 14px; }

/* --- بطاقة القسم (مسطّحة، هادئة) --- */
#settingsThemeTab .theme-group {
    background: var(--surface-solid);
    border: 1px solid var(--border-main);
    border-radius: var(--pane-radius);
    margin-bottom: 12px;
    overflow: hidden;
}

/* إزالة السهم ▾ القديم من dashboard.css — لدينا سهم خاص */
#settingsThemeTab .theme-group-title::after { content: none; }

/* --- رأس القسم: أيقونة محايدة + عنوان + عدّاد + سهم --- */
#settingsThemeTab .te-section-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 18px;
    cursor: pointer;
    user-select: none;
    transition: background-color .15s ease;
}

#settingsThemeTab .te-section-head:hover {
    background: color-mix(in srgb, var(--text-title) 4%, transparent);
}

.tg-icon {
    width: 34px;
    height: 34px;
    flex: none;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    /* خلفية داكنة محايدة (بدل الرمادي الباهت الذي كان يذوب مع الخلفية)
       وأيقونة بيضاء لتباين قوي. */
    background: var(--text-title);
    color: #ffffff;
    border: 1px solid var(--text-title);
    box-shadow: 0 2px 6px color-mix(in srgb, var(--text-title) 18%, transparent);
}

.tg-icon svg { width: 17px; height: 17px; }

.tg-title-wrap {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.tg-name {
    font-size: 14.5px;
    font-weight: 800;
    color: var(--text-title);
    line-height: 1.2;
    letter-spacing: -0.01em;
}

.tg-spacer { flex: 1; }

.tg-chev {
    flex: none;
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    transition: transform .2s ease;
}

/* مفتوح افتراضياً → السهم لأسفل؛ مطوي → يدور للأعلى */
#settingsThemeTab .theme-group.collapsed .tg-chev { transform: rotate(-90deg); }

/* العدّاد — محايد داكن (بدل الرمادي الباهت) */
#settingsThemeTab .theme-group-count {
    background: color-mix(in srgb, var(--text-title) 7%, transparent);
    color: var(--text-title);
    border: 1px solid var(--border-light);
    font-size: 11px;
    font-weight: 800;
}

/* زر «حفظ الحالي» — محسّن الوضوح: خلفية primary ناعمة + حدّ primary
   رفيع، بدل الأبيض الذي كان يبدو معطلاً. */
#settingsThemeTab .theme-save-btn {
    font-size: 12px;
    font-weight: 800;
    padding: 7px 13px;
    border-radius: 9px;
    background: color-mix(in srgb, var(--primary) 12%, var(--surface-main));
    color: var(--primary);
    border: 1px solid color-mix(in srgb, var(--primary) 28%, var(--border-main));
    cursor: pointer;
    transition: background .15s ease, color .15s ease, border-color .15s ease;
}
#settingsThemeTab .theme-save-btn:hover {
    background: var(--primary);
    color: #ffffff;
    border-color: var(--primary);
}

/* --- جسم القسم: قائمة ألوان بعمود واحد --- */
#settingsThemeTab .te-section-body {
    padding: 4px 18px 18px;
}

/* الطي: أولوية أعلى من قاعدة الشبكة كي يُخفى الجسم فعلاً عند الطي */
#settingsThemeTab .theme-group.collapsed .te-section-body { display: none; }

/* أقسام غير قابلة للطي (بطاقات الثيمات الجاهزة + ثيماتي المحفوظة):
   الرأس ليس زراً — أزل المؤشر والتأثير عند التحويم وأخفِ السهم. */
#settingsThemeTab .te-section-nofold .te-section-head {
    cursor: default;
    pointer-events: none;
}
#settingsThemeTab .te-section-nofold .te-section-head > .tg-icon,
#settingsThemeTab .te-section-nofold .te-section-head > .tg-title-wrap,
#settingsThemeTab .te-section-nofold .te-section-head > .theme-save-btn {
    pointer-events: auto;
}
#settingsThemeTab .te-section-nofold .te-section-head:hover {
    background: transparent;
}
#settingsThemeTab .te-section-nofold .tg-chev { display: none; }

/* ============================================================
   صفوف الألوان — نقطة + اسم + hex
   ============================================================ */
#settingsThemeTab .color-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 11px 10px;
    margin: 0;
    border-bottom: 1px solid var(--border-light);
    border-radius: 8px;
    transition: background-color .15s ease, transform .12s ease;
}

#settingsThemeTab .color-row:last-child { border-bottom: none; }

#settingsThemeTab .color-row:hover {
    background: color-mix(in srgb, var(--text-title) 4%, transparent);
}

#settingsThemeTab .cr-dot {
    position: relative;
    width: 30px;
    height: 30px;
    flex: none;
    border-radius: 8px;
    border: 1px solid rgba(0, 0, 0, .12);
    cursor: pointer;
    overflow: hidden;
    box-shadow: inset 0 0 0 2px rgba(255,255,255,.35), 0 1px 3px rgba(0, 0, 0, .10);
    transition: transform .12s ease, box-shadow .12s ease;
}
#settingsThemeTab .cr-dot:hover {
    transform: scale(1.06);
    box-shadow: inset 0 0 0 2px rgba(255,255,255,.5), 0 2px 8px rgba(0, 0, 0, .16);
}

#settingsThemeTab .cr-dot input[type=color] {
    position: absolute;
    inset: -4px;
    width: calc(100% + 8px);
    height: calc(100% + 8px);
    border: none;
    padding: 0;
    background: none;
    cursor: pointer;
    opacity: 0;
}

#settingsThemeTab .cr-name {
    flex: 1;
    min-width: 0;
    font-size: 13.5px;
    font-weight: 700;
    color: var(--text-title);
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
}

#settingsThemeTab .cr-hex {
    flex: none;
    width: 108px;
    border: 1px solid var(--border-main);
    outline: none;
    background: var(--surface-main);
    color: var(--text-title);
    font-family: var(--app-mono-family, ui-monospace, monospace);
    font-size: 12.5px;
    font-weight: 800;
    text-transform: uppercase;
    text-align: center;
    padding: 6px 10px;
    border-radius: 7px;
    transition: border-color .15s ease, background .15s ease, color .15s ease, box-shadow .15s ease;
}

#settingsThemeTab .cr-hex:focus {
    background: var(--surface-solid);
    border-color: var(--text-title);
    color: var(--text-title);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--text-title) 8%, transparent);
}

/* ============================================================
   بطاقات الثيمات الجاهزة/المحفوظة — معاينة 6 ألوان
   ============================================================ */
#settingsThemeTab .theme-presets-group .te-section-body {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
    gap: 10px;
    padding-top: 6px;
}

#settingsThemeTab .preset-card {
    position: relative;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 0;
    margin: 0;
    padding: 0;
    cursor: pointer;
    border: 1.5px solid var(--border-main);
    border-radius: 11px;
    overflow: hidden;
    background: var(--surface-solid);
    transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}

#settingsThemeTab .preset-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: color-mix(in srgb, var(--text-title) 35%, transparent);
}

#settingsThemeTab .preset-card:hover .preset-preview span:first-child {
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.3), 0 2px 8px rgba(0, 0, 0, 0.08);
}

/* معاينة الثيم: شبكة 2×3 متساوية من العيّنات اللونية. التخطيط المتساوي
   أسهل قراءةً للوهلة الأولى من تخطيط "العينة المهيمنة" السابق الذي كان
   يُخلّف مساحة فارغة في أسفل-يمين البطاقة. */
#settingsThemeTab .preset-preview {
    height: 84px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: 3px;
    padding: 6px;
    background: var(--bg-main);
}

#settingsThemeTab .preset-preview span {
    border-radius: 6px;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

#settingsThemeTab .preset-label {
    padding: 8px 10px 9px;
    font-size: 11.5px;
    font-weight: 700;
    color: var(--text-title);
    text-align: center;
    line-height: 1.3;
    border-top: 1px solid var(--border-light);
    background: var(--surface-solid);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* الثيم النشط */
#settingsThemeTab .preset-card.active {
    border-color: var(--text-title);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--text-title) 14%, transparent);
}

#settingsThemeTab .preset-card.active .preset-label {
    color: var(--text-title);
    background: color-mix(in srgb, var(--text-title) 4%, var(--surface-solid));
}

/* شارة "جديد" للثيمات المضافة حديثاً — شريط مدمج بحافة البطاقة العلوية
   بلون الشفق (أخضر/بنفسجي) لا يطغى على العيّنة. */
#settingsThemeTab .preset-badge {
    position: absolute;
    top: 0;
    inset-inline-start: 0;
    padding: 3px 8px 4px;
    font-size: 9.5px;
    font-weight: 800;
    letter-spacing: 0.04em;
    color: #ffffff;
    background: linear-gradient(135deg, #7B5DD9 0%, #3DCFE0 100%);
    border-bottom-right-radius: 7px;
    border-bottom-left-radius: 0;
    z-index: 2;
    text-transform: uppercase;
    box-shadow: 0 2px 6px rgba(123, 93, 217, 0.35);
}

/* الثيمات المحفوظة: زر الحذف كطبقة فوق المعاينة */
#settingsThemeTab .preset-card-custom .theme-preset-delete {
    position: absolute;
    top: 5px;
    inset-inline-end: 5px;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    font-size: 15px;
    line-height: 1;
    background: rgba(15, 23, 42, .5);
    color: #fff;
    border: none;
    border-radius: 50%;
    backdrop-filter: blur(4px);
    z-index: 1;
}

#settingsThemeTab .preset-card-custom .theme-preset-delete:hover {
    background: var(--danger);
}

/* ============================================================
   5) مفتاح تشغيل/إيقاف (toggle) لزر الألوان العائم
   ============================================================ */
.fcp-switch {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
    font: inherit;
    color: var(--text-main);
}
.fcp-switch input { position: absolute; opacity: 0; pointer-events: none; }
.fcp-track {
    position: relative;
    width: 44px;
    height: 24px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--text-secondary) 28%, transparent);
    transition: background .2s ease;
    flex: none;
}
.fcp-thumb {
    position: absolute;
    top: 3px;
    inset-inline-start: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(15, 23, 42, .25);
    transition: transform .2s cubic-bezier(.16,1,.3,1);
}
.fcp-switch input:checked + .fcp-track {
    background: var(--primary);
}
.fcp-switch input:checked + .fcp-track .fcp-thumb {
    transform: translateX(20px);
}
.fcp-switch input:focus-visible + .fcp-track {
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent);
}
.fcp-label {
    font-size: 12.5px;
    font-weight: 700;
    color: var(--text-secondary);
    min-width: 44px;
    text-align: start;
}
