:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-muted: #f8f9fb;
  --border: #d9dde3;
  --border-strong: #c8ced8;
  --text: #101828;
  --text-muted: #667085;
  --accent: #1f2937;
  --accent-soft: #e5e7eb;
  --success-soft: #ecfdf3;
  --warning-soft: #fff7e6;
  --warning-border: #f2cc8f;
  --selection-soft: #eff6ff;
  --selection-border: #bfdbfe;
  --danger-soft: #fef3f2;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-md: 0 12px 24px rgba(16, 24, 40, 0.06);
}

html { scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
}

a { color: inherit; }
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', monospace;
  font-size: 0.9em;
}

.app-header { backdrop-filter: saturate(120%) blur(8px); }
.panel-card,
.modal-content,
.offcanvas {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.navbar-brand { text-decoration: none; }
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.brand-title { font-size: 0.95rem; font-weight: 700; line-height: 1.1; }
.brand-subtitle { color: var(--text-muted); font-size: 0.73rem; line-height: 1.1; }
.nav-link { color: var(--text-muted); font-weight: 500; }
.nav-link:hover, .nav-link:focus { color: var(--accent); }

.hero-panel .panel-card { min-height: 100%; }
.eyebrow,
.status-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 1px solid var(--border);
  background: var(--surface-muted);
}
.status-chip { text-transform: none; letter-spacing: 0; }
.hero-title {
  font-size: clamp(1.8rem, 2vw, 2.65rem);
  line-height: 1.08;
  letter-spacing: -0.04em;
  max-width: 13ch;
  margin-bottom: 1rem;
}
.hero-copy {
  color: var(--text-muted);
  font-size: 0.98rem;
  max-width: 64ch;
}
.metrics-inline .metric-tile {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-muted);
  padding: 1rem;
  min-height: 104px;
}
.metric-tile-warm {
  background: var(--warning-soft);
  border-color: var(--warning-border);
}
.metric-label { color: var(--text-muted); font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.04em; }
.metric-value { font-size: 1.7rem; font-weight: 700; margin-top: 0.35rem; letter-spacing: -0.04em; }
.section-title { font-size: 1rem; font-weight: 700; }
.rule-list { display: grid; gap: 0.8rem; }
.rule-item {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  color: var(--text-muted);
}
.rule-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--accent);
  margin-top: 0.3rem;
  flex-shrink: 0;
}
.surface-note {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-muted);
  padding: 1rem;
}
.surface-note-title {
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.filters-card { top: 88px; }
.form-label {
  font-size: 0.76rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.45rem;
}
.form-control,
.form-select,
.btn {
  border-radius: var(--radius-sm);
}
.form-control,
.form-select {
  min-height: 42px;
  border-color: var(--border);
  background: #fff;
}
.form-control:focus,
.form-select:focus,
.btn:focus,
.nav-link:focus {
  border-color: #94a3b8;
  box-shadow: 0 0 0 0.2rem rgba(148, 163, 184, 0.18);
}
.btn-dark {
  background: var(--accent);
  border-color: var(--accent);
}
.btn-dark:hover,
.btn-dark:focus { background: #111827; border-color: #111827; }
.dataset-search-bar {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, rgba(255,255,255,0.98), rgba(248,250,252,0.96));
  padding: 1rem;
}
.dataset-search-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  gap: 0.75rem;
  align-items: center;
}
.dataset-search-input {
  min-height: 48px;
  font-size: 0.98rem;
}
.advanced-filter-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 48px;
  white-space: nowrap;
}
.advanced-filter-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5rem;
  min-height: 1.5rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(148, 163, 184, 0.45);
  font-size: 0.76rem;
  font-weight: 700;
}
.advanced-filters-stack {
  display: grid;
  gap: 0.9rem;
}
.advanced-filter-row {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-muted);
  padding: 1rem;
}
.advanced-filter-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr) minmax(0, 1.25fr) auto;
  gap: 0.75rem;
  align-items: end;
}
.advanced-filter-actions {
  display: flex;
  justify-content: flex-end;
}
.advanced-filter-empty {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  background: #fff;
  padding: 1rem;
}

.toolbar-strip,
.selection-bar {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-muted);
  padding: 0.8rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.selection-bar {
  background: var(--selection-soft);
  border-color: var(--selection-border);
}
.toolbar-left,
.toolbar-right,
.chip-row {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  flex-wrap: wrap;
}
.chip-row { min-height: 28px; }
.filter-chip {
  background: #fff;
  border: 1px solid var(--border);
  padding: 0.35rem 0.6rem;
  border-radius: 999px;
  font-size: 0.78rem;
  color: var(--text-muted);
}
.filter-chip-advanced {
  background: #fff7e6;
  border-color: var(--warning-border);
  color: #9a3412;
}
.legend {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--text-muted);
  font-size: 0.78rem;
}
.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--warning-soft);
}
.legend-selected .legend-swatch {
  background: var(--selection-soft);
  border-color: var(--selection-border);
}
.legend-last-change .legend-swatch {
  background: rgba(245, 158, 11, 0.16);
  border-color: rgba(245, 158, 11, 0.45);
}
.section-tabs .nav-link {
  color: var(--text-muted);
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding-left: 0;
  padding-right: 0;
  margin-right: 1.5rem;
}
.section-tabs .nav-link.active {
  color: var(--accent);
  background: transparent;
  border-bottom-color: var(--accent);
  font-weight: 700;
}

.channel-table-wrap,
.audit-table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #fff;
}
.channel-table,
.audit-table {
  min-width: 1500px;
  margin-bottom: 0;
}
.channel-table thead th,
.audit-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #fbfcfd;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.channel-table th[data-sort] {
  cursor: pointer;
  user-select: none;
}
.channel-table td,
.channel-table th,
.audit-table td,
.audit-table th {
  padding: 0.8rem 0.75rem;
  vertical-align: middle;
}
.checkbox-col { width: 48px; }
.sticky-col {
  position: sticky;
  left: 0;
  z-index: 3;
  background: inherit;
}
.channel-table tbody td.sticky-col,
.channel-table thead th.sticky-col { background: #fff; }
.channel-table tbody tr.row-manual td,
.channel-table tbody tr.row-manual td.sticky-col {
  background: var(--warning-soft);
}
.channel-table tbody tr.row-selected td,
.channel-table tbody tr.row-selected td.sticky-col {
  background: var(--selection-soft);
}
.channel-table tbody tr:hover td,
.channel-table tbody tr:hover td.sticky-col {
  background: #f8fafc;
}
.channel-table tbody tr.row-manual:hover td,
.channel-table tbody tr.row-manual:hover td.sticky-col { background: #fff2d6; }
.channel-table tbody tr.row-selected:hover td,
.channel-table tbody tr.row-selected:hover td.sticky-col { background: #dbeafe; }
.channel-table tbody td.cell-last-change,
.channel-table tbody td.cell-last-change.sticky-col {
  background: rgba(245, 158, 11, 0.16) !important;
  box-shadow: inset 0 0 0 1px rgba(245, 158, 11, 0.35);
  font-weight: 700;
  color: #7c2d12;
}
.channel-table tbody td.cell-last-change .channel-pill {
  background: rgba(255, 255, 255, 0.78);
  border-color: rgba(245, 158, 11, 0.45);
}
.channel-row { cursor: pointer; }
.sys-col,
.sys-field { color: #98a2b3; }
.channel-pill {
  display: inline-flex;
  padding: 0.22rem 0.52rem;
  border-radius: 999px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  font-size: 0.75rem;
}
.empty-state-cell {
  padding: 2.5rem 1rem !important;
  color: var(--text-muted);
  text-align: center;
}
.page-button.disabled { opacity: 0.5; pointer-events: none; }

.analytics-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #fff;
  padding: 1rem;
  height: 100%;
}
.analytics-bars {
  display: grid;
  gap: 0.7rem;
}
.analytics-bar-row {
  display: grid;
  gap: 0.35rem;
}
.analytics-bar-top {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.82rem;
}
.analytics-bar-track {
  width: 100%;
  height: 8px;
  background: var(--accent-soft);
  border-radius: 999px;
  overflow: hidden;
}
.analytics-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: inherit;
}

.offcanvas.detail-offcanvas { width: min(560px, 100vw); }
.detail-form .form-control[readonly] {
  background: #f8f9fb;
  color: #98a2b3;
}
.detail-section { background: #fff; }
.detail-last-change-note {
  border: 1px solid #f7d8a8;
  background: #fff7e6;
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
}
.detail-last-change-title {
  font-weight: 700;
  color: #b54708;
  margin-bottom: 0.15rem;
}
.detail-last-change-badges,
.history-last-change-note {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}
.detail-last-change-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.28rem 0.6rem;
  border-radius: 999px;
  background: #fff;
  border: 1px solid #f7d8a8;
  color: #b54708;
  font-size: 0.78rem;
  font-weight: 600;
}
.editable-field-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  padding: 0.85rem;
  height: 100%;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}
[data-editable-field].is-last-changed .editable-field-card {
  border-color: #f7b955;
  background: #fff7e6;
  box-shadow: 0 0 0 3px rgba(247, 185, 85, 0.14);
}
[data-editable-field].is-last-changed .form-label {
  color: #b54708;
  font-weight: 700;
}
.section-subtitle {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  font-weight: 700;
  margin-bottom: 1rem;
}
.locked-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  padding: 0.75rem;
}
.locked-card .locked-label {
  color: var(--text-muted);
  font-size: 0.76rem;
  margin-bottom: 0.2rem;
}
.locked-card .locked-value { font-weight: 600; }
.locked-card .lock-icon { color: var(--text-muted); }
.bulk-field-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  background: var(--surface-muted);
  height: 100%;
}
.bulk-field-card .form-check { margin-bottom: 0.75rem; }
.bulk-field-card.is-enabled {
  background: #fff;
  border-color: var(--border-strong);
}
.audit-change {
  display: inline-flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}
.audit-old,
.audit-new {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  font-size: 0.76rem;
}
.audit-old {
  background: var(--danger-soft);
  color: #b42318;
  text-decoration: line-through;
}
.audit-new {
  background: var(--success-soft);
  color: #027a48;
}
.toast {
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
}
.history-metric-value {
  font-size: 1.2rem;
}
.history-stack {
  display: grid;
  gap: 1rem;
}
.history-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #fff;
  padding: 1rem;
  box-shadow: var(--shadow-sm);
}
.history-card.is-current {
  border-color: var(--selection-border);
  background: #f8fbff;
}
.history-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.history-card-title {
  font-size: 1rem;
  font-weight: 700;
  margin: 0;
}
.history-version-pill,
.history-status-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.28rem 0.6rem;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
}
.history-version-pill {
  background: var(--surface-muted);
  border: 1px solid var(--border);
}
.history-status-current {
  background: var(--selection-soft);
  color: #1d4ed8;
}
.history-status-closed {
  background: var(--warning-soft);
  color: #b54708;
}
.history-date-block {
  display: grid;
  gap: 0.35rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}
.history-meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.history-meta-grid > div,
.history-meta-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  background: var(--surface-muted);
}
.history-meta-item.is-last-change {
  border-color: #f7b955;
  background: #fff7e6;
}
.history-meta-label,
.history-change-meta {
  display: block;
  color: var(--text-muted);
  font-size: 0.75rem;
}
.history-changes-list {
  display: grid;
  gap: 0.75rem;
}
.history-change {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
  border-top: 1px dashed var(--border);
  padding-top: 0.75rem;
}
.history-change:first-child {
  border-top: none;
  padding-top: 0;
}
.history-change.is-last-change {
  border: 1px solid #f7d8a8;
  border-radius: var(--radius-sm);
  background: #fffaf0;
  padding: 0.75rem;
}
.history-change.is-last-change:first-child {
  border-top: 1px solid #f7d8a8;
}
.history-last-change-note {
  margin-bottom: 1rem;
}
.history-last-change-label {
  font-size: 0.76rem;
  font-weight: 700;
  color: #b54708;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.history-change-field {
  font-weight: 600;
}

@media (max-width: 1199.98px) {
  .filters-card { position: static !important; }
}
@media (max-width: 767.98px) {
  .hero-title { max-width: none; }
  .toolbar-strip,
  .selection-bar { align-items: flex-start; }
  .dataset-search-grid,
  .advanced-filter-grid { grid-template-columns: 1fr; }
  .advanced-filter-actions { justify-content: stretch; }
  .advanced-filter-actions .btn { width: 100%; }
}
