/* --- Modal (General for Settings & other standard modals) --- */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  /* z-index was moved to common.css for the base .modal rule */
  /* It can be overridden by more specific modals if needed */
  justify-content: center;
  align-items: center;
}

.modal.active { /* This class is typically added by JS to show the modal */
  display: flex;
}

.modal-content { /* General modal content box */
  background-color: var(--color-bg);
  border-radius: var(--border-radius);
  width: 90%;
  max-width: 500px; /* Default max-width, can be overridden */
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  max-height: 90vh;
  overflow-y: auto;
  display: flex; /* Added to make flex-direction column work for header/body/footer */
  flex-direction: column;
}

.modal-header {
  padding: calc(var(--spacing-unit) * 2);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0; /* Prevent header from shrinking */
}

.modal-header h2 {
  margin: 0;
  font-size: 1.2rem;
  color: var(--color-primary);
}

.modal-body {
  padding: calc(var(--spacing-unit) * 2);
  overflow-y: auto; /* If body itself needs to scroll independently */
  flex-grow: 1; /* Allow body to take up available space */
}

.close-button { /* General close button for modals, often an icon-button */
  font-size: 1.2rem; /* If using text 'X' */
  padding: var(--spacing-unit); /* If it's just text/icon needing padding */
  /* Assumes .icon-button class might also be applied for consistent styling */
}

/* --- Form Elements (Commonly used in Settings) --- */
.form-group {
  margin-bottom: calc(var(--spacing-unit) * 3);
}

.form-group label { /* Label style specific to forms within settings/modals */
  font-weight: 600;
  display: block;
  margin-bottom: calc(var(--spacing-unit));
  color: var(--color-text-secondary);
}

.form-group input, /* Includes type text, password, email, etc. */
.form-group select {
  width: 100%;
  padding: calc(var(--spacing-unit));
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  font-family: inherit;
  font-size: 1rem;
  background-color: var(--color-bg);
  color: var(--color-text-main);
  box-sizing: border-box;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(0, 105, 199, 0.2);
}

/* API key input containers removed - API keys now handled in workers */


/* --- Toggle Switch Styling (Common in Settings) --- */
.toggle-switch {
    display: flex;
    align-items: center;
    margin-bottom: 15px;
}

.toggle-switch label { /* Label associated with a toggle switch */
    margin-right: 10px;
    /* Assuming it might use common label styles or need specific overrides */
    font-weight: normal; /* Example override if common label is too bold */
}

.toggle-switch .help-text { /* Help text specifically for a toggle switch */
    font-size: 0.8rem; /* Already in common.css, but can be fine-tuned */
    color: #666; /* Consider var(--color-text-secondary) */
    margin-left: 10px;
    margin-top: 0; /* Override common .help-text margin-top if needed */
}

.model-toggle { /* Specific container for model toggles, if any */
    margin: 15px 0;
}

.slider-container { /* For sliders if used alongside toggles or independently */
    display: flex;
    align-items: center;
    gap: 10px;
}

.slider-label { /* Label for a traditional range slider, if any */
    font-weight: 500;
    font-size: 0.9rem;
    color: #666; /* Consider var(--color-text-secondary) */
}

/* Visual style for the toggle switches themselves */
.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
    flex-shrink: 0; /* Prevent switch from shrinking in flex layouts */
}

.switch input { /* The hidden checkbox input */
    opacity: 0;
    width: 0;
    height: 0;
}

.slider { /* The track of the toggle switch */
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc; /* Consider var(--color-border) or a grey variable */
    transition: .4s;
}

.slider:before { /* The thumb of the toggle switch */
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white; /* Consider var(--color-bg) or a white variable */
    transition: .4s;
}

input:checked + .slider {
    background-color: var(--color-primary); /* Active color */
}

input:focus + .slider { /* Focus outline for accessibility */
    box-shadow: 0 0 0 2px rgba(0, 105, 199, 0.2); /* Similar to form input focus */
}

input:checked + .slider:before {
    transform: translateX(26px); /* Movement of the thumb */
}

.slider.round { /* Rounded track */
    border-radius: 24px;
}

.slider.round:before { /* Rounded thumb */
    border-radius: 50%;
}

/* --- Settings Page Sections (if settings is a full page/view rather than just modal) --- */
.settings-section {
    margin-bottom: 24px; /* Or calc(var(--spacing-unit) * 3) */
}

.settings-section h3 {
    margin-top: 0;
    margin-bottom: 16px; /* Or calc(var(--spacing-unit) * 2) */
    font-size: 1.1rem;
    color: #333; /* Consider var(--color-text-main) or var(--color-primary) */
    /* Potentially add a border-bottom like other section headers */
}

.settings-divider {
    border: none;
    height: 1px;
    background-color: var(--color-border);
    margin: calc(var(--spacing-unit) * 3) 0;
}

/* Credit Settings Styling */
.credits-overview {
    background: var(--color-bg-section);
    border-radius: var(--border-radius);
    padding: 16px;
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.credit-balance-display {
    display: flex;
    align-items: center;
    gap: 8px;
}

.credit-label {
    font-weight: 500;
    color: var(--color-text-secondary);
}

.credit-amount {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--color-primary);
}

.secondary-button {
    background-color: var(--color-bg-section);
    color: var(--color-text-main);
    border: 1px solid var(--color-border);
    padding: 8px 16px;
    border-radius: var(--border-radius);
    font-size: 0.9rem;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.secondary-button:hover {
    background-color: var(--color-border);
    border-color: var(--color-primary);
}

.enabled-packages-section {
    margin-top: 20px;
}

.enabled-packages-section h5 {
    margin: 0 0 12px 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--color-text-secondary);
}

.packages-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.package-badge {
    color: white;
    padding: 4px 12px;
    border-radius: 16px;
    font-size: 0.8rem;
    font-weight: 500;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* Transaction History Modal */
.transaction-history-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1001;
}

.transaction-history-modal .modal-content {
    background-color: var(--color-bg);
    border-radius: var(--border-radius);
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.transaction-history-modal .modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.transaction-history-modal .modal-header h3 {
    margin: 0;
    color: var(--color-text-main);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--color-text-secondary);
    padding: 4px;
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

.modal-close:hover {
    background-color: var(--color-bg-section);
}

.transaction-history-modal .modal-body {
    padding: 0;
    overflow-y: auto;
    flex-grow: 1;
}

.transactions-list {
    padding: 20px;
}

.transaction-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--color-border);
}

.transaction-item:last-child {
    border-bottom: none;
}

.transaction-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.transaction-type {
    font-weight: 500;
    color: var(--color-text-main);
}

.transaction-date {
    font-size: 0.85rem;
    color: var(--color-text-secondary);
}

.transaction-amount {
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.9rem;
}

.transaction-amount.deduction {
    background-color: rgba(239, 68, 68, 0.1);
    color: #dc2626;
}

.transaction-amount.addition {
    background-color: rgba(34, 197, 94, 0.1);
    color: #16a34a;
}

/* Credits Widget Pulse Animation */
@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(59, 130, 246, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(59, 130, 246, 0);
    }
}

/* Settings content wrapper - main container for all settings modules */
.settings-content-wrapper {
    height: 100%;
    width: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0;
    margin: 0;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    background: var(--color-bg);
    scroll-behavior: smooth;
    scrollbar-width: thin;
}

.settings-content-wrapper::-webkit-scrollbar {
    width: 8px;
}

.settings-content-wrapper::-webkit-scrollbar-track {
    background: var(--color-bg-section);
    border-radius: 4px;
}

.settings-content-wrapper::-webkit-scrollbar-thumb {
    background: var(--color-text-secondary);
    border-radius: 4px;
    opacity: 0.7;
}

.settings-content-wrapper::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-main);
    opacity: 1;
}

/* Settings module containers */
.settings-image-container,
.settings-credit-container,
.settings-advanced-container {
    padding: 24px;
    max-width: 1000px;
    width: 100%;
    margin: 0 auto;
    min-height: 100%;
    box-sizing: border-box;
}

/* Settings section header */
.settings-section-header {
    margin-bottom: 32px;
    padding-bottom: 16px;
    border-bottom: 2px solid var(--color-primary);
}

.settings-section-header h2 {
    margin: 0 0 8px 0;
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--color-text-main);
    display: flex;
    align-items: center;
    gap: 12px;
}

.settings-section-header p {
    margin: 0;
    font-size: 1rem;
    color: var(--color-text-secondary);
    line-height: 1.5;
}

/* Settings grid layouts */
.api-keys-grid,
.image-settings-grid,
.credit-settings-grid,
.advanced-settings-grid {
    display: grid;
    gap: 24px;
    margin-bottom: 32px;
}

/* Settings cards */
.settings-card,
.feature-card {
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    padding: 24px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.settings-card:hover,
.feature-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    border-color: var(--color-primary);
}

.feature-card {
    border-left: 4px solid var(--color-primary);
}

.settings-card h3,
.feature-card h3 {
    margin: 0 0 16px 0;
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--color-text-main);
}

/* Form styling within settings */
.settings-card .form-group,
.feature-card .form-group {
    margin-bottom: 20px;
}

.settings-card .form-group:last-child,
.feature-card .form-group:last-child {
    margin-bottom: 0;
}

.settings-card label,
.feature-card label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--color-text-main);
    font-size: 0.95rem;
}

.settings-card input,
.settings-card select,
.feature-card input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    font-size: 1rem;
    background: var(--color-bg);
    color: var(--color-text-main);
    transition: all 0.2s ease;
    box-sizing: border-box;
}

.settings-card input:focus,
.settings-card select:focus,
.feature-card input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* API key input containers removed - API keys now handled in workers */

/* Help text */
.help-text {
    margin-top: 6px;
    font-size: 0.85rem;
    color: var(--color-text-secondary);
    line-height: 1.4;
}

/* Settings actions (buttons at bottom) */
.settings-actions {
    margin-top: 40px;
    padding-top: 24px;
    border-top: 1px solid var(--color-border);
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: flex-start;
    position: sticky;
    bottom: 0;
    background: var(--color-bg);
    z-index: 10;
    padding-bottom: 24px;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05);
}

.settings-actions .primary-button,
.settings-actions .secondary-button,
.settings-actions .tertiary-button {
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    min-width: 120px;
    text-align: center;
}

.settings-actions .primary-button {
    background: var(--color-primary);
    color: white;
    box-shadow: 0 2px 4px rgba(99, 102, 241, 0.2);
}

.settings-actions .primary-button:hover:not(:disabled) {
    background: var(--color-primary-dark, #4f46e5);
    box-shadow: 0 4px 8px rgba(99, 102, 241, 0.3);
    transform: translateY(-1px);
}

.settings-actions .primary-button:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(99, 102, 241, 0.2);
}

.settings-actions .primary-button:disabled {
    cursor: not-allowed;
    transform: none;
}

.settings-actions .secondary-button {
    background: var(--color-bg-secondary);
    color: var(--color-text-main);
    border: 1px solid var(--color-border);
}

.settings-actions .secondary-button:hover:not(:disabled) {
    background: var(--color-bg-tertiary, #f1f5f9);
    border-color: var(--color-primary);
    transform: translateY(-1px);
}

.settings-actions .secondary-button:active:not(:disabled) {
    transform: translateY(0);
}

.settings-actions .secondary-button:disabled {
    cursor: not-allowed;
    opacity: 0.6;
    transform: none;
}

.settings-actions .tertiary-button {
    background: transparent;
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border);
}

.settings-actions .tertiary-button:hover:not(:disabled) {
    background: var(--color-bg-secondary);
    color: var(--color-text-main);
    border-color: var(--color-text-secondary);
}

.settings-actions .tertiary-button:active:not(:disabled) {
    transform: translateY(0);
}

.settings-actions .tertiary-button:disabled {
    cursor: not-allowed;
    opacity: 0.6;
    transform: none;
}

/* Loading animations for buttons */
@keyframes buttonPulse {
    0% { opacity: 0.7; }
    50% { opacity: 1; }
    100% { opacity: 0.7; }
}

.settings-actions button[disabled] {
    animation: buttonPulse 1.5s ease-in-out infinite;
}

/* Success animation */
@keyframes successScale {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1.02); }
}

.settings-actions button.success-animation {
    animation: successScale 0.3s ease-out;
}

/* Smooth transitions for all interactive elements */
.settings-card,
.feature-card,
.settings-actions button,
input,
select {
    transition: all 0.2s ease;
}

/* Focus ring for accessibility */
.settings-card:focus-within,
.feature-card:focus-within {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* Settings sidebar container styles */
.settings-sidebar-container {
    padding: 16px;
    background: #f8fafc;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
}

.settings-sidebar-container h3 {
    margin: 0 0 16px 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: #1f2937;
    padding-bottom: 8px;
    border-bottom: 2px solid #6366f1;
}

.settings-option {
    background: #fff;
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    padding: 12px 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.95rem;
    font-weight: 500;
    color: #374151;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 8px;
}

.settings-option:hover {
    background: #f1f5f9;
    border-color: #6366f1;
    color: #4f46e5;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.1);
}

.settings-option.active {
    background: #6366f1;
    border-color: #6366f1;
    color: #fff;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.2);
}

/* Credit module specific styles */
.credits-overview {
    background: var(--color-bg-section);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 24px;
    border: 1px solid var(--color-border);
}

.credit-balance-display {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.credit-label {
    font-weight: 500;
    color: var(--color-text-secondary);
    font-size: 1rem;
}

.credit-amount {
    font-size: 2rem;
    font-weight: 700;
    color: var(--color-primary);
}

.balance-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

/* Feature status indicators */
.feature-status {
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    border: 1px solid;
    margin-top: 12px;
}

.status-ready {
    background-color: #d4edda;
    border-color: #c3e6cb;
    color: #155724;
}

.status-warning {
    background-color: #fff3cd;
    border-color: #ffeaa7;
    color: #856404;
}

.status-error {
    background-color: #f8d7da;
    border-color: #f5c6cb;
    color: #721c24;
}

/* Feature requirements boxes */
.feature-requirements {
    background: var(--color-bg);
    padding: 16px;
    border-radius: 8px;
    margin: 16px 0;
}

.feature-requirements h4 {
    margin-top: 0;
    margin-bottom: 8px;
    font-size: 1rem;
}

.feature-requirements ul {
    margin: 8px 0;
    padding-left: 20px;
}

.feature-requirements li {
    margin-bottom: 4px;
    font-size: 0.9rem;
}

/* Toggle switches in advanced features */
.feature-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.feature-header h3 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 600;
}

/* Experimental features section */
.experimental-options {
    display: grid;
    gap: 16px;
}

.experimental-options label {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    cursor: pointer;
    padding: 12px;
    border-radius: 8px;
    transition: background-color 0.2s ease;
}

.experimental-options label:hover {
    background-color: var(--color-bg-section);
}

.experimental-options input[type="checkbox"] {
    margin: 0;
    margin-top: 2px;
    flex-shrink: 0;
}

.experimental-options strong {
    display: block;
    margin-bottom: 4px;
    font-weight: 600;
}

.experimental-options small {
    color: var(--color-text-secondary);
    font-size: 0.85rem;
    line-height: 1.3;
}

/* Usage statistics */
.stat-item {
    text-align: center;
    padding: 16px;
    background: var(--color-bg);
    border-radius: 8px;
    border: 1px solid var(--color-border);
}

.stat-value {
    font-size: 1.8rem;
    font-weight: bold;
    color: var(--color-primary);
    margin-bottom: 4px;
}

.stat-label {
    font-size: 0.9rem;
    color: var(--color-text-secondary);
}

/* Mobile responsiveness for Settings */
@media (max-width: 768px) {
    .settings-content-wrapper {
        padding: 0;
    }
    
    .settings-image-container,
    .settings-credit-container,
    .settings-advanced-container {
        padding: 16px;
    }
    
    .settings-section-header h2 {
        font-size: 1.5rem;
    }
    
    .settings-actions {
        position: static;
        margin-top: 24px;
        padding-top: 16px;
    }
    
    .settings-actions .primary-button,
    .settings-actions .secondary-button,
    .settings-actions .tertiary-button {
        flex: 1;
        min-width: auto;
    }
    
    .credit-amount {
        font-size: 1.5rem;
    }
    
    .balance-actions {
        flex-direction: column;
    }
    
    .experimental-options {
        gap: 12px;
    }
    
    .settings-sidebar-container {
        padding: 12px;
    }
    
    .settings-sidebar-container h3 {
        font-size: 1rem;
        margin-bottom: 12px;
    }
    
    .settings-option {
        padding: 10px 12px;
        font-size: 0.9rem;
        margin-bottom: 6px;
    }
    
    .settings-option:hover {
        transform: none; /* Disable hover transform on mobile */
    }
}

@media (max-width: 480px) {
    .settings-sidebar-container {
        padding: 8px;
    }
    
    .settings-option {
        padding: 8px 10px;
        font-size: 0.85rem;
    }
    
    .settings-sidebar-container h3 {
        font-size: 0.95rem;
    }
}
