// ============================================
// ADMIN SETTINGS - Mobile-First Compact Design
// ============================================
@import '../admin-shared.scss';

.admin-settings {
    min-height: 100%;
    padding: $admin-space-md;
    padding-bottom: calc($admin-space-md + 80px);
    animation: pageEnter 0.4s ease-out;

    @media (min-width: 768px) {
        padding: $admin-space-lg;
        padding-bottom: $admin-space-lg;
    }

    .container {
        display: grid;
        gap: $admin-space-sm;
        max-width: $admin-container-lg;
        margin: 0 auto;
    }
}

// ============================================
// LOADING STATE
// ============================================
.loading-wrapper {
    background: $glass-bg;
    backdrop-filter: blur(20px);
    border: 1px solid $glass-border;
    border-radius: $radius-md;
    padding: $admin-space-lg;
    text-align: center;
    animation: fadeIn 0.3s ease-out;

    .spinner {
        width: 32px;
        height: 32px;
        margin: 0 auto $admin-space-sm;
        border: 3px solid rgba($color-brand-primary, 0.15);
        border-top-color: $color-brand-primary;
        border-radius: 50%;
        animation: spin 0.7s linear infinite;
    }

    p {
        margin: 0;
        font-size: 0.8125rem;
        color: $color-text-secondary;
        font-weight: 600;
    }
}

// ============================================
// SETTINGS CONTENT
// ============================================
.settings-content {
    display: grid;
    gap: $admin-space-sm;
}

.settings-form {
    display: grid;
    gap: $admin-space-sm;
}

// ============================================
// SETTINGS SECTIONS
// ============================================
.settings-section {
    background: $glass-bg;
    backdrop-filter: blur(20px);
    border: 1px solid $glass-border;
    border-radius: $radius-md;
    padding: $admin-space-sm;
    transition: all 0.2s ease;
    animation: staggerFade 0.3s ease-out backwards;

    @for $i from 1 through 10 {
        &:nth-child(#{$i}) {
            animation-delay: #{$i * 50}ms;
        }
    }

    &:hover {
        box-shadow: $shadow-sm;
    }

    @media (min-width: 768px) {
        padding: $admin-space-md;
    }
}

.section-title {
    display: flex;
    align-items: center;
    gap: $admin-space-xs;
    margin: 0 0 $admin-space-sm;
    font-size: 0.9375rem;
    font-weight: 700;
    background: $gradient-primary;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;

    .material-symbols-outlined,
    app-icon {
        font-size: 1.25rem;
        background: $gradient-primary;
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;
    }
}

// ============================================
// FORM GROUPS
// ============================================
.form-group {
    margin-bottom: $admin-space-sm;

    &:last-child {
        margin-bottom: 0;
    }
}

.form-label {
    display: flex;
    align-items: center;
    gap: $admin-space-2xs;
    margin-bottom: 4px;
    font-size: 0.6875rem;
    font-weight: 600;
    color: $color-text-secondary;
    text-transform: uppercase;
    letter-spacing: 0.02em;

    .hint {
        font-weight: 400;
        color: $color-text-tertiary;
        text-transform: none;
        letter-spacing: 0;
    }
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: $admin-space-xs $admin-space-sm;
    background: white;
    border: 1px solid $border-default;
    border-radius: $radius-sm;
    font-size: 0.8125rem;
    color: $color-text-primary;
    transition: all 0.15s ease;

    &:focus {
        outline: none;
        border-color: $color-brand-primary;
        box-shadow: 0 0 0 3px rgba($color-brand-primary, 0.1);
    }

    &::placeholder {
        color: $color-text-tertiary;
    }

    &:disabled {
        background: $color-gray-50;
        cursor: not-allowed;
    }
}

.form-textarea {
    min-height: 80px;
    resize: vertical;
}

.form-help {
    margin-top: 4px;
    font-size: 0.6875rem;
    color: $color-text-tertiary;
}

// ============================================
// FORM ROW (2 Columns)
// ============================================
.form-row {
    display: grid;
    gap: $admin-space-sm;

    @media (min-width: 480px) {
        grid-template-columns: repeat(2, 1fr);
    }
}

// ============================================
// TOGGLE SWITCH
// ============================================
.toggle-group {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: $admin-space-xs 0;
    border-bottom: 1px solid rgba($border-default, 0.5);

    &:last-child {
        border-bottom: none;
    }
}

.toggle-info {
    flex: 1;
    min-width: 0;
    padding-right: $admin-space-sm;

    .toggle-label {
        font-size: 0.8125rem;
        font-weight: 600;
        color: $color-text-primary;
    }

    .toggle-description {
        font-size: 0.6875rem;
        color: $color-text-tertiary;
        margin-top: 2px;
    }
}

.toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
    flex-shrink: 0;

    input {
        opacity: 0;
        width: 0;
        height: 0;

        &:checked + .toggle-slider {
            background: $color-brand-primary;

            &::before {
                transform: translateX(20px);
            }
        }

        &:focus + .toggle-slider {
            box-shadow: 0 0 0 3px rgba($color-brand-primary, 0.2);
        }
    }
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: $color-gray-200;
    border-radius: $radius-full;
    transition: all 0.2s ease;

    &::before {
        content: '';
        position: absolute;
        height: 18px;
        width: 18px;
        left: 3px;
        bottom: 3px;
        background: white;
        border-radius: 50%;
        box-shadow: 0 1px 3px rgba(black, 0.15);
        transition: all 0.2s ease;
    }
}

// ============================================
// COLOR PICKER
// ============================================
.color-input-group {
    display: flex;
    gap: $admin-space-xs;
    align-items: center;
}

.color-preview {
    width: 32px;
    height: 32px;
    border-radius: $radius-sm;
    border: 1px solid $border-default;
    cursor: pointer;
    transition: all 0.15s ease;

    &:hover {
        transform: scale(1.05);
    }
}

.color-input {
    flex: 1;
}

// ============================================
// API KEY / PASSWORD FIELD
// ============================================
.password-input-group {
    position: relative;

    .form-input {
        padding-right: 40px;
    }

    .toggle-visibility {
        position: absolute;
        right: 8px;
        top: 50%;
        transform: translateY(-50%);
        width: 28px;
        height: 28px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: transparent;
        border: none;
        border-radius: $radius-sm;
        color: $color-text-tertiary;
        cursor: pointer;
        transition: all 0.15s ease;

        &:hover {
            background: $color-gray-100;
            color: $color-text-primary;
        }
    }
}

// ============================================
// BUTTONS
// ============================================
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: $admin-space-xs $admin-space-sm;
    border-radius: $radius-sm;
    font-weight: 600;
    font-size: 0.75rem;
    border: none;
    cursor: pointer;
    transition: all 0.15s ease;

    app-icon,
    .material-symbols-outlined {
        font-size: 0.9375rem;
    }

    &--primary {
        background: $gradient-primary;
        color: white;

        &:hover:not(:disabled) {
            transform: translateY(-1px);
            box-shadow: 0 4px 12px rgba($color-brand-primary, 0.3);
        }
    }

    &--secondary {
        background: $color-gray-100;
        color: $color-text-secondary;

        &:hover:not(:disabled) {
            background: $color-gray-200;
        }
    }

    &--ghost {
        background: transparent;
        color: $color-brand-primary;

        &:hover:not(:disabled) {
            background: rgba($color-brand-primary, 0.08);
        }
    }

    &--danger {
        background: rgba($accent-red, 0.1);
        color: $accent-red;

        &:hover:not(:disabled) {
            background: rgba($accent-red, 0.15);
        }
    }

    &:disabled {
        opacity: 0.5;
        cursor: not-allowed;
    }
}

// ============================================
// SAVE BAR
// ============================================
.save-bar {
    position: fixed;
    bottom: 5rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: $admin-space-xs;
    padding: $admin-space-sm $admin-space-md;
    background: white;
    border-radius: $radius-md;
    box-shadow: $shadow-xl;
    z-index: 100;
    animation: popIn 0.3s ease-out;

    @media (min-width: 768px) {
        bottom: $admin-space-lg;
    }

    .btn {
        padding: $admin-space-xs $admin-space-md;
    }
}

// ============================================
// DANGER ZONE
// ============================================
.danger-zone {
    background: rgba($accent-red, 0.03);
    border-color: rgba($accent-red, 0.2);

    .section-title {
        background: linear-gradient(135deg, $accent-red, darken($accent-red, 10%));
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;

        .material-symbols-outlined,
        app-icon {
            background: linear-gradient(135deg, $accent-red, darken($accent-red, 10%));
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
    }
}

.danger-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: $admin-space-sm 0;
    border-bottom: 1px solid rgba($accent-red, 0.1);
    gap: $admin-space-sm;

    &:last-child {
        border-bottom: none;
        padding-bottom: 0;
    }

    @media (max-width: 480px) {
        flex-direction: column;
        align-items: stretch;
    }
}

.danger-info {
    flex: 1;

    h4 {
        font-size: 0.8125rem;
        font-weight: 600;
        color: $color-text-primary;
        margin: 0 0 2px;
    }

    p {
        font-size: 0.6875rem;
        color: $color-text-tertiary;
        margin: 0;
    }
}

// ============================================
// TOAST
// ============================================
.toast {
    position: fixed;
    bottom: 5rem;
    left: 50%;
    transform: translateX(-50%);
    padding: $admin-space-sm $admin-space-md;
    background: $color-gray-900;
    color: white;
    border-radius: $radius-md;
    font-size: 0.8125rem;
    font-weight: 500;
    box-shadow: $shadow-lg;
    z-index: 1000;
    animation: popIn 0.3s ease-out;

    &--success { background: $accent-green; }
    &--error { background: $accent-red; }

    @media (min-width: 768px) {
        bottom: $admin-space-lg;
    }
}

// ============================================
// CONFIRMATION MODAL
// ============================================
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(black, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: $admin-space-md;
    animation: fadeIn 0.2s ease-out;
}

.modal {
    width: 100%;
    max-width: 400px;
    background: white;
    border-radius: $radius-lg;
    box-shadow: $shadow-xl;
    overflow: hidden;
    animation: scaleIn 0.25s ease-out;

    &__header {
        display: flex;
        align-items: center;
        gap: $admin-space-xs;
        padding: $admin-space-sm $admin-space-md;
        border-bottom: 1px solid $border-default;

        app-icon,
        .material-symbols-outlined {
            font-size: 1.25rem;
            color: $accent-red;
        }

        h3 {
            font-size: 0.9375rem;
            font-weight: 700;
            color: $color-text-primary;
            margin: 0;
        }
    }

    &__body {
        padding: $admin-space-md;

        p {
            font-size: 0.8125rem;
            color: $color-text-secondary;
            margin: 0;
            line-height: 1.5;
        }
    }

    &__footer {
        display: flex;
        gap: $admin-space-xs;
        padding: $admin-space-sm $admin-space-md;
        border-top: 1px solid $border-default;
        justify-content: flex-end;
    }
}

// ============================================
// RESPONSIVE
// ============================================
@media (max-width: 640px) {
    .admin-settings {
        padding: $admin-space-sm;
        padding-bottom: calc($admin-space-sm + 80px);
    }

    .settings-section {
        padding: $admin-space-sm;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
