/* IssueForge Enterprise v1204 — Mode A :root Dark-Polarity Design System (WCAG 2.2 AA) */
:root {
  /* Locked Stitch & Material Design 3 Dark Tokens */
  --stitch-preview-canvas-bg: #0b0f14;
  --stitch-variant-card-bg: #182028;
  --bg-root: #0b0f14;
  --bg-canvas: #0b0f19;
  --bg-surface: #111827;
  --bg-card: #182028;
  --bg-surface-elevated: #161f30;
  --bg-surface-hover: #1e293b;
  --bg-glass: rgba(17, 24, 39, 0.86);

  /* Text Hierarchy (Contrast >= 4.5:1 on --bg-surface) */
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --text-disabled: #64748b;

  /* Brand & Semantic Accents */
  --accent-primary: #3b82f6;
  --accent-primary-hover: #2563eb;
  --accent-cyan: #38bdf8;
  --accent-success: #10b981;
  --accent-warning: #f59e0b;
  --accent-danger: #ef4444;
  --accent-info: #06b6d4;
  --accent-purple: #8b5cf6;

  /* Borders & Focus */
  --border-subtle: #1e293b;
  --border-strong: #334155;
  --focus-ring: #60a5fa;

  /* Typography */
  --font-sans: 'Public Sans', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  /* Spacing & Radii */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --touch-target-min: 44px;
}

/* Mandatory [hidden] rule so flex/grid utilities never override HTML hidden */
[hidden] {
  display: none !important;
}

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

html,
body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body:has(dialog[open]) {
  overflow: hidden;
}

/* WCAG 2.2 SC 2.4.11 / 2.4.13 Focus Appearance */
:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* Skip Link */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 1000;
  background: var(--accent-primary);
  color: #ffffff;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  text-decoration: none;
}

.skip-link:focus {
  left: 12px;
  top: 12px;
}

/* Sticky Top Navigation Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 20px;
}

.header-inner {
  max-width: 1560px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 62px;
  flex-wrap: nowrap;
}

.brand-cluster {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: linear-gradient(135deg, #2563eb, #38bdf8);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  box-shadow: 0 2px 10px rgba(59, 130, 246, 0.35);
}

.brand-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  white-space: nowrap;
}

.brand-version {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent-cyan);
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.25);
  padding: 2px 6px;
  border-radius: 999px;
}

/* Primary Navigation Tabs */
.primary-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  flex-wrap: nowrap;
  scrollbar-width: none;
  flex: 1 1 auto;
  min-width: 0;
  padding: 4px 0;
}

.primary-nav::-webkit-scrollbar {
  display: none;
}

.nav-tab {
  min-height: var(--touch-target-min);
  padding: 8px 12px;
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  transition: color 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
}

.nav-tab:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.04);
}

.nav-tab[aria-selected="true"],
.nav-tab.is-active {
  color: var(--text-primary);
  border-bottom-color: var(--accent-primary);
  background: rgba(59, 130, 246, 0.08);
  font-weight: 600;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.header-search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.header-search-input {
  width: 210px;
  min-height: 38px;
  padding: 6px 12px 6px 32px;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
}

.header-search-icon {
  position: absolute;
  left: 10px;
  color: var(--text-muted);
  pointer-events: none;
}

.tenant-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--accent-success);
  box-shadow: 0 0 8px var(--accent-success);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--touch-target-min);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.btn-sm {
  min-height: 36px;
  padding: 6px 10px;
  font-size: 12px;
}

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

.btn-primary:hover:not(:disabled) {
  background: var(--accent-primary-hover);
}

.btn-secondary {
  background: var(--bg-surface-elevated);
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-surface-hover);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.35);
  color: #fca5a5;
}

.btn-danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.25);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Main Workspace Shell */
.app-main {
  max-width: 1560px;
  margin: 0 auto;
  padding: 20px;
}

/* RFC-7807 Alert Banner & Toast */
.alert-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  margin-bottom: 16px;
  border-radius: var(--radius-md);
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.45);
  color: #fecaca;
}

.toast-banner {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 90;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--accent-primary);
  color: var(--text-primary);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  font-size: 13px;
  max-width: 420px;
}

/* Screen Sections */
.screen-section {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.screen-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.screen-title {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.screen-subtitle {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

/* Filter Pill Bars */
.filter-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.pill-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.pill-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-right: 4px;
}

.filter-pill {
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}

.filter-pill.is-active,
.filter-pill[aria-pressed="true"] {
  background: rgba(59, 130, 246, 0.18);
  border-color: var(--accent-primary);
  color: #ffffff;
}

/* Cards & Grids */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 18px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 18px;
  min-height: 118px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
}

.kpi-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
}

.kpi-value {
  font-size: 32px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.kpi-delta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 999px;
  width: fit-content;
}

.delta-good {
  background: rgba(16, 185, 129, 0.14);
  color: #34d399;
}

.delta-danger {
  background: rgba(239, 68, 68, 0.14);
  color: #f87171;
}

.delta-warn {
  background: rgba(245, 158, 11, 0.14);
  color: #fbbf24;
}

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

.grid-12 {
  display: grid;
  grid-template-columns: 7fr 5fr;
  gap: 16px;
}

.grid-split {
  display: grid;
  grid-template-columns: 5fr 7fr;
  gap: 16px;
  align-items: start;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-mono);
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge-sev1 {
  background: rgba(239, 68, 68, 0.16);
  border-color: rgba(239, 68, 68, 0.35);
  color: #fca5a5;
}

.badge-sev2 {
  background: rgba(245, 158, 11, 0.16);
  border-color: rgba(245, 158, 11, 0.35);
  color: #fcd34d;
}

.badge-sev3 {
  background: rgba(59, 130, 246, 0.16);
  border-color: rgba(59, 130, 246, 0.35);
  color: #93c5fd;
}

.badge-sev4 {
  background: rgba(148, 163, 184, 0.16);
  border-color: rgba(148, 163, 184, 0.35);
  color: #cbd5e1;
}

.badge-status-draft {
  background: rgba(148, 163, 184, 0.14);
  color: #cbd5e1;
}

.badge-status-active {
  background: rgba(245, 158, 11, 0.16);
  color: #fcd34d;
}

.badge-status-progress {
  background: rgba(59, 130, 246, 0.18);
  color: #93c5fd;
}

.badge-status-approved {
  background: rgba(16, 185, 129, 0.16);
  color: #6ee7b7;
}

/* Responsive Tables & Multi-Tenant Governance */
.table-shell {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.table-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-subtle);
}

.rls-tenant-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: #6ee7b7;
}

.table-scroll {
  overflow-x: auto;
  max-width: 100%;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 13px;
}

table.data-table th {
  padding: 11px 16px;
  background: var(--bg-surface-elevated);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}

table.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  vertical-align: middle;
}

table.data-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.025);
}

/* Forms & Validation */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

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

.form-field.full {
  grid-column: 1 / -1;
}

.form-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.char-counter {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  min-height: var(--touch-target-min);
  padding: 10px 12px;
  background: var(--bg-canvas);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
}

.form-textarea {
  min-height: 92px;
  resize: vertical;
  font-family: var(--font-sans);
}

.form-input.mono,
.form-textarea.mono {
  font-family: var(--font-mono);
  font-size: 12px;
}

.form-input:user-invalid,
.form-textarea:user-invalid,
[aria-invalid="true"] {
  border-color: var(--accent-danger);
}

.field-error {
  font-size: 12px;
  color: #fca5a5;
}

/* Triage Queue & Kanban */
.triage-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.triage-item {
  width: 100%;
  text-align: left;
  padding: 14px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.triage-item:hover {
  background: var(--bg-surface-elevated);
  border-color: var(--border-strong);
}

.triage-item.is-selected {
  border-color: var(--accent-primary);
  background: rgba(59, 130, 246, 0.08);
}

.kanban-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(220px, 1fr));
  gap: 12px;
  overflow-x: auto;
}

.kanban-col {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 260px;
}

.kanban-col-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
}

/* Code / Diagnostic Console */
.code-block {
  margin: 0;
  padding: 14px;
  border-radius: var(--radius-md);
  background: #070a10;
  border: 1px solid var(--border-subtle);
  font-family: var(--font-mono);
  font-size: 12px;
  color: #93c5fd;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Native Dialog Modal */
dialog.app-dialog {
  width: min(720px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.65);
}

dialog.app-dialog::backdrop {
  background: rgba(5, 8, 15, 0.78);
  backdrop-filter: blur(4px);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
}

.dialog-body {
  padding: 20px;
  overflow-y: auto;
  max-height: calc(100vh - 180px);
}

/* 5-State Skeleton & Empty States */
.skeleton {
  background: linear-gradient(90deg, #161f30 25%, #1e293b 50%, #161f30 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.empty-state {
  text-align: center;
  padding: 36px 20px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

/* Aging Bars */
.aging-row {
  display: grid;
  grid-template-columns: 76px 1fr 48px;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.aging-track {
  height: 10px;
  background: var(--bg-canvas);
  border-radius: 999px;
  overflow: hidden;
  display: flex;
}

/* Responsive Breakpoints */
@media (max-width: 1180px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .grid-12,
  .grid-split,
  .grid-2 {
    grid-template-columns: 1fr;
  }
  .header-search-wrap {
    display: none;
  }
}

@media (max-width: 720px) {
  .kpi-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }
  .app-main {
    padding: 12px;
  }
  .tenant-badge {
    display: none;
  }
}
