/* ========================================
 * jex 使用者設定頁樣式 (Material Design 3)
 * ========================================
 * 佈局樣式已移至公用 sidebar-layout.css
 * 此檔案僅保留頁面專屬樣式（密碼強度計、2FA、API 金鑰卡片等）
 * ======================================== */

/* ======== 外層容器（僅作為 CSS 變數作用域） ======== */
/* 說明：尺寸樣式已遷移至 sidebar-layout.css 的 .jex-sidebar-layout */
.jex-user-settings-container {
  /* 此處只作為 CSS 變數作用域，不含尺寸樣式 */
  color: var(--md-sys-color-on-surface);
}


/* ======== 密碼強度計 ======== */
.password-strength-meter {
  display: flex;
  gap: 6px;
  height: 4px;
  width: 100%;
  max-width: 400px;
  margin-top: 0.75rem;
}

.password-strength-meter .strength-bar {
  flex-grow: 1;
  background-color: var(--md-sys-color-surface-variant);
  border-radius: var(--md-sys-shape-corner-extra-small);
  transition: background-color 0.3s;
}

.password-strength-meter[data-strength="1"] .strength-bar:nth-child(-n+1) {
  background-color: var(--md-sys-color-error);
}

.password-strength-meter[data-strength="2"] .strength-bar:nth-child(-n+2) {
  background-color: var(--md-sys-color-primary);
}

.password-strength-meter[data-strength="3"] .strength-bar:nth-child(-n+3) {
  background-color: var(--md-sys-color-primary);
}

.password-strength-meter[data-strength="4"] .strength-bar:nth-child(-n+4) {
  background-color: var(--md-sys-color-success);
}

.password-match-status {
  font-size: 0.8rem;
  margin-top: 0.5rem;
  min-height: 1.2em;
  display: flex;
  align-items: center;
  gap: 4px;
}

.password-match-status.match {
  color: var(--md-sys-color-success);
}

.password-match-status.mismatch {
  color: var(--md-sys-color-error);
}

/* ======== 2FA / 互動區塊 ======== */
.jex-user-settings-container .content-section+.content-section {
  margin-top: 30px;
}

.jex-2fa-action {
  margin-top: 15px;
}

.jex-form-actions-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.jex-success-msg {
  margin-top: 15px;
  color: var(--md-sys-color-success);
  font-weight: 600;
}

/* ======== 2FA Switch - MD3 Switch ======== */
.toggle-switch {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 15px 0;
}

.toggle-switch input[type="checkbox"] {
  appearance: none;
  width: 52px;
  height: 32px;
  background-color: var(--md-sys-color-surface-variant);
  border: 2px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-full);
  position: relative;
  cursor: pointer;
  transition: all 0.2s;
  outline: none;
  padding: 0;
}

.toggle-switch input[type="checkbox"]:checked {
  background-color: var(--md-sys-color-primary);
  border-color: var(--md-sys-color-primary);
}

.toggle-switch input[type="checkbox"]::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background-color: var(--md-sys-color-outline);
  top: 50%;
  left: 6px;
  transform: translateY(-50%);
  transition: transform 0.2s, background-color 0.2s, width 0.2s, height 0.2s;
}

.toggle-switch input[type="checkbox"]:checked::before {
  background-color: var(--md-sys-color-on-primary);
  transform: translate(20px, -50%);
  width: 24px;
  height: 24px;
}

.toggle-switch label {
  cursor: pointer;
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
  margin: 0;
  font-size: 1rem;
}

.toggle-switch label.is-disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ======== Info Box ======== */
.info-box {
  padding: 16px;
  border-radius: var(--md-sys-shape-corner-small);
  margin: 16px 0;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.info-box.info {
  background-color: var(--md-sys-color-surface-variant);
  border-left: 4px solid var(--md-sys-color-primary);
}

.info-box.warning {
  background-color: var(--md-sys-color-warning-container);
  border-left: 4px solid var(--md-sys-color-warning);
  color: var(--md-sys-color-on-warning-container);
}

.info-box p {
  margin: 0;
  line-height: 1.5;
}

/* ==========================================
 * API Key Management
 * ========================================== */
.api-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 24px;
  margin-top: 24px;
}

.jex-api-card {
  background-color: var(--jex-bg-light);
  border-radius: var(--jex-container-radius);
  padding: 32px;
  transition: var(--jex-transition-standard);
  position: relative;
  overflow: hidden;
  border: none;
  box-shadow: none;
}

.jex-api-card:hover {
  background-color: var(--jex-bg-white);
  box-shadow: 0 0 0 6px var(--jex-container-glow);
  transform: translateY(-2px);
}

.api-card-header {
  margin-bottom: 24px;
}

.api-card-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.api-card-title h2 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--jex-text-main);
}

.api-status-badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 16px;
  border-radius: var(--md-sys-shape-corner-full);
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.5px;
}

.api-status-badge.active {
  background-color: var(--jex-success-bg);
  color: var(--jex-success);
  border: 1px solid var(--jex-success-border);
}

.api-status-badge.inactive {
  background-color: color-mix(in srgb, var(--md-sys-color-on-surface), transparent 92%);
  color: var(--jex-text-muted);
}

.api-card-desc p {
  margin: 0;
  font-size: 0.95rem;
  color: var(--jex-text-secondary);
  line-height: 1.6;
}

.api-card-body {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.api-input-wrapper {
  position: relative;
}

.jex-user-api-key-input {
  width: 100%;
  background-color: var(--jex-bg-white);
  border: 2px solid transparent;
  padding: 16px 20px;
  border-radius: var(--jex-radius-md);
  font-size: 1rem;
  color: var(--jex-text-main);
  transition: all 0.2s ease;
}

.jex-user-api-key-input:focus {
  outline: none;
  background-color: var(--jex-bg-white);
  border-color: var(--jex-primary);
  box-shadow: 0 0 0 4px var(--jex-container-glow);
}

.jex-key-saved-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--jex-success);
  font-weight: 500;
  padding: 12px 16px;
  background-color: var(--jex-success-bg);
  border-radius: var(--jex-radius-sm);
}

.jex-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 8px;
}

/* ==========================================
 * 密碼確認對話框（API 金鑰敏感操作）
 * ========================================== */
.jex-modal-overlay {
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, var(--md-sys-color-scrim), transparent 55%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 999999;
}

.jex-modal {
  width: min(520px, 100%);
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  border-radius: var(--md-sys-shape-corner-large);
  padding: 20px;
  box-shadow: 0 16px 48px color-mix(in srgb, var(--md-sys-color-scrim), transparent 65%);
  border: 1px solid color-mix(in srgb, var(--md-sys-color-outline), transparent 60%);
}

.jex-modal__title {
  margin: 0 0 8px 0;
  font-size: 1.15rem;
  font-weight: 650;
}

.jex-modal__desc {
  margin: 0 0 16px 0;
  color: var(--md-sys-color-on-surface-variant);
  line-height: 1.5;
}

.jex-modal__field label {
  display: block;
  font-weight: 600;
  margin-bottom: 8px;
}

.jex-modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

/* ======== Spinner adjustment ======== */
.spinner {
  float: none;
  margin: 0;
}

/* ======== 響應式：外層容器 ======== */
@media (max-width: 992px) {
  .jex-user-settings-container {
    width: calc(100% - 32px);
    margin: 1rem auto;
    padding: 0;
  }
}