/* =========================================================================
   modern-swal.css
   shadcn-style DARK dialog chrome for SweetAlert2. Fixed neutral colours -
   no theme tinting. Matches https://ui.shadcn.com/docs/components/radix/dialog
   - Black popup, subtle border, generous padding
   - Left-aligned header (title + description)
   - Inputs: zinc-900 background, zinc-800 border, white focus ring
   - Primary (Confirm): white background, black text
   - Cancel: transparent, zinc-800 border, white text
   - Destructive: red background, white text
   ========================================================================= */

:root {
    --ms-bg: #0a0a0a; /* popup background (near-black) */
    --ms-bg-elevated: #18181b; /* inputs / nested surfaces */
    --ms-bg-hover: #27272a;
    --ms-border: #27272a;
    --ms-border-soft: #1f1f23;
    --ms-text: #fafafa;
    --ms-text-muted: #a1a1aa;
    --ms-text-subtle: #71717a;
    --ms-text-placeholder: #52525b;
    --ms-ring: rgba(255, 255, 255, 0.30);

    /* Destructive */
    --ms-destructive: #dc2626;
    --ms-destructive-hover: #b91c1c;
}

/* ----- popup ----- */
.modern-swal-popup {
    background: var(--ms-bg) !important;
    color: var(--ms-text) !important;
    border: 1px solid var(--ms-border) !important;
    border-radius: 12px !important;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7),
    0 0 0 1px rgba(255, 255, 255, 0.02) inset !important;
    padding: 1.5rem !important;
    overflow: hidden;
    max-width: calc(100vw - 32px) !important; /* no horizontal scroll on small viewports */
    position: relative;
    /* No open/close transition - instant snap */
    transition: none !important;
    animation: none !important;
}

.modern-swal-popup .swal2-html-container {
    overflow-x: hidden !important;
}

.swal2-container.ms-backdrop {
    transition: none !important;
    animation: none !important;
}

@media (min-width: 640px) {
    .modern-swal-popup {
        padding: 1.75rem !important;
    }
}

/* ----- header (left-aligned, shadcn-style) ----- */
.modern-swal-popup .ms-header {
    text-align: left;
    margin-bottom: 1rem;
}

.modern-swal-popup .ms-title {
    color: var(--ms-text);
    font-size: 18px;
    font-weight: 600;
    line-height: 1.25;
    margin: 0 0 6px 0;
    letter-spacing: -0.01em;
}

.modern-swal-popup .ms-body {
    color: var(--ms-text-muted);
    font-size: 14px;
    line-height: 1.45;
    margin: 0;
}

/* ----- form labels ----- */
.modern-swal-popup .ms-label {
    display: block;
    color: var(--ms-text);
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 6px;
    text-align: left;
}

/* ----- inputs ----- */
.modern-swal-popup .ms-input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: var(--ms-bg-elevated);
    border: 1px solid var(--ms-border);
    border-radius: 8px;
    color: var(--ms-text);
    font-size: 14px;
    line-height: 1.5;
    transition: border-color .15s ease, box-shadow .15s ease;
}

.modern-swal-popup .ms-input::placeholder {
    color: var(--ms-text-placeholder);
}

.modern-swal-popup .ms-input:hover {
    border-color: var(--ms-bg-hover);
}

.modern-swal-popup .ms-input:focus {
    outline: none;
    border-color: var(--ms-text);
    box-shadow: 0 0 0 3px var(--ms-ring);
}

.modern-swal-popup .ms-input[readonly] {
    color: var(--ms-text-subtle);
    cursor: not-allowed;
}

/* ----- generic dark surface (callouts) ----- */
.modern-swal-popup .ms-card {
    background: var(--ms-bg-elevated);
    border: 1px solid var(--ms-border-soft);
    border-radius: 10px;
    padding: 12px;
}

/* ----- buttons (shadcn variants) ----- */
.modern-swal-popup .ms-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    line-height: 1;
    height: 36px;
    transition: background-color .15s ease, color .15s ease, border-color .15s ease, opacity .15s ease;
}

.modern-swal-popup .ms-btn:disabled {
    opacity: 0.5;
    pointer-events: none;
}

/* Primary - white bg, black text (shadcn `default` on dark) */
.modern-swal-popup .ms-btn-confirm {
    background: var(--ms-text);
    color: #0a0a0a;
    border: 1px solid var(--ms-text);
}

.modern-swal-popup .ms-btn-confirm:hover {
    background: #e4e4e7;
    border-color: #e4e4e7;
}

/* Outline - transparent, border, white text (shadcn `outline` on dark) */
.modern-swal-popup .ms-btn-cancel {
    background: transparent;
    color: var(--ms-text);
    border: 1px solid var(--ms-border);
}

.modern-swal-popup .ms-btn-cancel:hover {
    background: var(--ms-bg-elevated);
    border-color: var(--ms-bg-hover);
}

/* Destructive - red bg, white text (shadcn `destructive`) */
.modern-swal-popup .ms-btn-danger {
    background: var(--ms-destructive);
    color: #ffffff;
    border: 1px solid var(--ms-destructive);
}

.modern-swal-popup .ms-btn-danger:hover {
    background: var(--ms-destructive-hover);
    border-color: var(--ms-destructive-hover);
}

/* ----- close button (top-right X) ----- */
.modern-swal-popup .ms-close {
    color: var(--ms-text-subtle) !important;
    font-size: 18px !important;
    top: 12px !important;
    right: 14px !important;
    transition: color .15s ease;
    opacity: 0.7;
}

.modern-swal-popup .ms-close:hover {
    color: var(--ms-text) !important;
    opacity: 1;
}

/* ----- actions row ----- */
.modern-swal-popup .swal2-actions.ms-actions {
    display: flex !important;
    gap: 0.5rem !important;
    margin-top: 1.5rem !important;
    width: 100% !important;
    justify-content: flex-end !important;
    flex-wrap: wrap !important;
}

@media (max-width: 640px) {
    .modern-swal-popup .swal2-actions.ms-actions {
        justify-content: stretch !important;
    }

    .modern-swal-popup .swal2-actions.ms-actions .ms-btn {
        flex: 1;
        min-width: 0;
    }
}

/* ----- validation message ----- */
.modern-swal-popup .ms-validation {
    background: rgba(220, 38, 38, 0.10) !important;
    color: #fca5a5 !important;
    border: 1px solid rgba(220, 38, 38, 0.30) !important;
    border-radius: 8px !important;
    margin: 0.75rem 0 0 !important;
    padding: 0.5rem 0.75rem !important;
    font-size: 13px !important;
    display: flex !important;
    align-items: center !important;
    gap: 0.5rem !important;
}

.modern-swal-popup .ms-validation::before {
    display: none !important;
}

/* ----- backdrop ----- */
.swal2-container.ms-backdrop {
    background: rgba(0, 0, 0, 0.65) !important;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

/* ----- spinner card (modernSwal.loading) ----- */
.modern-swal-popup .ms-spinner-wrap {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 10px;
    background: var(--ms-bg-elevated);
    border: 1px solid var(--ms-border);
    color: var(--ms-text);
    margin: 0 auto 0.875rem;
}

/* ----- centered variant (used by success / error / loading where there's no form) ----- */
.modern-swal-popup .ms-header-centered {
    text-align: center;
}

.modern-swal-popup .ms-header-centered .ms-body {
    margin-left: auto;
    margin-right: auto;
    max-width: 24rem;
}

/* ----- status icon badge (success / error / warning / info / danger) ----- */
.modern-swal-popup .ms-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 999px;
    font-size: 22px;
    line-height: 1;
    margin: 0 0 0.875rem; /* left-aligned headers (e.g. danger) */
}

.modern-swal-popup .ms-header-centered .ms-icon {
    margin-left: auto;
    margin-right: auto;
}

.modern-swal-popup .ms-icon-success {
    background: rgba(16, 185, 129, 0.12);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.30);
}

.modern-swal-popup .ms-icon-error {
    background: rgba(220, 38, 38, 0.12);
    color: #f87171;
    border: 1px solid rgba(220, 38, 38, 0.30);
}

.modern-swal-popup .ms-icon-warning {
    background: rgba(245, 158, 11, 0.12);
    color: #fbbf24;
    border: 1px solid rgba(245, 158, 11, 0.30);
}

.modern-swal-popup .ms-icon-info {
    background: rgba(59, 130, 246, 0.12);
    color: #60a5fa;
    border: 1px solid rgba(59, 130, 246, 0.30);
}

/* ----- callouts: important notes inside dialogs -----
   Use instead of dim grey hints whenever the user MUST notice something.
   info = neutral note, warn = caution / prerequisites, danger = destructive. */
.modern-swal-popup .ms-callout {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.55;
    text-align: left;
}

.modern-swal-popup .ms-callout i {
    margin-top: 2px;
    font-size: 13px;
}

.modern-swal-popup .ms-callout strong {
    font-weight: 600;
}

.modern-swal-popup .ms-callout-info {
    background: rgba(59, 130, 246, 0.10);
    border: 1px solid rgba(59, 130, 246, 0.25);
    color: #bfdbfe;
}

.modern-swal-popup .ms-callout-info i {
    color: #60a5fa;
}

.modern-swal-popup .ms-callout-info strong {
    color: #dbeafe;
}

.modern-swal-popup .ms-callout-warn {
    background: rgba(245, 158, 11, 0.10);
    border: 1px solid rgba(245, 158, 11, 0.28);
    color: #fde68a;
}

.modern-swal-popup .ms-callout-warn i {
    color: #fbbf24;
}

.modern-swal-popup .ms-callout-warn strong {
    color: #fef3c7;
}

.modern-swal-popup .ms-callout-danger {
    background: rgba(220, 38, 38, 0.10);
    border: 1px solid rgba(220, 38, 38, 0.30);
    color: #fecaca;
}

.modern-swal-popup .ms-callout-danger i {
    color: #f87171;
}

.modern-swal-popup .ms-callout-danger strong {
    color: #fee2e2;
}

/* ----- helper: section spacing inside extra content ----- */
.modern-swal-popup .ms-extra {
    text-align: left;
}

.modern-swal-popup .ms-extra > * + * {
    margin-top: 0.875rem;
}

/* =========================================================================
   Apps picker widget (admin_user.php → Apps button dialog)
   Lives inside .modern-swal-popup .ms-extra
   ========================================================================= */
.ms-section-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--ms-text-muted);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    margin: 0 0 0.5rem;
}

/* Quick package picker */
.ms-pkg-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.ms-pkg-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    background: var(--ms-bg-elevated);
    border: 1px solid var(--ms-border);
    color: var(--ms-text);
    cursor: pointer;
    transition: background-color .12s ease, border-color .12s ease, color .12s ease;
}

.ms-pkg-btn:hover {
    background: var(--ms-bg-hover);
    border-color: var(--ms-bg-hover);
}

.ms-pkg-btn::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: var(--pkg-dot, var(--ms-text-subtle));
    box-shadow: 0 0 8px 0 var(--pkg-dot, transparent);
    opacity: 0.85;
}

/* Toolbar (filter + counters) */
.ms-apps-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.ms-apps-toolbar .ms-input {
    flex: 1 1 200px;
    min-width: 0;
}

.ms-apps-counter {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--ms-bg-elevated);
    border: 1px solid var(--ms-border);
    border-radius: 8px;
    color: var(--ms-text-muted);
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}

.ms-apps-counter strong {
    color: var(--ms-text);
    font-weight: 600;
}

/* Master controls */
.ms-master-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    padding: 8px 12px;
    background: var(--ms-bg-elevated);
    border: 1px solid var(--ms-border-soft);
    border-radius: 8px;
}

.ms-master-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--ms-text);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    user-select: none;
}

/* Scrollable apps area */
.ms-apps-scroll {
    max-height: 55vh;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 4px;
    margin-right: -4px;
}

.ms-apps-scroll::-webkit-scrollbar {
    width: 10px;
}

.ms-apps-scroll::-webkit-scrollbar-track {
    background: transparent;
}

.ms-apps-scroll::-webkit-scrollbar-thumb {
    background: var(--ms-bg-hover);
    border-radius: 999px;
    border: 2px solid var(--ms-bg);
}

.ms-apps-scroll::-webkit-scrollbar-thumb:hover {
    background: var(--ms-text-subtle);
}

/* Category card - sits under the popup background, holds the elevated app items */
.ms-category {
    background: #131316;
    border: 1px solid var(--ms-border);
    border-radius: 10px;
    overflow: hidden;
}

.ms-category + .ms-category {
    margin-top: 8px;
}

.ms-category-head {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: transparent;
    border: 0;
    cursor: pointer;
    color: var(--ms-text);
    transition: background-color .12s ease;
}

.ms-category-head:hover {
    background: var(--ms-bg-hover);
}

.ms-category-head .ms-cat-title {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    font-weight: 600;
}

.ms-category-head .ms-cat-pill {
    font-size: 11px;
    font-weight: 500;
    color: var(--ms-text-muted);
    background: var(--ms-bg);
    border: 1px solid var(--ms-border);
    border-radius: 999px;
    padding: 2px 8px;
}

.ms-category-head svg {
    width: 16px;
    height: 16px;
    color: var(--ms-text-subtle);
    transition: transform .15s ease;
}

.ms-category-head.is-collapsed svg {
    transform: rotate(-90deg);
}

.ms-category-body {
    display: grid;
    grid-template-columns: repeat(1, minmax(0, 1fr));
    gap: 8px;
    padding: 0 10px 10px;
}

@media (min-width: 640px) {
    .ms-category-body {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (min-width: 1024px) {
    .ms-category-body {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

/* App item card - elevated above the category card so it pops */
.ms-app-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 11px;
    background: #27272a; /* zinc-800 - lighter than the category card */
    border: 1px solid #3f3f46; /* zinc-700 - clearly visible separator */
    border-radius: 8px;
    cursor: pointer;
    transition: background-color .12s ease, border-color .12s ease;
    min-width: 0;
    overflow: hidden;
}

.ms-app-item:hover {
    background: #3f3f46;
    border-color: #52525b;
}

.ms-app-item.is-on {
    background: #3f3f46;
    border-color: #a1a1aa; /* bright outline when active */
}

.ms-app-item input[type="checkbox"] {
    display: none;
}

/* Custom checkbox indicator */
.ms-check {
    flex: 0 0 auto;
    width: 18px;
    height: 18px;
    border-radius: 4px;
    background: #18181b;
    border: 1.5px solid #71717a; /* zinc-500 - readable empty state */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: transparent;
    transition: background-color .12s, border-color .12s, color .12s;
}

.ms-app-item.is-on .ms-check {
    background: var(--ms-text);
    border-color: var(--ms-text);
    color: #0a0a0a;
}

.ms-check::after {
    content: '';
    width: 11px;
    height: 11px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' fill='%230a0a0a'%3E%3Cpath d='M10.207 3.293a1 1 0 0 1 0 1.414l-5 5a1 1 0 0 1-1.414 0l-2-2a1 1 0 1 1 1.414-1.414L4.5 7.586l4.293-4.293a1 1 0 0 1 1.414 0z'/%3E%3C/svg%3E");
    background-size: contain;
    background-repeat: no-repeat;
    opacity: 0;
    transform: scale(0.6);
    transition: opacity .12s ease, transform .12s ease;
}

.ms-app-item.is-on .ms-check::after {
    opacity: 1;
    transform: scale(1);
}

.ms-app-meta {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-width: 0;
    gap: 2px;
    overflow: hidden;
}

.ms-app-name {
    color: var(--ms-text);
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ms-app-key {
    color: #a1a1aa; /* zinc-400 - readable on the lighter card */
    font-size: 11px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Hide native SweetAlert2 icon/title since we draw our own */
.modern-swal-popup .swal2-icon {
    display: none !important;
}

.modern-swal-popup .swal2-title {
    display: none !important;
}

.modern-swal-popup .swal2-html-container {
    margin: 0 !important;
    padding: 0 !important;
    color: inherit !important;
}
