/* شُقّ حرفياً من settings.css (S505) — التخصيص العائم: الزر (FAB) + اللوحة +
   مكتبة الثيمات + حقول الألوان + مفتاح التشغيل (fcp-switch). يُحمَّل بعد
   settings.css مباشرة حفظاً لترتيب الـcascade كما كان قبل الشقّ. */

/* ============================================================
   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%);
    transition:
        transform 0.2s cubic-bezier(0.16, 1, 0.3, 1),
        box-shadow 0.2s ease;
    animation: cpFabIn 0.35s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.color-fab:hover {
    transform: scale(1.07) rotate(-6deg);
}

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

/* أربع نقاط ألوان تدور حول الزر — تصميم «النقاط المداريّة». كل نقطة بلون
   توكن من الثيم فتتبع تخصيص كل مستأجر، والدوران transform فقط فلا يعيد الرسم */
.color-fab-orbit {
    position: absolute;
    inset: -8px;
    animation: cpSpin 6s linear infinite;
    pointer-events: none;
}

.color-fab-orbit i {
    position: absolute;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    box-shadow: 0 1px 4px color-mix(in srgb, var(--ink, #1e1b2e) 30%, transparent);
}

.color-fab-orbit i:nth-child(1) {
    top: 0;
    right: 50%;
    background: var(--danger, #ef4444);
}

.color-fab-orbit i:nth-child(2) {
    bottom: 0;
    left: 0;
    background: var(--warning, #f59e0b);
}

.color-fab-orbit i:nth-child(3) {
    bottom: 0;
    right: 0;
    background: var(--success, #10b981);
}

.color-fab-orbit i:nth-child(4) {
    top: 0;
    left: 0;
    background: var(--info, #38bdf8);
}

.color-fab.is-open .color-fab-orbit {
    animation-play-state: paused;
    opacity: 0;
}

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

@keyframes cpSpin {
    to {
        transform: rotate(360deg);
    }
}

/* حركة مخفَّضة: النقاط تبقى دلالةً على أداة الألوان لكن ثابتة بلا دوران */
@media (prefers-reduced-motion: reduce) {
    .color-fab-orbit {
        animation: none;
    }
}

/* --- اللوحة --- */
.color-panel {
    position: fixed;
    bottom: 88px;
    left: 24px;
    z-index: var(--z-tool-panel);
    width: 392px;
    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 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes cpPanelIn {
    from {
        transform: translateY(14px) scale(0.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;
}

/* أزرار أيقونية 28×28 — 999px على مربّع = دائرة تامة، نفس لغة .close-btn
   و.add-circle-btn. كانت 8px فتشذّ عن حبّات .cp-btn أسفل اللوحة نفسها. */
.cp-action {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 999px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition:
        background 0.15s ease,
        color 0.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;
}

/* شريط التمرير: الطبقة الموحّدة في base.css (الأسطح الضيّقة). */

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

/* عنوان القسم — مثل sg-group-title في تبويب «الثيم والألوان»: سطر صغير
   خافت فوق البطاقة، بلا شارات مرقّمة ولا أحرف كبيرة مزخرفة. */
.cp-section-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-secondary);
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

/* --- مكتبة الثيمات — شبكة بطاقات مثل preset-row في الإعدادات
   (كبسولة عيّنات فوق الاسم + شارة نقطة للثيم النشط) --- */
.cp-presets {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
    gap: 8px;
}

.cp-preset {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 12px 8px 10px;
    border: 1px solid var(--border-main);
    border-radius: 12px;
    background: var(--surface-solid);
    cursor: pointer;
    overflow: hidden;
    transition:
        background-color 0.16s ease,
        border-color 0.16s ease,
        transform 0.16s ease;
}

.cp-preset:hover {
    border-color: color-mix(in srgb, var(--text-title) 30%, transparent);
    transform: translateY(-1px);
}

/* كبسولة العيّنات — خمس نقاط تلخّص هوية الثيم، بنفس شكل ‎.preset-swatches */
.cp-strip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 100%;
    padding: 6px 8px;
    background: var(--bg-main);
    border: 1px solid var(--border-light);
    border-radius: 999px;
}

.cp-strip span {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.cp-preset-name {
    max-width: 100%;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--text-title);
    text-align: center;
    line-height: 1.35;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* رقاقة الثيم النشط — نقطة في زاوية البطاقة مثل ‎.preset-active-chip */
.cp-active-chip {
    display: none;
    position: absolute;
    top: 7px;
    inset-inline-end: 7px;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent);
}

.cp-preset.is-active {
    border-color: var(--primary);
    background: color-mix(in srgb, var(--primary) 5%, var(--surface-solid));
}

.cp-preset.is-active .cp-active-chip {
    display: block;
}

/* --- حقل اللون (swatch + hex) — هادئ مثل صفوف color-row في الإعدادات:
    العيّنة نقطة مستديرة بلا غلاف محدَّد، وhex بئر وحيد بحدّ رفيع --- */
.cp-color-field {
    display: flex;
    align-items: center;
    gap: 8px;
    transition: none;
}

.cp-swatch {
    position: relative;
    width: 30px;
    height: 30px;
    flex: none;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.12);
    cursor: pointer;
    overflow: hidden;
    /* طبقات اللون+الشطرنج يكتبها settings-customizer.js في background-image */
    box-shadow:
        inset 0 0 0 2px rgba(255, 255, 255, 0.35),
        0 1px 3px rgba(0, 0, 0, 0.1);
    transition:
        transform 0.12s ease,
        box-shadow 0.12s ease;
}
.cp-swatch:hover {
    transform: scale(1.06);
    box-shadow:
        inset 0 0 0 2px rgba(255, 255, 255, 0.5),
        0 2px 8px rgba(0, 0, 0, 0.16);
}

.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: none;
    width: 92px;
    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: 12px;
    font-weight: 800;
    text-transform: uppercase;
    text-align: center;
    direction: ltr;
    padding: 6px 12px;
    border-radius: 999px;
    transition:
        border-color 0.15s ease,
        background 0.15s ease,
        box-shadow 0.15s ease;
}
.cp-hex:focus {
    background: var(--surface-solid);
    border-color: var(--text-title);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--text-title) 8%, transparent);
}

/* صف اللون الأساسي */
.cp-primary-row {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 48px;
    padding: 8px 14px;
    background: var(--surface-solid);
    border: 1px solid var(--border-main);
    border-radius: var(--pane-radius);
}
.cp-primary-row .cp-color-field {
    margin-inline-start: auto;
}
.cp-primary-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-title);
    white-space: nowrap;
}

/* --- حقل بحث الألوان — كبسولة بئر محايد مثل sg-search في الإعدادات --- */
.cp-search-wrap {
    position: relative;
    margin-bottom: 14px;
}
.cp-search-ico {
    position: absolute;
    top: 50%;
    inset-inline-start: 12px;
    transform: translateY(-50%);
    width: 15px;
    height: 15px;
    color: var(--text-secondary);
    pointer-events: none;
}
.cp-search-input {
    width: 100%;
    box-sizing: border-box;
    padding: 9px 14px 9px 36px;
    border: 1px solid var(--border-main);
    border-radius: 999px;
    background: color-mix(in srgb, var(--bg-main) 70%, var(--surface-solid));
    color: var(--text-title);
    font: inherit;
    font-size: 13px;
    font-weight: 500;
    outline: none;
    transition:
        border-color 0.15s ease,
        background-color 0.15s ease;
}
[dir='rtl'] .cp-search-input {
    padding: 9px 36px 9px 14px;
}
.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);
}

/* --- الألوان حسب القسم — بطاقة sg-list واحدة: كل مجموعة صفّ قابل للطيّ
   بفاصل خطّ شعرة (لا بطاقات متداخلة)، بنفس إيقاع sg-item في الإعدادات --- */
.cp-all-groups {
    background: var(--surface-solid);
    border: 1px solid var(--border-main);
    border-radius: var(--pane-radius);
    overflow: hidden;
}

.cp-group {
    border: none;
    border-radius: 0;
    background: transparent;
}
.cp-group + .cp-group {
    border-top: 1px solid var(--border-light);
}

.cp-group-head {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 48px;
    padding: 10px 14px;
    border: none;
    background: transparent;
    color: var(--text-title);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-align: start;
    transition: background-color 0.16s ease;
}
.cp-group-head:hover {
    background: var(--nav-bg-hover);
}

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

/* العدّاد — قيمة صفّ هادئة بلا حبّة، مثل theme-group-count في الإعدادات */
.cp-group-count {
    flex: none;
    min-width: 0;
    padding: 0;
    border-radius: 0;
    background: transparent;
    color: var(--text-secondary);
    font-size: 12.5px;
    font-weight: 600;
    display: inline;
}

.cp-group-chev {
    width: 15px;
    height: 15px;
    flex: none;
    color: var(--text-muted);
    transition: transform 0.2s ease;
}
/* مطويّ → السهم نحو جهة البداية؛ مفتوح → لأسفل (نفس سلوك tg-chev) */
.cp-group-chev {
    transform: rotate(-90deg);
}
.cp-group:not(.is-collapsed) .cp-group-chev {
    transform: rotate(0deg);
}

.cp-group-body {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 0 8px 6px;
}
.cp-group.is-collapsed .cp-group-body {
    display: none;
}

/* --- صف لون واحد (تسمية + حقل) — خطّ شعرة علويّ لكل صفّ مثل color-row --- */
.cp-color-row {
    display: grid;
    grid-template-columns: 1fr 130px;
    gap: 10px;
    align-items: center;
    min-height: 46px;
    padding: 6px 6px;
    border-top: 1px solid var(--border-light);
    border-radius: 0;
    transition: background-color 0.16s ease;
}
.cp-color-row:hover {
    background: var(--nav-bg-hover);
}

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

.cp-color-row .cp-color-field {
    justify-self: stretch;
    justify-content: space-between;
}
.cp-color-row .cp-hex {
    flex: 1;
    min-width: 0;
    width: auto;
    font-size: 11.5px;
    padding: 5px 6px;
}

/* --- تذييل اللوحة --- */
.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 0.15s ease,
        border-color 0.15s ease,
        color 0.15s ease,
        transform 0.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(0.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 0.3s cubic-bezier(0.16, 1, 0.3, 1),
        opacity 0.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;
    }
}


/* ============================================================
   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 0.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, 0.25);
    transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
.fcp-switch input:checked + .fcp-track {
    background: var(--primary);
}
/* الصفحة RTL: الإبهام مثبّت عند حافة البداية (يمين) بـ inset-inline-start،
   والتحريك بـ translateX موجب يدفعه خارج المسار يميناً. نستخدم القيمة السالبة
   لاتجاه RTL (نفس نمط sc-switch في sales-curve.css). */
html[dir='rtl'] .fcp-switch input:checked + .fcp-track .fcp-thumb {
    transform: translateX(-20px);
}
html:not([dir='rtl']) .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;
}

