/* ── Reset & Base ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body {
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: #f9fafb;
  color: #111827;
  line-height: 1.5;
}
a { color: inherit; text-decoration: none; }

/* ── Layout ─────────────────────────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }
.main   { flex: 1; min-width: 0; padding: 24px 28px; overflow-x: hidden; }

/* ── Sidebar ────────────────────────────────────────────────────────── */
.sidebar {
  width: 210px; min-width: 210px;
  background: #fff;
  border-right: 1px solid #e5e7eb;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar-logo {
  display: flex; align-items: center; gap: 10px;
  padding: 16px;
  border-bottom: 1px solid #f3f4f6;
}
.logo-icon {
  width: 28px; height: 28px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 13px; font-weight: 700;
  flex-shrink: 0;
}
.logo-name { font-size: 13px; font-weight: 600; color: #111827; }
.logo-sub  { font-size: 10px; color: #9ca3af; }

.nav { padding: 8px; flex: 1; }
.nav-section {
  font-size: 10px; font-weight: 600; color: #9ca3af;
  text-transform: uppercase; letter-spacing: .06em;
  padding: 12px 8px 4px;
}
.nav-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border-radius: 7px;
  font-size: 13px; color: #4b5563;
  cursor: pointer; transition: background .12s, color .12s;
  margin-bottom: 1px;
}
.nav-item:hover  { background: #f3f4f6; color: #111827; }
.nav-item.active { background: #f3f4f6; color: #111827; font-weight: 500; }
.nav-icon { font-size: 14px; width: 18px; text-align: center; }
.nav-dot  { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.dot-health { background: #10b981; }
.dot-pay    { background: #f59e0b; }
.dot-mort   { background: #6366f1; }

.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid #f3f4f6;
  font-size: 11px; color: #9ca3af;
}
.status-row { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.status-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.status-dot.ok   { background: #10b981; }
.status-dot.warn { background: #f59e0b; }
.status-dot.err  { background: #ef4444; }

/* ── Flash messages ──────────────────────────────────────────────────── */
.flash-container { margin-bottom: 16px; }
.flash {
  padding: 10px 14px; border-radius: 7px;
  font-size: 13px; margin-bottom: 8px;
}
.flash-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.flash-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }

/* ── Page header ─────────────────────────────────────────────────────── */
.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 24px; gap: 16px;
}
.page-title { font-size: 20px; font-weight: 600; color: #111827; }
.page-sub   { font-size: 13px; color: #6b7280; margin-top: 3px; }
.page-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }

/* ── Breadcrumb ──────────────────────────────────────────────────────── */
.breadcrumb {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: #9ca3af; margin-bottom: 6px;
}
.breadcrumb a { color: #6b7280; }
.breadcrumb a:hover { color: #111827; }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px; border-radius: 7px;
  font-size: 13px; font-weight: 500; cursor: pointer;
  border: 1px solid #e5e7eb;
  background: #fff; color: #374151;
  transition: background .12s, border-color .12s;
  white-space: nowrap;
}
.btn:hover { background: #f9fafb; border-color: #d1d5db; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-primary {
  background: #6366f1; border-color: #6366f1; color: #fff;
}
.btn-primary:hover { background: #4f46e5; border-color: #4f46e5; }
.btn-outline {
  background: transparent; border-color: #d1d5db; color: #374151;
}
.btn-outline:hover { background: #f3f4f6; }

/* ── Badges ──────────────────────────────────────────────────────────── */
.badge {
  display: inline-block; font-size: 11px; font-weight: 500;
  padding: 2px 7px; border-radius: 5px;
}
.badge-green  { background: #d1fae5; color: #065f46; }
.badge-red    { background: #fee2e2; color: #991b1b; }
.badge-blue   { background: #dbeafe; color: #1e40af; }
.badge-amber  { background: #fef3c7; color: #92400e; }
.badge-gray   { background: #f3f4f6; color: #6b7280; }

/* ── Tables ──────────────────────────────────────────────────────────── */
.table-wrap {
  border: 1px solid #e5e7eb; border-radius: 8px; overflow: hidden;
  overflow-x: auto;
}
.data-table {
  width: 100%; border-collapse: collapse; font-size: 12.5px;
}
.data-table th {
  padding: 8px 12px; text-align: left;
  font-weight: 500; font-size: 12px; color: #6b7280;
  background: #f9fafb; border-bottom: 1px solid #e5e7eb;
  white-space: nowrap;
}
.data-table td {
  padding: 7px 12px; border-bottom: 1px solid #f3f4f6;
  color: #374151; white-space: nowrap;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: #f9fafb; }
.col-actions { text-align: right; width: 100px; }
.link-btn {
  font-size: 12px; color: #6366f1; cursor: pointer;
  background: none; border: none; padding: 0 4px;
}
.link-btn:hover { color: #4f46e5; text-decoration: underline; }
.link-btn-danger { color: #ef4444; }
.link-btn-danger:hover { color: #dc2626; }

/* ── Section card ────────────────────────────────────────────────────── */
.section-card {
  background: #fff; border: 1px solid #e5e7eb;
  border-radius: 10px; overflow: hidden;
}
.section-card-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 14px 16px; border-bottom: 1px solid #f3f4f6;
}
.section-title { font-size: 14px; font-weight: 600; color: #111827; }
.section-sub   { font-size: 12px; color: #6b7280; margin-top: 2px; }

/* ── Dashboard domain grid ───────────────────────────────────────────── */
.domain-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}
.domain-card {
  background: #fff; border: 1px solid #e5e7eb;
  border-radius: 10px; padding: 16px;
}
.domain-card-header {
  display: flex; align-items: center; gap: 8px; margin-bottom: 6px;
}
.domain-icon { font-size: 18px; }
.domain-name { font-size: 14px; font-weight: 600; color: #111827; flex: 1; }
.domain-desc { font-size: 12px; color: #9ca3af; margin-bottom: 12px; }
.entity-stat-list { margin-bottom: 14px; }
.entity-stat {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 0; border-bottom: 1px solid #f3f4f6; font-size: 12px;
}
.entity-stat:last-child { border-bottom: none; }
.entity-stat-name  { color: #6b7280; }
.entity-stat-count { font-weight: 500; color: #111827; }
.domain-card-actions { display: flex; gap: 8px; }

/* ── Entity cards (domain page) ──────────────────────────────────────── */
.entity-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px; margin-bottom: 20px;
}
.entity-card {
  background: #fff; border: 1px solid #e5e7eb;
  border-radius: 8px; padding: 12px;
}
.entity-card-top { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.entity-initial {
  width: 32px; height: 32px; border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 600; flex-shrink: 0;
}
.entity-name  { font-size: 13px; font-weight: 500; }
.entity-count { font-size: 11px; color: #9ca3af; }
.entity-attrs { margin-bottom: 10px; }
.attr-tag {
  display: inline-block; font-size: 10px; padding: 1px 5px;
  border-radius: 4px; background: #f3f4f6; color: #6b7280;
  margin: 2px 2px 0 0; border: 1px solid #e5e7eb;
}
.attr-more { background: #e5e7eb; }
.entity-card-actions { display: flex; gap: 6px; }

/* ── Search bar ──────────────────────────────────────────────────────── */
.search-bar {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 12px;
}
.search-bar input {
  flex: 1; padding: 8px 12px; border-radius: 7px;
  border: 1px solid #e5e7eb; font-size: 13px;
  background: #fff; color: #111827; outline: none;
}
.search-bar input:focus { border-color: #6366f1; }
.search-count { font-size: 12px; color: #9ca3af; white-space: nowrap; }

/* ── Empty state ─────────────────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 48px 24px;
}
.empty-icon  { font-size: 32px; margin-bottom: 10px; }
.empty-title { font-size: 15px; font-weight: 500; color: #374151; margin-bottom: 4px; }
.empty-sub   { font-size: 13px; color: #9ca3af; }

/* ── Forms ───────────────────────────────────────────────────────────── */
.form-card {
  background: #fff; border: 1px solid #e5e7eb;
  border-radius: 10px; padding: 24px; max-width: 820px;
}
.form-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px; margin-bottom: 24px;
}
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group-id { opacity: .75; }
.form-label { font-size: 12px; font-weight: 500; color: #374151; }
.form-input {
  padding: 7px 10px; border: 1px solid #e5e7eb; border-radius: 7px;
  font-size: 13px; color: #111827; background: #fff; outline: none;
}
.form-input:focus  { border-color: #6366f1; }
.form-input[readonly] { background: #f9fafb; color: #9ca3af; cursor: not-allowed; }
.form-hint   { font-size: 10px; color: #9ca3af; }
.form-actions { display: flex; gap: 10px; }

/* ── Quick generate ──────────────────────────────────────────────────── */
.quick-gen-row { display: flex; flex-wrap: wrap; gap: 10px; padding: 16px; }
.gen-status {
  margin: 0 16px 16px; padding: 8px 12px; border-radius: 7px; font-size: 12px;
}
.gen-running { background: #eff6ff; color: #1d4ed8; }
.gen-ok      { background: #d1fae5; color: #065f46; }
.gen-err     { background: #fee2e2; color: #991b1b; }

/* ── Scale & Export ──────────────────────────────────────────────────── */
.scale-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.scale-card {
  background: #fff; border: 1px solid #e5e7eb;
  border-radius: 10px; padding: 16px;
}
.scale-card-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 12px;
}
.scale-domain-name { font-size: 14px; font-weight: 600; }
.scale-domain-sub  { font-size: 11px; color: #9ca3af; margin-top: 2px; }
.scale-total-badge {
  font-size: 12px; font-weight: 500; color: #6366f1;
  background: #ede9fe; padding: 3px 8px; border-radius: 6px;
  white-space: nowrap;
}
.entity-counts { margin-bottom: 12px; }
.entity-count-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 0; border-bottom: 1px solid #f3f4f6; font-size: 12px;
}
.entity-count-row:last-child { border-bottom: none; }
.count-pill {
  font-size: 11px; font-weight: 500; background: #f3f4f6;
  padding: 1px 7px; border-radius: 12px; color: #374151;
}
.slider-row {
  display: flex; align-items: center; gap: 10px; margin-bottom: 10px;
}
.slider-label { font-size: 11px; color: #9ca3af; white-space: nowrap; }
.scale-slider { flex: 1; accent-color: #6366f1; }
.scale-number-input { width: 90px; padding: 4px 8px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 13px; font-weight: 500; color: #111827; text-align: right; }
.slider-val   { font-size: 13px; font-weight: 600; color: #6366f1; min-width: 28px; text-align: right; }
.preview-row  { background: #f9fafb; border-radius: 6px; padding: 8px; margin-bottom: 10px; }
.preview-label{ font-size: 10px; color: #9ca3af; margin-bottom: 5px; }
.preview-counts { display: flex; flex-wrap: wrap; gap: 4px; }
.preview-chip {
  font-size: 11px; background: #ede9fe; color: #4c1d95;
  padding: 2px 7px; border-radius: 4px;
}
.scale-actions {
  display: flex; gap: 6px; flex-wrap: wrap;
}
.scale-status {
  margin-top: 10px; padding: 6px 10px; border-radius: 6px; font-size: 12px;
}
.scale-status-running { background: #eff6ff; color: #1d4ed8; }
.scale-status-ok      { background: #d1fae5; color: #065f46; }
.scale-status-err     { background: #fee2e2; color: #991b1b; }

.bulk-actions { display: flex; gap: 10px; flex-wrap: wrap; padding: 16px; }

/* ── Pipelines ───────────────────────────────────────────────────────── */
.pipeline-list    { padding: 0 16px; margin-bottom: 12px; }
.pipeline-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid #f3f4f6;
}
.pipeline-item:last-child { border-bottom: none; }
.pipeline-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; margin-top: 5px; }
.pipeline-body { flex: 1; }
.pipeline-name { font-size: 13px; font-weight: 500; }
.pipeline-desc { font-size: 12px; color: #6b7280; margin: 2px 0 6px; }
.pipeline-flow { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.flow-node {
  font-size: 11px; padding: 2px 7px; border-radius: 4px;
  background: #f3f4f6; border: 1px solid #e5e7eb; color: #374151;
}
.flow-arrow { font-size: 12px; color: #9ca3af; }
.pipeline-output-label {
  padding: 8px 16px; font-size: 11px; color: #9ca3af;
  border-top: 1px solid #f3f4f6; background: #f9fafb;
}

/* ── Ontology ────────────────────────────────────────────────────────── */
.mermaid-wrap {
  padding: 16px; overflow-x: auto; min-height: 80px;
  border-bottom: 1px solid #f3f4f6;
}
.mermaid-wrap svg { max-width: 100%; }
.edge-table { padding: 12px 16px; display: flex; flex-wrap: wrap; gap: 8px; }
.edge-row { display: flex; align-items: center; gap: 6px; }
.edge-from {
  font-size: 11px; padding: 2px 8px; border-radius: 5px;
  font-weight: 500;
}
.edge-to { font-size: 11px; color: #374151; }
.edge-arrow { font-size: 12px; color: #9ca3af; }

/* ── Pagination ───────────────────────────────────────────────────────────── */
.pagination {
  display: flex; align-items: center; gap: 4px;
  margin-top: 14px; flex-wrap: wrap;
}
.page-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 32px; height: 32px; padding: 0 8px;
  border-radius: 6px; font-size: 12px;
  border: 1px solid #e5e7eb; background: #fff; color: #374151;
  cursor: pointer; transition: background .12s; text-decoration: none;
}
.page-btn:hover { background: #f3f4f6; }
.page-btn-active {
  background: #6366f1; border-color: #6366f1; color: #fff; font-weight: 500;
}
.page-btn-ellipsis { border: none; background: none; cursor: default; color: #9ca3af; }

/* ── Metrics bar ─────────────────────────────────────────────────────────── */
.metrics-bar {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
}
.metric-card {
  background: #fff; border: 1px solid #e5e7eb;
  border-radius: 8px; padding: 12px 14px; text-align: center;
}
.metric-val { font-size: 20px; font-weight: 600; color: #111827; margin-bottom: 3px; }
.metric-lbl { font-size: 11px; color: #9ca3af; }

/* ── Metrics bar (pipeline detail) ──────────────────────────────────── */
.metrics-bar {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(120px,1fr));
  gap: 10px;
}
.metric-card {
  background: #fff; border: 1px solid #e5e7eb; border-radius: 9px;
  padding: 12px 14px; text-align: center;
}
.metric-val { font-size: 20px; font-weight: 600; color: #111827; margin-bottom: 2px; }
.metric-lbl { font-size: 11px; color: #9ca3af; }

/* ── Pagination ──────────────────────────────────────────────────────── */
.pagination {
  display: flex; gap: 4px; justify-content: center;
  margin-top: 16px; flex-wrap: wrap;
}
.page-btn {
  padding: 5px 10px; font-size: 12px; border-radius: 6px;
  border: 1px solid #e5e7eb; background: #fff; color: #374151;
  cursor: pointer; text-decoration: none; display: inline-block;
  transition: background .12s;
}
.page-btn:hover { background: #f3f4f6; }
.page-btn-active { background: #6366f1; border-color: #6366f1; color: #fff; }
.page-btn-active:hover { background: #6366f1; }
.page-btn-ellipsis { border: none; background: none; cursor: default; }
