*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  color-scheme: light;
  --bg: #f7f7f8;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f1f2;
  --border: #dedee1;
  --border-focus: #a3a3a3;
  --text: #171717;
  --text-muted: #525252;
  --text-dim: #737373;
  --accent: #e11d48;
  --accent-hover: #be123c;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-surface: rgba(220, 38, 38, 0.08);
  --success: #16a34a;
  --header-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  --tooltip-bg: #171717;
  --tooltip-text: #fafafa;
  --tooltip-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
  --radius: 8px;
  --radius-lg: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", monospace;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a0a0a;
  --bg-card: #141414;
  --bg-card-hover: #1a1a1a;
  --border: #262626;
  --border-focus: #525252;
  --text: #fafafa;
  --text-muted: #a3a3a3;
  --text-dim: #737373;
  --danger-surface: rgba(220, 38, 38, 0.12);
  --header-shadow: 0 1px 0 rgba(255, 255, 255, 0.04);
  --tooltip-bg: #f5f5f5;
  --tooltip-text: #171717;
  --tooltip-shadow: 0 6px 22px rgba(0, 0, 0, 0.55);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0a0a0a;
    --bg-card: #141414;
    --bg-card-hover: #1a1a1a;
    --border: #262626;
    --border-focus: #525252;
    --text: #fafafa;
    --text-muted: #a3a3a3;
    --text-dim: #737373;
    --danger-surface: rgba(220, 38, 38, 0.12);
    --header-shadow: 0 1px 0 rgba(255, 255, 255, 0.04);
    --tooltip-bg: #f5f5f5;
    --tooltip-text: #171717;
    --tooltip-shadow: 0 6px 22px rgba(0, 0, 0, 0.55);
  }
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

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

.auth-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  box-shadow: var(--header-shadow);
}

.auth-logo {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.02em;
}

.auth-nav {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.875rem;
}

.auth-nav a {
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s;
}

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

.auth-nav-group,
.auth-account-group {
  display: inline-flex;
  align-items: center;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}

.auth-nav-group > *,
.auth-account-group > * {
  padding: 0.38rem 0.65rem;
}

.auth-nav-group > * + *,
.auth-account-group > * + * {
  border-left: 1px solid var(--border);
}

.auth-user-name {
  color: var(--text);
  font-weight: 500;
}

.auth-nav .auth-signout {
  color: var(--danger);
  background: var(--danger-surface);
}

.auth-nav .auth-signout:hover {
  color: var(--danger-hover);
}

.auth-header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.theme-toggle {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text-muted);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}

#theme-toggle-icon {
  font-size: 1.1rem;
  line-height: 1;
}

.theme-toggle:hover {
  border-color: var(--border-focus);
  color: var(--text);
}

.auth-main {
  flex: 1;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  padding: 3rem 2rem;
}

h1 {
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  margin-bottom: 2rem;
}

h2 {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-top: 2.5rem;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1rem;
}

.info-grid {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 0.75rem 1.5rem;
  font-size: 0.9rem;
}

.info-grid dt {
  color: var(--text-muted);
  font-weight: 500;
}

.info-grid dd {
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

.passkey-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.passkey-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
}

.passkey-item-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.passkey-item-name {
  font-weight: 500;
}

.passkey-item-date {
  color: var(--text-dim);
  font-size: 0.8rem;
}

.section-description {
  margin: -0.35rem 0 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.settings-link-card,
.api-page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.settings-link-card p,
.api-page-header p {
  color: var(--text-muted);
  font-size: 0.875rem;
}

.api-page-header {
  align-items: flex-end;
  margin-bottom: 2rem;
}

.api-page-header h1 {
  margin: 0.25rem 0 0;
}

.page-back-link {
  color: var(--text-muted);
  font-size: 0.8125rem;
  text-decoration: none;
}

.page-back-link:hover { color: var(--text); }

.api-key-form,
.api-key-edit-form {
  display: grid;
  gap: 0.9rem;
}

.api-key-form input[type="text"],
.api-key-form select,
.api-key-edit-form input[type="text"] {
  width: 100%;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.field-label,
.api-key-form legend,
.api-key-edit-form legend {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
}

.api-key-form fieldset,
.api-key-edit-form fieldset {
  border: 0;
}

.api-key-scope-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
  margin-top: 0.4rem;
}

.api-key-scope-options label {
  display: flex;
  gap: 0.55rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}

.api-key-scope-options span,
.api-key-scope-options small {
  display: block;
}

.api-key-scope-options strong {
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

.api-key-scope-options small {
  color: var(--text-dim);
  font-size: 0.75rem;
}

.api-key-list {
  display: grid;
  gap: 0.75rem;
}

.api-key-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
}

.api-key-heading,
.api-key-actions,
.api-key-secret-actions,
.api-key-edit-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.api-key-heading {
  margin-bottom: 0.25rem;
}

.api-key-summary code,
.api-key-secret code {
  font-family: var(--font-mono);
  overflow-wrap: anywhere;
}

.api-key-status {
  padding: 0.08rem 0.45rem;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 0.68rem;
}

.api-key-status.is-active { color: var(--success); }
.api-key-status.is-revoked,
.api-key-status.is-expired { color: var(--text-dim); }

.api-key-scopes {
  margin-top: 0.3rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.75rem;
}

.api-key-dates {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.1rem 0.65rem;
  margin-top: 0.55rem;
  color: var(--text-dim);
  font-size: 0.75rem;
}

.api-key-dates dt { font-weight: 600; }

.api-key-secret p {
  margin: 0.35rem 0 0.75rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.api-key-secret-actions { margin-top: 0.8rem; }

.api-key-empty {
  display: grid;
  gap: 0.25rem;
}

.api-key-empty span {
  color: var(--text-muted);
  font-size: 0.875rem;
}

.api-key-dialog {
  width: min(680px, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  margin: auto;
  padding: 0;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  color: var(--text);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
}

.api-key-dialog::backdrop {
  background: rgba(0, 0, 0, 0.56);
}

.api-key-dialog > form,
.api-key-created-dialog > div {
  padding: 1.5rem;
}

.api-key-dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.api-key-dialog-header h2 {
  margin: 0;
  padding: 0;
  border: 0;
}

.api-key-dialog-header p {
  margin-top: 0.25rem;
  color: var(--text-muted);
  font-size: 0.8125rem;
}

.dialog-close {
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text-muted);
  font: inherit;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

.dialog-close:hover {
  border-color: var(--border-focus);
  color: var(--text);
}

.api-key-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding-top: 0.5rem;
}

.relative-time {
  position: relative;
  display: inline-block;
  cursor: help;
  text-decoration: underline dotted var(--border-focus);
  text-underline-offset: 0.2em;
}

.relative-time::after {
  content: attr(data-relative-label);
  position: absolute;
  top: calc(100% + 0.4rem);
  left: 0;
  z-index: 20;
  padding: 0.3rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--tooltip-bg);
  color: var(--tooltip-text);
  font-family: var(--font);
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: var(--tooltip-shadow);
  opacity: 0;
  transform: translateY(-0.2rem);
  transition:
    opacity 0.12s,
    transform 0.12s;
}

.relative-time:hover::after,
.relative-time:focus-visible::after {
  opacity: 1;
  transform: translateY(0);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
  background: var(--bg-card);
  color: var(--text);
  text-decoration: none;
}

.btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-focus);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-danger {
  color: var(--danger);
  border-color: transparent;
  background: transparent;
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

.btn-danger:hover {
  background: rgba(220, 38, 38, 0.1);
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

.login-methods {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.login-method {
  width: 100%;
  min-height: 3rem;
  padding: 0.65rem 1rem;
  flex-wrap: wrap;
  font-size: 0.95rem;
}

.last-used-details {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.last-used-badge {
  padding: 0.1rem 0.4rem;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 0.68rem;
  line-height: 1.4;
  opacity: 0.8;
}

.last-passkey-name {
  max-width: 12rem;
  overflow: hidden;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  white-space: nowrap;
  border-width: 0;
  clip-path: inset(50%);
}

.empty-state {
  color: var(--text-dim);
  font-size: 0.9rem;
  padding: 1.5rem;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.activity-table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.activity-table-scroll {
  margin-bottom: -3rem;
  padding-bottom: 3rem;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  -webkit-overflow-scrolling: touch;
}

.activity-table th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 500;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.activity-table td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.activity-table th:nth-child(2),
.activity-table td:nth-child(2) {
  width: 5rem;
}

.activity-table th:last-child,
.activity-table .activity-entry td:last-child {
  width: 12rem;
  white-space: nowrap;
}

.activity-entry.has-comment td {
  padding-bottom: 0.25rem;
  border-bottom: 0;
}

.activity-comment-row td {
  padding-top: 0;
  font-size: 0.8125rem;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

.activity-comment-label {
  color: var(--text-dim);
  font-weight: 500;
}

.activity-table a {
  color: var(--accent);
  text-decoration: none;
}

.activity-table a:hover {
  text-decoration: underline;
}

.status-msg {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  margin-bottom: 1rem;
}

.status-msg.error {
  background: rgba(220, 38, 38, 0.1);
  border: 1px solid rgba(220, 38, 38, 0.2);
  color: var(--danger);
}

.status-msg.success {
  background: rgba(22, 163, 74, 0.1);
  border: 1px solid rgba(22, 163, 74, 0.2);
  color: var(--success);
}

@media (max-width: 720px) {
  .auth-header {
    align-items: flex-start;
    gap: 1rem;
    padding: 1rem;
  }

  .auth-header-actions,
  .auth-nav {
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.75rem;
  }

  .auth-header-actions {
    max-width: 75%;
  }

  .auth-main {
    padding: 2rem 1rem;
  }

  .api-key-scope-options { grid-template-columns: 1fr; }
  .api-key-item { grid-template-columns: 1fr; }
  .settings-link-card,
  .api-page-header {
    align-items: stretch;
    flex-direction: column;
  }
}
