/* ═══════════════════════════════════════════════
   SessionFlow Admin — Components
   Modal, Toast, Notifications, Custom Select,
   Group Permissions
   ═══════════════════════════════════════════════ */

/* ═══════════════════════════════════════
   MODAL
   ═══════════════════════════════════════ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease;
}

.modal {
    width: 90%;
    max-width: 520px;
    max-height: 85vh;
    overflow-y: auto;
    animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 1.05rem;
    font-weight: 700;
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 24px;
    border-top: 1px solid var(--border);
}

/* ═══════════════════════════════════════
   TOAST
   ═══════════════════════════════════════ */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    padding: 14px 20px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideInRight 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    backdrop-filter: blur(20px);
    max-width: 380px;
    box-shadow: var(--shadow-lg);
}

.toast-success {
    background: rgba(16, 185, 129, 0.9);
    color: white;
}

.toast-error {
    background: rgba(239, 68, 68, 0.9);
    color: white;
}

.toast-warning {
    background: rgba(245, 158, 11, 0.9);
    color: white;
}

.toast-info {
    background: rgba(59, 130, 246, 0.9);
    color: white;
}

/* ═══════════════════════════════════════
   NOTIFICATION DROPDOWN
   ═══════════════════════════════════════ */
.notification-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 380px;
    max-height: 460px;
    background: var(--bg-secondary);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 500;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    overflow: hidden;
}

.notification-dropdown-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.notification-dropdown-header h4 {
    font-size: 0.95rem;
    font-weight: 700;
}

.notification-dropdown-header button {
    font-size: 0.75rem;
    color: var(--accent);
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 4px;
    transition: var(--transition);
}

.notification-dropdown-header button:hover {
    background: var(--accent-light);
}

.notification-dropdown-list {
    flex: 1;
    overflow-y: auto;
    max-height: 360px;
}

.notif-item {
    display: flex;
    gap: 12px;
    padding: 14px 20px;
    border-bottom: 1px solid rgba(99, 102, 241, 0.05);
    transition: var(--transition);
    cursor: pointer;
    align-items: flex-start;
}

.notif-item:hover {
    background: var(--bg-hover);
}

.notif-item.unread {
    background: var(--accent-light);
}

.notif-item.unread:hover {
    background: rgba(99, 102, 241, 0.12);
}

.notif-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    flex-shrink: 0;
    margin-top: 6px;
}

.notif-item:not(.unread) .notif-dot {
    background: var(--text-muted);
    opacity: 0.3;
}

.notif-content {
    flex: 1;
    min-width: 0;
}

.notif-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 2px;
}

.notif-message {
    font-size: 0.85rem;
    line-height: 1.4;
    color: var(--text-primary);
}

.notif-time {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.notif-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.notif-header-actions {
    display: flex;
    gap: 4px;
    align-items: center;
}

.notif-clear-btn {
    color: var(--danger) !important;
}

.notif-clear-btn:hover {
    background: rgba(239, 68, 68, 0.1) !important;
}

.notif-delete-btn {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    font-size: 1rem;
    color: var(--text-muted);
    cursor: pointer;
    opacity: 0;
    transition: var(--transition);
    margin-top: 2px;
}

.notif-item:hover .notif-delete-btn {
    opacity: 1;
}

.notif-delete-btn:hover {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
}

/* Search results highlight */
.search-highlight {
    background: rgba(99, 102, 241, 0.25);
    border-radius: 2px;
    padding: 0 2px;
}

/* ═══════════════════════════════════════
   GROUP WEBSITE PERMISSIONS
   ═══════════════════════════════════════ */

/* Toggle switch */
.perm-toggle-wrap {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
}

.perm-toggle-label {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    font-size: 0.88rem;
    color: var(--text-primary);
    user-select: none;
}

.perm-toggle-label input {
    display: none;
}

.perm-toggle-slider {
    display: inline-block;
    width: 38px;
    min-width: 38px;
    height: 20px;
    background: var(--border);
    border-radius: 20px;
    position: relative;
    transition: background 0.2s;
    flex-shrink: 0;
    overflow: hidden;
}

.perm-toggle-slider::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s;
}

.perm-toggle-label input:checked+.perm-toggle-slider {
    background: var(--accent);
}

.perm-toggle-label input:checked+.perm-toggle-slider::after {
    transform: translateX(18px);
}

.perm-toggle-hint {
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* Permission section */
.perm-website-section {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: rgba(0, 0, 0, 0.15);
}

.perm-toolbar {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}

.perm-website-list {
    max-height: 260px;
    overflow-y: auto;
    padding: 4px;
}

.perm-website-list::-webkit-scrollbar {
    width: 4px;
}

.perm-website-list::-webkit-scrollbar-track {
    background: transparent;
}

.perm-website-list::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.2);
    border-radius: 2px;
}

/* Website item */
.perm-website-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
    user-select: none;
}

.perm-website-item:hover {
    background: rgba(99, 102, 241, 0.06);
}

/* Custom checkbox */
.perm-website-item input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
    transition: all 0.15s;
}

.perm-website-item input[type="checkbox"]:checked {
    background: var(--accent);
    border-color: var(--accent);
}

.perm-website-item input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    top: 1px;
    left: 5px;
    width: 5px;
    height: 9px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.perm-website-info {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.perm-website-icon {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    object-fit: cover;
    flex-shrink: 0;
}

.perm-website-name {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.perm-website-cat {
    font-size: 0.7rem;
    padding: 1px 6px;
    border-radius: 20px;
    background: color-mix(in srgb, var(--cat-color) 15%, transparent);
    color: var(--cat-color);
    margin-left: 6px;
    white-space: nowrap;
}

.perm-website-url {
    font-size: 0.75rem;
    color: var(--text-muted);
    flex-shrink: 0;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.perm-counter {
    font-size: 0.78rem;
    color: var(--text-muted);
    padding: 8px 12px;
    text-align: right;
    border-top: 1px solid var(--border);
}

/* ═══════════════════════════════════════
   CUSTOM SELECT DROPDOWN
   ═══════════════════════════════════════ */

/* Hide native select when custom is active */
select.custom-select-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
    padding: 0 !important;
    margin: -1px !important;
}

/* Wrapper */
.custom-select-wrapper {
    position: relative;
    display: inline-block;
}

/* Trigger button */
.custom-select-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    transition: var(--transition);
    font-family: var(--font);
}

/* Size: select-sm (filter bars) */
.custom-select-wrapper.size-sm .custom-select-trigger {
    padding: 8px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    color: var(--text-primary);
}

/* Size: form-input (modals) */
.custom-select-wrapper.size-form .custom-select-trigger {
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    color: var(--text-primary);
    width: 100%;
}

/* Size: setting-value (settings page) */
.custom-select-wrapper.size-setting .custom-select-trigger {
    padding: 8px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    color: var(--text-primary);
    min-width: 120px;
}

/* Hover & focus state */
.custom-select-trigger:hover {
    border-color: var(--border-hover);
}

.custom-select-wrapper.open .custom-select-trigger {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

/* Label text */
.custom-select-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    text-align: left;
}

/* Chevron */
.custom-select-chevron {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    opacity: 0.5;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.custom-select-wrapper.open .custom-select-chevron {
    transform: rotate(180deg);
    opacity: 0.8;
}

/* Portal dropdown — appended to body, position:fixed to avoid overflow clipping */
.custom-select-dropdown-portal {
    position: fixed;
    max-height: 240px;
    overflow-y: auto;
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(99, 102, 241, 0.06);
    z-index: 99999;
    padding: 4px;
    opacity: 0;
    transform: translateY(-4px) scale(0.98);
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.custom-select-dropdown-portal.portal-open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Scrollbar */
.custom-select-dropdown-portal::-webkit-scrollbar {
    width: 4px;
}

.custom-select-dropdown-portal::-webkit-scrollbar-track {
    background: transparent;
}

.custom-select-dropdown-portal::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.2);
    border-radius: 2px;
}

/* Option item */
.custom-select-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
    user-select: none;
    white-space: nowrap;
}

.custom-select-option:hover {
    background: var(--accent-light);
    color: var(--text-primary);
}

.custom-select-option.selected {
    color: var(--accent);
    font-weight: 600;
}

.custom-select-option.selected:hover {
    background: var(--accent-light);
}

/* Checkmark for selected */
.custom-select-check {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    opacity: 0;
    color: var(--accent);
}

.custom-select-option.selected .custom-select-check {
    opacity: 1;
}