/*
 * app.css — Component styles for vanilla-htmx adapter.
 *
 * Uses ONLY CSS custom properties from tokens.css (generated by token_css_generator.py).
 * NO raw hex values — every color, space, and font value references a var(--*) token.
 * This file is the single place where semantic tokens are consumed.
 *
 * Spec: design/patterns/component/{button,form,table}.md
 */

/* ── Reset / base ────────────────────────────────────────────────────────── */

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

body {
  margin: 0;
  font-family: var(--font-family-body);
  font-size: var(--font-size-md);
  line-height: var(--font-line-md);
  color: var(--color-text-1);
  background: var(--color-surface-2);
}

/* Screen-reader only utility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Layout ──────────────────────────────────────────────────────────────── */

.top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-inset-sm) var(--space-page-gutter);
  background: var(--color-surface-1);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-card);
  position: sticky;
  top: 0;
  z-index: var(--zindex-sticky);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: var(--space-gap-md);
}

.nav-logo {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-heading);
  color: var(--color-primary);
  text-decoration: none;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: var(--space-gap-md);
}

.nav-user {
  font-size: var(--font-size-sm);
  color: var(--color-text-3);
}

.persona-select {
  font-size: var(--font-size-sm);
  padding: var(--space-inset-xs) var(--space-inset-sm);
  border: 1px solid var(--color-border-input);
  border-radius: var(--radius-control);
  background: var(--color-surface-1);
  color: var(--color-text-1);
  cursor: pointer;
}

.main-content {
  max-width: var(--space-content-max);
  margin: 0 auto;
  padding: var(--space-stack-lg) var(--space-page-gutter);
}

.app-footer {
  text-align: center;
  padding: var(--space-inset-md);
  color: var(--color-text-3);
  font-size: var(--font-size-xs);
  border-top: 1px solid var(--color-border);
  margin-top: var(--space-stack-xl);
}

/* ── Page header ─────────────────────────────────────────────────────────── */

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-stack-md);
}

.page-title {
  font-size: var(--font-size-3xl);
  font-weight: var(--font-weight-heading);
  color: var(--color-text-1);
  margin: 0;
}

/* ── Card ─────────────────────────────────────────────────────────────────── */

.card {
  background: var(--color-surface-1);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: var(--space-inset-xl);
  margin-bottom: var(--space-stack-md);
}

.card--centered {
  max-width: 480px;
  margin: var(--space-stack-xl) auto;
  text-align: center;
}

/* ── Buttons (button.md spec) ─────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-gap-xs);
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  font-family: var(--font-family-body);
  font-weight: var(--font-weight-label);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: var(--motion-transition-control);
  box-shadow: var(--shadow-xs);
}

.btn:focus-visible {
  outline: 2px solid var(--color-border-focus);
  outline-offset: 2px;
  box-shadow: var(--shadow-focus-ring);
}

.btn:disabled {
  background: var(--color-surface-3);
  border-color: var(--color-border);
  color: var(--color-text-disabled);
  cursor: not-allowed;
  box-shadow: none;
}

/* Sizes */
.btn-sm  { height: 28px; padding: 0 var(--space-inset-sm); font-size: var(--font-size-sm); }
.btn-md  { height: 36px; padding: 0 var(--space-inset-md); font-size: var(--font-size-md); }
.btn-lg  { height: 44px; padding: 0 var(--space-inset-lg); font-size: var(--font-size-lg); }

/* Variants */
.btn-primary {
  background: var(--color-primary);
  color: var(--color-text-on-primary);
}
.btn-primary:hover:not(:disabled) { background: var(--color-primary-hover); box-shadow: var(--shadow-sm); }
.btn-primary:active:not(:disabled) { background: var(--color-primary-active); box-shadow: none; }

.btn-secondary {
  background: var(--color-surface-1);
  border-color: var(--color-border-strong);
  color: var(--color-text-2);
}
.btn-secondary:hover:not(:disabled) { background: var(--color-surface-2); }

.btn-danger {
  background: var(--color-danger);
  color: var(--color-text-on-danger);
}
.btn-danger:hover:not(:disabled) { background: var(--color-danger-hover); }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--color-text-2);
  box-shadow: none;
}
.btn-ghost:hover:not(:disabled) { background: var(--color-surface-2); }

.btn-danger-ghost {
  color: var(--color-danger);
}
.btn-danger-ghost:hover:not(:disabled) { background: var(--color-danger-subtle); }

/* ── Forms (form.md spec) ─────────────────────────────────────────────────── */

.form-field {
  margin-bottom: var(--space-stack-md);
}

.form-label {
  display: block;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-label);
  color: var(--color-text-2);
  margin-bottom: var(--space-gap-xs);
}

.required-marker {
  color: var(--color-danger);
  margin-left: 2px;
}

.form-input {
  display: block;
  width: 100%;
  height: 36px;
  padding: var(--space-inset-xs) var(--space-inset-md);
  border: 1px solid var(--color-border-input);
  border-radius: var(--radius-input);
  background: var(--color-surface-1);
  color: var(--color-text-1);
  font-size: var(--font-size-md);
  font-family: var(--font-family-body);
  transition: var(--motion-transition-control);
  box-sizing: border-box;
}

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

.form-input:focus {
  border-color: var(--color-border-focus);
  outline: 2px solid var(--color-border-focus);
  outline-offset: -1px;
  box-shadow: var(--shadow-focus-ring);
}

.form-input--readonly {
  background: var(--color-surface-2);
  color: var(--color-text-2);
  cursor: default;
}

.form-input--error {
  border-color: var(--color-danger-border);
  background: var(--color-danger-subtle);
}

.form-hint, .form-caption {
  font-size: var(--font-size-xs);
  color: var(--color-text-3);
  margin-top: var(--space-gap-xs);
}

.form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-gap-sm);
  margin-top: var(--space-stack-lg);
}

.form-actions--center { justify-content: center; }

.checkbox-label {
  display: flex;
  align-items: center;
  gap: var(--space-gap-sm);
  font-size: var(--font-size-sm);
  color: var(--color-text-2);
  cursor: pointer;
}

/* System fields hidden for non-IT personas */
[data-persona="ops"] .form-field--system[data-system-field="true"],
[data-persona="ceo"] .form-field--system[data-system-field="true"] {
  display: none;
}

/* ── Table (table.md spec) ───────────────────────────────────────────────── */

.toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-gap-sm);
  margin-bottom: var(--space-stack-md);
}

.toolbar-search {
  max-width: 280px;
}

.paging-mode-switcher {
  display: flex;
  gap: var(--space-gap-xs);
  margin-bottom: var(--space-stack-sm);
}

.table-wrapper {
  background: var(--color-surface-1);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  overflow-x: auto;
  margin-bottom: var(--space-stack-md);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-md);
  font-family: var(--font-family-body);
}

.th {
  background: var(--color-surface-3);
  color: var(--color-text-2);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-label);
  padding: var(--space-inset-sm) var(--space-inset-md);
  border-bottom: 1px solid var(--color-border-strong);
  text-align: left;
  white-space: nowrap;
}

.th--actions { text-align: right; }

.th-sort-link {
  color: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: var(--space-gap-xs);
  cursor: pointer;
}
.th-sort-link:hover { color: var(--color-primary); }

.td {
  padding: var(--space-inset-xs) var(--space-inset-md);
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 320px;
}

.td--actions {
  text-align: right;
  white-space: nowrap;
  display: flex;
  gap: var(--space-gap-xs);
  justify-content: flex-end;
}

.tr:hover .td { background: var(--color-primary-subtle); }
.tr--alt .td { background: var(--color-surface-2); }
.tr--alt:hover .td { background: var(--color-primary-subtle); }

.text-empty { color: var(--color-text-3); }
.text-caption { font-size: var(--font-size-xs); color: var(--color-text-3); }
.text-secondary { color: var(--color-text-2); }

/* ── Pagination (table.md spec) ─────────────────────────────────────────── */

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-gap-xs);
  flex-wrap: wrap;
  margin-top: var(--space-stack-md);
}

.pagination-count {
  font-size: var(--font-size-sm);
  color: var(--color-text-3);
  margin-right: var(--space-gap-md);
}

.pagination-ellipsis {
  color: var(--color-text-3);
  padding: 0 var(--space-gap-xs);
}

.cursor-pagination {
  display: flex;
  justify-content: center;
  margin-top: var(--space-stack-md);
}

/* ── Error / status banners ─────────────────────────────────────────────── */

.error-banner {
  background: var(--color-danger-subtle);
  border: 1px solid var(--color-danger-border);
  border-radius: var(--radius-card);
  color: var(--color-danger);
  padding: var(--space-inset-md);
  margin-bottom: var(--space-stack-md);
  font-size: var(--font-size-md);
}

.error-banner--page {
  text-align: left;
}

.error-message {
  font-weight: var(--font-weight-label);
  margin: 0 0 var(--space-gap-xs);
}

.error-code {
  margin: 0;
}

.error-details {
  margin: var(--space-gap-sm) 0 0;
  padding-left: var(--space-inset-md);
}

.error-details-block {
  margin-top: var(--space-stack-sm);
  font-size: var(--font-size-sm);
}

.retry-hint {
  color: var(--color-text-3);
  font-size: var(--font-size-sm);
  margin-top: var(--space-gap-sm);
}

/* ── Status / health badges ─────────────────────────────────────────────── */

.health-summary {
  display: flex;
  align-items: center;
  gap: var(--space-gap-lg);
  margin-bottom: var(--space-stack-md);
}

.health-badge {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  padding: var(--space-inset-xs) var(--space-inset-md);
  border-radius: var(--radius-badge);
}

.health-badge--ok       { background: var(--color-success-subtle); color: var(--color-status-ok); }
.health-badge--degraded { background: var(--color-warning-subtle); color: var(--color-warning-text); }
.health-badge--down     { background: var(--color-danger-subtle);  color: var(--color-status-down); }

.status-badge {
  display: inline-block;
  font-size: var(--font-size-xs);
  padding: 2px 6px;
  border-radius: var(--radius-badge);
}

.status-badge--ok       { background: var(--color-success-subtle); color: var(--color-status-ok); }
.status-badge--degraded { background: var(--color-warning-subtle); color: var(--color-warning-text); }
.status-badge--down     { background: var(--color-danger-subtle);  color: var(--color-status-down); }

/* ── Login page ─────────────────────────────────────────────────────────── */

.login-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 70vh;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--color-surface-1);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: var(--space-inset-xl);
}

.login-title {
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-heading);
  color: var(--color-text-1);
  margin: 0 0 var(--space-stack-lg);
  text-align: center;
}

/* ── Delete confirm ─────────────────────────────────────────────────────── */

.delete-warning {
  background: var(--color-danger-subtle);
  border: 1px solid var(--color-danger-border);
  border-radius: var(--radius-card);
  padding: var(--space-inset-md);
  margin-bottom: var(--space-stack-md);
  color: var(--color-danger);
}

.detail-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--space-gap-xs) var(--space-gap-lg);
  margin: 0 0 var(--space-stack-md);
}

.detail-term {
  font-weight: var(--font-weight-label);
  color: var(--color-text-2);
  font-size: var(--font-size-sm);
}

.detail-value {
  color: var(--color-text-1);
  font-size: var(--font-size-md);
  margin: 0;
}

/* ── Detail footer ──────────────────────────────────────────────────────── */

.detail-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: var(--space-stack-md);
  padding-top: var(--space-stack-md);
  border-top: 1px solid var(--color-border);
}

/* ── Success state ──────────────────────────────────────────────────────── */

.success-icon {
  font-size: var(--font-size-4xl, 30px);
  color: var(--color-success);
  margin-bottom: var(--space-stack-sm);
}

/* ── Code block ──────────────────────────────────────────────────────────── */

.code-block {
  background: var(--color-surface-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  padding: var(--space-inset-md);
  font-family: var(--font-family-mono);
  font-size: var(--font-size-sm);
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
}
