/* ============================================================
   Awall surface stylesheet: components.css
   Split from styles.css (F1, issue #186) — NO rule changes.
   Owns: shared component library: card, metric-card, data-table, status-tags, form inputs, buttons, toggle
   Concatenating every surfaces/*.css in base.html <link> order
   reproduces the original styles.css byte-for-byte.
   ============================================================ */
.card {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: var(--space-6);
}

/* Vertical stack of cards/panels with consistent spacing. The base
   content-wrapper does not gap its children, so stacked .card siblings
   (e.g. memory document detail, per-user memory tab) would otherwise touch. */
.card-stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.card-section-title {
  font-size: var(--font-size-md);
  font-weight: 600;
  color: var(--color-text-heading);
  margin-bottom: var(--space-2);
}

.card-section-desc {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  line-height: 1.6;
  margin-bottom: var(--space-6);
}

/* ---------------------------------------------------------
   9b. Card header / shared card utilities
   --------------------------------------------------------- */
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

.card-title {
  font-size: var(--font-size-md);
  font-weight: 600;
  color: var(--color-text-heading);
}

.card-link {
  font-size: var(--font-size-sm);
  color: var(--color-primary);
  text-decoration: none;
  font-weight: 500;
}

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

.card-divider {
  height: 1px;
  background: var(--color-border);
  margin: var(--space-4) 0;
}

/* ---------------------------------------------------------
   10. Metric cards grid
   --------------------------------------------------------- */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-6);
  margin-bottom: var(--space-6);
}

.metric-card {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: var(--space-6);
  border-top: 3px solid var(--color-border);
  transition: box-shadow var(--transition-base),
              transform var(--transition-base),
              border-color var(--transition-base);
}

.metric-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lift);
  border-right-color: var(--color-primary-ring);
  border-bottom-color: var(--color-primary-ring);
  border-left-color: var(--color-primary-ring);
}

.metric-card--danger {
  border-top-color: var(--color-danger);
}

.metric-card--success {
  border-top-color: var(--color-success);
}

.metric-card--primary {
  border-top-color: var(--color-primary);
}

.metric-unit {
  font-size: var(--font-size-lg);
  font-weight: 400;
  color: var(--color-text-muted);
  margin-left: 2px;
}

.metric-card-label {
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: var(--space-2);
}

.metric-card-value {
  font-size: var(--font-size-3xl);
  font-weight: 700;
  color: var(--color-text-heading);
  line-height: 1;
  margin-bottom: var(--space-2);
}

.metric-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
  min-width: 0;
}

.metric-card-top .metric-card-label {
  margin-bottom: 0;
  min-width: 0;
}

.metric-spark {
  flex: 0 0 auto;
  width: 72px;
  height: 28px;
  display: block;
  overflow: visible;
  margin-bottom: 0.25rem;
}

.metric-spark-line {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.metric-spark-area {
  fill: currentColor;
  fill-opacity: 0.14;
  stroke: none;
}

.metric-spark-baseline {
  stroke: var(--color-border);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  opacity: 0.6;
}

.metric-spark--muted   { color: var(--color-text-muted); }
.metric-spark--success { color: var(--color-success); }
.metric-spark--danger  { color: var(--color-danger); }
.metric-spark--primary { color: var(--color-primary); }

@media (max-width: 480px) {
  .metric-spark { width: 56px; height: 24px; }
}

.metric-card-desc {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
}

/* Empty-value state for metric cards (e.g., latency with no samples).
   Keeps the unit visible so the field still reads as "metric — ms"
   rather than just a bare em-dash. */
.metric-card-value-empty {
  color: var(--color-text-muted);
  font-weight: 600;
}

.metric-card-value-empty .metric-unit {
  color: var(--color-text-muted);
}

/* Top-of-page alert banner (e.g., Redis offline). Sits above the
   metrics row and breathes from them with a generous bottom margin. */
.alert.alert--top {
  margin-bottom: var(--space-6);
}

/* ---------------------------------------------------------
   11. Data table
   --------------------------------------------------------- */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
  table-layout: fixed;
}

/* Content-variable tables (e.g. the audit log: long action-code pills,
   target reprs, user agents). Fixed layout gives every column an equal
   slice, so a long nowrap pill or an unbreakable string overflows into the
   next column. Auto layout sizes each column to its content; overflow-wrap
   lets any unbreakable string wrap inside its own cell instead of spilling. */
.data-table--auto {
  table-layout: auto;
}

.data-table--auto tbody td {
  overflow-wrap: anywhere;
}

/* A status-tag pill carries its own horizontal padding, which pushes its
   label ~10px right of the plain-text column header above it. Pull the
   leading pill back by that padding (mirrors .status-tag's 10px left padding)
   so the value lines up under its header. 16px cell padding absorbs it. */
.data-table--auto tbody td > .status-tag:first-child {
  margin-left: -10px;
}

.data-table thead th {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

.data-table tbody td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text-body);
  vertical-align: middle;
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.data-table tbody tr {
  transition: background var(--transition-fast);
}

.data-table tbody tr:hover {
  background: var(--color-surface);
  cursor: default;
}

.data-table tbody tr[data-clickable]:hover {
  cursor: pointer;
}

.data-table tbody tr[data-clickable]:focus-visible {
  outline: none;
  background: var(--color-surface);
  box-shadow: inset 0 0 0 2px var(--color-primary);
  cursor: pointer;
}

/* Right-aligned numeric column for data-tables (metric values, counts).
   tabular-nums holds digits in a fixed-width grid so figures line up down
   the column; the heading color + weight make the number the row's focus.
   Higher specificity than `.data-table thead th` flips its left-align. */
.data-table th.col-num,
.data-table td.col-num {
  text-align: right;
}

.data-table td.col-num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--color-text-heading);
  white-space: nowrap;
}

.guardrail-name {
  display: block;
  font-weight: 500;
  color: var(--color-text-heading);
}

.guardrail-type-hint {
  display: block;
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  font-family: var(--font-mono);
}

/* ---------------------------------------------------------
   12. Status tags
   --------------------------------------------------------- */
.status-tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  font-size: var(--font-size-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

/* Request status */
.status-tag--blocked,
.status-tag[data-status="blocked"] {
  background: var(--color-danger-bg);
  color: var(--color-danger-strong);
}

.status-tag--allowed,
.status-tag[data-status="allowed"] {
  background: var(--color-success-bg);
  color: var(--color-success-strong);
}

.status-tag--degraded,
.status-tag[data-status="degraded"] {
  /* Service-degraded path (e.g. AWall LLM backend was down). Distinct
     yellow/amber so admins triage backend outages separately from
     security blocks (which are red). */
  background: var(--color-warning-bg);
  color: var(--color-warning-strong);
}

.status-tag--rate-limited,
.status-tag[data-status="rate_limited"] {
  /* Per-key usage limit reached. Amber-leaning like degraded but borrowing
     the warning palette — it's a quota event, not a security block. */
  background: var(--color-warning-bg);
  color: var(--color-warning-strong);
}

.status-tag--error,
.status-tag[data-status="error"],
.status-tag[data-status="stream_error"] {
  /* Upstream failure — pre-stream ("error", #306) or mid-stream/disconnect
     ("stream_error", #73). Danger-toned like blocked: the request did not
     complete, and before #73 these rows wore the allowed badge. */
  background: var(--color-danger-bg);
  color: var(--color-danger-strong);
}

.status-tag--test,
.status-tag[data-status="test"] {
  /* Atak no-upstream test traffic (#163) — neutral so it reads as "not real
     customer traffic" rather than a status outcome. */
  background: var(--color-surface);
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
}

.status-tag--role {
  /* Role-aware monitor finding on a tool/assistant message (#259) — info-toned
     so it reads as "something to look at" (visibility), not a block. */
  background: var(--color-info-bg);
  color: var(--color-info-strong);
}

.status-tag--collapsed {
  /* Agentic round-trips collapsed into one user-turn row (#307) — info-toned,
     a structural affordance ("this turn bundles N tool calls"), not an outcome. */
  background: var(--color-info-bg);
  color: var(--color-info-strong);
}

/* Guardrail active/inactive */
.status-tag--active {
  background: var(--color-success-bg);
  color: var(--color-success-strong);
}

.status-tag--inactive {
  background: var(--color-surface);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}

/* Status tag for monitor mode */
.status-tag--monitor {
  background-color: var(--color-monitor-bg);
  color: var(--color-monitor-text);
}

/* Status tag for mask mode (#261) */
.status-tag--mask {
  background-color: var(--color-primary-light);
  color: var(--color-primary-hover);
}

/* Role chips (admin /users/ page). Subtle background + role-specific accent
   so the role of every row is legible at a glance without shouting. */
.status-tag--role-user {
  background: var(--color-surface);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}

.status-tag--role-manager {
  background: var(--color-primary-light, var(--color-surface));
  color: var(--color-primary);
}

.status-tag--role-admin {
  background: var(--color-warning-bg);
  color: var(--color-warning-strong);
}

/* Mode selector (guardrails page) */
.mode-selector {
  display: inline-flex;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-btn);
  overflow: hidden;
}
.mode-btn {
  padding: 4px 12px;
  font-size: var(--font-size-xs);
  font-weight: 500;
  border: none;
  background: var(--color-bg);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.mode-btn:not(:last-child) {
  border-right: 1px solid var(--color-border);
}
.mode-btn:hover {
  background: var(--color-surface);
}
.mode-btn--selected {
  color: #fff;
  font-weight: 600;
}
.mode-btn--selected[data-mode="active"] {
  background: var(--color-success-strong);
}
.mode-btn--selected[data-mode="monitor"] {
  background: var(--color-warning-strong);
}
.mode-btn--selected[data-mode="disabled"] {
  background: var(--color-text-muted);
}
/* mask is an action (redact-and-forward), not a block — keyed to primary (#260/#261) */
.mode-btn--selected[data-mode="mask"] {
  background: var(--color-primary);
}
/* "inherit" = no per-role override; read as a neutral default, not a coloured mode */
.mode-btn--selected[data-mode="inherit"] {
  background: var(--color-surface);
  color: var(--color-text-body);
  box-shadow: inset 0 0 0 1px var(--color-border);
}

/* Per-role override panel on guardrail cards (#261) */
.role-overrides {
  margin-top: var(--space-3);
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-2);
}
.role-overrides-summary {
  font-size: var(--font-size-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  cursor: pointer;
  user-select: none;
}
.role-overrides-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: var(--space-2);
}
.role-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.role-row-label {
  font-size: var(--font-size-xs);
  color: var(--color-text-body);
}
.role-overrides-hint {
  margin: 0;
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
}
.mode-selector--sm .mode-btn {
  padding: 2px 8px;
}

/* ---------------------------------------------------------
   13. Form inputs
   --------------------------------------------------------- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.form-label {
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--color-text-body);
}

.form-input,
input[type="text"].form-input,
input[type="password"].form-input,
input[type="number"].form-input,
input[type="email"].form-input,
select.form-input,
textarea.form-input {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  font-size: var(--font-size-base);
  font-family: var(--font-family);
  color: var(--color-text-heading);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-input);
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  line-height: 1.5;
}

.form-input:hover {
  border-color: #d1d5db;
}

.form-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-focus-ring);
}

.form-input::placeholder {
  color: var(--color-text-muted);
}

.form-input:read-only:not(:focus) {
  background: var(--color-surface);
  color: var(--color-text-muted);
  cursor: default;
}

.form-group--checkbox {
  flex-direction: row;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.form-checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--color-text-body);
  cursor: pointer;
  user-select: none;
}

.form-checkbox {
  width: 16px;
  height: 16px;
  margin: 0;
  flex-shrink: 0;
  accent-color: var(--color-primary);
  cursor: pointer;
}

.form-group--checkbox .form-hint,
.form-group--checkbox .form-field-error {
  flex-basis: 100%;
  margin-left: calc(16px + var(--space-2));
}

.form-hint {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  line-height: 1.5;
}

.form-field-error {
  font-size: var(--font-size-xs);
  color: var(--color-danger);
  font-weight: 500;
}

.form-error-banner {
  padding: var(--space-3) var(--space-4);
  background: var(--color-danger-bg);
  border: 1px solid var(--color-danger-border-soft);
  border-radius: var(--radius-card);
  font-size: var(--font-size-sm);
  /* Strong-Semantic Rule (DESIGN.md §2): text on the tinted danger surface
     uses the -strong companion so it clears the 4.5:1 AA body floor in both
     themes (#b91c1c on #fef2f2 light / #fca5a5 on #2d0a0a dark). */
  color: var(--color-danger-strong);
  font-weight: 500;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
  margin-top: var(--space-2);
}

/* ---------------------------------------------------------
   14. Buttons
   --------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 12px 24px;
  font-size: var(--font-size-base);
  font-weight: 600;
  font-family: var(--font-family);
  /* Transparent 1px border so bordered variants (.btn-secondary) and
     borderless ones (.btn-primary/.btn-danger) share the same box height. */
  border: 1px solid transparent;
  border-radius: var(--radius-btn);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--transition-fast), color var(--transition-fast),
    box-shadow var(--transition-fast), transform var(--transition-fast);
  line-height: 1;
  letter-spacing: -0.005em;
}

.btn:hover {
  text-decoration: none;
}

.btn:active {
  transform: translateY(1px);
}

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

.btn:disabled,
.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background: var(--color-primary);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--color-primary-hover);
  color: #ffffff;
}

.btn-secondary {
  background: var(--color-bg);
  color: var(--color-text-body);
  border: 1px solid var(--color-border);
}

.btn-secondary:hover {
  background: var(--color-surface);
  color: var(--color-text-heading);
}

.btn-danger {
  background: var(--color-danger);
  color: #ffffff;
}

.btn-danger:hover {
  background: var(--color-danger-strong);
  color: #ffffff;
}

.btn-sm {
  padding: 6px 14px;
  font-size: var(--font-size-sm);
  border-radius: var(--radius-tag);
}

.btn-block {
  width: 100%;
}

/* Buttons that pair an icon with a label.
   .btn-icon  — leading SVG. Slight opacity for weight, sits inside
                the flex track so the parent .btn-save's `gap` handles
                spacing (no own margin).
   .btn-label — text container. Gains a ::before spinner slot only
                while the button is in saving state.
   .btn--saving — disables the button, hides the leading icon and
                swaps the label text via JS, drops a spinner where
                the icon used to be. */
.btn-save {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
}

.btn .btn-icon {
  flex-shrink: 0;
  opacity: 0.85;
}

.btn--saving {
  cursor: progress;
  pointer-events: none;
  opacity: 0.7;
}

.btn--saving .btn-icon {
  display: none;
}

.btn--saving .btn-label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.btn--saving .btn-label::before {
  content: "";
  width: 13px;
  height: 13px;
  border-radius: var(--radius-pill);
  border: 2px solid currentColor;
  border-right-color: transparent;
  animation: btn-saving-spin 720ms linear infinite;
}

@keyframes btn-saving-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .btn--saving .btn-label::before {
    animation: none;
    border-right-color: currentColor;
    opacity: 0.5;
  }
}

/* Segmented radio group used by settings choices (e.g., block-message
   verbosity: Generic / Detailed). Native radio is hidden but kept for
   keyboard arrow navigation and form semantics. The visible state is
   carried by the parent label via :has(input:checked). */
.radio-group {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.radio-option {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 10px 16px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-input);
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--color-text-body);
  cursor: pointer;
  user-select: none;
  transition: background var(--transition-fast),
              color var(--transition-fast),
              border-color var(--transition-fast),
              box-shadow var(--transition-fast);
}

.radio-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.radio-option::before {
  content: "";
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-pill);
  background: var(--color-bg);
  box-shadow: inset 0 0 0 0 var(--color-primary);
  transition: border-color var(--transition-fast),
              box-shadow var(--transition-fast);
}

.radio-option:hover {
  background: var(--color-surface);
  color: var(--color-text-heading);
}

.radio-option:has(input[type="radio"]:focus-visible) {
  outline: none;
  box-shadow: 0 0 0 3px var(--color-primary-focus-ring);
}

.radio-option:has(input[type="radio"]:checked) {
  color: var(--color-text-heading);
  border-color: var(--color-primary-ring);
  background: var(--color-bg);
}

.radio-option:has(input[type="radio"]:checked)::before {
  border-color: var(--color-primary);
  box-shadow: inset 0 0 0 3.5px var(--color-primary);
}

/* Inline icon for status alerts (e.g., the green saved-success
   confirmation under settings forms). Alerts that don't include an
   icon stay block-level as before. */
.alert:has(.alert-icon) {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.alert-icon {
  flex-shrink: 0;
}

/* ---------------------------------------------------------
   15. Toggle switch
   --------------------------------------------------------- */
.toggle-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  flex-shrink: 0;
}

.toggle-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.toggle-slider {
  position: relative;
  display: block;
  width: 44px;
  height: 24px;
  background: var(--color-border);
  border-radius: var(--radius-pill);
  transition: background var(--transition-base);
}

.toggle-slider::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  background: #ffffff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform var(--transition-base);
}

.toggle-input:checked + .toggle-slider {
  background: var(--color-primary);
}

.toggle-input:checked + .toggle-slider::after {
  transform: translateX(20px);
}

.toggle-input:focus-visible + .toggle-slider {
  box-shadow: 0 0 0 3px var(--color-primary-ring);
}

