/*
 * Layout — page container, account menu, flash messages, sign-in page.
 * The app shell (sidebar, theme toggle) lives in shell.css.
 * Used by app/views/layouts/application.html.erb.
 */

/* ---------- Account menu (avatar dropdown) ---------- */

.user-menu {
  position: relative;
}

.user-menu__trigger {
  display: inline-flex;
  align-items: center;
  padding: var(--space-1);
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  background: transparent;
  cursor: pointer;
}

.user-menu__trigger:hover,
.user-menu__trigger[aria-expanded="true"] {
  background: var(--color-surface-sunken);
}

.user-menu__trigger[aria-expanded="true"] {
  border-color: var(--color-border);
}

/* Avatar frame: initials render underneath, the profile image on top.
   If the image is absent or fails to load, the initials stay visible. */
.user-menu__avatar-frame {
  position: relative;
  display: block;
  width: 2rem;
  height: 2rem;
}

.user-menu__initials {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--color-surface-sunken);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  font-size: var(--text-xs);
  font-weight: var(--font-bold);
}

.user-menu__avatar {
  position: relative;
  display: block;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  object-fit: cover;
  background: var(--color-surface);
}

.user-menu__dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + var(--space-2));
  z-index: 40;
  min-width: 15rem;
  max-width: calc(100vw - var(--space-8, 4rem));
  padding: var(--space-2);
  background: var(--color-raised);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

/* The dropdown is display:block when open; [hidden] must always win. */
.user-menu__dropdown[hidden] {
  display: none !important;
}

.user-menu__identity {
  display: grid;
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-2);
  border-bottom: 1px solid var(--color-border);
}

.user-menu__name {
  font-weight: var(--font-semibold);
  color: var(--color-text);
}

.user-menu__email {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  overflow-wrap: anywhere;
}

.user-menu .button_to {
  display: block;
}

/* Sign out renders as a full-width menu item, overriding the global button
   skin (double class beats the input[type="submit"] specificity). */
.user-menu .user-menu__item {
  display: block;
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-text);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  line-height: 1.4;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.user-menu .user-menu__item:hover,
.user-menu .user-menu__item:focus-visible {
  background: var(--color-surface-sunken);
  color: var(--color-text);
}

/* Flash messages */
.flash-stack {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5) 0;
}

/* The ERB loop leaves whitespace, so :empty never matches an empty stack. */
.flash-stack:not(:has(.flash)) {
  display: none;
}

.flash {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  border: 1px solid transparent;
}

.flash__close {
  flex: 0 0 auto;
  padding: 0 var(--space-1);
  border: 0;
  background: transparent;
  color: inherit;
  font-size: var(--text-lg);
  line-height: 1;
  cursor: pointer;
}

.flash__close:hover {
  background: transparent;
  opacity: 0.7;
}

.flash--notice {
  background: var(--color-success-bg);
  color: var(--color-success-fg);
  border-color: var(--color-success-fg);
}

.flash--alert {
  background: var(--color-danger-bg);
  color: var(--color-danger-fg);
  border-color: var(--color-danger-fg);
}

/* Sign-in page: chromeless, centered, no card (mirrors ctv-performance). */
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--space-5);
  background: var(--color-surface);
}

.login-card {
  width: 100%;
  max-width: 340px;
  text-align: center;
}

.login-card .product-brand--login {
  flex-direction: column;
  gap: 20px;
  margin-bottom: 40px;
}

.product-brand--login .product-brand__mark {
  width: 52px;
  height: 52px;
}

.product-brand--login .product-brand__name {
  font-size: 40px;
}

.login-title {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.login-card .flash {
  margin-bottom: var(--space-4);
  text-align: left;
}

/* The repo-wide .button_to is inline-block; login buttons fill the column */
.login-card .button_to {
  display: block;
}

.login-button {
  width: 100%;
  padding: 12px;
  font-size: 13px;
}

/* Ink button in light mode; the heading token flips it to a light button in dark mode */
.login-button--primary {
  background: var(--color-heading);
  border-color: var(--color-heading);
  color: var(--color-surface);
}

.login-button--primary:hover {
  opacity: 0.88;
}

.login-hint {
  margin-top: 16px;
  color: var(--color-text-muted);
  font-size: 11px;
}
