/* ==========================================================================
   SD Manager — Phase 5a authentication: full-screen auth layout, sign-in screen,
   status bar, menu account
   Builds on tokens and components from style.css / activities.css.
   ========================================================================== */

/* Signed-in notice under the top bar */
.auth-status {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  /* Same centered column as the top bar and page content. */
  margin: 12px max(var(--gutter), calc((100% - 1320px) / 2 + var(--gutter))) 0;
  padding: 10px 14px;
  border: 1px solid color-mix(in srgb, var(--info) 30%, transparent);
  border-radius: var(--radius);
  background: var(--info-soft);
  color: var(--text-2);
  font-size: 13.5px;
}

.auth-status[hidden] { display: none; }
.auth-status .icon { margin-top: 3px; color: var(--info); }
.auth-status p { min-width: 0; overflow-wrap: anywhere; }
.auth-status strong { color: var(--text); }
.auth-status + .content { padding-top: 16px; }

/* Demo session (localhost only): amber, so it never looks like a signed-in account */
.auth-status--demo {
  border-color: color-mix(in srgb, var(--warning) 30%, transparent);
  background: var(--warning-soft);
}

.auth-status--demo .icon { color: var(--warning); }

/* Workspace connection (Phase 5c.1). The text always states the status; color only supports it. */
.auth-status[data-workspace="connected"] .icon { color: var(--success); }

.auth-status:is([data-workspace="denied"], [data-workspace="not-found"], [data-workspace="error"]) {
  border-color: color-mix(in srgb, var(--warning) 30%, transparent);
  background: var(--warning-soft);
}

.auth-status:is([data-workspace="denied"], [data-workspace="not-found"], [data-workspace="error"]) .icon {
  color: var(--warning);
}

.auth-status[data-workspace] p > span { display: block; }

.auth-status:has(.auth-status-retry) { flex-wrap: wrap; }
.auth-status:has(.auth-status-retry) p { flex: 1 1 14rem; }

.auth-status-retry {
  flex-shrink: 0;
  min-height: 44px;
  margin-left: auto;
}

/* ---------- Signed-in workspace views (Phase 5c.2a): real profiles, no demo data ---------- */

/* Sidebar pill while signed in: blue "workspace" instead of the amber demo label */
.demo-pill--live {
  background: rgb(147 180 255 / 0.12);
  color: #bfd0ff;
}

.workspace-profile {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
  padding: 16px 18px;
}

.workspace-profile-name {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 750;
  color: var(--text);
  overflow-wrap: anywhere;
}

.workspace-profile-sub {
  font-size: 13px;
  color: var(--text-muted);
}

/* Profile trigger with no profile selected */
.avatar--none {
  background: var(--accent-soft);
  color: var(--accent-text);
}

.avatar--lg {
  width: 48px;
  height: 48px;
  font-size: 16px;
}

.workspace-empty .btn { min-height: 44px; }

/* ---------- Profile create/edit (Phase 5c.2b, local emulator only) ---------- */

.page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.page-actions .btn,
.workspace-profile .btn { min-height: 44px; }

.workspace-profile { flex-wrap: wrap; }
.workspace-profile-text { flex: 1 1 12rem; min-width: 0; }

/* Shown next to disabled controls: why they are disabled (never color or state alone). */
.workspace-readonly-note {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  max-width: 60ch;
  margin: -6px 0 16px;
  font-size: 13px;
  color: var(--text-muted);
  text-align: left;
}

.workspace-readonly-note .icon { margin-top: 2px; flex: none; }
.workspace-empty .workspace-readonly-note { margin: 0; }

.page-actions .btn:disabled,
.workspace-profile .btn:disabled,
.workspace-empty .btn:disabled { cursor: not-allowed; opacity: 0.55; }

.profile-form-preview {
  display: flex;
  justify-content: center;
}

/* Sidebar pill in local emulator mode: test data, clearly not the live workspace */
.demo-pill--emulator {
  background: rgb(74 222 128 / 0.12);
  color: #86efac;
}

/* ---------- Full-screen auth layout (replaces the app shell) ---------- */

.auth-layout {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 100dvh;
}

/* Brand panel: navy in both themes, like the sidebar */
.auth-hero {
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: calc(18px + env(safe-area-inset-top, 0px)) calc(var(--gutter) + env(safe-area-inset-right, 0px))
    64px calc(var(--gutter) + env(safe-area-inset-left, 0px));
  background:
    radial-gradient(520px 320px at 100% 0%, rgb(45 212 191 / 0.22), transparent 70%),
    radial-gradient(420px 300px at 0% 100%, rgb(45 212 191 / 0.1), transparent 70%),
    var(--sidebar-bg);
  color: var(--sidebar-text);
}

.auth-hero-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding-right: 56px; /* room for the theme toggle */
}

.auth-hero-brand .brand-name { color: #fff; }
.auth-hero-copy,
.auth-hero-foot { display: none; }

.auth-hero-title {
  max-width: 22ch;
  font-family: var(--font-display);
  font-size: clamp(28px, 3vw, 38px);
  font-weight: 750;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: #fff;
}

.auth-hero-points {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 28px;
  font-size: 15px;
}

.auth-hero-points li {
  display: flex;
  align-items: center;
  gap: 12px;
}

.auth-hero-points .icon {
  width: 36px;
  height: 36px;
  padding: 8px;
  border-radius: 11px;
  background: rgb(45 212 191 / 0.12);
  color: var(--teal-300);
}

.auth-hero-foot {
  font-size: 13px;
  color: var(--sidebar-muted);
}

/* Theme toggle: top-right corner of the screen (on the navy band on phones) */
.icon-btn.auth-theme-toggle {
  position: absolute;
  top: calc(18px + env(safe-area-inset-top, 0px));
  right: calc(var(--gutter) + env(safe-area-inset-right, 0px));
  width: 44px;
  height: 44px;
  border-color: rgb(255 255 255 / 0.14);
  background: rgb(255 255 255 / 0.06);
  color: var(--sidebar-text);
  box-shadow: none;
}

.icon-btn.auth-theme-toggle:hover {
  background: var(--sidebar-hover);
  color: #fff;
}

.auth-panel {
  display: flex;
  justify-content: center;
  /* The card overlaps the navy band on phones. */
  margin-top: -40px;
  padding: 0 calc(var(--gutter) + env(safe-area-inset-right, 0px)) calc(32px + env(safe-area-inset-bottom, 0px))
    calc(var(--gutter) + env(safe-area-inset-left, 0px));
}

.auth-main {
  display: flex;
  justify-content: center;
  width: 100%;
  outline: none;
}

/* Session check */
.auth-pending {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
  max-width: 440px;
  padding: 40px 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  color: var(--text-muted);
  font-weight: 600;
}

.auth-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: auth-spin 0.8s linear infinite;
}

@keyframes auth-spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .auth-spinner { animation-duration: 2.4s; }
}

/* Sign-in page */
.auth-page {
  display: flex;
  justify-content: center;
  width: 100%;
}

.card.auth-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 440px;
  padding: 28px 22px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.auth-title {
  font-family: var(--font-display);
  font-size: clamp(22px, 5vw, 26px);
  font-weight: 750;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.auth-sub {
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

.auth-sub strong { color: var(--text); }
.auth-card .form-error { margin: 0; }

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 4px;
}

.password-field { position: relative; }
.password-field .input { padding-right: 52px; }

.icon-btn.password-toggle {
  position: absolute;
  top: 0;
  right: 0;
  width: 44px;
  height: 44px;
  border: 0;
  background: transparent;
  box-shadow: none;
  color: var(--text-muted);
}

.icon-btn.password-toggle:hover { background: transparent; color: var(--text); }

.auth-check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-2);
  cursor: pointer;
}

.auth-check input {
  width: 20px;
  height: 20px;
  margin: 0;
  flex: none;
  accent-color: var(--accent);
}

.auth-check + .field-hint { margin-top: -12px; }

.auth-submit { width: 100%; height: 48px; font-size: 15px; }
.auth-submit[aria-busy="true"] { opacity: 0.75; cursor: progress; }
.auth-submit .icon { width: 18px; height: 18px; }

.auth-link {
  align-self: center;
  min-height: 44px;
  padding: 8px 12px;
}

.auth-link .icon { width: 16px; height: 16px; }

.auth-note,
.auth-hint {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}

.auth-note .icon,
.auth-hint .icon { margin-top: 3px; flex: none; }

.auth-hint {
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--info-soft);
  color: var(--text-2);
}

.auth-hint .icon { color: var(--info); }
.auth-hint code { font-size: 12.5px; overflow-wrap: anywhere; }

.auth-note {
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.auth-notice {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--success-soft);
  color: var(--success);
  font-size: 13.5px;
  font-weight: 600;
}

.auth-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 4px;
}

.auth-actions .btn { flex: 1; min-width: 160px; height: 46px; }

/* Which sign-in service this screen uses (local development hosts only) */
.auth-mode {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--info) 30%, transparent);
  border-radius: 12px;
  background: var(--info-soft);
  color: var(--text-2);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.auth-mode .icon { margin-top: 2px; flex: none; color: var(--info); }
.auth-mode strong { color: var(--text); }
.auth-mode a { color: var(--accent-text); font-weight: 600; text-decoration: underline; }

.auth-mode--emulator {
  border-color: color-mix(in srgb, var(--success) 35%, transparent);
  background: var(--success-soft);
}

.auth-mode--emulator .icon { color: var(--success); }

/* Explicit demo entry (localhost only) — visually separate from signing in */
.auth-demo {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
  padding: 14px;
  border: 1px dashed color-mix(in srgb, var(--warning) 45%, transparent);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--warning-soft) 60%, transparent);
}

.auth-demo-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 10px;
}

.auth-demo-title { font-size: 14px; font-weight: 700; }
.auth-demo-text { font-size: 13px; color: var(--text-muted); }
.auth-demo-btn { width: 100%; height: 44px; }

/* Account section in the header profile menu */
.menu-sep {
  height: 1px;
  margin: 6px 4px;
  background: var(--border);
  list-style: none;
}

.menu-account {
  padding: 4px 10px 6px;
  list-style: none;
}

.menu-account-label {
  font-size: 12px;
  font-weight: 650;
  color: var(--text-muted);
}

.menu-account-email {
  margin-top: 2px;
  font-size: 14px;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.menu-account-flag { margin-top: 4px; }

/* Email verification status (icon + text, never color alone) */
.menu-account-verify {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  font-size: 13px;
  font-weight: 650;
}

.menu-account-verify[data-verified="true"] { color: var(--success); }
.menu-account-verify[data-verified="false"] { color: var(--warning); }

.menu-account-feedback {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.4;
  overflow-wrap: anywhere;
  color: var(--text-2);
  background: var(--info-soft);
}

.menu-account-feedback[data-tone="success"] { background: var(--success-soft); }
.menu-account-feedback[data-tone="error"] { background: var(--warning-soft); }

.menu-account-action[aria-busy="true"] { cursor: progress; }
.menu-account-action:disabled { opacity: 0.6; }
.menu-account-action span { min-width: 0; }

.menu-account-action {
  display: flex;
  align-items: center;
  gap: 10px;
  width: calc(100% + 20px);
  min-height: 44px;
  margin: 6px -10px 0;
  padding: 8px 10px;
  border: 0;
  border-radius: 12px;
  background: none;
  font-size: 14px;
  font-weight: 650;
  color: var(--text-2);
  text-align: left;
  cursor: pointer;
}

.menu-account-action:hover { background: var(--surface-hover); color: var(--text); }
.menu-account-action:focus-visible { outline-offset: -2px; }
.menu-account-action .icon { width: 18px; height: 18px; color: var(--accent-text); }

@media (min-width: 640px) {
  .card.auth-card { padding: 36px 36px 32px; }
}

/* Desktop: brand panel on the left, sign-in centered on the right */
@media (min-width: 960px) {
  .auth-layout {
    grid-template-columns: minmax(360px, 42%) 1fr;
    grid-template-rows: none;
  }

  .auth-hero {
    justify-content: space-between;
    padding: calc(40px + env(safe-area-inset-top, 0px)) 48px calc(36px + env(safe-area-inset-bottom, 0px))
      calc(48px + env(safe-area-inset-left, 0px));
  }

  .auth-hero-brand { padding-right: 0; }
  .auth-hero-copy,
  .auth-hero-foot { display: block; }

  .icon-btn.auth-theme-toggle {
    top: calc(24px + env(safe-area-inset-top, 0px));
    right: calc(28px + env(safe-area-inset-right, 0px));
    border-color: var(--border);
    background: var(--surface);
    color: var(--text-2);
    box-shadow: var(--shadow-sm);
  }

  .icon-btn.auth-theme-toggle:hover {
    background: var(--surface-hover);
    color: var(--text);
  }

  .auth-panel {
    align-items: center;
    margin-top: 0;
    padding: 88px 48px 48px;
  }

  .card.auth-card { box-shadow: var(--shadow); }
}

/* ---------- Archive / restore and profile management (Phase 5c.2c) ---------- */

.workspace-profile-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.workspace-flash { margin-bottom: 16px; }

.tag--active {
  background: var(--success-soft);
  color: var(--success);
}

.profile-section {
  margin-bottom: 16px;
  padding: 16px 18px;
}

.profile-section-title {
  margin-bottom: 10px;
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 750;
  color: var(--text);
}

.profile-section-count { color: var(--text-muted); font-weight: 600; }

.profile-section-empty { color: var(--text-muted); font-size: 14px; }

.profile-list {
  display: flex;
  flex-direction: column;
}

.profile-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}

.profile-row:first-child { border-top: 0; }

.profile-row-text {
  display: flex;
  flex: 1 1 12rem;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  min-width: 0;
}

.profile-row-name {
  font-weight: 650;
  color: var(--text);
  overflow-wrap: anywhere;
}

.profile-row .tag { display: inline-flex; align-items: center; gap: 4px; }
.profile-row--archived .tag {
  background: color-mix(in srgb, var(--text-muted) 14%, transparent);
  color: var(--text-2);
}

/* Archived rows read as inactive without relying on color: the tag says "Archived". */
.profile-row--archived .avatar { filter: grayscale(0.7); opacity: 0.75; }

.profile-row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.profile-row-actions .btn { min-height: 44px; }

.profile-row-actions .btn:disabled { cursor: not-allowed; opacity: 0.55; }

.profile-status-confirm {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

/* "Manage profiles" link in the profile menu (workspace mode) */
.menu-manage {
  width: 100%;
  margin: 4px 0 0;
  color: var(--text);
  text-decoration: none;
}
