:root {
  --primary: #2563eb;
  --bg: #f4f6fb;
  --card-bg: #ffffff;
  --border: #e2e6ee;
  --text: #1b2333;
  --muted: #667085;
}

* { box-sizing: border-box; }

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

.topbar {
  background: var(--primary);
  color: white;
  padding: 20px 32px;
}
.topbar-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}
.topbar h1 { margin: 0 0 4px; font-size: 22px; }
.topbar p { margin: 0; opacity: 0.9; font-size: 14px; }
.lang-buttons {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.lang-btn {
  background: rgba(255,255,255,0.15);
  color: white;
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.lang-btn:hover { background: rgba(255,255,255,0.25); }
.lang-btn.active {
  background: white;
  color: var(--primary);
  border-color: white;
  font-weight: 600;
}

main {
  max-width: 1000px;
  margin: 24px auto;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
}

.dropzone {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 24px;
  text-align: center;
  cursor: pointer;
  margin-bottom: 16px;
}
.dropzone.dragover { border-color: var(--primary); background: #eef2ff; }
.dropzone img { max-width: 220px; max-height: 220px; margin-top: 12px; border-radius: 6px; }
.pdf-badge {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 12px;
  padding: 8px 14px; border-radius: 6px; background: #eef2ff; border: 1px solid var(--border);
  font-size: 13px; color: var(--text);
}

.match-filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.match-filter-row label { font-size: 13px; color: var(--muted); }
.match-filter-row .meta-select { max-width: 260px; }

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  text-decoration: underline;
  font-size: inherit;
  padding: 0;
}

.primary-btn {
  background: var(--primary);
  color: white;
  border: none;
  padding: 10px 18px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}
.primary-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.primary-btn:hover:not(:disabled) { background: #1d4ed8; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}
.match-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
  text-align: center;
  transition: box-shadow 0.15s, border-color 0.15s;
}
.match-card:hover { border-color: var(--primary); box-shadow: 0 2px 8px rgba(37,99,235,0.15); }
.match-card img { width: 100%; height: 110px; object-fit: cover; border-radius: 6px; margin-bottom: 6px; }
.match-card .mname { font-size: 12px; font-weight: 600; }
.match-card .mmeta { font-size: 11px; color: var(--muted); }
.match-card .mscore { font-size: 10px; color: var(--primary); margin-top: 4px; }

.detail-header {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-bottom: 16px;
}
.detail-header img { width: 100px; height: 100px; object-fit: contain; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; flex-shrink: 0; }
.detail-header-text { flex: 1; min-width: 0; }
.detail-header h2 { margin: 0 0 4px; }
.detail-header p { margin: 0; color: var(--muted); font-size: 13px; }
[contenteditable="true"] {
  border-radius: 4px;
  padding: 2px 4px;
  margin: -2px -4px;
  cursor: text;
}
[contenteditable="true"]:hover { background: #f4f6fb; box-shadow: 0 0 0 1px var(--border); }
[contenteditable="true"]:focus {
  outline: none;
  background: white;
  box-shadow: 0 0 0 2px var(--primary);
}

.meta-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}
.meta-select, .meta-tag-input {
  font-size: 13px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 4px 6px;
  background: #f4f6fb;
}
.meta-select { max-width: 220px; }
.meta-tag-input { flex: 1; min-width: 160px; }
.meta-style-input { flex: 0 0 auto; width: 130px; font-weight: 600; color: var(--text); }
.meta-select:focus, .meta-tag-input:focus { outline: none; border-color: var(--primary); background: white; }
.add-feature-btn {
  display: inline-block;
  margin-top: 12px;
  font-weight: 600;
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
th .th-sub { font-weight: 400; font-size: 11px; }
.no-smv { color: #b91c1c; font-style: italic; }
input.qty-input { width: 55px; padding: 4px; border: 1px solid var(--border); border-radius: 4px; }
.qty-range { display: inline-block; margin-top: 2px; color: #98a2b3; font-size: 11px; white-space: nowrap; }

.total-row {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
  font-size: 16px;
  align-items: baseline;
}
.total-row strong { font-size: 22px; color: var(--primary); }
.export-buttons {
  display: flex;
  gap: 8px;
  margin-right: auto;
}
.secondary-btn {
  background: white;
  color: var(--primary);
  border: 1px solid var(--primary);
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.secondary-btn:hover { background: #eef2ff; }
.secondary-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal[hidden] { display: none; }
.modal-content {
  background: white; border-radius: 10px; padding: 20px;
  width: 480px; max-height: 70vh; display: flex; flex-direction: column; gap: 10px;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; }
.modal-header h3 { margin: 0; }
#pickerSearch { padding: 8px; border: 1px solid var(--border); border-radius: 6px; }
.picker-results { overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 4px; }
.picker-item { padding: 8px; border: 1px solid var(--border); border-radius: 6px; cursor: pointer; font-size: 13px; display: flex; gap: 10px; align-items: center; }
.picker-item:hover { background: #eef2ff; }
.picker-item .pi-smv { color: var(--primary); font-weight: 600; float: right; }
.picker-item .pi-body { flex: 1; min-width: 0; }
.picker-item .pi-thumb {
  flex-shrink: 0; width: 44px; height: 44px; border-radius: 5px; overflow: hidden;
  background: #f4f6fb; border: 1px solid var(--border);
}
.picker-item .pi-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.picker-image-preview {
  position: fixed;
  width: 380px;
  height: 380px;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid var(--primary);
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
  background: white;
  z-index: 100;
  pointer-events: none;
}
.picker-image-preview img { width: 100%; height: 100%; object-fit: contain; display: block; background: var(--bg); }
.picker-group-header {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--primary);
  background: #eef2ff;
  padding: 4px 8px;
  border-radius: 4px;
  margin-top: 6px;
}

.picker-breadcrumb {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}
.picker-breadcrumb button {
  background: none; border: none; color: var(--primary); cursor: pointer;
  font-size: 12px; padding: 2px 4px; text-decoration: underline;
}
.picker-breadcrumb button:last-child { color: var(--muted); text-decoration: none; font-weight: 600; cursor: default; }
.picker-group-item {
  padding: 10px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.picker-group-item:hover { background: #eef2ff; border-color: var(--primary); }
.picker-group-item .pgi-arrow { color: var(--muted); }

.change-btn {
  background: none; border: 1px solid var(--border); border-radius: 4px;
  padding: 3px 8px; cursor: pointer; font-size: 11px; color: var(--muted);
}
.change-btn:hover { border-color: var(--primary); color: var(--primary); }

.reorder-cell { white-space: nowrap; }
.reorder-btn {
  background: none; border: 1px solid var(--border); border-radius: 4px;
  width: 22px; height: 22px; line-height: 1; cursor: pointer; font-size: 10px;
  color: var(--muted); padding: 0; margin-right: 2px;
}
.reorder-btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.reorder-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.delete-btn {
  background: none; border: 1px solid var(--border); border-radius: 4px;
  padding: 3px 8px; cursor: pointer; font-size: 12px; color: #b91c1c;
}
.delete-btn:hover { border-color: #b91c1c; background: #fef2f2; }

.detail-toggle-btn {
  background: none; border: 1px solid var(--border); border-radius: 4px;
  width: 22px; height: 22px; line-height: 1; cursor: pointer; font-size: 10px;
  color: var(--muted); padding: 0;
}
.detail-toggle-btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.detail-toggle-btn:disabled { opacity: 0.25; cursor: not-allowed; }

.bol-detail-row td { padding: 0; border-bottom: 1px solid var(--border); }
.bol-detail-wrap { padding: 10px 14px 14px 46px; background: #f9fafc; }
.bol-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.bol-table th { text-align: left; color: var(--muted); font-weight: 600; padding: 4px 6px; border-bottom: 1px solid var(--border); }
.bol-table td { padding: 4px 6px; border-bottom: 1px solid #eef0f5; }
.bol-table .bol-smv-col { text-align: right; color: var(--primary); font-weight: 600; white-space: nowrap; }
.bol-empty { color: var(--muted); font-size: 12px; font-style: italic; padding: 4px 6px; }

.export-modal-content { width: 360px; }
.export-modal-prompt { font-size: 13px; color: var(--muted); margin: 0 0 4px; }
.export-modal-option { width: 100%; text-align: center; }
