/* Account chip + dropdown — workspace header surface for the
 * Phase 2 auth UI. The chip mirrors .machine-chip on the far-right
 * of the workspace__actions row, opens a dropdown on click.
 *
 * Loaded by index.html (workspace shell) only — auth-shell pages
 * have their own styling via auth.css.
 */

.account-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 6px;
  margin-left: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--fg);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--t-fast) var(--ease),
              border-color var(--t-fast) var(--ease);
}
.account-chip:hover { background: var(--surface-3); border-color: var(--border-strong); }
.account-chip[aria-expanded="true"] { background: var(--surface-3); border-color: var(--accent); }

.account-chip__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--surface-4);
  transition: background var(--t-fast) var(--ease),
              box-shadow var(--t-fast) var(--ease);
}
.account-chip__dot[data-state="online"] {
  background: var(--success);
  box-shadow: 0 0 6px rgba(94, 226, 160, 0.6);
}
.account-chip__dot[data-state="offline"] {
  background: var(--surface-4);
}

.account-chip__initial {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #4c5cff);
  color: white;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.account-chip__caret {
  font-size: 9px;
  color: var(--fg-dim);
  margin-left: 2px;
}

/* Signed-out variant — quieter than the signed-in chip so users don't
 * misinterpret it as an active account chip. */
.account-chip--signed-out {
  background: transparent;
  border-color: transparent;
  padding: 4px 10px;
  font-weight: 500;
  color: var(--fg-muted);
}
.account-chip--signed-out:hover {
  background: var(--surface-2);
  color: var(--fg);
  border-color: var(--border);
}

/* Wrap so the popover anchors below the chip rather than the
 * workspace__actions row. */
.account-chip-host {
  position: relative;
  display: inline-flex;
  align-items: center;
}

/* ---------------- Dropdown ---------------- */

.account-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 40;
  min-width: 260px;
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-2);
  padding: 4px;
  display: grid;
  gap: 1px;
  animation: account-menu-pop 140ms var(--ease);
}
.account-menu[hidden] { display: none; }

@keyframes account-menu-pop {
  from { opacity: 0; transform: translateY(-4px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0)     scale(1); }
}

.account-menu__identity {
  padding: 10px 12px 8px;
  display: grid;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.account-menu__name {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
  letter-spacing: -0.005em;
}
.account-menu__email {
  font-size: 11.5px;
  color: var(--fg-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-menu__item {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--fg);
  font: inherit;
  font-size: 12.5px;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--t-fast) var(--ease);
}
.account-menu__item:hover { background: var(--surface-2); }
.account-menu__item:focus-visible {
  outline: none;
  background: var(--surface-2);
  border-color: var(--accent);
}
.account-menu__item-icon {
  font-size: 13px;
  width: 16px;
  text-align: center;
  color: var(--fg-muted);
}
.account-menu__item-count {
  margin-left: auto;
  font-size: 11px;
  color: var(--fg-dim);
}

.account-menu__item--ghost {
  color: var(--fg-dim);
  cursor: not-allowed;
}
.account-menu__item--ghost:hover { background: transparent; }
.account-menu__item--ghost .account-menu__item-count {
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-dim);
}

.account-menu__divider {
  height: 1px;
  background: var(--border);
  margin: 4px 4px;
}

.account-menu__item--danger {
  color: var(--fg);
}
.account-menu__item--danger:hover {
  background: rgba(255, 122, 138, 0.10);
  color: var(--danger);
}

/* ---------------- Sign-out confirmation modal ---------------- */

.logout-confirm-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 11, 0.78);
  backdrop-filter: blur(8px);
  display: grid;
  place-items: center;
  z-index: 70;
  animation: fade-in var(--t-med) var(--ease);
}
.logout-confirm-backdrop[hidden] { display: none; }

.logout-confirm {
  width: min(420px, calc(100vw - 32px));
  background: linear-gradient(180deg, var(--surface-1), var(--bg-tint));
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 22px 22px 18px;
  box-shadow: var(--shadow-2);
}
.logout-confirm__title {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--fg);
}
.logout-confirm__body {
  font-size: 13px;
  color: var(--fg-muted);
  line-height: 1.5;
  margin-bottom: 18px;
}
.logout-confirm__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ---------------- Connect-modal account bar ---------------- */
/* Sits at the very top of the "Connect a machine" modal so login is
   reachable before any machine exists. account-chip.js drives the
   data-state swap between anon and signed-in. */
.modal__account {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.modal__account-label {
  font-size: 12.5px;
  color: var(--fg-muted);
}
.modal__account[data-state="signedin"] .modal__account-label {
  color: var(--fg);
  font-weight: 500;
}
.modal__account-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

/* ---------------- Mobile — bottom-sheet style dropdown ---------------- */

@media (max-width: 720px) {
  .account-chip { padding: 4px 6px; }
  .account-chip__caret { display: none; }

  .account-menu {
    position: fixed;
    top: auto;
    right: 8px;
    bottom: 8px;
    left: 8px;
    width: auto;
    min-width: 0;
    max-height: 60vh;
    overflow-y: auto;
    border-radius: var(--radius-lg);
    padding: 6px 6px 12px;
  }
  .account-menu::before {
    content: "";
    display: block;
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: var(--surface-4);
    margin: 6px auto 8px;
  }
  .account-menu__item {
    padding: 12px 14px;
    font-size: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .account-menu,
  .logout-confirm-backdrop {
    animation: none !important;
  }
}
