/* ══════════════════════════════════════════════════════════════════════════
   AI Chat Console — Shared UI Component Kit
   Modern buttons, cards, forms, toasts, modals, pricing cards, etc.
   Load order: tokens.css → app.css → ui.css → page css.
   Used by every user-facing page (dashboard, account, auth, public, landing).
   Everything themes automatically via tokens.css variables — no raw hues here.
   ══════════════════════════════════════════════════════════════════════════ */

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: inherit; font-size: var(--fs-sm); font-weight: var(--fw-semibold);
  line-height: 1; padding: 11px 20px; border-radius: var(--r-sm);
  border: 1px solid transparent; cursor: pointer; text-decoration: none;
  white-space: nowrap; user-select: none;
  transition: transform var(--t-fast) var(--ease-out),
              box-shadow var(--t-base) var(--ease-out),
              background-color var(--t-fast) ease, border-color var(--t-fast) ease,
              color var(--t-fast) ease, filter var(--t-fast) ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--grad-brand); color: var(--on-accent);
  box-shadow: var(--shadow-accent);
}
.btn-primary:hover { filter: brightness(1.06); transform: translateY(-1px); box-shadow: var(--shadow-accent), var(--shadow-2); }
.btn-primary:active { transform: scale(.97); filter: brightness(.97); }

.btn-ghost {
  background: transparent; color: var(--text); border-color: var(--border-strong);
}
.btn-ghost:hover { background: var(--accent-softer); border-color: var(--primary); color: var(--primary); }

.btn-soft {
  background: var(--accent-soft); color: var(--primary);
}
.btn-soft:hover { background: var(--accent-ring); }

.btn-danger {
  background: var(--danger); color: #fff;
}
.btn-danger:hover { filter: brightness(1.08); }
.btn-danger-soft { background: var(--danger-soft); color: var(--danger); }
.btn-danger-soft:hover { background: rgba(239,68,68,.20); }

.btn-lg { padding: 15px 28px; font-size: var(--fs-base); border-radius: var(--r-md); }
.btn-sm { padding: 8px 14px; font-size: var(--fs-xs); }
.btn-block { width: 100%; }

/* Icon-only / compact buttons (sidebar theme-toggle, collapse, Personas,
   Memory, credit badge): restore app.css's tighter 7px padding, which the
   generic .btn rule above otherwise wins on cascade order (same specificity,
   later file) — that regression was inflating these buttons and squeezing
   the credit badge out of the sidebar row. Also stay borderless; the
   .btn-ghost border is meant for full-size labeled buttons. */
.btn.btn-icon {
  padding: 7px; border-radius: var(--r-xs);
  border-color: transparent !important;
}
.btn-icon.btn-ghost:hover { background: var(--accent-soft); }

/* Icon-only round button */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: var(--r-sm);
  background: transparent; border: none; color: var(--muted); cursor: pointer;
  transition: background-color var(--t-fast) ease, color var(--t-fast) ease;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover { background: var(--accent-soft); color: var(--primary); }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); box-shadow: var(--shadow-1);
}
.card-glass {
  background: var(--surface-glass);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  border: 1px solid var(--border-glass);
  border-radius: var(--r-lg); box-shadow: var(--shadow-2);
}
.lift { transition: transform var(--t-base) var(--ease-out), box-shadow var(--t-base) var(--ease-out); }
.lift:hover { transform: translateY(-3px); box-shadow: var(--shadow-3); }

/* Gradient hairline border (padding-box/border-box trick) */
.grad-border {
  border: 1px solid transparent;
  background:
    linear-gradient(var(--surface), var(--surface)) padding-box,
    var(--grad-brand) border-box;
}

/* ── Form controls ───────────────────────────────────────────────────────── */
.field,
input.field, select.field, textarea.field {
  display: block; width: 100%;
  font-family: inherit; font-size: var(--fs-base); color: var(--text);
  background: var(--surface-2); border: 1.5px solid var(--border);
  border-radius: var(--r-sm); padding: 11px 14px;
  transition: border-color var(--t-fast) ease, box-shadow var(--t-fast) ease, background-color var(--t-fast) ease;
}
.field:hover { border-color: var(--border-strong); }
.field:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--accent-ring);
  background: var(--surface);
}
.field::placeholder { color: var(--muted-2); }
textarea.field { resize: vertical; min-height: 90px; }
.field-label {
  display: block; font-size: var(--fs-xs); font-weight: var(--fw-semibold);
  color: var(--muted); margin-bottom: 6px; letter-spacing: .02em;
}

/* Toggle switch (pure CSS checkbox) */
.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .slider {
  position: absolute; inset: 0; cursor: pointer; border-radius: var(--r-full);
  background: var(--border-strong);
  transition: background-color var(--t-base) var(--ease-out);
}
.switch .slider::before {
  content: ""; position: absolute; width: 18px; height: 18px;
  left: 3px; top: 3px; border-radius: 50%;
  background: #fff; box-shadow: var(--shadow-1);
  transition: transform var(--t-base) var(--ease-spring);
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(18px); }
.switch input:focus-visible + .slider { box-shadow: 0 0 0 3px var(--accent-ring); }

/* ── Badges & pills ──────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: var(--fs-xs); font-weight: var(--fw-semibold);
  padding: 4px 10px; border-radius: var(--r-full);
  background: var(--accent-soft); color: var(--primary);
  white-space: nowrap;
}
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger  { background: var(--danger-soft);  color: var(--danger); }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: var(--fs-xs); font-weight: var(--fw-medium);
  padding: 6px 13px; border-radius: var(--r-full);
  background: var(--surface); border: 1px solid var(--border); color: var(--muted);
  transition: border-color var(--t-fast) ease, color var(--t-fast) ease, background-color var(--t-fast) ease;
}
.pill:hover { border-color: var(--primary); color: var(--primary); background: var(--accent-softer); }

/* ── Toast notifications (shared base — position via #toast-stack) ───────── */
#toast-stack {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px;
  z-index: 2000; pointer-events: none;
  width: max-content; max-width: calc(100vw - 32px);
}
.toast {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-glass);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  color: var(--text);
  border: 1px solid var(--border-glass); border-left: 3px solid var(--primary);
  border-radius: var(--r-sm);
  padding: 11px 14px; font-size: var(--fs-sm);
  box-shadow: var(--shadow-3);
  pointer-events: auto;
  opacity: 0; transform: translateY(12px) scale(.97);
  transition: opacity var(--t-base) var(--ease-out), transform var(--t-base) var(--ease-out);
}
.toast.visible { opacity: 1; transform: translateY(0) scale(1); }
.toast.toast-success { border-left-color: var(--success); }
.toast.toast-error   { border-left-color: var(--danger); }
.toast .toast-icon { flex-shrink: 0; display: flex; color: var(--primary); }
.toast.toast-success .toast-icon { color: var(--success); }
.toast.toast-error   .toast-icon { color: var(--danger); }
.toast .toast-msg { flex: 1; white-space: nowrap; }
.toast .toast-action {
  flex-shrink: 0; background: none; border: none; cursor: pointer;
  color: var(--primary); font-weight: var(--fw-bold); font-size: var(--fs-sm);
  padding: 2px 4px; border-radius: 4px; font-family: inherit;
}
.toast .toast-action:hover { text-decoration: underline; }
.toast .toast-close {
  flex-shrink: 0; background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: var(--fs-sm); padding: 0 0 0 2px; line-height: 1;
}
@media (max-width: 768px) {
  #toast-stack { width: calc(100vw - 32px); }
  .toast .toast-msg { white-space: normal; }
}

/* ── Modals (modern pass over the app.css base) ──────────────────────────── */
.modal-overlay {
  background: rgba(8, 10, 18, .45);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.modal-card {
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-4);
  animation: modalIn var(--t-slow) var(--ease-out);
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(14px) scale(.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
/* Bottom-sheet variant on small screens */
@media (max-width: 640px) {
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal-card {
    max-width: 100%; border-radius: var(--r-lg) var(--r-lg) 0 0;
    padding-bottom: max(24px, env(safe-area-inset-bottom));
    animation: sheetIn var(--t-slow) var(--ease-out);
  }
  @keyframes sheetIn {
    from { opacity: 0; transform: translateY(40px); }
    to   { opacity: 1; transform: translateY(0); }
  }
}

/* ── Pricing cards (landing + register) ──────────────────────────────────── */
.pricing-grid {
  display: flex; flex-wrap: nowrap; align-items: stretch;
  gap: var(--sp-5);
  overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x proximity;
  padding: 4px 4px var(--sp-3);
  -webkit-overflow-scrolling: touch;
}
.pricing-grid::-webkit-scrollbar { height: 8px; }
.pricing-grid::-webkit-scrollbar-thumb { background: var(--border); border-radius: var(--r-full); }
.pricing-card {
  position: relative; display: flex; flex-direction: column; gap: var(--sp-3);
  flex: 0 0 250px; max-width: 270px;
  scroll-snap-align: start;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: var(--sp-6) var(--sp-5);
  box-shadow: var(--shadow-1);
  transition: transform var(--t-base) var(--ease-out), box-shadow var(--t-base) var(--ease-out), border-color var(--t-base) ease;
}
.pricing-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-3); border-color: var(--accent-300); }
.pricing-card.popular {
  border: 1px solid transparent;
  background:
    linear-gradient(var(--surface), var(--surface)) padding-box,
    var(--grad-brand) border-box;
  box-shadow: var(--shadow-accent);
}
.pricing-card .pc-flag {
  position: absolute; top: -12px; left: 50%; transform: translateX(-50%);
  background: var(--grad-brand); color: var(--on-accent);
  font-size: var(--fs-xs); font-weight: var(--fw-bold);
  padding: 4px 14px; border-radius: var(--r-full); white-space: nowrap;
  box-shadow: var(--shadow-accent);
}
.pricing-card .pc-name { font-size: var(--fs-md); font-weight: var(--fw-bold); color: var(--text-strong); }
.pricing-card .pc-price { font-size: var(--fs-2xl); font-weight: var(--fw-bold); color: var(--text-strong); line-height: 1.1; }
.pricing-card .pc-price small { font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--muted); }
.pricing-card .pc-desc { font-size: var(--fs-sm); color: var(--muted); }
.pricing-card ul.pc-feats { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.pricing-card ul.pc-feats li {
  display: flex; align-items: flex-start; gap: 8px;
  font-size: var(--fs-sm); color: var(--text);
}
.pricing-card ul.pc-feats li::before {
  content: "✓"; color: var(--success); font-weight: var(--fw-bold); flex-shrink: 0;
}
.pricing-card .pc-cta { margin-top: var(--sp-2); }

/* ── FAQ accordion (native <details>) ────────────────────────────────────── */
.faq-item {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); overflow: hidden;
  transition: border-color var(--t-fast) ease, box-shadow var(--t-base) ease;
}
.faq-item + .faq-item { margin-top: var(--sp-3); }
.faq-item[open] { border-color: var(--accent-300); box-shadow: var(--shadow-1); }
.faq-item summary {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  cursor: pointer; list-style: none;
  padding: 16px 20px; font-weight: var(--fw-semibold); font-size: var(--fs-base);
  color: var(--text-strong);
  -webkit-tap-highlight-color: transparent;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after {
  content: "+"; font-size: 1.2rem; font-weight: 400; color: var(--muted);
  transition: transform var(--t-base) var(--ease-out);
  flex-shrink: 0;
}
.faq-item[open] summary::after { transform: rotate(45deg); color: var(--primary); }
.faq-item .faq-body {
  padding: 0 20px 18px; font-size: var(--fs-sm); color: var(--muted); line-height: var(--lh-normal);
}

/* ── Skeleton shimmer ────────────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease infinite;
  border-radius: var(--r-xs);
}
@keyframes shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

/* ── Empty states ────────────────────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--sp-3); padding: var(--sp-7) var(--sp-5); text-align: center;
}
.empty-state .es-icon {
  width: 52px; height: 52px; border-radius: var(--r-md);
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--primary);
}
.empty-state .es-title { font-weight: var(--fw-semibold); color: var(--text-strong); font-size: var(--fs-base); }
.empty-state .es-hint { font-size: var(--fs-sm); color: var(--muted); max-width: 360px; }

/* ── Scroll-reveal (ui.js IntersectionObserver adds .in-view) ────────────── */
.reveal { opacity: 0; transform: translateY(18px); transition: opacity .6s var(--ease-out), transform .6s var(--ease-out); }
.reveal.in-view { opacity: 1; transform: translateY(0); }

/* ── Gradient headline text ──────────────────────────────────────────────── */
.grad-text {
  background: var(--grad-text);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}

/* ── Themed thin scrollbars ──────────────────────────────────────────────── */
.nice-scroll { scrollbar-width: thin; scrollbar-color: var(--accent-ring) transparent; }
.nice-scroll::-webkit-scrollbar { width: 8px; height: 8px; }
.nice-scroll::-webkit-scrollbar-track { background: transparent; }
.nice-scroll::-webkit-scrollbar-thumb { background: var(--accent-ring); border-radius: var(--r-full); }
.nice-scroll::-webkit-scrollbar-thumb:hover { background: var(--primary); }

/* ── Public sticky nav (includes/public_nav.php) ─────────────────────────── */
.public-nav {
  position: sticky; top: 0; z-index: 50;
  /* Fully transparent at rest so the page shows straight through — the landing
     hero's mesh (.landing-page::before) reaches the top of the page, so the bar
     picks up its colour without needing a tint of its own. Any wash or bottom
     hairline here just re-creates the "separate band with a seam" look. */
  background: transparent;
  border-bottom: 1px solid transparent;
  /* backdrop-filter starts at blur(0px) rather than being absent, so the
     compositor keeps a backdrop layer for this element at all times. Adding
     or removing the backdrop-filter property outright (rather than easing
     its value) makes Chrome/Edge tear the layer down and rebuild it on the
     next scroll-direction change, which paints one opaque frame first —
     seen as a white box flashing over the page right as .scrolled drops off
     near the top. Easing the blur amount instead avoids that rebuild. */
  -webkit-backdrop-filter: blur(0px) saturate(100%);
  backdrop-filter: blur(0px) saturate(100%);
  transition: background-color var(--t-base) ease, border-color var(--t-base) ease,
    box-shadow var(--t-base) ease, backdrop-filter var(--t-base) ease, -webkit-backdrop-filter var(--t-base) ease;
}
/* Frosted only once content scrolls under it, for legibility. */
.public-nav.scrolled {
  background: var(--surface-glass);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  border-bottom-color: var(--border-glass);
  box-shadow: var(--shadow-1);
}
.public-nav-in {
  max-width: 1140px; margin: 0 auto; padding: 14px 22px;
  display: flex; align-items: center; gap: var(--sp-5);
}
.pn-brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: var(--fw-bold); font-size: var(--fs-md); color: var(--text-strong);
  text-decoration: none; white-space: nowrap;
}
.pn-brand:hover { text-decoration: none; }
.pn-brand-mark {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: var(--r-sm);
  background: var(--grad-brand); color: var(--on-accent);
  box-shadow: var(--shadow-accent);
}
.pn-links { display: flex; gap: 4px; margin-left: auto; }
.pn-links a {
  font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--muted);
  text-decoration: none; padding: 8px 13px; border-radius: var(--r-full);
  transition: color var(--t-fast) ease, background-color var(--t-fast) ease;
}
.pn-links a:hover, .pn-links a.active { color: var(--primary); background: var(--accent-softer); text-decoration: none; }
.pn-actions { display: flex; align-items: center; gap: 10px; }
#pn-theme-toggle .pn-icon-moon { display: none; }
[data-theme="dark"] #pn-theme-toggle .pn-icon-moon,
[data-theme="oled"] #pn-theme-toggle .pn-icon-moon { display: block; }
[data-theme="dark"] #pn-theme-toggle .pn-icon-sun,
[data-theme="oled"] #pn-theme-toggle .pn-icon-sun { display: none; }
@media (max-width: 760px) {
  .pn-links { display: none; }
  .pn-actions { margin-left: auto; }
}

/* ── Public footer (includes/public_footer.php) ──────────────────────────── */
.public-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  margin-top: var(--sp-8);
}
.public-footer-in {
  max-width: 1140px; margin: 0 auto; padding: var(--sp-7) 22px var(--sp-5);
  display: grid; grid-template-columns: 2.2fr 1fr 1fr 1fr; gap: var(--sp-6);
}
.pf-col { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.pf-col-brand { gap: 12px; max-width: 340px; }
.pf-tag { font-size: var(--fs-sm); color: var(--muted); line-height: var(--lh-normal); }
.pf-head {
  font-size: var(--fs-xs); font-weight: var(--fw-bold); text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted-2); margin-bottom: 2px;
}
.pf-col a:not(.pn-brand) {
  font-size: var(--fs-sm); color: var(--muted); text-decoration: none;
  transition: color var(--t-fast) ease;
}
.pf-col a:not(.pn-brand):hover { color: var(--primary); text-decoration: none; }

/* Contact block — only rendered for settings the admin actually filled in */
.pf-contact { display: flex; flex-direction: column; gap: 8px; }
.pf-contact-row {
  display: flex; align-items: flex-start; gap: 8px;
  font-size: var(--fs-sm); color: var(--muted); line-height: 1.45;
}
.pf-contact-row svg { color: var(--muted-2); flex-shrink: 0; margin-top: 3px; }

/* Payment methods — mirrors the gateways enabled in admin settings */
.pf-pay { display: flex; flex-direction: column; gap: 7px; }
.pf-pay-head {
  font-size: var(--fs-xs); font-weight: var(--fw-semibold);
  text-transform: uppercase; letter-spacing: .06em; color: var(--muted-2);
}
.pf-pay-row { display: flex; flex-wrap: wrap; gap: 6px; }
.pf-pay-chip {
  font-size: var(--fs-xs); color: var(--muted);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r-xs); padding: 4px 10px; white-space: nowrap;
}

.public-footer-base {
  border-top: 1px solid var(--border);
  padding: var(--sp-4) 22px; text-align: center;
  font-size: var(--fs-xs); color: var(--muted-2);
  display: flex; flex-wrap: wrap; align-items: center;
  justify-content: center; gap: 8px;
}
.pf-base-sep { opacity: .5; }

@media (max-width: 900px) {
  .public-footer-in { grid-template-columns: 1fr 1fr 1fr; }
  /* Brand spans the full row so its paragraph + contact rows keep a readable
     measure instead of being crushed into a third of the width. */
  .pf-col-brand { grid-column: 1 / -1; max-width: 460px; }
}
@media (max-width: 640px) {
  .public-footer-in { grid-template-columns: 1fr; gap: var(--sp-5); }
  .pf-col-brand { max-width: none; }
  .pf-base-sep { display: none; }
  .public-footer-base { flex-direction: column; gap: 4px; }
}

/* ── Reduced motion — disable kit animation/transform effects ────────────── */
@media (prefers-reduced-motion: reduce) {
  .btn, .icon-btn, .lift, .pricing-card, .toast, .modal-card, .switch .slider,
  .switch .slider::before, .faq-item summary::after, .skeleton, .reveal {
    transition: none !important;
    animation: none !important;
  }
  .reveal { opacity: 1; transform: none; }
  .btn:hover, .btn:active, .lift:hover, .pricing-card:hover { transform: none; }
}
