:root {
  color-scheme: light;
  --bg: #f4f5f2;
  --panel: #ffffff;
  --line: #d9ddd3;
  --text: #1d2421;
  --muted: #687069;
  --accent: #b5262e;
  --accent-dark: #8f1f25;
  --soft: #e8ece5;
  --focus: #244f85;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}

button,
input,
select {
  font: inherit;
}

.app {
  min-height: 100vh;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  margin-bottom: 14px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  letter-spacing: 0;
}

h2 {
  font-size: 15px;
}

.topbar p,
.result-head p,
.detail-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.search-panel {
  display: grid;
  grid-template-columns: minmax(320px, 1.5fr) 110px 130px 140px minmax(240px, 1fr) auto auto;
  gap: 10px;
  align-items: end;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

label {
  display: grid;
  gap: 5px;
  min-width: 0;
}

label span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

input,
select {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 7px 9px;
}

.search-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 84px;
  gap: 8px;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.primary {
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-weight: 700;
  padding: 0 16px;
}

.primary:hover {
  background: var(--accent-dark);
}

.secondary {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--soft);
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
  padding: 0 14px;
}

.secondary:hover {
  background: #dde3da;
}

.primary:disabled,
.secondary:disabled {
  cursor: wait;
  opacity: 0.72;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 14px;
  margin-top: 14px;
}

.results,
.detail {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.result-head,
.detail-head {
  display: grid;
  gap: 6px;
  min-height: 58px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

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

.result-tools select {
  width: 110px;
}

.loading-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.loading-badge[hidden] {
  display: none;
}

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid #c8cec4;
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
}

.loading-cell {
  align-items: center;
  gap: 8px;
}

.loading-cell .spinner {
  margin-right: 8px;
  vertical-align: -2px;
}

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

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 178px);
}

table {
  width: 100%;
  border-collapse: collapse;
  white-space: nowrap;
}

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eef1eb;
  color: #4c554d;
  font-size: 11px;
  text-transform: uppercase;
}

td.description,
td.section,
td.models {
  white-space: normal;
  min-width: 190px;
}

td.models {
  max-width: 260px;
}

.part-no-cell {
  display: grid;
  gap: 4px;
}

.rev-badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 20px;
  border-radius: 4px;
  background: #edf1f7;
  color: #244f85;
  padding: 2px 6px;
  font-size: 11px;
  font-weight: 800;
}

.part-family {
  color: var(--muted);
  font-size: 11px;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover,
tbody tr.is-selected {
  background: #fff4e0;
}

.detail {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  max-height: calc(100vh - 118px);
}

.history-list {
  overflow: auto;
  padding: 10px;
}

.part-notes {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.part-notes[hidden] {
  display: none;
}

.part-notes h3 {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.part-note {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f9faf7;
  padding: 8px;
  font-size: 12px;
  line-height: 1.45;
}

.part-note p {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  color: var(--muted);
}

.part-note span,
.part-note a {
  border-radius: 999px;
  background: var(--soft);
  color: #394139;
  padding: 2px 7px;
  font-size: 11px;
  text-decoration: none;
}

.part-note a {
  color: var(--focus);
}

.revision-panel {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.revision-panel h3 {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.revision-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  padding: 8px;
  text-align: left;
}

.revision-row:hover {
  background: #fff4e0;
}

.revision-row span {
  display: grid;
  gap: 2px;
}

.revision-row em,
.revision-row small {
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
}

.history-item {
  display: grid;
  gap: 4px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.history-item:first-child {
  padding-top: 0;
}

.history-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-weight: 800;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  background: var(--soft);
  color: #394139;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 700;
}

.history-meta,
.history-models {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.empty {
  padding: 18px;
  color: var(--muted);
}

@media (max-width: 1180px) {
  .search-panel {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .search-box,
  .section-filter {
    grid-column: span 2;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .detail {
    max-height: none;
  }
}

@media (max-width: 720px) {
  .app {
    padding: 10px;
  }

  .search-panel {
    grid-template-columns: 1fr;
  }

  .search-box,
  .section-filter {
    grid-column: auto;
  }
}
