:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --ink: #111827;
  --muted: #64748b;
  --line: #e5e7eb;
  --accent: #1f2a44;
  --accent-2: #3b82f6;
  --shadow: 0 6px 20px rgba(15, 23, 42, 0.08);
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Space Grotesk", system-ui, -apple-system, sans-serif;
  background: linear-gradient(180deg, #f4f6fb 0%, #f7f9fc 100%);
  color: var(--ink);
}

.app {
  max-width: none;
  width: 100%;
  margin: 0;
  padding: 20px 32px 40px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}

.topbar h1 {
  margin: 0 0 6px;
  font-size: 26px;
  font-family: "Sora", "Space Grotesk", system-ui, -apple-system, sans-serif;
  letter-spacing: -0.2px;
}


.topbar p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.notice {
  display: none;
  border: 1px solid #bbf7d0;
  background: #ecfdf5;
  color: #065f46;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  margin: 0 0 16px;
}

.notice.show {
  display: block;
}

button {
  border: 1px solid var(--line);
  background: #fff;
  padding: 8px 14px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
}

button.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

button.danger {
  background: #dc2626;
  color: #fff;
  border-color: #dc2626;
}

button.ghost.danger {
  background: #fff;
  color: #dc2626;
  border-color: #fecaca;
}

button.primary svg,
button.ghost svg {
  width: 14px;
  height: 14px;
}

button.ghost {
  background: #fff;
}

.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
}

.sidebar {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  height: fit-content;
}

.sidebar__header {
  margin-bottom: 12px;
}

.case-list {
  display: grid;
  gap: 10px;
}

.case-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: #fff;
  cursor: pointer;
  display: grid;
  gap: 6px;
}

.case-card.active {
  border-color: #9ca3af;
  background: #f9fafb;
}

.case-card__title {
  font-weight: 600;
  margin-bottom: 6px;
}

.case-card__meta {
  font-size: 12px;
  color: var(--muted);
}

.case-card__row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.case-card__row button.ghost {
  padding: 4px 8px;
  font-size: 11px;
}

.case-card__row input[type="checkbox"] {
  transform: translateY(1px);
}

.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eef2ff;
  color: #3730a3;
}

.main .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.panel__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.panel__actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.loader {
  display: none;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid #e5e7eb;
  border-top-color: var(--accent-2);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

select {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  font-family: inherit;
  font-size: 13px;
  background: #fff;
}

h2 {
  margin: 0 0 6px;
  font-size: 20px;
}

h3, h4 {
  margin: 0 0 8px;
}

.meta {
  color: var(--muted);
  font-size: 12px;
}

.tabs {
  display: inline-flex;
  gap: 4px;
  background: #eef2f7;
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 12px;
}

.tab {
  border: none;
  background: transparent;
  padding: 6px 12px;
  border-radius: 8px;
}

.tab.active {
  background: #fff;
  box-shadow: var(--shadow);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

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

.gt-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}

.section-list {
  display: grid;
  gap: 10px;
}

.section {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}

.section__title {
  font-weight: 600;
  margin-bottom: 8px;
}

.subheading {
  font-size: 12px;
  font-weight: 600;
  color: #1e293b;
  margin: 6px 0 4px;
}

.bullet-list {
  margin: 0 0 6px 16px;
  padding: 0;
  color: var(--muted);
  font-size: 13px;
}

.filters {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.filter-group {
  display: flex;
  gap: 6px;
  background: #eef2f7;
  padding: 4px;
  border-radius: 999px;
}

.filter {
  border: none;
  background: transparent;
  padding: 6px 10px;
  border-radius: 999px;
}

.filter.active {
  background: #fff;
  box-shadow: var(--shadow);
}

.table-wrap {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.table th, .table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.status {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
}

.status.matched { background: #d1fae5; color: #065f46; }
.status.partial { background: #fef3c7; color: #92400e; }
.status.missing { background: #fee2e2; color: #991b1b; }
.status.extra { background: #e0e7ff; color: #3730a3; }

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.metric-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  text-align: center;
}

.metric-card .value {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
}

.aggregate-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
}

.bar-group {
  display: grid;
  gap: 8px;
}

.bar {
  height: 8px;
  background: #f3f4f6;
  border-radius: 999px;
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  background: var(--accent-2);
}

.section-score-list {
  display: grid;
  gap: 6px;
}

.section-score {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  background: #f8fafc;
  padding: 6px 8px;
  border-radius: 8px;
}

.metric-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.metric-list li {
  display: flex;
  justify-content: space-between;
  background: #f8fafc;
  padding: 6px 8px;
  border-radius: 8px;
}

.sme-grid {
  display: grid;
}

.sme-grid .card {
  display: grid;
  gap: 10px;
}

.sme-grid .card .field {
  display: grid;
  gap: 6px;
}

.sme-grid .card .field input,
.sme-grid .card .field select,
.sme-grid .card .field textarea {
  width: 100%;
}

.sme-grid .card .field span {
  font-weight: 600;
  color: #1f2937;
}

.sme-grid .card .primary {
  justify-self: flex-end;
}

textarea {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
  background: #f9fafb;
  color: var(--ink);
}

.donut {
  width: 140px;
  height: 140px;
  margin: 0 auto 10px;
  border-radius: 50%;
  background: conic-gradient(#111827 0deg, #111827 120deg, #f59e0b 120deg, #f59e0b 200deg, #ef4444 200deg, #ef4444 300deg, #6366f1 300deg, #6366f1 360deg);
}

.legend {
  display: grid;
  gap: 6px;
  font-size: 12px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.dropdown {
  position: relative;
}

.dropdown button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.dropdown button::after {
  content: "▾";
  font-size: 12px;
  color: var(--muted);
}

#run-selected-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

#run-selected-btn .icon {
  width: 14px;
  height: 14px;
}

.global-loader {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.08);
  backdrop-filter: blur(2px);
  z-index: 999;
}

.global-loader .spinner {
  width: 24px;
  height: 24px;
  border-width: 3px;
}

.section-loading {
  opacity: 0.5;
  pointer-events: none;
}

.skeleton {
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(90deg, #eef2f7 25%, #f8fafc 37%, #eef2f7 63%);
  background-size: 400% 100%;
  animation: shimmer 1.2s ease infinite;
  margin: 6px 0;
}

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

.modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.3);
  z-index: 1000;
}

.modal.open {
  display: flex;
}

.modal__content {
  width: 420px;
  background: #fff;
  border-radius: 16px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 18px;
}

.modal__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.modal__body {
  display: grid;
  gap: 12px;
}

.modal__body .field span {
  font-weight: 600;
  color: #1f2937;
}

.modal__body select,
.modal__body input {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  background: #f9fafb;
  color: var(--ink);
}

.case-preview {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  max-height: 140px;
  overflow: auto;
  background: #f8fafc;
}

.case-preview li {
  font-size: 12px;
  color: var(--muted);
  padding: 4px 0;
}

.modal__footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}

.field {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: #111827;
  color: #fff;
  padding: 10px 14px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.2s ease;
  z-index: 1001;
  font-size: 12px;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.dropdown__menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px;
  display: none;
  min-width: 240px;
  box-shadow: var(--shadow);
  z-index: 10;
}

.dropdown__menu button {
  width: 100%;
  text-align: left;
  border: none;
  padding: 10px 12px;
  background: transparent;
  border-radius: 8px;
}

.dropdown__menu .bundle-meta {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.dropdown__menu button:hover {
  background: #f3f4f6;
}

.dropdown.open .dropdown__menu {
  display: block;
}

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .gt-grid { grid-template-columns: 1fr; }
  .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .aggregate-grid { grid-template-columns: 1fr; }
}
