/* ===== User Preferences — Subject Picker & Settings ===== */

/* Subject Picker Modal */
.subject-picker-card {
  max-width: 540px;
  max-height: 80vh;
  overflow-y: auto;
}

.subject-pick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px;
  margin: 16px 0;
}

.subject-pick-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: background 0.15s, border-color 0.15s;
  font-size: 0.9rem;
  user-select: none;
}

.subject-pick-row:hover {
  background: var(--color-surface, #f4f4f5);
}

.subject-pick-row.checked {
  background: #eef2ff;
  border-color: #4338ca;
}

.subject-pick-row input[type="checkbox"] {
  accent-color: #4338ca;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.subject-pick-footer {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  justify-content: flex-end;
}

/* Gear / Settings button in header */
.settings-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  padding: 4px 6px;
  border-radius: 6px;
  opacity: 0.7;
  transition: opacity 0.15s, background 0.15s;
  line-height: 1;
}

.settings-btn:hover {
  opacity: 1;
  background: rgba(0,0,0,0.07);
}

/* Customize gear chip in subject row */
.subject-chip.subject-customize {
  background: none;
  border: 2px dashed #c7d2fe;
  color: #6366f1;
  font-size: 1rem;
  padding: 4px 10px;
  opacity: 0.8;
}

.subject-chip.subject-customize:hover {
  background: #eef2ff;
  opacity: 1;
}

/* User Settings Modal */
.user-settings-card {
  max-width: 460px;
}

.settings-section {
  margin: 16px 0;
  padding-bottom: 16px;
  border-bottom: 1px solid #e5e7eb;
}

.settings-section:last-of-type {
  border-bottom: none;
}

.settings-label {
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #6b7280;
  margin-bottom: 8px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.95rem;
}

.settings-hint {
  font-size: 0.85rem;
  color: #6b7280;
  margin: 0 0 10px;
}

/* Answer language radio options */
.answer-lang-opts {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.answer-lang-opt {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  border: 2px solid transparent;
  font-size: 0.9rem;
  transition: background 0.15s, border-color 0.15s;
  user-select: none;
}

.answer-lang-opt:hover {
  background: var(--color-surface, #f4f4f5);
}

.answer-lang-opt.active {
  background: #eef2ff;
  border-color: #4338ca;
}

.answer-lang-opt input[type="radio"] {
  accent-color: #4338ca;
}

/* Button variants */
.secondary-btn {
  background: transparent;
  color: #4338ca;
  border: 2px solid #4338ca;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.15s;
}

.secondary-btn:hover {
  background: #eef2ff;
}

.primary-btn.small {
  padding: 6px 12px;
  font-size: 0.85rem;
}

/* ===== RTL Support ===== */
[dir="rtl"] .header-inner {
  flex-direction: row-reverse;
}

[dir="rtl"] .auth-area {
  flex-direction: row-reverse;
}

[dir="rtl"] #subjectRow {
  direction: rtl;
}

[dir="rtl"] .input-section {
  direction: rtl;
}

[dir="rtl"] .result-card {
  direction: rtl;
  text-align: right;
}

[dir="rtl"] .subject-pick-footer {
  flex-direction: row-reverse;
}

[dir="rtl"] .settings-row {
  flex-direction: row-reverse;
}

[dir="rtl"] .answer-lang-opts {
  direction: rtl;
}

[dir="rtl"] .tab-bar {
  direction: rtl;
}

[dir="rtl"] .footer-inner {
  flex-direction: row-reverse;
}

/* Buy Credits button in header auth area */
.buy-credits-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: 20px;
  border: 1.5px solid #4338CA;
  background: transparent;
  color: #4338CA;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  margin-right: 6px;
}
.buy-credits-btn:hover {
  background: #4338CA;
  color: #fff;
}

/* ===== Reply Language Picker (header, logged-in only) ===== */
.reply-lang-wrap {
  position: relative;
  margin-right: 6px;
}

.reply-lang-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 9px;
  border-radius: 20px;
  border: 1.5px solid #c7d2fe;
  background: transparent;
  color: #4338CA;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.reply-lang-btn:hover {
  background: #eef2ff;
  border-color: #4338ca;
}

.reply-lang-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  list-style: none;
  margin: 0;
  padding: 6px;
  z-index: 200;
  min-width: 150px;
  max-height: 280px;
  overflow-y: auto;
}

.reply-lang-menu li {
  padding: 7px 12px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.88rem;
  color: #374151;
  transition: background 0.12s;
}

.reply-lang-menu li:hover {
  background: #f3f4f6;
}

.reply-lang-menu li.active {
  background: #eef2ff;
  color: #4338ca;
  font-weight: 600;
}

.reply-lang-menu.hidden {
  display: none;
}

/* ── Lingua risposta AI — nuovo design in-menu ── */
.prefs-lang-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  border-radius: 8px;
  font-size: 0.88rem;
  color: #374151;
  transition: background 0.12s;
  user-select: none;
}
.prefs-lang-row:hover { background: #f3f4f6; }
.prefs-lang-row svg { flex-shrink: 0; color: #6b7280; }
.prefs-lang-current {
  margin-left: auto;
  color: #4338ca;
  font-weight: 600;
  font-size: 0.82rem;
  white-space: nowrap;
}
.prefs-lang-opts {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px 12px 8px;
}
.prefs-lang-opts.hidden { display: none; }
.prefs-lang-opt {
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid #e5e7eb;
  background: #fff;
  font-size: 0.82rem;
  cursor: pointer;
  color: #374151;
  transition: all 0.12s;
  font-family: inherit;
}
.prefs-lang-opt:hover { background: #f3f4f6; border-color: #c7d2fe; }
.prefs-lang-opt.active { background: #eef2ff; border-color: #4338ca; color: #4338ca; font-weight: 600; }

.subject-mismatch-hint {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.8rem;
  margin-bottom: 0.6rem;
  background: #fffbeb;
  border: 1px solid #fcd34d;
  border-radius: 8px;
  font-size: 0.82rem;
  color: #92400e;
  animation: fadeIn 0.2s ease;
}
.subject-mismatch-hint span { flex: 1; }
.mismatch-switch-btn {
  padding: 0.2rem 0.6rem;
  background: #f59e0b;
  color: #fff;
  border: none;
  border-radius: 5px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}
.mismatch-switch-btn:hover { background: #d97706; }
.mismatch-dismiss-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: #92400e;
  opacity: 0.6;
  font-size: 0.85rem;
  padding: 0 0.2rem;
}
.mismatch-dismiss-btn:hover { opacity: 1; }

.cache-note {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.9rem;
  margin-bottom: 0.75rem;
  background: #f0fdf4;
  border: 1px solid #86efac;
  border-radius: 8px;
  font-size: 0.82rem;
  color: #166534;
  font-weight: 500;
}

.disclaimer-note {
  flex-basis: 100%;
  width: 100%;
  font-size: 0.72rem;
  font-family: inherit;
  letter-spacing: normal;
  text-transform: none;
  color: var(--text-muted, #9ca3af);
  opacity: 0.9;
  line-height: 1.5;
  text-align: center;
  margin: 4px 0 0;
  padding: 0 8px;
}

/* ===== Credits stripe (between nav tabs and subject bar) ===== */
.credits-stripe {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 16px;
  background: rgba(67, 56, 202, 0.06);
  border-bottom: 1px solid rgba(67, 56, 202, 0.12);
  font-size: 0.8rem;
  gap: 10px;
}
.credits-stripe.hidden { display: none; }
.credits-stripe-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--text-secondary, #6b7280);
  font-weight: 500;
}
.credits-stripe-badge svg { stroke: #4338CA; }
.credits-stripe-badge #creditsCount { color: #4338CA; font-weight: 600; }
.credits-stripe-buy {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 14px;
  background: #4338CA;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.credits-stripe-buy:hover { background: #3730a3; }

/* ===== Buy Credits button in header (always visible when signed in) ===== */
.buy-credits-header-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 11px;
  background: #4338CA;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
.buy-credits-header-btn:hover { background: #3730A3; }
.buy-credits-header-btn.hidden { display: none; }

/* ===== Gear / Preferences button ===== */
.prefs-wrap { position: relative; }

.prefs-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1.5px solid rgba(99,102,241,0.25);
  background: transparent;
  color: #4338CA;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.prefs-btn:hover { background: rgba(67,56,202,0.07); border-color: rgba(99,102,241,0.5); }
.prefs-btn[aria-expanded="true"] { background: rgba(67,56,202,0.1); border-color: #4338CA; }

/* ===== Preferences dropdown ===== */
.prefs-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: #fff;
  border: 1.5px solid #e5e7eb;
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.12);
  min-width: 210px;
  z-index: 9999;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.prefs-menu.hidden { display: none; }

.prefs-section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #9ca3af;
  padding: 4px 8px 2px;
}

/* Override: reply-lang-menu inside prefs-menu is not absolutely positioned */
.prefs-menu .reply-lang-menu {
  position: static;
  box-shadow: none;
  border: none;
  border-radius: 0;
  padding: 0;
  max-height: 160px;
  overflow-y: auto;
}

.prefs-divider {
  height: 1px;
  background: #f3f4f6;
  margin: 6px 0;
}

.prefs-action-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  background: transparent;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: #374151;
  cursor: pointer;
  text-align: left;
  transition: background 0.1s;
}
.prefs-action-btn:hover { background: #f3f4f6; }
.prefs-buy-btn { color: #4338CA; font-weight: 600; }
.prefs-buy-btn:hover { background: #ede9fe; }

/* Credits + Buy Credits vertical stripe */
.credits-buy-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 0;
}

/* Promo code block inside Buy Credits popup */
.promo-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}
.promo-block input {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid #c7d2fe;
  border-radius: 10px;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.15s;
  box-sizing: border-box;
}
.promo-block input:focus { border-color: #4338ca; }
.promo-apply-btn {
  width: 100%;
  padding: 12px;
  background: #4338ca;
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.promo-apply-btn:hover { background: #3730a3; }

/* Logo-anchored prefs menu — fixed below logo, positioned by JS */
#logoPrefsMenu {
  position: fixed;
  right: auto;
}

/* Credit info row at bottom of prefs menu */
.prefs-credit-info {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px 6px;
  font-size: 11px;
  color: #9ca3af;
  line-height: 1.4;
  flex-wrap: wrap;
}
.prefs-credit-info svg { flex-shrink: 0; opacity: 0.45; }
.pricing-link-sm {
  color: #6366f1;
  text-decoration: none;
  font-weight: 600;
  white-space: nowrap;
}
.pricing-link-sm:hover { text-decoration: underline; }

/* Pricing modal — action cost table */
.pricing-action-list {
  background: #f9fafb;
  border-radius: 10px;
  padding: 4px 0;
  margin: 12px 0 0;
  border: 1px solid #f3f4f6;
}
.pricing-action-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 14px;
  font-size: 13px;
  color: #374151;
  border-bottom: 1px solid #f3f4f6;
}
.pricing-action-row:last-child { border-bottom: none; }
.pricing-action-cost { font-weight: 700; color: #4338ca; }
.pricing-action-cost.free { color: #16a34a; }
