/* WAF Policy — inspector-style layout, self-contained */

.waf-page {
  display: flex;
  flex-direction: column;
  gap: 0;
  flex: 1;
  min-height: 0;
  padding: 14px 20px 20px;
  overflow: auto;
}

.waf-topbar {
  align-items: stretch;
  min-height: auto;
  padding: 0;
}

.waf-topbar-inner {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  min-height: var(--header-height);
  padding: 10px 16px;
}

.waf-topbar-start {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1 1 auto;
}

.waf-topbar-icon {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: linear-gradient(145deg, var(--shell-active), var(--shell-panel));
  border: 1px solid var(--shell-border);
  color: var(--shell-accent);
}

.waf-topbar-icon svg {
  width: 20px;
  height: 20px;
}

.waf-topbar-copy {
  min-width: 0;
}

.waf-topbar-eyebrow {
  margin: 0 0 2px;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--shell-muted);
}

.waf-topbar-copy h1 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--shell-text);
}

.waf-topbar-desc {
  margin: 3px 0 0;
  font-size: 0.72rem;
  line-height: 1.45;
  color: var(--shell-muted);
  max-width: 42rem;
}

.waf-topbar-end {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 1 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.waf-topbar-cluster {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
}

.waf-topbar-cluster--context {
  padding: 4px 6px 4px 10px;
  border: 1px solid var(--shell-border);
  border-radius: var(--radius-md);
  background: var(--shell-elevated);
}

.waf-topbar-cluster--actions {
  padding: 4px;
  border: 1px solid var(--shell-border);
  border-radius: var(--radius-md);
  background: var(--shell-panel);
}

.waf-topbar-divider {
  width: 1px;
  align-self: stretch;
  min-height: 24px;
  margin: 0 2px;
  background: var(--shell-border);
}

.waf-topbar-site .sr-select-field {
  gap: 6px;
}

.waf-topbar-site .sr-select-label {
  font-size: 0.62rem;
}

.waf-topbar-site select {
  min-width: 120px !important;
  max-width: 160px;
  min-height: 30px !important;
  padding-top: 4px !important;
  padding-bottom: 4px !important;
  font-size: 0.76rem !important;
}

.waf-topbar-user {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.waf-topbar-user .user-pill {
  max-width: 168px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 4px 8px;
  font-size: 0.68rem;
}

.waf-topbar-user .btn.ghost.sm {
  padding: 4px 8px;
  font-size: 0.68rem;
}

.waf-topbar-settings-link {
  white-space: nowrap;
}

.waf-topbar-btn-group {
  display: inline-flex;
  align-items: stretch;
  gap: 6px;
}

.waf-topbar-btn-group .btn {
  min-height: 32px;
  padding: 6px 12px;
  font-size: 0.76rem;
}

.waf-topbar-btn-group .btn.secondary {
  background: var(--shell-elevated);
}

.waf-dirty-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.66rem;
  font-weight: 600;
  color: var(--warn);
  background: var(--warn-soft);
  border: 1px solid rgba(245, 158, 11, 0.25);
  white-space: nowrap;
}

.waf-dirty-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--warn);
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.2);
}

/* ── Status strip ─────────────────────────────────────────── */

.waf-status-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0 0 12px;
  padding: 9px 12px;
  border: 1px solid var(--shell-border);
  border-radius: var(--radius-sm);
  background: var(--shell-panel);
  font-size: 0.76rem;
  color: var(--shell-text-secondary);
  line-height: 1.4;
}

.waf-status-dot {
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--shell-muted);
}

.waf-status-strip.is-on .waf-status-dot {
  background: var(--success);
  box-shadow: 0 0 0 3px var(--success-soft);
}

.waf-status-strip.is-off .waf-status-dot {
  background: var(--warn);
  box-shadow: 0 0 0 3px var(--warn-soft);
}

.waf-status-strip.is-saved .waf-status-dot {
  background: var(--shell-accent);
  box-shadow: 0 0 0 3px var(--shell-active);
}

.waf-status-strip.is-error .waf-status-dot {
  background: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-soft);
}

.waf-status-text {
  font-weight: 600;
  color: var(--shell-text);
}

.waf-status-meta {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--shell-muted);
  white-space: nowrap;
}

/* ── Tab bar ──────────────────────────────────────────────── */

.waf-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 14px;
  padding: 3px;
  border: 1px solid var(--shell-border);
  border-radius: var(--radius-md);
  background: var(--shell-elevated);
  overflow-x: auto;
  scrollbar-width: none;
}

.waf-tabs::-webkit-scrollbar { display: none; }

.waf-tab {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: none;
  border-radius: calc(var(--radius-md) - 2px);
  background: transparent;
  font-family: inherit;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--shell-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s, box-shadow 0.12s;
}

.waf-tab:hover {
  color: var(--shell-text-secondary);
  background: rgba(255, 255, 255, 0.6);
}

.waf-tab.is-active {
  color: var(--shell-text);
  background: var(--shell-panel);
  box-shadow: var(--shadow-xs);
}

.waf-tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--shell-accent);
  background: var(--shell-active);
}

/* ── Panels ───────────────────────────────────────────────── */

.waf-panels {
  flex: 1;
  min-height: 0;
}

.waf-panel[hidden] {
  display: none !important;
}

/* ── Cards ────────────────────────────────────────────────── */

.waf-card {
  padding: 16px 18px;
  border: 1px solid var(--shell-border);
  border-radius: var(--radius-md);
  background: var(--shell-panel);
  min-width: 0;
}

.waf-card--full {
  padding: 18px 20px;
}

.waf-card--shield {
  background: linear-gradient(160deg, #fff 55%, var(--accent-soft) 160%);
}

.waf-card h2 {
  margin: 0 0 4px;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--shell-text);
}

.waf-card-lead {
  margin: 0 0 14px;
  font-size: 0.74rem;
  color: var(--shell-muted);
  line-height: 1.45;
  max-width: 52ch;
}

.waf-subheading {
  margin: 18px 0 10px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--shell-muted);
}

.waf-card-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.waf-card-toolbar h2 { margin-bottom: 2px; }
.waf-card-toolbar .waf-card-lead { margin-bottom: 0; }

.waf-card-toolbar-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* ── Overview grid ────────────────────────────────────────── */

.waf-overview-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  gap: 12px;
  align-items: start;
}

.waf-shield-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}

.waf-shield-head p {
  margin: 0;
  font-size: 0.74rem;
  color: var(--shell-muted);
  line-height: 1.45;
  max-width: 36ch;
}

/* Protection toggle */
.waf-switch {
  position: relative;
  flex-shrink: 0;
  cursor: pointer;
}

.waf-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.waf-switch-track {
  position: relative;
  display: block;
  width: 44px;
  height: 26px;
  border-radius: 999px;
  background: var(--shell-border-strong);
  transition: background 0.18s;
}

.waf-switch-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.2);
  transition: transform 0.18s;
}

.waf-switch input:checked + .waf-switch-track {
  background: var(--shell-accent);
}

.waf-switch input:checked + .waf-switch-track::after {
  transform: translateX(18px);
}

.waf-switch input:focus-visible + .waf-switch-track {
  outline: 2px solid var(--shell-accent);
  outline-offset: 2px;
}

/* Mode picker */
.waf-mode-picker {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.waf-mode-option {
  position: relative;
  cursor: pointer;
}

.waf-mode-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.waf-mode-option-body {
  display: flex;
  flex-direction: column;
  gap: 3px;
  height: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--shell-border);
  border-radius: var(--radius-sm);
  background: var(--shell-elevated);
  transition: border-color 0.14s, background 0.14s, box-shadow 0.14s;
}

.waf-mode-option strong {
  font-size: 0.8rem;
  color: var(--shell-text);
}

.waf-mode-option small {
  font-size: 0.68rem;
  color: var(--shell-muted);
  line-height: 1.35;
}

.waf-mode-option:hover .waf-mode-option-body {
  border-color: var(--shell-border-strong);
}

.waf-mode-option:has(input:checked) .waf-mode-option-body {
  border-color: var(--accent-muted);
  background: var(--shell-active);
  box-shadow: var(--shadow-xs);
}

.waf-mode-option:has(input:focus-visible) .waf-mode-option-body {
  outline: 2px solid var(--shell-accent);
  outline-offset: 1px;
}

/* Threshold slider */
.waf-threshold-block {
  margin-bottom: 16px;
}

.waf-threshold-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 8px;
}

.waf-threshold-top label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--shell-muted);
}

.waf-threshold-top output {
  font-size: 0.9rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--shell-accent);
}

.waf-threshold-block input[type="range"] {
  width: 100%;
  height: 6px;
  margin: 0;
  accent-color: var(--shell-accent);
  cursor: pointer;
}

.waf-threshold-hints {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 0.64rem;
  color: var(--shell-muted);
}

/* ── Field blocks ─────────────────────────────────────────── */

.waf-field-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.waf-field-block > span {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--shell-muted);
}

.waf-field-block input[type="text"],
.waf-field-block input[type="url"],
.waf-field-block textarea,
.waf-card textarea {
  width: 100%;
  padding: 8px 10px;
  font-size: 0.78rem;
  line-height: 1.45;
  border: 1px solid var(--shell-border);
  border-radius: var(--radius-sm);
  background: var(--shell-elevated);
  color: var(--shell-text);
  resize: vertical;
}

.waf-field-block input:focus,
.waf-card textarea:focus {
  outline: none;
  border-color: var(--accent-muted);
  box-shadow: 0 0 0 3px var(--shell-active);
}

/* ── Detection grid ───────────────────────────────────────── */

.waf-detection-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.waf-toggle-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.waf-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  color: var(--shell-text-secondary);
  cursor: pointer;
  transition: background 0.1s;
}

.waf-toggle-row:hover {
  background: var(--shell-elevated);
}

.waf-toggle-row input {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--shell-accent);
  cursor: pointer;
}

.waf-toggle-row input.waf-inline-num {
  width: 64px;
  height: 28px;
  padding: 2px 6px;
  border: 1px solid var(--shell-border);
  border-radius: var(--radius-sm);
  background: var(--shell-surface);
  color: var(--shell-text);
  font: inherit;
  cursor: text;
}

/* ── Threat categories ────────────────────────────────────── */

.waf-cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 8px;
}

.waf-cat-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--shell-border);
  border-radius: var(--radius-sm);
  background: var(--shell-elevated);
  font-size: 0.74rem;
  font-weight: 500;
  color: var(--shell-text-secondary);
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s, color 0.12s;
  user-select: none;
}

.waf-cat-item:hover {
  border-color: var(--shell-border-strong);
}

.waf-cat-item:has(input:checked) {
  border-color: var(--accent-muted);
  background: var(--shell-active);
  color: var(--shell-accent);
}

.waf-cat-item input {
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: var(--shell-accent);
  flex-shrink: 0;
}

/* ── Custom rules ─────────────────────────────────────────── */

.waf-rules {
  display: grid;
  gap: 10px;
}

.waf-rule {
  padding: 14px 16px;
  border: 1px solid var(--shell-border);
  border-radius: var(--radius-sm);
  background: var(--shell-elevated);
}

.waf-rule-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.waf-rule-head strong {
  font-size: 0.82rem;
  color: var(--shell-text);
}

.waf-rule-head .btn.ghost.sm {
  flex-shrink: 0;
}

.waf-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}

.waf-fields--stack { grid-template-columns: 1fr; }

.waf-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.waf-field > span {
  font-size: 0.64rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--shell-muted);
}

.waf-field input[type="text"],
.waf-field input[type="number"],
.waf-field input[type="url"] {
  padding: 7px 10px;
  font-size: 0.76rem;
}

.waf-empty {
  margin: 0;
  padding: 28px 16px;
  text-align: center;
  font-size: 0.78rem;
  color: var(--shell-muted);
  border: 1px dashed var(--shell-border);
  border-radius: var(--radius-sm);
  background: var(--shell-elevated);
}

/* ── Trust grid ─────────────────────────────────────────────── */

.waf-trust-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.waf-card--span {
  grid-column: 1 / -1;
}

.waf-inline-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

/* ── Test lab ─────────────────────────────────────────────── */

.waf-test-layout {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 12px;
  align-items: start;
}

.waf-test-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.waf-card--console {
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 280px;
}

.waf-console-head {
  padding: 8px 12px;
  border-bottom: 1px solid var(--shell-border);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--shell-muted);
  background: var(--shell-elevated);
}

.waf-console-out {
  flex: 1;
  margin: 0;
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  line-height: 1.55;
  color: var(--shell-text);
  white-space: pre-wrap;
  word-break: break-word;
  overflow: auto;
  background: #1e1f24;
  color: #e2e8f0;
  min-height: 220px;
}

/* ── Footnote ─────────────────────────────────────────────── */

.waf-footnote {
  margin: 14px 0 0;
  font-size: 0.68rem;
  color: var(--shell-muted);
  text-align: center;
}

.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;
}

/* ── Responsive ───────────────────────────────────────────── */

@media (max-width: 1024px) {
  .waf-overview-grid,
  .waf-test-layout {
    grid-template-columns: 1fr;
  }

  .waf-mode-picker {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .waf-page { padding: 0 12px 16px; }

  .waf-topbar-inner {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 12px 14px;
  }

  .waf-topbar-end {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }

  .waf-topbar-cluster--context,
  .waf-topbar-cluster--actions {
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
  }

  .waf-topbar-desc {
    display: none;
  }

  .waf-topbar-site select {
    max-width: none;
    flex: 1;
  }

  .waf-topbar-btn-group {
    width: 100%;
  }

  .waf-topbar-btn-group .btn {
    flex: 1;
  }

  .waf-detection-grid,
  .waf-trust-grid,
  .waf-inline-fields {
    grid-template-columns: 1fr;
  }

  .waf-status-meta {
    margin-left: 0;
    width: 100%;
  }
}

@media (max-width: 480px) {
  .waf-tabs {
    flex-wrap: nowrap;
  }
}
