/* ============================================
   SETTINGS PAGE
   ============================================ */

/* Reset body/html margins and padding */
html, body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
}

body {
  font-family: var(--font-family-base);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* App Wrapper (Pushed by main Sidebar) */
.app-wrapper {
  margin-left: 260px;
  transition: margin-left 300ms cubic-bezier(0.2, 0, 0.2, 1);
  min-height: 100vh;
  background-color: var(--color-bg);
}

.sidebar-nav.collapsed ~ .app-wrapper {
  margin-left: 90px;
}

@media (max-width: 1024px) {
  .app-wrapper {
    margin-left: 0;
  }
}

/* Settings Container */
.settings-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Settings Header */
.settings-header {
  padding: 32px 48px 16px 48px;
  background-color: var(--color-bg);
}

.settings-header h1 {
  font-family: var(--font-family-base);
  font-size: 24px;
  font-weight: 400;
  color: var(--color-text);
  margin: 0;
}

/* Settings Layout (Sidebar + Content) */
.settings-layout {
  display: flex;
  flex: 1;
  background-color: var(--color-bg);
}

/* Settings Sidebar (Left Navigation) */
.settings-sidebar {
  width: 240px;
  background-color: var(--color-bg);
  padding: 24px 16px 24px 32px;
  min-height: calc(100vh - 120px);
  border: none;
}

.settings-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.settings-nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--color-text);
  font-family: var(--font-family-base);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: background-color 150ms;
}

.settings-nav-item:hover {
  background-color: rgba(0, 0, 0, 0.04);
}

.settings-nav-item.active {
  background-color: rgba(0, 0, 0, 0.08);
  font-family: var(--font-family-base);
}

.settings-nav-item svg {
  flex-shrink: 0;
  color: rgba(0, 0, 0, 0.65);
}

/* Settings Content (Right Side) */
.settings-content {
  flex: 1;
  padding: 32px 48px;
  max-width: 900px;
  background-color: transparent;
}

/* Settings Section */
.settings-section {
  display: none;
}

.settings-section.active {
  display: block;
}

/* Settings Card */
.settings-card {
  background-color: var(--color-bg);
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 8px;
  padding: 28px;
  margin-bottom: 24px;
}

.settings-card h2 {
  font-family: var(--font-family-base);
  font-size: 16px;
  font-weight: 600;
  color: var(--color-text);
  margin: 0 0 20px 0;
}

.settings-card .help-text {
  font-size: 14px;
  color: var(--color-text-secondary);
  line-height: 1.6;
  margin: 0;
}

/* Inline Avatar (next to name field) */
.field-value-with-avatar {
  display: flex;
  align-items: center;
  gap: 12px;
}

.profile-avatar-inline {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: var(--color-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-family-base);
  font-size: 16px;
  font-weight: 600;
  flex-shrink: 0;
}

.field-value-with-avatar .field-value {
  flex: 1;
}

/* Field Grid */
.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 20px;
}

.field-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-item-fullname {
  grid-column: span 2;
}

.field-item label {
  font-family: var(--font-family-base);
  font-size: 13px;
  color: rgba(0, 0, 0, 0.6);
  text-transform: none;
}

.field-value {
  padding: 10px 12px;
  background-color: #FFFFFF;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 6px;
  font-family: var(--font-family-base);
  font-size: 14px;
  color: var(--color-text);
  word-break: break-word;
}

.field-value-mono {
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  font-size: 13px;
}

/* Billing Plan */
.billing-plan {
  display: flex;
  align-items: center;
  gap: 20px;
}

.billing-plan-icon {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  background-color: rgba(123, 168, 46, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.billing-plan-icon svg {
  color: var(--color-primary);
}

.billing-plan-info {
  flex: 1;
}

.billing-plan-name {
  font-family: var(--font-family-medium);
  font-size: 18px;
  color: var(--color-text);
  margin: 0 0 4px 0;
}

.billing-plan-frequency {
  font-size: 14px;
  color: var(--color-text-secondary);
  margin: 0 0 8px 0;
}

.billing-plan-renewal {
  font-size: 13px;
  color: var(--color-text-secondary);
  margin: 0;
}

/* Billing Payment */
.billing-payment {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.billing-payment-method {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  color: var(--color-text);
}

.billing-payment-method svg {
  color: var(--color-text-secondary);
}

/* Invoices Table */
.billing-invoices {
  overflow-x: auto;
  max-height: 340px;
  overflow-y: auto;
}

.billing-invoices .invoices-table thead {
  position: sticky;
  top: 0;
  background: white;
  z-index: 1;
}

.invoices-table {
  width: 100%;
  border-collapse: collapse;
}

.invoices-table thead {
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.invoices-table th {
  text-align: left;
  padding: 12px 16px;
  font-family: var(--font-family-medium);
  font-size: 13px;
  color: var(--color-text-secondary);
  font-weight: 500;
}

.invoices-table td {
  padding: 16px;
  font-size: 14px;
  color: var(--color-text);
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

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

.invoices-table .no-invoices {
  text-align: center;
  color: var(--color-text-secondary);
  padding: 32px 16px;
}

.invoice-action {
  color: var(--color-text);
  text-decoration: underline;
  cursor: pointer;
  background: none;
  border: none;
  font-family: var(--font-family-base);
  font-size: 14px;
}

.invoice-action:hover {
  color: var(--color-primary);
}

/* Billing Cancellation */
.billing-cancellation {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

/* Button Styles */
.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 20px;
  background-color: transparent;
  color: var(--color-text);
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: 999px;
  font-family: var(--font-family-base);
  font-size: 14px;
  cursor: pointer;
  transition: all 150ms;
}

.btn-secondary::before {
  display: none;
}

.btn-secondary:hover {
  background-color: rgba(0, 0, 0, 0.04);
  border-color: rgba(0, 0, 0, 0.3);
}

.btn-danger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 20px;
  background-color: transparent;
  color: var(--color-error);
  border: 2px solid var(--color-error);
  border-radius: 999px;
  font-family: var(--font-family-base);
  font-size: 14px;
  cursor: pointer;
  transition: all 150ms;
}

.btn-danger:hover {
  background-color: rgba(239, 68, 68, 0.06);
  border-color: var(--color-error);
}

.btn-danger:active {
  background-color: rgba(239, 68, 68, 0.1);
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 1024px) {
  .settings-header {
    padding: 24px 32px 16px 32px;
  }

  .settings-layout {
    flex-direction: column;
  }

  .settings-sidebar {
    width: 100%;
    padding: 16px;
    min-height: auto;
  }

  .settings-nav {
    flex-direction: row;
    overflow-x: auto;
    gap: 8px;
  }

  .settings-nav-item {
    white-space: nowrap;
    flex-shrink: 0;
  }

  .settings-content {
    padding: 24px 32px;
  }

  .settings-card {
    padding: 24px;
  }

  .field-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .credits-display {
    flex-direction: column;
    text-align: center;
    padding: 24px;
  }

  .credits-amount {
    font-size: 28px;
  }
}

@media (max-width: 640px) {
  .settings-header {
    padding: 20px 16px 12px 16px;
  }

  .settings-header h1 {
    font-size: 24px;
  }

  .settings-content {
    padding: 20px 16px;
  }

  .settings-card {
    padding: 20px;
  }

  .settings-card h2 {
    font-size: 16px;
    margin-bottom: 16px;
  }
}

/* ============================================
   Credits Section
   ============================================ */
.credits-balance-display {
  text-align: center;
  padding: 32px 0;
}

.credits-balance-amount {
  font-size: 48px;
  font-family: var(--font-family-bold);
  color: var(--color-primary);
  margin-bottom: 8px;
}

.credits-balance-label {
  font-size: 16px;
  color: var(--color-text-secondary);
  margin-bottom: 16px;
}

.credits-purchase-form {
  margin-top: 24px;
}

.form-label {
  display: block;
  font-family: var(--font-family-base);
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text);
  margin-bottom: 12px;
}

.amount-selection {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
}

.amount-option {
  flex: 1;
  position: relative;
  cursor: pointer;
}

.amount-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.amount-label {
  display: block;
  padding: 12px 20px;
  background: #FFFFFF;
  border: 2px solid rgba(0, 0, 0, 0.1);
  border-radius: 6px;
  text-align: center;
  font-family: var(--font-family-medium);
  font-size: 16px;
  color: var(--color-text);
  transition: all 150ms;
}

.amount-option:hover .amount-label {
  border-color: rgba(0, 0, 0, 0.2);
  background: #fafafa;
}

.amount-option input[type="radio"]:checked ~ .amount-label {
  border-color: var(--color-primary);
  background: rgba(123, 168, 46, 0.05);
  color: var(--color-primary);
  font-weight: 600;
}

.amount-option-other .amount-label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 12px;
}

.custom-amount-input {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: 4px;
  font-family: var(--font-family-base);
  font-size: 14px;
  color: var(--color-text);
  background: white;
  box-sizing: border-box;
  margin-top: 4px;
}

.custom-amount-input:focus {
  outline: none;
  border-color: var(--color-primary);
}

.custom-amount-input::placeholder {
  color: rgba(0, 0, 0, 0.4);
}

.credits-amount-display {
  text-align: center;
  padding: 24px;
  background: #faf8f5;
  border-radius: 8px;
  margin-bottom: 24px;
  font-size: 18px;
  color: var(--color-text-secondary);
}

.credits-count {
  display: block;
  font-family: var(--font-family-bold);
  font-size: 56px;
  color: var(--color-text);
  margin-bottom: 8px;
  line-height: 1;
}

.btn-purchase-credits {
  width: 100%;
  padding: 14px 24px;
  background: var(--color-primary);
  color: white;
  border: none;
  border-radius: 999px;
  font-family: var(--font-family-medium);
  font-size: 16px;
  cursor: pointer;
  transition: all 200ms;
}

.btn-purchase-credits:hover {
  background: var(--color-primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(123, 168, 46, 0.3);
}

.btn-purchase-credits:active {
  background: var(--color-primary-active);
  transform: translateY(0);
}

.btn-purchase-credits:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ============================================
   BILLING & SUBSCRIPTION STYLES
   ============================================ */

/* Invoice Status Badges */
.invoice-status {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-family: var(--font-family-medium);
  font-weight: 500;
}

.invoice-status.status-paid {
  background-color: rgba(16, 185, 129, 0.1);
  color: #059669;
}

.invoice-status.status-pending {
  background-color: rgba(245, 158, 11, 0.1);
  color: #d97706;
}

.invoice-status.status-failed {
  background-color: rgba(239, 68, 68, 0.1);
  color: #dc2626;
}

/* Button Link Style (for Download buttons) */
.btn-link {
  background: none;
  border: none;
  color: var(--color-text);
  text-decoration: underline;
  cursor: pointer;
  font-family: var(--font-family-base);
  font-size: 14px;
  padding: 0;
}

.btn-link:hover {
  color: var(--color-primary);
}

/* Settings modal overrides — structure uses style.css .modal-overlay pattern */
.modal-footer {
  padding: 24px 2rem;
}

/* Subscription Plans Grid */
.subscription-plans {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 24px;
  margin: 0;
}

.subscription-plan {
  background: white;
  border: 2px solid rgba(0, 0, 0, 0.1);
  border-radius: 12px;
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  position: relative;
  transition: all 200ms;
}

.subscription-plan:hover {
  border-color: rgba(0, 0, 0, 0.2);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

.subscription-plan.popular {
  border-color: var(--color-primary);
  box-shadow: 0 8px 24px rgba(123, 168, 46, 0.15);
}

.subscription-plan.current {
  border-color: #6366f1;
  background-color: rgba(99, 102, 241, 0.02);
}

.plan-badge {
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-primary);
  color: white;
  padding: 4px 16px;
  border-radius: 12px;
  font-size: 12px;
  font-family: var(--font-family-medium);
  font-weight: 600;
  white-space: nowrap;
}

.plan-badge.current-badge {
  background: #6366f1;
}

.plan-header {
  text-align: center;
  margin-bottom: 24px;
  padding-bottom: 24px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.plan-name {
  font-family: var(--font-family-medium);
  font-size: 24px;
  color: var(--color-text);
  margin: 0 0 12px 0;
  font-weight: 500;
}

.plan-price {
  margin: 16px 0;
}

.plan-price-amount {
  font-family: var(--font-family-bold);
  font-size: 48px;
  color: var(--color-text);
  font-weight: 700;
  line-height: 1;
}

.plan-price-period {
  font-size: 18px;
  color: var(--color-text-secondary);
  margin-left: 4px;
}

.plan-description {
  font-size: 14px;
  color: var(--color-text-secondary);
  margin: 12px 0 0 0;
  line-height: 1.5;
}

.plan-features {
  flex: 1;
  margin-bottom: 24px;
}

.plan-credits {
  background: rgba(123, 168, 46, 0.1);
  padding: 16px;
  border-radius: 8px;
  text-align: center;
  font-size: 14px;
  color: var(--color-text-secondary);
  margin-bottom: 20px;
}

.plan-credits strong {
  display: block;
  font-size: 32px;
  color: var(--color-primary);
  font-family: var(--font-family-bold);
  margin-bottom: 4px;
  line-height: 1;
}

.plan-features-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.plan-features-list li {
  padding: 10px 0;
  font-size: 14px;
  color: var(--color-text);
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.plan-features-list li::before {
  content: "✓";
  color: var(--color-primary);
  font-weight: bold;
  font-size: 16px;
  flex-shrink: 0;
}

.btn-select-plan {
  width: 100%;
  padding: 14px 24px;
  background: transparent;
  color: var(--color-primary);
  border: 2px solid var(--color-primary);
  border-radius: 999px;
  font-family: var(--font-family-medium);
  font-size: 16px;
  cursor: pointer;
  transition: all 200ms;
  font-weight: 500;
}

.btn-select-plan:hover {
  background: rgba(123, 168, 46, 0.06);
  border-color: var(--color-primary);
}

.btn-select-plan:active {
  background: rgba(123, 168, 46, 0.1);
}

.btn-select-plan:disabled,
.btn-select-plan.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  background: transparent;
  color: var(--color-text-secondary);
  border-color: rgba(0, 0, 0, 0.15);
}

.subscription-plan.current .btn-select-plan {
  background: transparent;
  color: #6366f1;
  border-color: #6366f1;
  cursor: default;
}

.subscription-plan.current .btn-select-plan:hover {
  background: transparent;
  color: #6366f1;
  transform: none;
  box-shadow: none;
}

/* Past-due payment banner */
.billing-past-due-banner {
  background: #FEF3F2;
  border: 1px solid #FCA5A5;
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 16px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.past-due-content {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.past-due-content svg {
  flex-shrink: 0;
  margin-top: 1px;
  color: #DC2626;
}

.past-due-title {
  font-family: var(--font-family-medium);
  font-size: 14px;
  color: #991B1B;
  margin: 0 0 4px 0;
}

.past-due-text {
  font-size: 13px;
  color: #7F1D1D;
  margin: 0;
  line-height: 1.5;
}

.btn-past-due-update {
  flex-shrink: 0;
  padding: 8px 16px;
  background: #DC2626;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-family: var(--font-family-medium);
  cursor: pointer;
  white-space: nowrap;
  transition: background 200ms;
}

.btn-past-due-update:hover {
  background: #B91C1C;
}

/* Billing interval toggle */
.billing-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 28px;
}

.billing-toggle-label {
  font-size: 14px;
  color: var(--color-text-secondary);
  transition: color 200ms;
}

.billing-toggle-label.active {
  color: var(--color-text);
  font-family: var(--font-family-medium);
}

.billing-toggle-save {
  font-size: 12px;
  color: var(--color-primary);
  font-family: var(--font-family-medium);
}

.billing-toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  cursor: pointer;
}

.billing-toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.billing-toggle-slider {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.15);
  border-radius: 24px;
  transition: background 200ms;
}

.billing-toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 200ms;
}

.billing-toggle-switch input:checked + .billing-toggle-slider {
  background: var(--color-primary);
}

.billing-toggle-switch input:checked + .billing-toggle-slider::before {
  transform: translateX(20px);
}

.plan-effective-monthly {
  font-size: 13px;
  color: var(--color-primary);
  margin: 4px 0 0 0;
  font-family: var(--font-family-medium);
}

/* Scheduled change badge at bottom of plan card */
.plan-badge-bottom {
  position: absolute;
  bottom: -12px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-text-secondary);
  color: white;
  padding: 4px 16px;
  border-radius: 20px;
  font-size: 12px;
  font-family: var(--font-family-medium);
  white-space: nowrap;
}

.subscription-plan.scheduled {
  border-color: var(--color-text-secondary);
}

.btn-select-plan.scheduled-btn {
  background: transparent;
  color: var(--color-primary);
  border-color: var(--color-primary);
  cursor: default;
  opacity: 1;
}

.cancel-downgrade-link {
  color: var(--color-primary);
  text-decoration: underline;
  font-size: 14px;
  cursor: pointer;
}

.cancel-downgrade-link:hover {
  color: var(--color-primary-dark, #5a8a2a);
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .modal-content-large {
    max-width: 100%;
  }

  .subscription-plans {
    grid-template-columns: 1fr;
  }

  .modal-body {
    padding: 20px;
  }

  .modal-header {
    padding: 20px;
  }
}
