:root {
  --ink: #18202b;
  --muted: #657084;
  --line: #d9dee7;
  --panel: #ffffff;
  --page: #f4f6f8;
  --soft: #eef3f7;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --danger: #b42318;
  --amber: #8a5a00;
}

* {
  box-sizing: border-box;
}

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

button,
input,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
  border-radius: 6px;
  min-height: 36px;
  padding: 0 12px;
  cursor: pointer;
}

button:hover {
  border-color: #9ca9bb;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 68px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
}

h1,
h2,
p {
  margin: 0;
}

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

h2 {
  font-size: 18px;
  letter-spacing: 0;
}

#status {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.actions,
.rowActions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

#saveButton,
#addButton {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent-dark);
}

main {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 16px 20px 28px;
}

.settings {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  padding: 12px 0;
}

.settings label {
  display: grid;
  grid-template-columns: auto 120px auto;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.settings input {
  width: 120px;
}

.tabs {
  display: flex;
  gap: 8px;
  padding: 8px 0 14px;
  overflow-x: auto;
}

.tab {
  min-width: 120px;
  background: #ffffff;
}

.tab.active {
  background: #1f2937;
  color: #ffffff;
  border-color: #1f2937;
}

.workspace {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

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

.collectionShell {
  overflow: auto;
  margin-bottom: 14px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.collectionTable {
  width: 100%;
  min-width: 1180px;
  border-collapse: collapse;
  table-layout: fixed;
}

.collectionTable th,
.collectionTable td {
  border-bottom: 1px solid #edf0f4;
  padding: 7px 9px;
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.collectionTable th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fafc;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0;
}

.collectionTable th:nth-child(1),
.collectionTable td:nth-child(1) {
  width: 92px;
}

.collectionTable th:nth-child(2),
.collectionTable td:nth-child(2) {
  width: 180px;
}

.collectionTable td:nth-child(4),
.collectionTable td:nth-child(5),
.collectionTable td:nth-child(6),
.collectionTable td:nth-child(7),
.collectionTable th:nth-child(3),
.collectionTable th:nth-child(4),
.collectionTable th:nth-child(5),
.collectionTable th:nth-child(6),
.collectionTable th:nth-child(7),
.collectionTable td:nth-child(3) {
  width: 105px;
  text-align: right;
}

.collectionTable th:nth-child(8),
.collectionTable td:nth-child(8),
.collectionTable th:nth-child(9),
.collectionTable td:nth-child(9) {
  min-width: 230px;
}

.collectionTable tbody tr {
  cursor: pointer;
}

.collectionTable tbody tr:hover,
.collectionTable tbody tr.selected {
  background: #eef8f6;
}

.collectionEmpty td {
  color: var(--muted);
  text-align: center;
  height: 48px;
}

.strong {
  font-weight: 700;
}

.noteCell {
  color: var(--muted);
}

.thumb,
.thumbPlaceholder {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  border-radius: 7px;
}

.thumb {
  object-fit: cover;
  background: var(--soft);
}

.thumbPlaceholder {
  color: var(--muted);
  background: var(--soft);
}

#rangeMeta {
  color: var(--muted);
  margin-top: 3px;
  font-size: 12px;
}

.itemDialog {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(15, 23, 42, 0.34);
  color: var(--ink);
}

.itemDialog[hidden] {
  display: none;
}

.dialogPanel {
  width: min(1120px, 100%);
  max-height: calc(100dvh - 44px);
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 24px 80px rgba(24, 32, 43, 0.22);
}

.dialogHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}

.dialogHeader h3 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}

#dialogMeta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.dialogBody {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr) 210px;
  gap: 14px;
  padding: 14px 16px 16px;
  max-height: calc(100dvh - 130px);
  overflow: auto;
}

.imagePane {
  min-width: 0;
}

.imageInput {
  display: none;
}

.imageDrop {
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 4 / 5;
  padding: 8px;
  background: var(--soft);
  color: var(--muted);
  border-style: dashed;
  overflow: hidden;
  text-align: center;
}

.imageDrop.dragging {
  border-color: var(--accent);
  background: #eef8f6;
}

.imageDrop img {
  display: none;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.imageDrop.hasImage {
  background: #ffffff;
  border-style: solid;
}

.imageDrop.hasImage img {
  display: block;
}

.imageDrop.hasImage span {
  display: none;
}

.fields {
  display: grid;
  gap: 10px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 1fr));
  gap: 10px;
}

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

label span {
  color: var(--muted);
  font-size: 12px;
}

.wide {
  grid-column: span 2;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  padding: 8px 9px;
  min-height: 36px;
}

textarea {
  resize: vertical;
  min-height: 74px;
}

input:focus,
textarea:focus {
  outline: 2px solid rgba(15, 118, 110, 0.18);
  border-color: var(--accent);
}

.calc {
  display: grid;
  align-content: space-between;
  gap: 12px;
  border-left: 1px solid var(--line);
  padding-left: 14px;
}

dl {
  display: grid;
  gap: 8px;
  margin: 0;
}

dl div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 7px;
  border-bottom: 1px solid #edf0f4;
}

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

dd {
  margin: 0;
  font-weight: 700;
  text-align: right;
}

.deleteButton {
  color: var(--danger);
}

.duplicateButton {
  color: var(--amber);
}

.ghostButton {
  background: #ffffff;
  color: var(--ink);
}

@media (max-width: 1050px) {
  .dialogBody {
    grid-template-columns: 160px minmax(0, 1fr);
  }

  .calc {
    grid-column: 1 / -1;
    border-left: 0;
    border-top: 1px solid var(--line);
    padding: 12px 0 0;
  }

  dl {
    grid-template-columns: repeat(4, minmax(110px, 1fr));
  }
}

@media (max-width: 720px) {
  .topbar,
  .sectionHead {
    align-items: stretch;
    flex-direction: column;
  }

  main {
    padding: 12px;
  }

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

  .grid,
  dl {
    grid-template-columns: 1fr;
  }

  .wide {
    grid-column: auto;
  }
}
