:root {
  color-scheme: light;
  --color-page: #f1f5f9;
  --color-surface: #ffffff;
  --color-surface-subtle: #f8fafc;
  --color-border: #cbd5e1;
  --color-border-strong: #94a3b8;
  --color-text: #0f172a;
  --color-muted: #475569;
  --color-primary: #1d4ed8;
  --color-primary-hover: #1e40af;
  --color-primary-text: #ffffff;
  --color-focus: #2563eb;
  --color-success: #166534;
  --color-success-bg: #dcfce7;
  --color-warning: #854d0e;
  --color-warning-bg: #fef9c3;
  --color-danger: #991b1b;
  --color-danger-bg: #fee2e2;
  --color-neutral: #334155;
  --color-neutral-bg: #e2e8f0;
  --shadow-panel: 0 8px 24px rgba(15, 23, 42, 0.08);
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --radius-sm: 0.375rem;
  --radius-md: 0.625rem;
  --radius-lg: 0.875rem;
  --font-size-xs: 0.75rem;
  --font-size-sm: 0.875rem;
  --font-size-base: 1rem;
  --font-size-lg: 1.125rem;
  --font-size-xl: 1.5rem;
  --line-height-tight: 1.25;
  --line-height-base: 1.5;
  --control-height: 2.75rem;
  --content-width: 75rem;
  --login-width: 28rem;
  --transition-fast: 160ms ease-out;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 20rem;
  background: var(--color-page);
}

body {
  min-height: 100dvh;
  margin: 0;
  color: var(--color-text);
  background: var(--color-page);
  font-family: "Segoe UI Variable", Aptos, "Segoe UI", sans-serif;
  font-size: var(--font-size-base);
  line-height: var(--line-height-base);
}

button,
input {
  font: inherit;
}

button {
  touch-action: manipulation;
}

.login-panel[hidden],
.dashboard[hidden],
.agent-error[hidden] {
  display: none;
}

.skip-link {
  position: fixed;
  top: var(--space-2);
  left: var(--space-2);
  z-index: 10;
  padding: var(--space-2) var(--space-3);
  color: var(--color-primary-text);
  background: var(--color-primary);
  border-radius: var(--radius-sm);
  transform: translateY(-200%);
}

.skip-link:focus {
  transform: translateY(0);
}

.page-shell {
  width: min(100% - (var(--space-4) * 2), var(--content-width));
  margin-inline: auto;
  padding-block: var(--space-8);
}

.login-panel,
.dashboard {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow-panel);
}

.login-panel {
  width: min(100%, var(--login-width));
  margin: var(--space-10) auto 0;
  padding: var(--space-6);
}

.panel-heading,
.dashboard-header {
  margin-bottom: var(--space-6);
}

.eyebrow {
  margin: 0 0 var(--space-1);
  color: var(--color-primary);
  font-size: var(--font-size-xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: var(--font-size-xl);
  line-height: var(--line-height-tight);
}

.panel-description,
.checked-at {
  margin: var(--space-2) 0 0;
  color: var(--color-muted);
  font-size: var(--font-size-sm);
}

.login-form {
  display: grid;
  gap: var(--space-4);
}

.form-field {
  display: grid;
  gap: var(--space-2);
}

.form-field label {
  font-size: var(--font-size-sm);
  font-weight: 700;
}

.form-field input {
  min-height: var(--control-height);
  width: 100%;
  padding: var(--space-2) var(--space-3);
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
}

.form-field input:hover {
  border-color: var(--color-muted);
}

.form-field input:focus-visible,
.button:focus-visible,
.platform-link:focus-visible,
.skip-link:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
}

.button {
  min-height: var(--control-height);
  padding: var(--space-2) var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-weight: 700;
  cursor: pointer;
  transition: background-color var(--transition-fast), border-color var(--transition-fast);
}

.button-primary {
  color: var(--color-primary-text);
  background: var(--color-primary);
  border-color: var(--color-primary);
}

.button-primary:hover:not(:disabled) {
  background: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
}

.button-secondary {
  color: var(--color-text);
  background: var(--color-surface);
  border-color: var(--color-border-strong);
}

.button-secondary:hover:not(:disabled) {
  background: var(--color-surface-subtle);
  border-color: var(--color-muted);
}

.button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.status-line {
  min-height: var(--space-6);
  margin: var(--space-4) 0 0;
  color: var(--color-muted);
  font-size: var(--font-size-sm);
}

.status-line[data-tone="error"] {
  color: var(--color-danger);
}

.status-line[data-tone="success"] {
  color: var(--color-success);
}

.dashboard {
  padding: var(--space-6);
}

.dashboard-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
}

.dashboard-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2);
}

.dashboard-status {
  margin: 0 0 var(--space-4);
}

.copy-status {
  min-height: 0;
  margin: 0 0 var(--space-4);
}

.copy-status:empty {
  margin-bottom: 0;
}

.version-table-wrap {
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

.version-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.version-table caption {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.version-table th,
.version-table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  text-align: left;
  vertical-align: top;
}

.version-table thead th {
  color: var(--color-muted);
  background: var(--color-surface-subtle);
  font-size: var(--font-size-xs);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.version-table thead th:first-child {
  width: 20%;
}

.version-table tbody th {
  font-size: var(--font-size-sm);
  font-weight: 700;
}

.version-table tbody tr:last-child > * {
  border-bottom: 0;
}

.agent-state {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  align-items: start;
  gap: var(--space-2) var(--space-3);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: var(--space-6);
  padding: var(--space-1) var(--space-2);
  color: var(--color-neutral);
  background: var(--color-neutral-bg);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-xs);
  font-weight: 700;
  line-height: var(--line-height-tight);
}

.status-badge[data-state="available"] {
  color: var(--color-success);
  background: var(--color-success-bg);
}

.status-badge[data-state="unavailable"] {
  color: var(--color-warning);
  background: var(--color-warning-bg);
}

.status-badge[data-state="error"] {
  color: var(--color-danger);
  background: var(--color-danger-bg);
}

.image-value {
  min-width: 0;
  padding-top: var(--space-1);
  color: var(--color-text);
  font-family: ui-monospace, "Cascadia Code", "Segoe UI Mono", monospace;
  font-size: var(--font-size-sm);
  line-height: var(--line-height-base);
  overflow-wrap: anywhere;
}

.agent-error {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--color-danger);
  font-size: var(--font-size-xs);
  overflow-wrap: anywhere;
}

.service-access {
  display: grid;
  grid-column: 1 / -1;
  padding-top: var(--space-2);
  border-top: 1px solid var(--color-border);
}

.service-access-row {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr) max-content;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  padding-block: var(--space-1);
}

.service-access-label {
  color: var(--color-muted);
  font-size: var(--font-size-xs);
  font-weight: 700;
}

.service-access-value {
  min-width: 0;
  overflow-wrap: anywhere;
}

.platform-link {
  width: fit-content;
  color: var(--color-primary);
  font-size: var(--font-size-sm);
  font-weight: 700;
  text-underline-offset: var(--space-1);
}

.platform-link:hover {
  color: var(--color-primary-hover);
}

.api-endpoint {
  color: var(--color-text);
  font-family: ui-monospace, "Cascadia Code", "Segoe UI Mono", monospace;
  font-size: var(--font-size-xs);
}

.copy-button {
  min-width: var(--control-height);
  padding-inline: var(--space-3);
  font-size: var(--font-size-sm);
}

@media (max-width: 45rem) {
  .page-shell {
    width: min(100% - (var(--space-3) * 2), var(--content-width));
    padding-block: var(--space-4);
  }

  .login-panel {
    margin-top: var(--space-4);
  }

  .login-panel,
  .dashboard {
    padding: var(--space-4);
  }

  .dashboard-header {
    display: grid;
  }

  .dashboard-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .version-table-wrap {
    overflow: visible;
    border: 0;
  }

  .version-table,
  .version-table tbody {
    display: block;
  }

  .version-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }

  .version-table tbody {
    display: grid;
    gap: var(--space-3);
  }

  .version-table tbody tr {
    display: grid;
    overflow: hidden;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
  }

  .version-table tbody th,
  .version-table tbody td {
    display: grid;
    grid-template-columns: minmax(7rem, 35%) minmax(0, 1fr);
    gap: var(--space-3);
    padding: var(--space-3);
    border-bottom: 1px solid var(--color-border);
  }

  .version-table tbody th::before,
  .version-table tbody td::before {
    content: attr(data-label);
    color: var(--color-muted);
    font-size: var(--font-size-xs);
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }

  .version-table tbody tr:last-child > *,
  .version-table tbody tr > *:last-child {
    border-bottom: 0;
  }

  .agent-state {
    grid-template-columns: 1fr;
  }

  .agent-error {
    grid-column: auto;
  }

  .service-access-row {
    grid-template-columns: minmax(0, 1fr) max-content;
  }

  .service-access-label {
    grid-column: 1 / -1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .button {
    transition: none;
  }
}
