@use '../globals' as *;

/**
 * Settings Page Styles
 *
 * Styles for the plugin settings page with tabbed interface.
 *
 * @package MultilingualPressZone
 * @since 1.0.0
 */

.multilingual-press-zone-settings {
    max-width: 1200px;
    margin: 0 auto;
    padding: $spacing-lg;

    // Header
    &__header {
        margin-bottom: $spacing-xl;

        h1 {
            margin-bottom: $spacing-sm;
            color: $text-primary;
        }

        .description {
            color: $text-secondary;
            font-size: 14px;
            margin: 0;
        }
    }

    // Content container
    &__content {
        background: $background-white;
        border: 1px solid $border-color;
        border-radius: $border-radius-md;
        padding: $spacing-lg;
        margin-top: $spacing-lg;
    }
}

// Settings sections
.settings-section {
    h2 {
        margin-bottom: $spacing-lg;
        padding-bottom: $spacing-md;
        border-bottom: 2px solid $border-color;
        color: $text-primary;
        font-size: 18px;
        font-weight: 600;
    }

    h3 {
        margin-top: $spacing-lg;
        margin-bottom: $spacing-md;
        color: $text-primary;
        font-size: 16px;
        font-weight: 600;
    }

    .description {
        color: $text-secondary;
        font-size: 13px;
        margin-top: $spacing-xs;
        line-height: 1.5;
    }

    // Spacing between form groups
    > * + * {
        margin-top: $spacing-lg;
    }
}

// API Key wrapper with show/hide button
.api-key-wrapper {
    display: flex;
    gap: $spacing-sm;
    align-items: center;

    input {
        flex: 1;
    }

    button {
        flex-shrink: 0;
    }
}

// API actions (test button + status)
.api-actions {
    display: flex;
    gap: $spacing-md;
    align-items: center;
    margin-top: $spacing-lg;
}

// Connection status indicator
.connection-status {
    display: flex;
    align-items: center;
    gap: $spacing-sm;
    font-size: 14px;

    .status-success {
        display: flex;
        align-items: center;
        gap: $spacing-xs;
        color: $success-color;
        font-weight: 500;
    }

    .status-error {
        display: flex;
        align-items: center;
        gap: $spacing-xs;
        color: $error-color;
        font-weight: 500;
    }

    .status-unknown {
        color: $text-secondary;
    }
}

// Cache statistics
.cache-stats {
    background: $background-light;
    border: 1px solid $border-color;
    border-radius: $border-radius-md;
    padding: $spacing-lg;
    margin: $spacing-lg 0;

    h3 {
        margin-top: 0;
        margin-bottom: $spacing-md;
    }
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: $spacing-md;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: $spacing-sm $spacing-md;
    background: $background-white;
    border: 1px solid $border-color;
    border-radius: $border-radius-sm;

    .stat-label {
        color: $text-secondary;
        font-size: 13px;
        font-weight: 500;
    }

    .stat-value {
        color: $text-primary;
        font-size: 16px;
        font-weight: 600;
    }
}

// Danger zone
.danger-zone {
    margin-top: $spacing-xl;
    padding: $spacing-lg;
    background: lighten($error-color, 45%);
    border: 1px solid lighten($error-color, 30%);
    border-radius: $border-radius-md;

    h3 {
        margin-top: 0;
        color: $error-color;
    }

    .description {
        color: darken($error-color, 10%);
        margin-bottom: $spacing-md;
    }
}

// Modal actions
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: $spacing-sm;
    margin-top: $spacing-lg;
    padding-top: $spacing-md;
    border-top: 1px solid $border-color;
}

// Loading state
.multilingual-press-zone-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: $spacing-xl;
    min-height: 300px;

    p {
        margin-top: $spacing-md;
        color: $text-secondary;
    }
}

.multilingual-press-zone-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid $border-color;
    border-top-color: $primary-color;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

// Error state
.multilingual-press-zone-error {
    padding: $spacing-xl;
    text-align: center;
    color: $error-color;

    .error-message {
        margin-top: $spacing-md;
        padding: $spacing-md;
        background: lighten($error-color, 45%);
        border: 1px solid lighten($error-color, 30%);
        border-radius: $border-radius-md;
        color: darken($error-color, 10%);
        font-weight: 500;
    }
}

/* ==========================================================================
   Exceptions Tab
   ========================================================================== */

.tpz-exceptions {

    // Add exception form row
    &__add-form {
        display: flex;
        gap: $spacing-sm;
        align-items: center;
        margin-bottom: $spacing-lg;
    }

    &__text-input {
        flex: 1;
        min-width: 0;
    }

    &__match-select {
        flex-shrink: 0;
        min-width: 120px;
    }

    // Exceptions table
    &__table {
        width: 100%;
        border-collapse: collapse;
        border: 1px solid $border-color;
        border-radius: $border-radius-md;
        margin-bottom: $spacing-lg;

        th,
        td {
            padding: $spacing-sm $spacing-md;
            text-align: left;
            border-bottom: 1px solid $border-color;
        }

        th {
            background: $background-light;
            font-weight: 600;
            font-size: 13px;
            color: $text-secondary;
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        td {
            font-size: 14px;
            color: $text-primary;
        }

        tbody tr:last-child td {
            border-bottom: none;
        }

        tbody tr:hover {
            background: $background-light;
        }
    }

    &__cell-text {
        word-break: break-word;
    }

    &__cell-type {
        width: 120px;
    }

    &__cell-actions {
        width: 60px;
        text-align: center;
    }

    // Empty state
    &__empty {
        color: $text-secondary;
        font-style: italic;
        padding: $spacing-md 0;
    }

    // Bulk import section
    &__bulk {
        margin-top: $spacing-lg;
        padding-top: $spacing-lg;
        border-top: 1px solid $border-color;
    }

    &__bulk-textarea {
        width: 100%;
        resize: vertical;
        min-height: 100px;
        font-family: inherit;
        font-size: 14px;
        padding: $spacing-sm $spacing-md;
        border: 1px solid $border-color;
        border-radius: $border-radius-sm;

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

    &__bulk-actions {
        margin-top: $spacing-sm;
    }

    // Sync status bar
    &__sync {
        display: flex;
        align-items: center;
        gap: $spacing-md;
        margin-top: $spacing-lg;
        padding-top: $spacing-md;
        border-top: 1px solid $border-color;
    }

    &__sync-dot {
        width: 8px;
        height: 8px;
        border-radius: 50%;
        flex-shrink: 0;

        &--synced {
            background-color: #16a34a;
        }

        &--unsynced {
            background-color: #dc2626;
        }

        &--pending {
            background-color: #f59e0b;
            animation: tpz-pulse 1.2s ease-in-out infinite;
        }
    }

    &__sync-text {
        color: $text-secondary;
        font-size: 13px;
    }
}

@keyframes tpz-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ==========================================================================
   Responsive Design
   ========================================================================== */

@media screen and (max-width: 782px) {
    .multilingual-press-zone-settings {
        padding: $spacing-md;

        &__content {
            padding: $spacing-md;
        }
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .api-key-wrapper {
        flex-direction: column;
        align-items: stretch;

        button {
            width: 100%;
        }
    }

    .api-actions {
        flex-direction: column;
        align-items: stretch;

        button {
            width: 100%;
        }
    }

    .modal-actions {
        flex-direction: column;

        button {
            width: 100%;
        }
    }

    .tpz-exceptions {
        &__add-form {
            flex-direction: column;
            align-items: stretch;

            input,
            select {
                min-width: 0;
                width: 100%;
            }

            button {
                width: 100%;
            }
        }

        &__sync {
            flex-direction: column;
            align-items: flex-start;
        }
    }
}

/* ==========================================================================
   Dark Mode Support
   ========================================================================== */

@media (prefers-color-scheme: dark) {
    .multilingual-press-zone-settings {
        &__header {
            h1 {
                color: $dark-text;
            }

            .description {
                color: lighten($text-secondary, 20%);
            }
        }

        &__content {
            background: $dark-surface;
            border-color: $dark-border;
        }
    }

    .settings-section {
        h2, h3 {
            color: $dark-text;
            border-color: $dark-border;
        }

        .description {
            color: lighten($text-secondary, 20%);
        }
    }

    .cache-stats {
        background: $dark-bg;
        border-color: $dark-border;
    }

    .stat-item {
        background: $dark-surface;
        border-color: $dark-border;

        .stat-label {
            color: lighten($text-secondary, 20%);
        }

        .stat-value {
            color: $dark-text;
        }
    }

    .danger-zone {
        background: rgba($error-color, 0.1);
        border-color: rgba($error-color, 0.3);

        .description {
            color: lighten($error-color, 20%);
        }
    }

    .multilingual-press-zone-loading p {
        color: lighten($text-secondary, 20%);
    }

    .multilingual-press-zone-spinner {
        border-color: $dark-border;
        border-top-color: lighten($primary-color, 15%);
    }

    .multilingual-press-zone-error {
        .error-message {
            background: rgba($error-color, 0.1);
            border-color: rgba($error-color, 0.3);
            color: lighten($error-color, 20%);
        }
    }

    .tpz-exceptions {
        &__table {
            border-color: $dark-border;

            th {
                background: $dark-bg;
                color: $dark-text;
                border-color: $dark-border;
            }

            td {
                color: $dark-text;
                border-color: $dark-border;
            }

            tbody tr:hover {
                background: $dark-bg;
            }
        }

        &__empty {
            color: lighten($text-secondary, 20%);
        }

        &__bulk {
            border-color: $dark-border;
        }

        &__bulk-textarea {
            background: $dark-bg;
            color: $dark-text;
            border-color: $dark-border;
        }

        &__sync {
            border-color: $dark-border;
        }

        &__sync-text {
            color: lighten($text-secondary, 20%);
        }
    }
}

// Explicit dark mode class (WordPress admin color scheme)
body.admin-color-midnight,
body.admin-color-ectoplasm {
    .multilingual-press-zone-settings {
        &__header {
            h1 {
                color: $dark-text;
            }

            .description {
                color: lighten($text-secondary, 20%);
            }
        }

        &__content {
            background: $dark-surface;
            border-color: $dark-border;
        }
    }

    .settings-section {
        h2, h3 {
            color: $dark-text;
            border-color: $dark-border;
        }

        .description {
            color: lighten($text-secondary, 20%);
        }
    }

    .cache-stats {
        background: $dark-bg;
        border-color: $dark-border;
    }

    .stat-item {
        background: $dark-surface;
        border-color: $dark-border;

        .stat-label {
            color: lighten($text-secondary, 20%);
        }

        .stat-value {
            color: $dark-text;
        }
    }
}
