:root {
  --bg: #070910;
  --panel: rgba(13, 18, 30, 0.74);
  --line: rgba(255, 255, 255, 0.09);
  --text: #f5f7ff;
  --muted: #98a4bd;
  --cyan: #50e6ff;
  --blue: #7080ff;
  --red: #ff6b7d;
  --radius: 24px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 20px;
  background:
    radial-gradient(circle at 15% 12%, rgba(80, 90, 255, 0.11), transparent 28%),
    radial-gradient(circle at 85% 20%, rgba(70, 230, 255, 0.07), transparent 32%),
    linear-gradient(180deg, #070910, #0a0e18 48%, #070910);
  color: var(--text);
  font-family: Inter, sans-serif;
}

a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; }

a:focus-visible,
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.auth-shell {
  width: min(420px, 100%);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: 'Space Grotesk', sans-serif;
  letter-spacing: 0.06em;
  margin-bottom: 40px;
  justify-content: center;
}

.brand-logo {
  display: block;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  object-fit: contain;
}

.brand strong { font-weight: 700; }
.brand strong span { color: var(--cyan); }

.auth-card {
  background: linear-gradient(180deg, rgba(18, 25, 41, 0.82), rgba(9, 13, 23, 0.74));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.38);
  backdrop-filter: blur(18px);
  padding: 40px;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--cyan);
  opacity: 0.88;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.17em;
  margin: 0 0 18px;
  font-weight: 600;
}

.eyebrow span {
  display: inline-block;
  width: 32px;
  height: 1px;
  background: linear-gradient(90deg, var(--cyan), transparent);
}

.auth-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: clamp(1.5rem, 4vw, 1.9rem);
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin: 0 0 8px;
}

.auth-hint {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.6;
  margin: 0 0 28px;
}

.field {
  margin-bottom: 18px;
}

.field label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin-bottom: 8px;
  color: var(--text);
}

.field input {
  width: 100%;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 13px 14px;
  color: var(--text);
  transition: border-color 0.2s ease, background 0.2s ease;
}

.field input:hover { border-color: rgba(255, 255, 255, 0.18); }
.field input:focus-visible {
  border-color: var(--cyan);
  background: rgba(255, 255, 255, 0.05);
  outline: none;
}

.field-hint {
  margin: 6px 0 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.btn {
  display: inline-flex;
  width: 100%;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 22px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  transition: transform 0.2s ease;
  font-weight: 600;
  cursor: pointer;
}

.btn:hover { transform: translateY(-2px); }

.btn.primary {
  background: linear-gradient(135deg, rgba(80, 230, 255, 0.25), rgba(112, 128, 255, 0.28));
  box-shadow: 0 16px 30px rgba(80, 230, 255, 0.18);
  color: var(--text);
}

.btn[disabled] {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.btn[disabled]:hover { transform: none; }

.status-message {
  margin: 0 0 18px;
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--muted);
}

.status-message.error {
  background: rgba(255, 107, 125, 0.12);
  border: 1px solid rgba(255, 107, 125, 0.35);
  color: var(--red);
}

.status-message.success {
  background: rgba(80, 230, 255, 0.1);
  border: 1px solid rgba(80, 230, 255, 0.3);
  color: var(--cyan);
}

.auth-links {
  margin-top: 18px;
  text-align: center;
  font-size: 0.88rem;
}

.auth-links a {
  color: var(--cyan);
}

.auth-links a:hover { text-decoration: underline; }

.divider {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 26px 0;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--line);
}

.auth-footer {
  margin-top: 24px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
}

.auth-footer a { color: var(--text); }
.auth-footer a:hover { color: var(--cyan); }

@media (max-width: 480px) {
  .auth-card { padding: 28px 22px; }
  body { padding: 32px 16px; }
}

/* ---------------------------------------------------------------------- */
/* Dashboard app shell (Phase 6A) — reuses the same tokens/typography as   */
/* the auth pages, but needs a full-width layout instead of the centered  */
/* auth-card, hence scoped under body.app-body rather than touching the   */
/* shared `body` rule the auth pages rely on.                             */
/* ---------------------------------------------------------------------- */

body.app-body {
  display: block;
  padding: 0;
  align-items: unset;
  justify-content: unset;
}

.loading-state {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.95rem;
  text-align: center;
  padding: 24px;
}

/* [hidden] and .loading-state{display:flex} have equal specificity, and this author
   stylesheet overrides the UA default [hidden]{display:none} — without this rule, JS
   setting the `hidden` attribute would not actually hide the element. */
.loading-state[hidden] {
  display: none;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-shell[hidden] {
  display: none;
}

.app-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(9, 13, 23, 0.6);
  backdrop-filter: blur(18px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-status-banner {
  margin: 0;
  border-radius: 0;
  border-left: none;
  border-right: none;
  text-align: center;
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: 'Space Grotesk', sans-serif;
  letter-spacing: 0.06em;
  flex-shrink: 0;
}

.app-brand strong { font-weight: 700; }
.app-brand strong span { color: var(--cyan); }

.app-brand-tag {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
}

.app-topbar-user {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.app-user-id {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  min-width: 0;
  text-align: right;
}

.app-user-name {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 40vw;
}

/* Purely visual (see dashboard.js): reflects the role already returned by
   GET /api/auth/me, never a permission decided in the browser. */
.role-badge {
  display: inline-block;
  margin-left: 6px;
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--cyan);
  border: 1px solid rgba(80, 230, 255, 0.35);
  border-radius: 999px;
  padding: 2px 8px;
  vertical-align: middle;
}

/* Same [hidden]-vs-author-stylesheet specificity issue as .loading-state/.app-shell —
   see the note above .loading-state[hidden]. */
.role-badge[hidden] {
  display: none;
}

.app-user-email {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 40vw;
}

.btn.ghost {
  width: auto;
  min-height: 40px;
  padding: 0 18px;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 0.85rem;
}

.btn.ghost:hover { border-color: rgba(255, 255, 255, 0.24); }

.app-layout {
  display: flex;
  flex: 1;
  min-height: 0;
}

.app-nav {
  width: 220px;
  flex-shrink: 0;
  border-right: 1px solid var(--line);
  padding: 24px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 11px 14px;
  border-radius: 12px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
}

/* Same [hidden]-vs-author-stylesheet specificity issue as .loading-state/.app-shell —
   see the note above .loading-state[hidden]. Needed for #nav-admin, hidden for non-ADMIN. */
.nav-item[hidden] {
  display: none;
}

a.nav-item:hover { background: rgba(255, 255, 255, 0.04); }

.nav-item.active {
  background: rgba(80, 230, 255, 0.1);
  color: var(--cyan);
  font-weight: 600;
}

.nav-item.disabled {
  color: var(--muted);
  cursor: default;
}

.nav-badge {
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  flex-shrink: 0;
}

.app-main {
  flex: 1;
  min-width: 0;
  padding: 36px 32px 60px;
}

.app-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: clamp(1.6rem, 3vw, 2.1rem);
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin: 0 0 8px;
}

.app-hint {
  color: var(--muted);
  font-size: 0.94rem;
  line-height: 1.6;
  margin: 0 0 32px;
}

.app-section-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.1rem;
  margin: 40px 0 16px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.info-card,
.feature-card {
  background: linear-gradient(180deg, rgba(18, 25, 41, 0.82), rgba(9, 13, 23, 0.74));
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
}

.info-card-label {
  margin: 0 0 8px;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.info-card-value {
  margin: 0 0 4px;
  font-size: 1.1rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.info-card-sub {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.feature-card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
  font-weight: 600;
}

.feature-card-text {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.5;
}

@media (max-width: 860px) {
  .app-layout { flex-direction: column; }

  .app-nav {
    width: 100%;
    flex-direction: row;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--line);
    padding: 12px 16px;
  }

  .nav-item { white-space: nowrap; }
}

@media (max-width: 560px) {
  .app-topbar { padding: 14px 16px; }
  .app-brand-tag { display: none; }
  .app-user-name,
  .app-user-email { max-width: 32vw; }
  .app-main { padding: 24px 16px 48px; }
}

/* ---------------------------------------------------------------------- */
/* Projects (Phase 7B) — reuses the Dashboard app shell/card tokens above. */
/* ---------------------------------------------------------------------- */

.app-hint { overflow-wrap: anywhere; }

#new-project-btn,
.project-form-actions .btn,
.project-detail-actions .btn {
  width: auto;
}

#new-project-btn {
  margin-bottom: 24px;
}

/* Same [hidden]-vs-author-stylesheet specificity issue already documented above
   (.loading-state[hidden]/.app-shell[hidden]/etc. from Phase 6A): .btn sets
   display:inline-flex and .project-detail-actions sets display:flex, both with the same
   specificity as the UA's [hidden]{display:none}, so an author rule with a `display`
   always wins regardless of hidden. Needed for #new-project-btn (ADMIN-only) and
   #admin-project-actions (ADMIN-only edit/archive controls). */
#new-project-btn[hidden] {
  display: none;
}

.project-detail-actions[hidden] {
  display: none;
}

.project-grid {
  list-style: none;
  margin: 0;
  padding: 0;
}

.project-card-item {
  list-style: none;
}

.project-card {
  display: block;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.project-card:hover {
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
}

.project-card-meta {
  margin-top: 10px;
}

.back-link {
  color: var(--cyan);
  font-size: 0.9rem;
  display: inline-block;
  margin-bottom: 8px;
}

.back-link:hover { text-decoration: underline; }

.project-form {
  background: linear-gradient(180deg, rgba(18, 25, 41, 0.82), rgba(9, 13, 23, 0.74));
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 24px;
  max-width: 520px;
}

.field textarea {
  width: 100%;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 13px 14px;
  color: var(--text);
  resize: vertical;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.field textarea:hover { border-color: rgba(255, 255, 255, 0.18); }
.field textarea:focus-visible {
  border-color: var(--cyan);
  background: rgba(255, 255, 255, 0.05);
  outline: none;
}

.project-form-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.project-form-actions .btn {
  min-width: 140px;
}

.project-detail-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin: 24px 0 12px;
}

.btn.ghost.danger {
  border-color: rgba(255, 107, 125, 0.35);
  color: var(--red);
}

.btn.ghost.danger:hover { border-color: rgba(255, 107, 125, 0.55); }

@media (max-width: 560px) {
  .project-form { padding: 18px; }
  .project-form-actions .btn,
  .project-detail-actions .btn { width: 100%; }
}

/* Agents reuse the existing project cards/forms and app shell. */
#new-agent-btn {
  width: auto;
  margin-bottom: 24px;
}

#new-agent-btn[hidden] {
  display: none;
}

.agents-page .app-title {
  overflow-wrap: anywhere;
}

/* Keep the role readable even when a long username is truncated. */
.agents-page .app-user-name {
  display: flex;
  align-items: center;
}

.agents-page #current-user-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.agents-page .app-user-name .role-badge {
  flex-shrink: 0;
}

@media (max-width: 560px) {
  .agents-page .app-topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .agents-page .app-topbar-user {
    width: 100%;
    justify-content: space-between;
  }

  .agents-page .app-user-id {
    align-items: flex-start;
    text-align: left;
    flex: 1;
  }

  .agents-page .app-user-name {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    max-width: 100%;
    overflow: visible;
  }

  .agents-page #current-user-name {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .agents-page .app-user-name .role-badge {
    margin-left: 0;
  }

  .agents-page .app-user-email {
    max-width: 100%;
  }

  .agents-page #logout-btn {
    flex-shrink: 0;
  }
}

/* Local auth controls; no inline styles or external icon dependency. */
.password-field { position: relative; }
.field .password-field input { padding-right: 3.5rem; }
.password-toggle {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.password-toggle:hover, .password-toggle[aria-pressed="true"] { color: var(--text); }
.password-toggle svg { fill: none; stroke: currentColor; stroke-width: 1.8; }

.password-checklist {
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.6;
}
.password-checklist [data-rule-icon] { display: inline-block; width: 1.2em; }
.password-checklist .is-met { color: var(--text); }
.password-checklist .requirement-state {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
