/* Wave 7: authentication, account controls, read-only states, and audit. */

.auth-main {
  display: grid;
  min-height: calc(100vh - 157px);
  place-items: center;
}

.auth-shell {
  width: min(100%, 460px);
  margin-inline: auto;
}

.auth-card {
  padding: 28px;
  border: 1px solid var(--a-border);
  border-radius: var(--a-radius);
  background: var(--a-surface);
}

.auth-card--compact {
  width: min(100%, 430px);
}

.auth-card__header {
  margin-bottom: 22px;
}

.auth-card__header h1 {
  font-size: 1.75rem;
}

.auth-card__header p:last-child {
  margin: 8px 0 0;
  color: var(--a-muted);
}

.auth-form {
  display: grid;
  gap: 17px;
}

.auth-field input[type="text"],
.auth-field input[type="password"] {
  width: 100%;
  min-height: 44px;
  padding: 9px 11px;
  border: 1px solid var(--a-border);
  border-radius: var(--a-radius);
  color: var(--a-ink);
  background: var(--a-surface);
}

.auth-field input:hover {
  border-color: var(--a-faint);
}

.auth-field input:focus {
  border-color: var(--a-accent);
}

.auth-submit {
  width: 100%;
  min-height: 44px;
  margin-top: 3px;
}

.auth-alert {
  display: grid;
  gap: 2px;
  margin-bottom: 18px;
  padding: 12px 14px;
  border: 1px solid var(--a-border);
  border-radius: var(--a-radius);
  font-size: 0.875rem;
}

.auth-alert--error {
  border-color: var(--a-danger-border);
  color: var(--a-st-unmatched-fg);
  background: var(--a-danger-wash);
}

.auth-alert--warning {
  border-color: var(--a-st-auto-fg);
  color: var(--a-st-auto-fg);
  background: var(--a-st-auto-bg);
}

.auth-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.auth-actions .button,
.audit-filters .button,
.audit-filters select {
  min-height: 44px;
}

.auth-actions form,
.auth-user__logout {
  margin: 0;
}

.auth-user {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 11px;
  padding-left: 16px;
  border-left: 1px solid var(--a-border-soft);
  font-size: 0.8125rem;
  white-space: nowrap;
}

.auth-user__identity {
  display: grid;
  min-width: 0;
  line-height: 1.25;
}

.auth-user__name {
  max-width: 150px;
  overflow: hidden;
  color: var(--a-ink);
  text-overflow: ellipsis;
}

.auth-user__role {
  color: var(--a-muted);
}

.auth-user__link,
.auth-user__logout-button {
  min-height: 44px;
  padding: 10px 8px;
  border: 0;
  border-radius: var(--a-radius);
  color: var(--a-accent);
  background: transparent;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  text-decoration: none;
}

.auth-user__link:hover,
.auth-user__logout-button:hover {
  color: var(--a-accent-hover);
  background: var(--a-accent-wash);
}

.auth-readonly-notice {
  padding: 24px;
  border: 1px solid var(--a-border);
  border-radius: var(--a-radius);
  background: var(--a-surface);
}

.auth-readonly-notice p:last-child {
  margin-bottom: 0;
  color: var(--a-muted);
}

.audit-page__heading {
  margin-bottom: 20px;
}

.audit-page__heading p:last-child {
  margin: 0;
  color: var(--a-muted);
}

.audit-filters {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 18px;
  padding: 16px;
  border: 1px solid var(--a-border);
  border-radius: var(--a-radius);
  background: var(--a-surface);
}

.audit-filters .field {
  width: min(260px, 100%);
}

.audit-filters .text-link {
  min-height: 42px;
  align-content: center;
}

.audit-table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--a-border);
  border-radius: var(--a-radius);
  background: var(--a-surface);
}

.audit-table {
  width: 100%;
  min-width: 900px;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.audit-table th,
.audit-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--a-border-soft);
  text-align: left;
  vertical-align: top;
}

.audit-table th {
  color: var(--a-muted);
  background: var(--a-bg);
  font-size: 0.75rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.audit-table tbody tr:last-child td {
  border-bottom: 0;
}

.audit-table__time,
.audit-action {
  white-space: nowrap;
}

.audit-table__details {
  max-width: 420px;
  overflow-wrap: anywhere;
  color: var(--a-muted);
}

.audit-action {
  display: inline-flex;
  padding: 2px 7px;
  border-radius: 999px;
  color: var(--a-accent);
  background: var(--a-accent-wash);
  font-size: 0.75rem;
}

.audit-empty {
  padding-block: 36px !important;
  color: var(--a-muted);
  text-align: center !important;
}

@media (max-width: 1120px) {
  .app-header__inner {
    flex-wrap: wrap;
    padding-block: 10px;
  }

  .app-nav {
    order: 3;
    width: 100%;
    margin: 0;
    overflow-x: auto;
  }

  .database-count {
    margin-left: auto;
  }
}

@media (max-width: 720px) {
  .auth-main {
    min-height: auto;
    place-items: start center;
  }

  .auth-card {
    padding: 20px;
  }

  .auth-user {
    width: 100%;
    justify-content: flex-end;
    padding: 8px 0 0;
    border-top: 1px solid var(--a-border-soft);
    border-left: 0;
  }

  .database-count {
    display: none;
  }

  .audit-filters {
    align-items: stretch;
    flex-direction: column;
  }

  .audit-filters .field,
  .audit-filters .button {
    width: 100%;
  }
}

@media (max-width: 440px) {
  .auth-actions {
    align-items: stretch;
    flex-direction: column-reverse;
  }

  .auth-actions .button,
  .auth-actions form,
  .auth-actions form .button {
    width: 100%;
  }

  .auth-user {
    align-items: stretch;
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .auth-user__identity {
    width: 100%;
  }
}
