/* ═══════════════════════════════════════════════════════════════
   مفضلاتي — الطبقة 4: المكوّنات
   كل مكوّن مستقل: زر، حقل، بطاقة، شريحة، لوحة، جدول، تنبيه، نافذة.
   الألوان كلها من التوكنز. لا قيم سِحرية.
   ═══════════════════════════════════════════════════════════════ */

@layer components {
    /* ═══ الأزرار ═══════════════════════════════════════════════ */
    .btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        min-height: 36px;
        padding: 6px 14px;
        border: 1px solid transparent;
        border-radius: var(--r-sm);
        font-size: var(--fs-sm);
        font-weight: 600;
        white-space: nowrap;
        transition: background var(--d-1) var(--ease),
                    border-color var(--d-1) var(--ease),
                    color var(--d-1) var(--ease);
    }

    .btn:active {
        transform: translateY(1px);
    }

    .btn:disabled {
        opacity: 0.45;
        cursor: not-allowed;
        transform: none;
    }

    .btn svg {
        flex: none;
    }

    .btn--solid {
        background: var(--solid);
        color: var(--on-solid);
    }

    .btn--solid:hover {
        background: var(--solid-hover);
        color: var(--on-solid);
    }

    .btn--outline {
        background: var(--surface);
        border-color: var(--border);
        color: var(--text);
    }

    .btn--outline:hover {
        background: var(--surface-hover);
        border-color: var(--border-strong);
        color: var(--text);
    }

    .btn--ghost {
        color: var(--text-mute);
    }

    .btn--ghost:hover {
        background: var(--surface-sunken);
        color: var(--text);
    }

    .btn--danger {
        background: var(--danger-soft);
        border-color: color-mix(in srgb, var(--danger) 32%, transparent);
        color: var(--danger);
    }

    .btn--danger:hover {
        background: var(--danger);
        border-color: var(--danger);
        color: var(--surface);
    }

    .btn--block {
        width: 100%;
    }

    .btn--sm {
        min-height: 30px;
        padding: 3px 10px;
        font-size: var(--fs-xs);
    }

    /* أزرار الأيقونات */
    .iconbtn {
        display: inline-grid;
        place-items: center;
        width: 30px;
        height: 30px;
        flex: none;
        border: 1px solid transparent;
        border-radius: var(--r-sm);
        color: var(--text-faint);
        transition: background var(--d-1) var(--ease), color var(--d-1) var(--ease);
    }

    .iconbtn:hover {
        background: var(--surface-sunken);
        color: var(--text);
    }

    .iconbtn:disabled {
        opacity: 0.3;
        cursor: not-allowed;
        background: none;
    }

    .iconbtn--danger:hover {
        background: var(--danger-soft);
        color: var(--danger);
    }

    .iconbtn--solid {
        background: var(--surface);
        border-color: var(--border);
    }

    /* ═══ الحقول ════════════════════════════════════════════════ */
    .field {
        display: flex;
        flex-direction: column;
        gap: 5px;
        margin-block-end: var(--s-4);
    }

    .field__label {
        display: flex;
        align-items: center;
        gap: 5px;
        color: var(--text-mute);
        font-size: var(--fs-sm);
        font-weight: 600;
    }

    .field__label svg {
        color: var(--text-faint);
    }

    .field__hint {
        color: var(--text-faint);
        font-size: var(--fs-xs);
    }

    .input,
    .select {
        width: 100%;
        min-height: 38px;
        padding: 7px 10px;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--r-sm);
        font-size: var(--fs-sm);
        transition: border-color var(--d-1) var(--ease), box-shadow var(--d-1) var(--ease);
    }

    .input:hover,
    .select:hover {
        border-color: var(--border-strong);
    }

    .input:focus,
    .select:focus {
        outline: none;
        border-color: var(--accent);
        box-shadow: 0 0 0 3px var(--accent-soft);
    }

    .input[aria-invalid="true"] {
        border-color: var(--danger);
    }

    .input--ltr {
        direction: ltr;
        text-align: start;
        font-variant-numeric: tabular-nums;
    }

    .input--pin {
        font-size: var(--fs-lg);
        font-weight: 600;
        letter-spacing: 0.02em;
        text-align: center;
    }

    .select {
        appearance: none;
        padding-inline-end: 30px;
        background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                          linear-gradient(135deg, currentColor 50%, transparent 50%);
        background-position: calc(100% - 15px) 52%, calc(100% - 10px) 52%;
        background-size: 5px 5px, 5px 5px;
        background-repeat: no-repeat;
        cursor: pointer;
    }

    /* حقل البحث داخل شريط الأدوات يتمدد ليأخذ المتاح */
    .toolbar > .search {
        flex: 1 1 240px;
        min-width: 0;
    }

    /* قائمة الترتيب داخل شريط الأدوات: بعرض محتواها لا بعرض الشريط */
    .toolbar .select {
        flex: 0 0 auto;
        width: auto;
        min-width: 152px;
    }

    @media (max-width: 640px) {
        .toolbar > .search {
            flex: 1 1 100%;
            order: -1;
        }
    }

    html[dir="rtl"] .select {
        background-position: 15px 52%, 10px 52%;
    }

    /* حقل البحث */
    .search {
        display: flex;
        align-items: center;
        gap: var(--s-2);
        min-height: 38px;
        padding-inline: 10px;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--r-sm);
        transition: border-color var(--d-1) var(--ease), box-shadow var(--d-1) var(--ease);
    }

    .search:hover {
        border-color: var(--border-strong);
    }

    .search:focus-within {
        border-color: var(--accent);
        box-shadow: 0 0 0 3px var(--accent-soft);
    }

    .search svg {
        flex: none;
        color: var(--text-faint);
    }

    .search input {
        flex: 1;
        min-width: 0;
        background: none;
        border: 0;
        outline: none;
        font-size: var(--fs-sm);
    }

    .search input::-webkit-search-cancel-button {
        appearance: none;
    }

    /* مفتاح لوحة مفاتيح */
    .kbd {
        display: inline-grid;
        place-items: center;
        min-width: 18px;
        height: 18px;
        padding-inline: 4px;
        border: 1px solid var(--border-strong);
        border-block-end-width: 2px;
        border-radius: var(--r-xs);
        background: var(--surface-hover);
        color: var(--text-faint);
        font-family: inherit;
        font-size: 10px;
        font-weight: 600;
    }

    /* مبدّل مجمّع */
    .segmented {
        display: inline-flex;
        gap: 2px;
        padding: 2px;
        background: var(--surface-sunken);
        border-radius: var(--r-sm);
    }

    .segmented button {
        padding: 4px 10px;
        border-radius: var(--r-xs);
        color: var(--text-mute);
        font-size: var(--fs-xs);
        font-weight: 600;
        transition: background var(--d-1) var(--ease), color var(--d-1) var(--ease);
    }

    .segmented button:hover {
        color: var(--text);
    }

    .segmented button[aria-pressed="true"] {
        background: var(--surface);
        color: var(--text);
        box-shadow: var(--sh-1);
    }

    /* ═══ روابط الشريط الجانبي ══════════════════════════════════ */
    .rail__link {
        display: flex;
        align-items: center;
        gap: var(--s-2);
        padding: 6px 10px;
        border-radius: var(--r-sm);
        color: var(--text-mute);
        font-size: var(--fs-sm);
        transition: background var(--d-1) var(--ease), color var(--d-1) var(--ease);
    }

    .rail__link:hover {
        background: var(--surface-sunken);
        color: var(--text);
    }

    .rail__link.is-active {
        background: var(--accent-soft);
        color: var(--accent-ink);
        font-weight: 600;
    }

    .rail__link svg {
        flex: none;
        opacity: 0.8;
    }

    .rail__count {
        margin-inline-start: auto;
        color: var(--text-faint);
        font-size: var(--fs-xs);
        font-variant-numeric: tabular-nums;
    }

    .rail__link.is-active .rail__count {
        color: inherit;
        opacity: 0.7;
    }

    .rail__cat {
        display: flex;
        align-items: center;
        gap: var(--s-2);
        padding: 5px 10px;
        border-radius: var(--r-sm);
        color: var(--text-mute);
        font-size: var(--fs-sm);
        white-space: nowrap;
    }

    .rail__cat:hover {
        background: var(--surface-sunken);
        color: var(--text);
    }

    .rail__cat.is-active {
        background: var(--surface);
        color: var(--text);
        font-weight: 600;
        box-shadow: var(--sh-1);
    }

    .rail__dot {
        width: 6px;
        height: 6px;
        flex: none;
        border-radius: var(--r-full);
        background: var(--border-strong);
    }

    .rail__cat.is-active .rail__dot {
        background: var(--accent);
    }

    /* ═══ بطاقة المفضلة ═════════════════════════════════════════ */
    .card {
        position: relative;
        display: flex;
        align-items: center;
        gap: var(--s-3);
        padding: var(--s-3);
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--r-md);
        transition: border-color var(--d-2) var(--ease),
                    box-shadow var(--d-2) var(--ease),
                    transform var(--d-2) var(--ease),
                    opacity var(--d-2) var(--ease);
    }

    .card:hover,
    .card:focus-within {
        border-color: var(--border-strong);
        box-shadow: var(--sh-2);
        transform: translateY(-1px);
    }

    .card[hidden] {
        display: none;
    }

    .card.is-dragging {
        opacity: 0.4;
    }

    .card.is-target {
        border-color: var(--accent);
        box-shadow: 0 0 0 2px var(--accent-soft);
    }

    .card__link {
        display: flex;
        flex: 1;
        align-items: center;
        gap: var(--s-3);
        min-width: 0;
        color: inherit;
    }

    .card__link:hover {
        color: inherit;
    }

    .card__link:focus-visible {
        outline: none;
    }

    .card__tile {
        display: grid;
        place-items: center;
        width: 36px;
        height: 36px;
        flex: none;
        border-radius: var(--r-sm);
        background: color-mix(in srgb, var(--c, var(--accent)) 14%, transparent);
        color: color-mix(in srgb, var(--c, var(--accent)) 78%, var(--text));
    }

    .card__body {
        display: flex;
        flex: 1;
        flex-direction: column;
        min-width: 0;
    }

    .card__title {
        overflow: hidden;
        font-size: var(--fs-base);
        font-weight: 600;
        line-height: 1.4;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .card__host {
        flex: 0 1 auto;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .card__host::before {
        content: "·";
        margin-inline-end: 6px;
        color: var(--text-faint);
    }

    .card__sub {
        display: flex;
        align-items: center;
        gap: 6px;
        min-width: 0;
        color: var(--text-faint);
        font-size: var(--fs-xs);
        line-height: 1.5;
    }

    /*
     * التصنيف نصّ هادئ بلون محايد: لون البطاقة يخصّ المفضلة نفسها (في مربّع
     * الأيقونة)، وتلوين التصنيف به كان يجعل التصنيف الواحد بألوان مختلفة
     * فيبدو عشوائياً.
     */
    .card__cat {
        order: -1;
        flex: 0 1 auto;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        color: var(--text-faint);
    }

    .collection[data-view="grid"] .card__host {
        display: none;
    }

    .collection[data-view="list"] .card__cat {
        max-width: 45%;
    }

    /* وضع القائمة: صف مضغوط */
    .collection[data-view="list"] .card {
        padding: 6px var(--s-3);
        border-radius: var(--r-sm);
    }

    .collection[data-view="list"] .card:hover {
        transform: none;
        box-shadow: none;
        background: var(--surface-hover);
    }

    .collection[data-view="list"] .card__tile {
        width: 26px;
        height: 26px;
        border-radius: var(--r-xs);
    }

    .collection[data-view="list"] .card__title {
        flex: 0 1 auto;
        font-size: var(--fs-sm);
    }

    .collection[data-view="list"] .card__title::after {
        content: "·";
        margin-inline-start: 8px;
        color: var(--text-faint);
    }

    /* وضع القائمة: سطر واحد — العنوان والتصنيف في البداية، النطاق في الطرف الآخر */
    .collection[data-view="list"] .card__body {
        flex-direction: row;
        align-items: baseline;
        gap: 10px;
    }

    .collection[data-view="list"] .card__sub {
        flex: 1 1 auto;
    }

    .collection[data-view="list"] .card__sub {
        justify-content: space-between;
        gap: var(--s-4);
    }

    /* ═══ الشرائح ═══════════════════════════════════════════════ */
    .chip {
        display: inline-flex;
        align-items: center;
        gap: 4px;
        padding: 2px 8px;
        border: 1px solid transparent;
        border-radius: var(--r-full);
        background: var(--surface-sunken);
        color: var(--text-mute);
        font-size: var(--fs-xs);
        font-weight: 500;
        white-space: nowrap;
    }

    .chip--cat {
        background: color-mix(in srgb, var(--c, var(--text-faint)) 11%, transparent);
        color: color-mix(in srgb, var(--c, var(--text-faint)) 78%, var(--text));
    }

    .chip--filter {
        cursor: pointer;
        transition: background var(--d-1) var(--ease), color var(--d-1) var(--ease);
    }

    .chip--filter:hover {
        background: var(--border);
    }

    .chip--filter[aria-pressed="true"] {
        background: var(--solid);
        color: var(--on-solid);
    }

    .chip__n {
        color: var(--text-faint);
        font-variant-numeric: tabular-nums;
    }

    .chip--filter[aria-pressed="true"] .chip__n {
        color: inherit;
        opacity: 0.7;
    }

    /* ═══ اللوحات ═══════════════════════════════════════════════ */
    .panel {
        padding: var(--s-4);
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--r-md);
    }

    .panel + .panel {
        margin-block-start: var(--s-4);
    }

    .panel__head {
        margin-block-end: var(--s-4);
    }

    .panel__head h2 {
        display: flex;
        align-items: center;
        gap: var(--s-2);
        font-size: var(--fs-base);
    }

    .panel__head svg {
        color: var(--text-faint);
    }

    .panel__head p {
        margin-block-start: 2px;
        color: var(--text-faint);
        font-size: var(--fs-sm);
    }

    .grid-2 {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
        gap: var(--s-4);
        align-items: start;
    }

    .grid-2 + .panel {
        margin-block-start: var(--s-4);
    }

    /* قائمة مفتاح/قيمة — عمودان على الشاشات الواسعة حتى لا تتباعد الأطراف */
    .kv {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 330px), 1fr));
        gap: 0 var(--s-5);
    }

    .kv__row {
        display: flex;
        flex-wrap: wrap;
        align-items: baseline;
        justify-content: space-between;
        gap: var(--s-2);
        padding-block: 8px;
        border-block-end: 1px solid var(--border);
    }

    .kv__row:last-child {
        border-block-end: 0;
        padding-block-end: 0;
    }

    .kv__k {
        color: var(--text-mute);
        font-size: var(--fs-sm);
    }

    .kv__v {
        max-width: 100%;
        font-size: var(--fs-sm);
        font-weight: 600;
        text-align: end;
    }

    /* ═══ الجدول ════════════════════════════════════════════════ */
    .table-wrap {
        overflow-x: auto;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--r-md);
    }

    .table {
        width: 100%;
        font-size: var(--fs-sm);
        text-align: start;
    }

    .table th {
        padding: 10px 12px;
        background: var(--surface-hover);
        border-block-end: 1px solid var(--border);
        color: var(--text-faint);
        font-size: var(--fs-xs);
        font-weight: 600;
        text-align: start;
        white-space: nowrap;
    }

    .table td {
        padding: 9px 12px;
        border-block-end: 1px solid var(--border);
        vertical-align: middle;
    }

    .table tbody tr:last-child td {
        border-block-end: 0;
    }

    .table tbody tr:hover {
        background: var(--surface-hover);
    }

    .cell-site {
        display: flex;
        align-items: center;
        gap: var(--s-2);
        min-width: 0;
    }

    .cell-site__tile {
        display: grid;
        place-items: center;
        width: 28px;
        height: 28px;
        flex: none;
        border-radius: var(--r-xs);
        background: color-mix(in srgb, var(--c, var(--accent)) 14%, transparent);
        color: color-mix(in srgb, var(--c, var(--accent)) 78%, var(--text));
    }

    .cell-site__name {
        display: block;
        overflow: hidden;
        font-weight: 600;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .cell-site__url {
        display: block;
        overflow: hidden;
        color: var(--text-faint);
        font-size: var(--fs-xs);
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .cell-actions {
        display: flex;
        align-items: center;
        justify-content: flex-end;
        gap: 2px;
    }

    .swatch-mark {
        display: inline-block;
        width: 14px;
        height: 14px;
        border: 1px solid var(--border-strong);
        border-radius: var(--r-xs);
        background: var(--c, var(--border-strong));
        vertical-align: -2px;
    }

    /* ═══ التنبيهات ═════════════════════════════════════════════ */
    .alert {
        display: flex;
        align-items: flex-start;
        gap: var(--s-2);
        padding: 10px 12px;
        margin-block-end: var(--s-4);
        border: 1px solid transparent;
        border-radius: var(--r-sm);
        font-size: var(--fs-sm);
    }

    .alert--error {
        background: var(--danger-soft);
        border-color: color-mix(in srgb, var(--danger) 28%, transparent);
        color: var(--danger);
    }

    .alert--warn {
        background: var(--warning-soft);
        border-color: color-mix(in srgb, var(--warning) 28%, transparent);
        color: var(--warning);
    }

    .badge {
        display: inline-flex;
        align-items: center;
        gap: 4px;
        padding: 1px 7px;
        border-radius: var(--r-full);
        font-size: var(--fs-xs);
        font-weight: 600;
    }

    .badge--ok {
        background: var(--success-soft);
        color: var(--success);
    }

    .badge--warn {
        background: var(--warning-soft);
        color: var(--warning);
    }

    /* ═══ الحالات الفارغة ═══════════════════════════════════════ */
    .empty {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: var(--s-2);
        padding: var(--s-7) var(--s-4);
        border: 1px dashed var(--border-strong);
        border-radius: var(--r-md);
        text-align: center;
    }

    .empty__ico {
        display: grid;
        place-items: center;
        width: 44px;
        height: 44px;
        border-radius: var(--r-md);
        background: var(--surface-sunken);
        color: var(--text-faint);
    }

    .empty h2 {
        font-size: var(--fs-md);
    }

    .empty p {
        max-width: 34ch;
        color: var(--text-mute);
        font-size: var(--fs-sm);
    }

    .empty .btn {
        margin-block-start: var(--s-2);
    }

    .no-results {
        display: none;
        padding: var(--s-5) var(--s-4);
        color: var(--text-faint);
        font-size: var(--fs-sm);
        text-align: center;
    }

    .no-results.is-visible {
        display: block;
    }

    /* ═══ التنبيهات العائمة ═════════════════════════════════════ */
    .toasts {
        position: fixed;
        inset-block-end: var(--s-4);
        inset-inline-start: var(--s-4);
        z-index: 60;
        display: flex;
        flex-direction: column;
        gap: var(--s-2);
        width: min(360px, calc(100vw - 2 * var(--s-4)));
        pointer-events: none;
    }

    .toast {
        display: flex;
        align-items: flex-start;
        gap: var(--s-2);
        padding: 9px 12px;
        background: var(--surface);
        border: 1px solid var(--border);
        border-inline-start: 3px solid var(--text-faint);
        border-radius: var(--r-sm);
        box-shadow: var(--sh-2);
        font-size: var(--fs-sm);
        pointer-events: auto;
        animation: toast-in var(--d-3) var(--ease);
    }

    .toast--success {
        border-inline-start-color: var(--success);
    }

    .toast--error {
        border-inline-start-color: var(--danger);
    }

    .toast__msg {
        flex: 1;
        min-width: 0;
    }

    .toast__x {
        flex: none;
        color: var(--text-faint);
        font-size: 1rem;
        line-height: 1;
    }

    .toast__x:hover {
        color: var(--text);
    }

    .toast.is-out {
        opacity: 0;
        transform: translateY(6px);
        transition: opacity var(--d-2) var(--ease), transform var(--d-2) var(--ease);
    }

    @keyframes toast-in {
        from {
            opacity: 0;
            transform: translateY(8px);
        }
    }

    /* ═══ النافذة ═══════════════════════════════════════════════ */
    .dialog {
        width: min(400px, calc(100vw - 2rem));
        margin: auto;
        padding: var(--s-5);
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--r-lg);
        box-shadow: var(--sh-3);
        color: var(--text);
    }

    .dialog::backdrop {
        background: rgba(10, 10, 12, 0.45);
    }

    .dialog h3 {
        margin-block-end: var(--s-2);
        font-size: var(--fs-md);
    }

    .dialog p {
        color: var(--text-mute);
        font-size: var(--fs-sm);
    }

    .dialog__actions {
        display: flex;
        justify-content: flex-end;
        gap: var(--s-2);
        margin-block-start: var(--s-5);
    }

    /* ═══ لوحة الرمز السري ══════════════════════════════════════ */
    .login__card {
        padding: var(--s-5);
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--r-lg);
        box-shadow: var(--sh-2);
        text-align: center;
    }

    .login__mark {
        display: inline-grid;
        place-items: center;
        width: 44px;
        height: 44px;
        margin-block-end: var(--s-3);
        border-radius: var(--r-md);
        background: var(--solid);
        color: var(--on-solid);
    }

    .login__card h1 {
        font-size: var(--fs-lg);
    }

    .login__sub {
        margin-block: 2px var(--s-4);
        color: var(--text-mute);
        font-size: var(--fs-sm);
    }

    .login__foot {
        margin-block-start: var(--s-4);
        color: var(--text-faint);
        font-size: var(--fs-xs);
    }

    .pin-dots {
        display: flex;
        justify-content: center;
        gap: 9px;
        margin-block: var(--s-4);
        direction: ltr;
    }

    .pin-dots span {
        width: 11px;
        height: 11px;
        border: 2px solid var(--border-strong);
        border-radius: var(--r-full);
        transition: background var(--d-1) var(--ease), border-color var(--d-1) var(--ease);
    }

    .pin-dots span.is-on {
        background: var(--solid);
        border-color: var(--solid);
    }

    .pad {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
        direction: ltr;
    }

    .pad button {
        min-height: 48px;
        padding: 12px 0;
        background: var(--surface-hover);
        border: 1px solid var(--border);
        border-radius: var(--r-sm);
        color: var(--text);
        font-size: var(--fs-md);
        font-weight: 600;
        transition: background var(--d-1) var(--ease), border-color var(--d-1) var(--ease);
    }

    .pad button:hover {
        background: var(--accent-soft);
        border-color: var(--accent);
    }

    .pad button:active {
        transform: translateY(1px);
    }

    .pad button[data-pin-enter] {
        background: var(--solid);
        border-color: var(--solid);
        color: var(--on-solid);
    }

    .pad button[data-pin-enter]:hover {
        background: var(--solid-hover);
        border-color: var(--solid-hover);
    }

    .login__card.is-shaking {
        animation: shake var(--d-3) var(--ease);
    }

    @keyframes shake {
        25% { transform: translateX(-5px); }
        50% { transform: translateX(5px); }
        75% { transform: translateX(-3px); }
    }

    /* ═══ نموذج المفصلة ═════════════════════════════════════════ */
    .panel--form {
        max-width: 620px;
    }

    .icon-grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
        gap: 6px;
    }

    .icon-opt input {
        position: absolute;
        opacity: 0;
        pointer-events: none;
    }

    .icon-opt__box {
        display: grid;
        place-items: center;
        aspect-ratio: 1;
        background: var(--surface-hover);
        border: 1px solid var(--border);
        border-radius: var(--r-sm);
        color: var(--text-mute);
        cursor: pointer;
        transition: background var(--d-1) var(--ease),
                    border-color var(--d-1) var(--ease),
                    color var(--d-1) var(--ease);
    }

    .icon-opt__box:hover {
        background: var(--accent-soft);
        color: var(--accent);
    }

    .icon-opt input:checked + .icon-opt__box {
        background: var(--accent-soft);
        border-color: var(--accent);
        color: var(--accent);
    }

    .icon-opt input:focus-visible + .icon-opt__box {
        outline: 2px solid var(--accent);
        outline-offset: 2px;
    }

    .field-group {
        border: 0;
        padding: 0;
        margin-inline: 0;
        min-inline-size: 0;
    }

    .field-group > legend {
        padding: 0;
    }

    .color-grid {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
        align-items: center;
    }

    .swatch-btn {
        width: 28px;
        height: 28px;
        background: var(--c, var(--border-strong));
        border: 2px solid transparent;
        border-radius: var(--r-sm);
        box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
        transition: transform var(--d-1) var(--ease), border-color var(--d-1) var(--ease);
    }

    .swatch-btn:hover {
        transform: scale(1.08);
    }

    .swatch-btn.is-on {
        border-color: var(--text);
    }

    .color-picker {
        width: 34px;
        height: 28px;
        padding: 2px;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--r-sm);
        cursor: pointer;
    }

    .preview {
        display: flex;
        align-items: center;
        gap: var(--s-3);
        padding: var(--s-3);
        background: var(--surface-hover);
        border: 1px dashed var(--border-strong);
        border-radius: var(--r-md);
    }

    .preview__icon {
        display: grid;
        place-items: center;
        width: 36px;
        height: 36px;
        flex: none;
        border-radius: var(--r-sm);
        background: color-mix(in srgb, var(--c, var(--accent)) 14%, transparent);
        color: color-mix(in srgb, var(--c, var(--accent)) 78%, var(--text));
    }

    .preview__title {
        display: block;
        overflow: hidden;
        font-weight: 600;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .preview__host {
        display: block;
        overflow: hidden;
        color: var(--text-faint);
        font-size: var(--fs-xs);
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .form-actions {
        display: flex;
        flex-wrap: wrap-reverse;
        align-items: center;
        justify-content: space-between;
        gap: var(--s-2);
        margin-block-start: var(--s-5);
        padding-block-start: var(--s-4);
        border-block-start: 1px solid var(--border);
    }

    /* ═══ سجل النشاط ════════════════════════════════════════════ */
    .log {
        max-height: 260px;
        overflow: auto;
        padding: var(--s-3);
        background: var(--surface-sunken);
        border-radius: var(--r-sm);
        color: var(--text-mute);
        font-size: var(--fs-xs);
        line-height: 1.9;
        white-space: pre;
    }

    /* ═══ مقبض السحب ════════════════════════════════════════════ */
    .card__grip {
        display: grid;
        place-items: center;
        width: 14px;
        flex: none;
        align-self: stretch;
        color: var(--text-faint);
        opacity: 0.35;
        cursor: grab;
        transition: opacity var(--d-1) var(--ease);
    }

    .card:hover .card__grip {
        opacity: 1;
    }

    .card__grip:active {
        cursor: grabbing;
    }

    .collection[data-view="list"] .card__grip {
        width: 10px;
    }

    /* ═══ تبديل المظهر: أيقونتان، واحدة ظاهرة ══════════════════ */
    .theme-ico--sun {
        display: none;
    }

    html[data-theme="dark"] .theme-ico--sun {
        display: block;
    }

    html[data-theme="dark"] .theme-ico--moon {
        display: none;
    }

    /* أيقونة اتجاهية تُعكس في RTL */
    html[dir="rtl"] .icon-flip-rtl {
        display: inline-flex;
        transform: scaleX(-1);
    }

    /* سهم «نقل لأعلى»: دوران 180° لأيقونة chevron */
    .icon-up {
        transform: rotate(180deg);
    }
}
