:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-2: #eef3f2;
  --ink: #172121;
  --muted: #62706d;
  --line: #dce4e2;
  --accent: #0f7a68;
  --accent-strong: #09594d;
  --danger: #b42318;
  --shadow: 0 14px 40px rgba(20, 35, 35, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.workspace {
  display: grid;
  grid-template-columns: 306px minmax(0, 1fr);
  min-height: calc(100vh - 40px);
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.sidebar {
  padding: 20px 14px;
  border-right: 1px solid var(--line);
  background: #fbfcfc;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 8px;
  color: white;
  background: var(--accent);
  font-weight: 700;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  color: var(--muted);
  margin-top: 2px;
}

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

.nav-item {
  display: block;
  width: 100%;
  padding: 11px 12px;
  border: 0;
  border-radius: 7px;
  color: var(--muted);
  background: transparent;
  text-align: left;
  text-decoration: none;
  white-space: nowrap;
}

.nav-item.active {
  color: var(--ink);
  background: var(--surface-2);
  font-weight: 600;
}

.nav-item:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.content {
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 22px 24px;
  border-bottom: 1px solid var(--line);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
  line-height: 1.2;
}

h2 {
  font-size: 17px;
  line-height: 1.3;
}

.topbar p {
  margin-top: 6px;
  color: var(--muted);
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.button {
  min-height: 38px;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: var(--surface);
  font-weight: 600;
}

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

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

.button.ghost {
  background: #f8faf9;
}

.button.lookup {
  align-self: end;
  white-space: nowrap;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 16px;
  padding: 18px;
}

.panel {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.span-2 {
  grid-column: span 2;
}

.span-4 {
  grid-column: span 4;
}

.span-5 {
  grid-column: span 5;
}

.span-7 {
  grid-column: span 7;
}

.span-8 {
  grid-column: span 8;
}

.span-12 {
  grid-column: span 12;
}

.panel-title {
  margin-bottom: 16px;
}

.row-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.grid {
  display: grid;
  gap: 14px;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

label {
  display: grid;
  gap: 7px;
}

label span,
legend {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

input,
select {
  height: 40px;
  padding: 0 11px;
}

textarea {
  min-height: 40px;
  padding: 10px 11px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 122, 104, 0.13);
}

fieldset {
  min-width: 0;
  margin: 16px 0;
  padding: 0;
  border: 0;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.segmented label {
  display: block;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: grid;
  min-height: 42px;
  place-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: #fff;
  text-align: center;
}

.segmented input:checked + span {
  border-color: var(--accent);
  background: #e8f4f1;
  font-weight: 700;
}

.customer-fields {
  margin-top: 4px;
}

.seller-details {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 14px;
  margin: 6px 0 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf9;
}

.seller-details span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.seller-details strong {
  display: block;
  margin-top: 2px;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.hidden {
  display: none;
}

.inline-row {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

.grow {
  flex: 1 1 auto;
}

.items-table {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.table-head,
.item-row {
  display: grid;
  grid-template-columns: 56px minmax(260px, 1fr) 110px 140px 140px 48px;
  align-items: center;
  gap: 8px;
  min-width: 820px;
  padding: 10px;
}

.table-head {
  color: var(--muted);
  background: #f8faf9;
  font-size: 13px;
  font-weight: 700;
}

.item-row {
  border-top: 1px solid var(--line);
}

.item-row input {
  height: 36px;
}

.icon-button {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--danger);
  background: white;
  font-weight: 700;
}

.totals {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 16px;
  padding-top: 14px;
  color: var(--muted);
}

.totals strong {
  color: var(--ink);
}

.checkbox-line {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.checkbox-line input {
  width: 16px;
  height: 16px;
}

.upload-zone {
  display: grid;
  min-height: 106px;
  place-items: center;
  border: 1px dashed #aab9b6;
  border-radius: 8px;
  background: #f8faf9;
  text-align: center;
}

.upload-zone input {
  display: none;
}

.upload-zone span {
  color: var(--ink);
}

.tech-descriptions {
  display: grid;
  gap: 12px;
}

.tech-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.tech-card.is-active {
  border-color: #2f6f6a;
  box-shadow: 0 0 0 2px rgba(47, 111, 106, 0.14);
}

.tech-card-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.4fr) auto;
  gap: 8px;
  align-items: end;
}

.tech-card-header label {
  min-width: 0;
}

.tech-card-header select {
  width: 100%;
}

.tech-remove-button {
  margin-bottom: 1px;
}

.tech-attachments {
  display: grid;
  gap: 10px;
}

.tech-attachment-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.tech-upload-button {
  display: inline-grid;
  width: max-content;
  place-items: center;
}

.tech-paste-button {
  width: max-content;
}

.tech-image-input {
  display: none;
}

.tech-image-preview {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 10px;
}

.tech-image-thumb {
  position: relative;
  min-width: 0;
}

.tech-image-thumb img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 7px;
}

.tech-image-thumb .icon-button {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  border-color: rgba(180, 35, 24, 0.35);
  background: rgba(255, 255, 255, 0.94);
}

.tech-image-thumb span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(13, 27, 27, 0.38);
}

.modal.hidden {
  display: none;
}

.modal-panel {
  display: grid;
  gap: 16px;
  width: min(920px, 100%);
  max-height: min(760px, calc(100vh - 44px));
  overflow: auto;
  padding: 18px;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.modal-header,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.modal-actions {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.library-list {
  display: grid;
  gap: 12px;
}

.library-page {
  min-height: 100vh;
}

.library-workspace {
  display: block;
  min-height: calc(100vh - 40px);
}

.library-content {
  padding-top: 0;
}

.library-toolbar,
.library-group-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.library-toolbar {
  grid-template-columns: minmax(240px, 1.4fr) minmax(190px, 0.9fr) minmax(190px, 0.9fr) auto;
}

.library-group-grid .icon-button {
  align-self: end;
}

.library-choice-stack {
  display: grid;
  gap: 8px;
}

.status-line {
  min-height: 18px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.library-editor {
  display: grid;
  gap: 12px;
}

.library-editor.hidden {
  display: none;
}

.library-row {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.library-row-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
}

.registry-toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.registry-admin {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.registry-admin-row {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(160px, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.registry-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.registry-table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
}

.registry-table th,
.registry-table td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.registry-table th {
  color: var(--muted);
  background: #f8faf9;
  font-size: 13px;
}

.registry-table tbody tr {
  cursor: pointer;
}

.registry-table tbody tr:hover {
  background: #f8faf9;
}

.registry-table tbody tr:last-child td {
  border-bottom: 0;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.status-badge.draft {
  color: #71520b;
  background: #fff4d8;
}

.status-badge.exported {
  color: #075c4e;
  background: #dcf3ee;
}

.registry-empty {
  padding: 28px 12px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1020px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    overflow-x: auto;
  }

  .topbar {
    display: grid;
  }

  .span-4,
  .span-5,
  .span-7,
  .span-8 {
    grid-column: span 12;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 0;
  }

  .workspace {
    min-height: 100vh;
    border: 0;
  }

  .topbar,
  .form-grid {
    padding: 14px;
  }

  .grid.two,
  .seller-details,
  .segmented {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: span 1;
  }

  .inline-row,
  .top-actions,
  .row-actions,
  .row-title {
    display: grid;
  }

  .modal {
    padding: 12px;
  }

  .library-row-header {
    grid-template-columns: 1fr;
  }

  .library-toolbar,
  .library-group-grid,
  .registry-toolbar,
  .registry-admin-row,
  .tech-card-header {
    grid-template-columns: 1fr;
  }

  .tech-remove-button {
    width: 100%;
  }
}
