/*
 * Account UI: the header slot, the avatar menu, the sign-in dialog, and the
 * toast the account flow needs on pages that don't load styles.css.
 *
 * A third stylesheet rather than blocks in both styles.css and pages.css:
 * these components appear on all four pages, and the tokens below are already
 * declared twice in this repo — a third copy of ~250 lines would have drifted
 * within a release.
 *
 * Values come from the account-flow design canvas. They resolve to the same
 * palette both existing stylesheets define, with fallbacks so this file is
 * self-contained if it ever loads alone.
 */

/*
 * The UA stylesheet's `[hidden] { display: none }` is the WEAKEST rule there
 * is: any author rule that sets `display` beats it. Several components here
 * are flex containers toggled via the hidden property, so without this they
 * set the attribute and stay visible — which shipped once, rendering the
 * provider list and the OTP pane at the same time.
 *
 * styles.css solves this per selector (`.share-overlay[hidden]`, …). One rule
 * is safer: a new toggled element cannot forget to opt in.
 */
[hidden] {
  display: none !important;
}

.auth-slot {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

/* ---- Sign in button ---- */

.auth-signin-btn {
  border-radius: 8px;
  padding: 0.45rem 0.7rem;
  font-size: 0.85rem;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  background: var(--primary, #2563eb);
  color: #fff;
  border: 1px solid transparent;
  transition: background 0.15s ease;
}

.auth-signin-btn:hover {
  background: #1d4ed8;
}

.auth-signin-btn:focus-visible {
  outline: 2px solid #1d4ed8;
  outline-offset: 2px;
}

/* ---- Avatar + account menu ---- */

.auth-menu {
  position: relative;
  display: flex;
  align-items: center;
}

.auth-avatar-btn {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 3px 6px 3px 3px;
  border: 0;
  border-radius: 999px;
  background: #eef2ff;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s ease;
}

.auth-avatar-btn:hover {
  background: #e0e7ff;
}

.auth-avatar-btn:focus-visible {
  outline: 2px solid var(--primary, #2563eb);
  outline-offset: 2px;
}

.auth-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: #eef2ff;
  border: 1px solid #c7d2fe;
  color: #1d4ed8;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  /* Initials must not be selectable — the avatar is a button, not text. */
  user-select: none;
}

.auth-avatar-lg {
  width: 56px;
  height: 56px;
  font-size: 1.25rem;
}

.auth-avatar-chevron {
  display: flex;
  color: var(--muted, #6b7280);
}

/*
 * `fixed`, not `absolute`, and positioned by JS.
 *
 * .app-header carries `overflow: hidden` — it is what makes the max-height
 * collapse-on-scroll animation work — so an absolutely positioned dropdown is
 * CLIPPED by the header, not merely stacked behind the toolbar. Raising
 * z-index cannot fix that (90 already beats the toolbar's 10). A fixed element
 * escapes an ancestor's overflow because its containing block is the viewport,
 * so long as no ancestor has transform/filter/will-change/contain — none does
 * here. src/auth.js sets top/right from the button's rect on open.
 */
.auth-dropdown {
  position: fixed;
  z-index: 90;
  width: 264px;
  padding: 6px 0;
  border: 1px solid var(--border, #d1d5db);
  border-radius: 12px;
  background: var(--panel-bg, #ffffff);
  box-shadow: 0 12px 32px -8px rgba(15, 23, 42, 0.22);
  animation: auth-dropdown-in 0.14s ease;
}

@keyframes auth-dropdown-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.auth-dropdown-identity {
  padding: 10px 14px 12px;
}

.auth-dropdown-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text, #1f2937);
}

.auth-dropdown-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 3px;
}

.auth-dropdown-email {
  font-size: 0.78rem;
  color: var(--muted, #6b7280);
  /* Long addresses must not widen the menu. */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-plan-badge {
  flex-shrink: 0;
  padding: 1px 7px;
  border: 1px solid #fde68a;
  border-radius: 999px;
  background: #fffbeb;
  color: #92400e;
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.4px;
}

.auth-dropdown-divider {
  height: 1px;
  margin: 6px 0;
  background: #eef2f7;
}

.auth-dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  width: 100%;
  padding: 8px 14px;
  border: 0;
  background: none;
  color: var(--text, #1f2937);
  font-family: inherit;
  font-size: 0.875rem;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.auth-dropdown-item:hover,
.auth-dropdown-item:focus-visible {
  background: #f3f4f6;
  outline: none;
}

.auth-dropdown-icon {
  display: flex;
  color: var(--muted, #6b7280);
}

/* ---- Sign-in dialog ---- */

.signin-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  animation: signin-fade-in 0.2s ease;
}

.signin-modal {
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - 3rem);
  overflow-y: auto;
  border-radius: 16px;
  background: var(--panel-bg, #ffffff);
  box-shadow:
    0 25px 50px -12px rgba(0, 0, 0, 0.25),
    0 0 0 1px rgba(0, 0, 0, 0.05);
  animation: signin-scale-in 0.25s ease;
}

@keyframes signin-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes signin-scale-in {
  from {
    opacity: 0;
    transform: scale(0.97);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.signin-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
}

.signin-modal-header h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text, #1f2937);
}

.signin-close-btn {
  display: flex;
  padding: 4px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--muted, #6b7280);
  cursor: pointer;
}

.signin-close-btn:hover {
  background: #f3f4f6;
  color: var(--text, #1f2937);
}

.signin-modal-body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 12px 24px 24px;
}

.signin-lede {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--muted, #6b7280);
}

/* Wraps the divider + email field + button so the whole factor can be hidden
   as a unit when the server says it is unavailable. */
.signin-email-option {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.signin-providers {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

.signin-provider-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.625rem;
  padding: 11px;
  border: 1px solid var(--border, #d1d5db);
  border-radius: 8px;
  background: var(--panel-bg, #ffffff);
  color: var(--text, #1f2937);
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.signin-provider-btn:hover {
  background: #f9fafb;
  border-color: #9ca3af;
}

.signin-provider-btn:focus-visible {
  outline: 2px solid var(--primary, #2563eb);
  outline-offset: 2px;
}

.signin-divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--muted, #6b7280);
  font-size: 0.8rem;
}

.signin-divider::before,
.signin-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border, #d1d5db);
}

.signin-field {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.signin-field label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text, #1f2937);
}

.signin-field input {
  padding: 10px 12px;
  border: 1px solid var(--border, #d1d5db);
  border-radius: 8px;
  background: var(--panel-bg, #ffffff);
  color: var(--text, #1f2937);
  font-family: inherit;
  font-size: 0.9375rem;
}

.signin-field input:focus {
  outline: none;
  border-color: var(--primary, #2563eb);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.signin-otp-input {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1.35rem !important;
  letter-spacing: 0.4em;
  text-align: center;
}

.signin-primary-btn {
  padding: 11px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--primary, #2563eb);
  color: #fff;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease;
}

.signin-primary-btn:hover:not(:disabled) {
  background: #1d4ed8;
}

.signin-primary-btn:disabled {
  opacity: 0.65;
  cursor: default;
}

.signin-error {
  margin: -0.5rem 0 0;
  font-size: 0.8rem;
  line-height: 1.4;
  color: #b91c1c;
}

.signin-otp-actions {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
}

.signin-link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--primary, #2563eb);
  font-family: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  text-decoration: underline;
}

.signin-link-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.signin-reassurance {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 10px 12px;
  border: 1px solid #eef2f7;
  border-radius: 8px;
  background: #f8fafc;
}

.signin-reassurance-icon {
  display: flex;
  flex-shrink: 0;
  margin-top: 1px;
  color: #047857;
}

.signin-reassurance p {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--muted, #6b7280);
}

@media (max-width: 520px) {
  .signin-overlay {
    padding: 0.75rem;
  }

  .auth-dropdown {
    width: min(264px, calc(100vw - 1.5rem));
  }
}

/* ---- Toast ----
 * Lives here, not in styles.css, because the account flow raises toasts on
 * pages that never load the editor's stylesheet. index.html loads both files;
 * this is the only definition.
 */

.toast-status {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 1200;
  max-width: min(90vw, 380px);
  padding: 0.75rem 0.9rem;
  border-radius: 10px;
  border: 1px solid #dbeafe;
  background: #eff6ff;
  color: #1e3a8a;
  font-size: 0.88rem;
  line-height: 1.3;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.18);
  transform: translateY(-8px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.toast-status.visible {
  transform: translateY(0);
  opacity: 1;
}

.toast-status.warn {
  border-color: #fed7aa;
  background: #fff7ed;
  color: #9a3412;
}

.toast-status.error {
  border-color: #fecaca;
  background: #fef2f2;
  color: #b91c1c;
}
