/* ==================== الأنماط الأصلية ==================== */
h1:focus {
    outline: none;
}

.valid.modified:not([type=checkbox]) {
    outline: 1px solid #26b050;
}

.invalid {
    outline: 1px solid #e50000;
}

.validation-message {
    color: #e50000;
}

.blazor-error-boundary {
    background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwLjE4NSA5Mi4xODMxIDI5MC41NDUgOTIuNzk1IDI5MC42NTYgOTIuOTk2QzI5MC44NzcgOTMuNTEzIDI5MSA5NC4wODE1IDI5MSA5NC42NzgyIDI5MSA5Ny4wNjUxIDI4OS4wMzggOTkgMjg2LjYxNyA5OUwyNDAuMzgzIDk5QzIzNy45NjMgOTkgMjM2IDk3LjA2NTEgMjM2IDk0LjY3ODIgMjM2IDk0LjM3OTkgMjM2LjAzMSA5NC4wODg2IDIzNi4wODkgOTMuODA3MkwyMzYuMzM4IDkzLjAxNjIgMjM2Ljg1OCA5Mi4xMzE0IDI1OS40NzMgNTMuNjI5NCAyNTkuOTYxIDUyLjc5ODUgMjYwLjQwNyA1Mi4yNjU4QzI2MS4yIDUxLjQ4MzcgMjYyLjI5NiA1MSAyNjMuNTA2IDUxWk0yNjMuNTg2IDY2LjAxODNDMjYwLjczNyA2Ni4wMTgzIDI1OS4zMTMgNjcuMTI0NSAyNTkuMzEzIDY5LjMzNyAyNTkuMzEzIDY5LjYxMDIgMjU5LjMzMiA2OS44NjA4IDI1OS4zNzEgNzAuMDg4N0wyNjEuNzk1IDg0LjAxNjEgMjY1LjM4IDg0LjAxNjEgMjY3LjgyMSA2OS43NDc1QzI2Ny44NiA2OS43MzA5IDI2Ny44NzkgNjkuNTg3NyAyNjcuODc5IDY5LjMxNzkgMjY3Ljg3OSA2Ny4xMTgyIDI2Ni40NDggNjYuMDE4MyAyNjMuNTg2IDY2LjAxODNaTTI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121;
    padding: 1rem 1rem 1rem 3.7rem;
    color: white;
}

    .blazor-error-boundary::after {
        content: "An error has occurred.";
    }

.darker-border-checkbox.form-check-input {
    border-color: #929292;
}

.form-floating > .form-control-plaintext::placeholder,
.form-floating > .form-control::placeholder {
    color: var(--bs-secondary-color);
    text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder,
.form-floating > .form-control:focus::placeholder {
    text-align: start;
}

/* ==================== المتغيرات — Light ==================== */
:root {
    --bg: #f4f5f9;
    --surface: #ffffff;
    --surface-2: #f8f9fc;
    --border: #e5e8f0;
    --text: #0f172a;
    --text-muted: #64748b;
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #eef2ff;
    --success: #10b981;
    --success-dark: #059669;
    --danger: #ef4444;
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, .06);
    --shadow-md: 0 4px 14px rgba(15, 23, 42, .08);
    --radius: 16px;
    --radius-sm: 12px;
    --dim-scanner: rgba(8, 8, 20, .70);
    --dim-camera: rgba(8, 8, 20, .75);
    --dim-crop: rgba(10, 10, 20, .92);
    --dim-detail: rgba(8, 8, 20, .60);
}

/* ==================== المتغيرات — Dark ==================== */
[data-theme="dark"] {
    --bg: #0f1419;
    --surface: #1a1f26;
    --surface-2: #232932;
    --border: #2d333d;
    --text: #e8eaed;
    --text-muted: #9aa0a6;
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #1e1b4b;
    --success: #10b981;
    --success-dark: #059669;
    --danger: #ef4444;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, .3);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, .4);
    --dim-scanner: rgba(0, 0, 0, .78);
    --dim-camera: rgba(0, 0, 0, .82);
    --dim-crop: rgba(0, 0, 0, .95);
    --dim-detail: rgba(0, 0, 0, .72);
}

/* ==================== انتقال سلس للثيم ==================== */
html, body,
.app-shell,
.group-card,
.group-info,
.product-item,
.topbar,
.topbar-title,
.app-header,
.carousel-blazor,
.form-card,
.field input,
.field textarea,
.detail-modal,
.detail-content,
.detail-actions,
.cart-item,
.order-card,
.search-input-wrap,
.icon-btn {
    transition: background-color .25s ease, color .25s ease, border-color .25s ease;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Tahoma, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    font-size: 15px;
    overscroll-behavior-y: contain;
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
}

input, textarea {
    font-family: inherit;
    -webkit-user-select: text;
    user-select: text;
}

/* ==================== الهيكل ==================== */
.app-shell {
    max-width: 640px;
    margin: 0 auto;
    padding: 14px 12px calc(78px + env(safe-area-inset-bottom, 0px));
    min-height: 100vh;
}

@supports (padding: env(safe-area-inset-top)) {
    .app-shell {
        padding-top: calc(14px + env(safe-area-inset-top));
        padding-left: calc(12px + env(safe-area-inset-left));
        padding-right: calc(12px + env(safe-area-inset-right));
    }

    .topbar {
        top: calc(8px + env(safe-area-inset-top));
    }
}

/* ==================== الرأس ==================== */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
    padding: 4px 2px;
}

    .app-header h1 {
        font-size: 1.35rem;
        font-weight: 800;
        margin: 0;
    }

    .app-header p {
        margin: 2px 0 0;
        font-size: .78rem;
        color: var(--text-muted);
    }

.search-btn-header {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    font-size: 1.1rem;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background .2s, border-color .2s;
}

    .search-btn-header:hover {
        background: var(--primary-light);
        border-color: var(--primary);
    }

/* ==================== الكاروسيل ==================== */
.carousel-blazor {
    position: relative;
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 16px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    aspect-ratio: 16 / 7;
}

.carousel-image-wrap {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: linear-gradient(135deg, var(--primary-light), var(--primary));
    position: relative;
}

    .carousel-image-wrap img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        display: block;
        animation: carouselFadeIn .45s ease;
    }

@keyframes carouselFadeIn {
    from {
        opacity: 0;
        transform: scale(1.03);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.carousel-dots {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 6px;
    z-index: 5;
    padding: 5px 10px;
    background: rgba(0, 0, 0, .35);
    border-radius: 20px;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.carousel-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: rgba(255, 255, 255, .5);
    border: none;
    padding: 0;
    cursor: pointer;
    transition: width .25s ease, background .25s ease;
}

    .carousel-dot.active {
        width: 20px;
        border-radius: 4px;
        background: #fff;
    }

/* ==================== شبكة المجموعات ==================== */
.groups-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

@media (min-width: 480px) {
    .groups-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 720px) {
    .groups-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ==================== الشريط العلوي ==================== */
.topbar {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface);
    padding: 8px;
    border-radius: 14px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    margin-bottom: 14px;
    position: sticky;
    top: 8px;
    z-index: 40;
    backdrop-filter: blur(8px);
}

.icon-btn {
    width: 38px;
    height: 38px;
    border-radius: 11px;
    background: var(--surface-2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.05rem;
    border: 1px solid var(--border);
    transition: background .2s, transform .15s, color .2s, border-color .2s;
    flex-shrink: 0;
    color: var(--text);
}

    .icon-btn:active {
        transform: scale(.93);
    }

    .icon-btn:hover {
        background: var(--primary-light);
        color: var(--primary);
        border-color: var(--primary);
    }

.topbar-title {
    flex: 1;
    font-weight: 700;
    font-size: .95rem;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    padding: 9px 14px;
    border-radius: 11px;
    font-weight: 700;
    font-size: .82rem;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    box-shadow: 0 3px 10px rgba(79, 70, 229, .28);
    transition: background .2s, transform .15s;
    flex-shrink: 0;
    white-space: nowrap;
}

    .btn-primary:hover {
        background: var(--primary-dark);
    }

    .btn-primary:active {
        transform: scale(.96);
    }

/* ==================== نموذج الإضافة ==================== */
.form-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 18px 14px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    margin-bottom: 16px;
    animation: formSlideIn .22s cubic-bezier(.34, 1.3, .64, 1);
}

@keyframes formSlideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==================== الصورة ==================== */
.image-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 18px;
}

.image-preview {
    width: 110px;
    height: 110px;
    border-radius: 50%;
    overflow: hidden;
    border: 3px solid var(--primary-light);
    background: var(--surface-2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.4rem;
    color: var(--text-muted);
    box-shadow: var(--shadow-sm);
}

    .image-preview img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

.image-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.chip-btn {
    padding: 7px 14px;
    border-radius: 22px;
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 700;
    font-size: .78rem;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    transition: background .2s, transform .15s;
    border: none;
    font-family: inherit;
}

    .chip-btn:hover {
        background: var(--primary-light);
        filter: brightness(.95);
    }

    .chip-btn:active {
        transform: scale(.95);
    }

    .chip-btn.danger {
        background: rgba(239, 68, 68, .12);
        color: var(--danger);
    }

        .chip-btn.danger:hover {
            background: rgba(239, 68, 68, .2);
        }

/* ==================== الحقول ==================== */
.field {
    margin-bottom: 13px;
}

    .field label {
        display: block;
        font-size: .78rem;
        font-weight: 700;
        color: var(--text-muted);
        margin-bottom: 5px;
    }

    .field input, .field textarea {
        width: 100%;
        padding: 11px 13px;
        border: 1.5px solid var(--border);
        border-radius: var(--radius-sm);
        font-size: .92rem;
        background: var(--surface-2);
        color: var(--text);
        outline: none;
        transition: border-color .2s, background .2s, box-shadow .2s;
    }

        .field input:focus, .field textarea:focus {
            border-color: var(--primary);
            background: var(--surface);
            box-shadow: 0 0 0 4px rgba(79, 70, 229, .12);
        }

    .field textarea {
        resize: vertical;
        min-height: 70px;
        line-height: 1.5;
    }

/* ==================== الباركود ==================== */
.barcode-wrap {
    display: flex;
    gap: 8px;
}

    .barcode-wrap input {
        flex: 1;
        cursor: pointer;
        font-family: 'Courier New', monospace;
        letter-spacing: 1px;
        font-weight: 600;
    }

.scan-btn {
    width: 46px;
    border-radius: var(--radius-sm);
    background: var(--primary);
    color: #fff;
    font-size: 1.15rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .2s, transform .15s;
    box-shadow: 0 3px 10px rgba(79, 70, 229, .28);
}

    .scan-btn:hover {
        background: var(--primary-dark);
    }

    .scan-btn:active {
        transform: scale(.93);
    }

/* ==================== أزرار النموذج ==================== */
.form-actions {
    display: flex;
    gap: 10px;
    margin-top: 16px;
}

.btn-save {
    flex: 1;
    padding: 12px;
    background: var(--success);
    color: #fff;
    border-radius: var(--radius-sm);
    font-weight: 700;
    font-size: .92rem;
    box-shadow: 0 3px 10px rgba(16, 185, 129, .3);
    transition: background .2s, transform .15s;
}

    .btn-save:hover {
        background: var(--success-dark);
    }

    .btn-save:active {
        transform: scale(.97);
    }

.btn-cancel {
    padding: 12px 20px;
    background: var(--surface-2);
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    font-weight: 700;
    font-size: .88rem;
    border: 1px solid var(--border);
    transition: background .2s;
}

    .btn-cancel:hover {
        background: var(--surface);
    }

/* ==================== الحالات الفارغة ==================== */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

    .empty-state .emoji {
        font-size: 3.2rem;
        margin-bottom: 14px;
        opacity: .55;
        display: block;
    }

    .empty-state p {
        margin: 4px 0;
        font-size: .9rem;
    }

    .empty-state .hint {
        font-size: .76rem;
        opacity: .75;
    }

/* ==================== التنبيهات ==================== */
.alert {
    padding: 11px 14px;
    border-radius: var(--radius-sm);
    font-size: .85rem;
    margin-bottom: 12px;
}

.alert-danger {
    background: rgba(239, 68, 68, .12);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, .25);
}

/* ==================== الأزرار العائمة ==================== */
.fab-bar {
    position: fixed;
    bottom: calc(76px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 10px;
    z-index: 150;
    animation: fabBarIn .25s cubic-bezier(.34, 1.3, .64, 1);
    will-change: transform, opacity;
}

@keyframes fabBarIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

.fab {
    height: 52px;
    padding: 0 22px;
    border-radius: 26px;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-weight: 700;
    font-size: .88rem;
    color: #fff;
    border: none;
    cursor: pointer;
    transition: transform .15s ease, box-shadow .2s ease;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    white-space: nowrap;
}

    .fab svg {
        width: 18px;
        height: 18px;
        fill: currentColor;
    }

    .fab:active {
        transform: scale(.95);
    }

.fab-scan {
    background: linear-gradient(135deg, #4f46e5, #4338ca);
    box-shadow: 0 6px 20px rgba(79, 70, 229, .45);
}

    .fab-scan:hover {
        box-shadow: 0 10px 26px rgba(79, 70, 229, .55);
    }

.fab-add {
    background: linear-gradient(135deg, #10b981, #059669);
    box-shadow: 0 6px 20px rgba(16, 185, 129, .45);
}

    .fab-add:hover {
        box-shadow: 0 10px 26px rgba(16, 185, 129, .55);
    }

/* ==================== نظام النوافذ الموحّد ==================== */
.overlay-base {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity .18s ease, visibility 0s linear .18s;
}

    .overlay-base.active {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
        transition: opacity .18s ease, visibility 0s linear 0s;
    }

.modal-base {
    transform: scale(.96) translateY(8px);
    opacity: 0;
    transition: transform .22s cubic-bezier(.34, 1.3, .64, 1), opacity .18s ease;
    will-change: transform, opacity;
}

.overlay-base.active .modal-base {
    transform: scale(1) translateY(0);
    opacity: 1;
}

/* ==================== الكاميرا ==================== */
.camera-overlay {
    background: var(--dim-camera);
}

.camera-modal {
    background: #16162a;
    border-radius: 22px;
    padding: 14px;
    width: 100%;
    max-width: 460px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .75), 0 0 0 1px rgba(255, 255, 255, .06);
}

.camera-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    color: #fff;
}

    .camera-head h5 {
        margin: 0;
        font-size: .95rem;
        font-weight: 700;
    }

.camera-head-actions {
    display: flex;
    gap: 8px;
}

.camera-icon-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(255,255,255,.1);
    color: #fff;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .2s;
    border: none;
    cursor: pointer;
}

    .camera-icon-btn:hover {
        background: rgba(255,255,255,.22);
    }

#camera-view {
    border-radius: 14px;
    overflow: hidden;
    background: #000;
    min-height: 260px;
}

    #camera-view video {
        width: 100% !important;
        height: auto !important;
        display: block;
    }

.camera-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 24px;
    margin-top: 16px;
    padding-bottom: 4px;
}

.shutter-btn {
    width: 68px;
    height: 68px;
    border-radius: 50%;
    background: #fff;
    border: 4px solid rgba(255,255,255,.35);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .6);
    cursor: pointer;
    transition: transform .12s, box-shadow .2s;
    position: relative;
    flex-shrink: 0;
}

    .shutter-btn:active {
        transform: scale(.92);
        box-shadow: 0 0 0 3px rgba(79, 70, 229, .9);
    }

    .shutter-btn::after {
        content: '';
        position: absolute;
        inset: 6px;
        border-radius: 50%;
        background: #fff;
        border: 2px solid #e5e8f0;
    }

.camera-side-btn {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: rgba(255,255,255,.12);
    color: #fff;
    font-size: 1.3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .2s;
    border: none;
    cursor: pointer;
    flex-shrink: 0;
}

    .camera-side-btn:hover {
        background: rgba(255,255,255,.25);
    }

.camera-hint {
    text-align: center;
    color: #9ca3af;
    font-size: .78rem;
    margin-top: 10px;
}

/* ==================== القصاص (شاشة كاملة) ==================== */
.crop-fullscreen {
    padding: 0;
    align-items: stretch;
    justify-content: stretch;
    background: var(--dim-crop);
    flex-direction: column;
}

.crop-topbar {
    padding: 12px 16px;
    padding-top: calc(12px + env(safe-area-inset-top, 0px));
    background: #16162a;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
    flex-shrink: 0;
}

.crop-title {
    color: #fff;
    font-weight: 700;
    font-size: .95rem;
    margin-bottom: 10px;
    text-align: center;
}

.crop-ratio-buttons {
    display: flex;
    gap: 6px;
    justify-content: center;
    flex-wrap: wrap;
}

.ratio-btn {
    padding: 8px 16px;
    border-radius: 20px;
    background: rgba(255, 255, 255, .1);
    color: #e5e7eb;
    font-size: .8rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: background .15s, color .15s;
    white-space: nowrap;
    min-width: 54px;
    font-family: inherit;
}

    .ratio-btn:hover {
        background: rgba(255, 255, 255, .18);
    }

    .ratio-btn.active {
        background: var(--primary);
        color: #fff;
    }

.crop-container {
    flex: 1;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    min-height: 0;
}

#crop-target {
    display: block;
    max-width: 100%;
    max-height: 100%;
}

.crop-error {
    padding: 10px 16px;
    background: #7f1d1d;
    color: #fee2e2;
    font-size: .85rem;
    text-align: center;
    flex-shrink: 0;
}

.crop-toolbar {
    padding: 12px 16px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    display: flex;
    gap: 10px;
    background: #16162a;
    border-top: 1px solid rgba(255, 255, 255, .08);
    flex-shrink: 0;
}

.btn-crop-cancel,
.btn-crop-confirm {
    flex: 1;
    padding: 14px;
    border-radius: 14px;
    font-weight: 700;
    font-size: .95rem;
    border: none;
    cursor: pointer;
    transition: opacity .15s, transform .12s;
    font-family: inherit;
    min-width: 0;
}

.btn-crop-cancel {
    background: rgba(255, 255, 255, .1);
    color: #fff;
}

.btn-crop-confirm {
    background: linear-gradient(135deg, #4f46e5, #4338ca);
    color: #fff;
    box-shadow: 0 4px 14px rgba(79, 70, 229, .4);
}

    .btn-crop-cancel:disabled,
    .btn-crop-confirm:disabled {
        opacity: .6;
        cursor: not-allowed;
    }

    .btn-crop-confirm:active:not(:disabled),
    .btn-crop-cancel:active:not(:disabled) {
        transform: scale(.97);
    }

/* ==================== تفاصيل المنتج — الأساسي ==================== */
.detail-overlay {
    background: var(--dim-detail);
}

.detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}

    .detail-header h5 {
        margin: 0;
        font-size: 1rem;
        font-weight: 700;
    }

.detail-img {
    width: 140px;
    height: 140px;
    border-radius: 20px;
    object-fit: cover;
    margin: 0 auto 14px;
    display: block;
    background: var(--surface-2);
    border: 1px solid var(--border);
}

.detail-img-empty {
    width: 140px;
    height: 140px;
    border-radius: 20px;
    margin: 0 auto 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-2);
    border: 1px solid var(--border);
    font-size: 3rem;
    color: var(--text-muted);
}

.detail-barcode {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: 'Courier New', monospace;
    font-size: .85rem;
    background: var(--primary-light);
    color: var(--primary);
    padding: 6px 14px;
    border-radius: 8px;
    font-weight: 700;
    letter-spacing: 1px;
    margin-bottom: 8px;
}

.btn-edit {
    padding: 13px 18px;
    background: var(--primary);
    color: #fff;
    border-radius: 12px;
    font-weight: 700;
    font-size: .9rem;
    box-shadow: 0 3px 10px rgba(79, 70, 229, .3);
}

    .btn-edit:hover {
        background: var(--primary-dark);
    }

.btn-delete {
    padding: 13px 18px;
    background: rgba(239, 68, 68, .12);
    color: var(--danger);
    border-radius: 12px;
    font-weight: 700;
    font-size: .9rem;
}

    .btn-delete:hover {
        background: rgba(239, 68, 68, .2);
    }

/* ==================== صفحة البحث ==================== */
.search-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
}

.search-input-wrap {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: 14px;
    padding: 0 12px;
    transition: border-color .2s, box-shadow .2s;
    box-shadow: var(--shadow-sm);
    height: 44px;
    min-width: 0;
}

    .search-input-wrap:focus-within {
        border-color: var(--primary);
        box-shadow: 0 0 0 4px rgba(79, 70, 229, .12);
    }

.search-icon {
    font-size: .95rem;
    color: var(--text-muted);
    margin-left: 6px;
    flex-shrink: 0;
}

.search-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 10px 6px;
    font-size: .95rem;
    color: var(--text);
    outline: none;
    font-family: inherit;
    min-width: 0;
}

    .search-input::placeholder {
        color: var(--text-muted);
    }

.search-clear {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: .8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
    flex-shrink: 0;
    transition: background .15s;
}

    .search-clear:hover {
        background: rgba(239, 68, 68, .15);
        color: var(--danger);
    }

.search-count {
    font-size: .82rem;
    color: var(--text-muted);
    margin-bottom: 10px;
    padding: 0 4px;
}

    .search-count strong {
        color: var(--primary);
        font-weight: 800;
    }

.search-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    margin-top: 5px;
}

.search-group-tag {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: .7rem;
    background: var(--surface-2);
    color: var(--text-muted);
    padding: 2px 8px;
    border-radius: 6px;
    border: 1px solid var(--border);
    font-weight: 600;
}

.search-price {
    display: inline-flex;
    align-items: center;
    font-size: .75rem;
    background: rgba(16, 185, 129, .12);
    color: var(--success);
    padding: 2px 8px;
    border-radius: 6px;
    font-weight: 800;
}

.search-add-cart {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--success);
    color: #fff;
    font-size: 1.2rem;
    font-weight: 800;
    border: none;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(16, 185, 129, .35);
    transition: transform .15s;
}

    .search-add-cart:active {
        transform: scale(.9);
    }

/* ==================== صفحة السلة ==================== */
.cart-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.cart-info {
    flex: 1;
    min-width: 0;
}

.cart-price {
    font-size: .8rem;
    color: var(--success);
    font-weight: 700;
    margin-top: 2px;
}

.cart-qty {
    display: inline-flex;
    align-items: center;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 20px;
    overflow: hidden;
    flex-shrink: 0;
}

    .cart-qty button {
        width: 30px;
        height: 30px;
        background: none;
        border: none;
        font-size: 1.1rem;
        font-weight: 700;
        color: var(--primary);
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .cart-qty span {
        min-width: 26px;
        text-align: center;
        font-weight: 700;
        font-size: .9rem;
    }

.cart-remove {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: rgba(239, 68, 68, .12);
    color: var(--danger);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .8rem;
    flex-shrink: 0;
}

.cart-total {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px;
    margin: 14px 0;
    background: var(--primary-light);
    border-radius: var(--radius);
    font-weight: 700;
}

    .cart-total strong {
        color: var(--primary);
        font-size: 1.15rem;
        font-weight: 800;
    }

/* ==================== لوحة الإدارة — الطلبات ==================== */
.order-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.order-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

    .order-head strong {
        font-size: 1rem;
        margin-left: 6px;
    }

.order-status {
    font-size: .7rem;
    padding: 3px 10px;
    border-radius: 12px;
    font-weight: 700;
    background: var(--surface-2);
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.order-status-جديد {
    background: rgba(245, 158, 11, .15);
    color: #f59e0b;
    border-color: rgba(245, 158, 11, .3);
}

.order-status-قيد {
    background: rgba(59, 130, 246, .15);
    color: #3b82f6;
    border-color: rgba(59, 130, 246, .3);
}

.order-time {
    color: var(--text-muted);
    font-size: .7rem;
    font-family: 'Courier New', monospace;
}

.order-visitor {
    background: var(--surface-2);
    padding: 8px 12px;
    border-radius: 10px;
    font-size: .85rem;
    border: 1px solid var(--border);
}

    .order-visitor a {
        color: var(--primary);
        text-decoration: none;
        font-weight: 700;
        font-family: 'Courier New', monospace;
    }

.order-items {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.order-item {
    display: flex;
    justify-content: space-between;
    font-size: .85rem;
    padding: 4px 0;
    border-bottom: 1px dashed var(--border);
}

    .order-item:last-child {
        border-bottom: none;
    }

.order-total {
    text-align: left;
    font-size: .9rem;
    padding-top: 6px;
    border-top: 2px solid var(--border);
}

    .order-total strong {
        color: var(--success);
        font-size: 1rem;
    }

.order-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.btn-mini {
    padding: 7px 14px;
    border-radius: 10px;
    font-size: .78rem;
    font-weight: 700;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    cursor: pointer;
    transition: background .15s;
}

    .btn-mini:hover {
        background: var(--surface);
    }

.btn-mini-success {
    background: var(--success);
    color: #fff;
    border-color: var(--success);
}

    .btn-mini-success:hover {
        background: var(--success-dark);
    }

.btn-mini-danger {
    background: rgba(239, 68, 68, .12);
    color: var(--danger);
    border-color: rgba(239, 68, 68, .25);
}

    .btn-mini-danger:hover {
        background: rgba(239, 68, 68, .2);
    }

/* ==================== إصلاح Cropper.js ==================== */
.cropper-container {
    direction: ltr !important;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

.cropper-bg {
    background-image: none !important;
}

/* ==================== شاشات صغيرة ==================== */
@media (max-width: 380px) {
    .app-shell {
        padding: 10px 10px calc(78px + env(safe-area-inset-bottom, 0px));
    }

    .app-header h1 {
        font-size: 1.2rem;
    }

    .group-emoji {
        width: 30px;
        height: 30px;
        font-size: .95rem;
    }

    .image-preview {
        width: 96px;
        height: 96px;
    }

    .product-thumb {
        width: 52px;
        height: 52px;
    }

    .product-name {
        font-size: .88rem;
    }

    .fab {
        height: 48px;
        padding: 0 18px;
        font-size: .82rem;
    }

        .fab svg {
            width: 16px;
            height: 16px;
        }

    .carousel-blazor {
        aspect-ratio: 16 / 8;
    }

    .search-btn-header {
        width: 38px;
        height: 38px;
        font-size: 1rem;
    }

    .ratio-btn {
        padding: 7px 12px;
        font-size: .75rem;
        min-width: 46px;
    }

    .bottom-tabs {
        height: 56px;
    }

    .tab-icon {
        font-size: 1.25rem;
    }

    .tab-label {
        font-size: .62rem;
    }
}

@media (max-width: 340px) {
    .tab-label {
        display: none;
    }

    .tab {
        gap: 0;
    }
}

@media screen and (display-mode: standalone) {
    body::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: env(safe-area-inset-top, 0px);
        background: var(--bg);
        z-index: 9999;
    }
}

/* ==================== شبكة المجموعات (تعريف ثاني) ==================== */
.groups-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
    padding: 12px;
    padding-bottom: 100px;
}

/* ==================== بطاقة المجموعة ==================== */
.group-card {
    display: block;
    position: relative;
    aspect-ratio: 1 / 1;
    border-radius: 18px;
    overflow: hidden;
    cursor: pointer;
    background: var(--surface);
    border: 1px solid var(--border);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
    text-decoration: none;
    color: inherit;
    content-visibility: auto;
    contain-intrinsic-size: 0 180px;
}

    .group-card:active {
        filter: brightness(0.85);
    }

    .group-card.reveal {
        opacity: 0;
        transform: translateY(14px);
        transition: opacity .3s cubic-bezier(.22, .61, .36, 1), transform .3s cubic-bezier(.22, .61, .36, 1);
        transition-delay: var(--reveal-delay, 0ms);
    }

        .group-card.reveal.is-visible {
            opacity: 1;
            transform: translateY(0);
            transition-delay: 0ms, 0ms;
        }

.group-media {
    position: absolute;
    top: 0;
    inset-inline: 0;
    height: 70%;
    background: var(--bg);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

    .group-media img {
        position: absolute;
        inset: 0;
        width: 100%;
        height: 100%;
        object-fit: cover;
        object-position: center;
        display: block;
    }

.group-media-empty {
    font-size: 56px;
}

.group-info {
    position: absolute;
    bottom: 0;
    inset-inline: 0;
    height: 30%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 4px 8px;
    box-sizing: border-box;
    background: var(--surface);
    overflow: hidden;
}

.group-name {
    font-weight: 800;
    font-size: 14px;
    line-height: 1.2;
    color: var(--text);
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.group-count {
    font-size: 11px;
    line-height: 1.2;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ==================== الشريط العلوي ==================== */
.topbar-title {
    display: flex;
    align-items: center;
    gap: 8px;
}

.topbar-thumb {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    object-fit: cover;
    background: var(--surface-2);
}

/* ==================== مودال التفاصيل ==================== */
.detail-overlay {
    position: fixed;
    inset: 0;
    background: var(--dim-detail);
    backdrop-filter: blur(3px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
    z-index: 100;
}

    .detail-overlay.active {
        opacity: 1;
        pointer-events: auto;
    }

.detail-modal {
    width: 100%;
    max-width: 440px;
    max-height: 85vh;
    background: var(--surface);
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(12px) scale(.98);
    transition: transform .25s ease;
}

.detail-overlay.active .detail-modal {
    transform: translateY(0) scale(1);
}

.detail-body {
    padding: 0;
    overflow-y: auto;
    flex: 1;
}

.detail-hero {
    position: relative;
    width: 100%;
    height: 280px;
    overflow: hidden;
    background: var(--bg);
    isolation: isolate;
}

.detail-hero-bg {
    position: absolute;
    inset: -30px;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    filter: blur(28px) saturate(1.25) brightness(.85);
    opacity: .55;
    z-index: 0;
    transform: scale(1.1);
    pointer-events: none;
}

[data-theme="dark"] .detail-hero-bg {
    filter: blur(28px) saturate(1.25) brightness(.55);
    opacity: .45;
}

.detail-hero img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
    padding: 12px;
    box-sizing: border-box;
    display: block;
    z-index: 1;
}

.detail-hero-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 72px;
    color: var(--text-muted);
}

.detail-hero-close {
    position: absolute;
    top: 10px;
    inset-inline-start: 10px;
    z-index: 2;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, .45);
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s ease;
}

    .detail-hero-close:active {
        background: rgba(0, 0, 0, .7);
    }

.detail-content {
    padding: 16px;
}

.detail-name {
    font-size: 20px;
    font-weight: 800;
    margin-bottom: 6px;
    color: var(--text);
}

.detail-desc {
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-muted);
    margin-bottom: 14px;
}

.detail-price {
    display: inline-block;
    font-size: 18px;
    font-weight: 800;
    color: var(--primary);
    background: rgba(79, 70, 229, .12);
    padding: 6px 16px;
    border-radius: 999px;
}

[data-theme="dark"] .detail-price {
    background: rgba(99, 102, 241, .18);
}

.detail-actions {
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
    background: var(--surface);
}

.btn-add-cart {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 14px;
    background: var(--primary);
    color: #fff;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: transform .12s ease;
}

    .btn-add-cart:active {
        transform: scale(.97);
    }

/* ==================== بطاقة المنتج ==================== */
.product-item {
    position: relative !important;
    display: flex !important;
    align-items: center !important;
    padding: 12px !important;
    padding-inline-start: 116px !important;
    padding-inline-end: 62px !important;
    height: 116px !important;
    box-sizing: border-box !important;
    background: var(--surface) !important;
    border: 1px solid var(--border) !important;
    border-radius: 16px !important;
    overflow: hidden !important;
    cursor: pointer;
    color: var(--text);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
    content-visibility: auto;
    contain-intrinsic-size: 0 116px;
}

    .product-item:active {
        filter: brightness(0.9) !important;
    }

    .product-item.reveal {
        opacity: 0;
        transform: translateY(14px);
        transition: opacity .3s cubic-bezier(.22, .61, .36, 1), transform .3s cubic-bezier(.22, .61, .36, 1);
        transition-delay: var(--reveal-delay, 0ms);
    }

        .product-item.reveal.is-visible {
            opacity: 1;
            transform: translateY(0);
            transition-delay: 0ms, 0ms;
        }

.product-info {
    flex: 1 !important;
    min-width: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: center !important;
}

.product-name {
    font-weight: 700;
    font-size: 15px;
    margin-bottom: 3px;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.product-desc {
    font-size: 12.5px;
    color: var(--text-muted);
    line-height: 1.35;
    margin-bottom: 6px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.product-price {
    display: inline-block;
    align-self: flex-start;
    font-size: 13.5px;
    font-weight: 700;
    color: var(--primary);
    background: rgba(79, 70, 229, .12);
    padding: 2px 10px;
    border-radius: 999px;
}

[data-theme="dark"] .product-price {
    background: rgba(99, 102, 241, .18);
}

.product-add {
    position: absolute !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    inset-inline-end: 12px !important;
    width: 38px !important;
    height: 38px !important;
    border: none !important;
    border-radius: 50% !important;
    background: var(--primary) !important;
    color: #fff !important;
    font-size: 22px !important;
    line-height: 1 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

    .product-add:active {
        filter: brightness(0.85) !important;
    }

/* ==================== قائمة المنتجات ==================== */
.products-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
    padding-bottom: 100px;
}
