/* Shelf Recognition app styles: hand-written, no framework. */

:root {
  --own: #1a7f37;
  --competitor: #cf222e;
  --brand: #bf8700;
  --own-only: #0969da;
  --unknown: #6e7781;
  --text: #1f2328;
  --text-muted: #59636e;
  --border: #d1d9e0;
  --bg: #f6f8fa;
  --panel: #ffffff;
  --accent: #0969da;
  --danger: #cf222e;
  --ok: #1a7f37;
  --zebra: #f0f3f6;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

a {
  color: var(--accent);
}

a:hover {
  text-decoration-thickness: 2px;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Top navigation */

.topbar {
  background: #1f2328;
}

.topbar nav {
  display: flex;
  gap: 2px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
}

.topbar a {
  color: #e6edf3;
  text-decoration: none;
  padding: 12px 14px;
  font-weight: 500;
}

.topbar a:hover {
  background: #2b3138;
}

.topbar a[aria-current="page"] {
  box-shadow: inset 0 -3px 0 var(--accent);
  color: #ffffff;
}

/* Layout */

.content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

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

.page-header h1 {
  font-size: 22px;
  margin: 0 0 4px;
}

.page-header .meta {
  margin: 0;
  color: var(--text-muted);
}

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

.panel h2 {
  font-size: 16px;
  margin: 0 0 12px;
}

.panel.narrow {
  max-width: 560px;
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

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

.danger-panel {
  border-color: color-mix(in srgb, var(--danger) 40%, var(--border));
}

.error-panel {
  max-width: 560px;
  margin: 32px auto;
}

/* Flash */

.flash {
  background: color-mix(in srgb, var(--ok) 12%, var(--panel));
  border: 1px solid color-mix(in srgb, var(--ok) 45%, var(--border));
  border-radius: 8px;
  color: #116329;
  font-weight: 500;
  margin-bottom: 16px;
  padding: 10px 14px;
}

/* Filters */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.filters input[type="search"] {
  flex: 1 1 240px;
  min-width: 200px;
}

/* Table */

.count {
  color: var(--text-muted);
  margin: 4px 0 8px;
}

.table,
#product-table {
  border-collapse: collapse;
  width: 100%;
  background: var(--panel);
}

.table th,
.table td,
#product-table th,
#product-table td {
  border-bottom: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
  vertical-align: middle;
}

.table thead th,
#product-table thead th {
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.table tbody tr:nth-child(even),
#product-table tbody tr:nth-child(even) {
  background: var(--zebra);
}

/* Thumbnail with image-count badge */

.thumb {
  position: relative;
  display: inline-block;
  width: 64px;
  height: 64px;
  line-height: 0;
  border-radius: 6px;
  overflow: hidden;
  background: var(--bg);
}

.thumb img {
  width: 64px;
  height: 64px;
  object-fit: cover;
}

.thumb-badge {
  position: absolute;
  right: 4px;
  bottom: 4px;
  background: rgba(31, 35, 40, 0.85);
  color: #ffffff;
  border-radius: 10px;
  font-size: 11px;
  line-height: 1;
  padding: 3px 6px;
}

.thumb-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 64px;
  color: var(--text-muted);
}

/* Badges */

.badge {
  display: inline-block;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  padding: 5px 9px;
  white-space: nowrap;
}

.badge-own {
  background: var(--own);
  color: #ffffff;
}

.badge-competitor {
  background: var(--competitor);
  color: #ffffff;
}

/* Forms */

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field label {
  font-weight: 600;
  font-size: 13px;
}

input[type="text"],
input[type="search"],
input:not([type]),
select {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  min-width: 0;
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.checkbox {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  color: var(--text);
}

.error {
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
  margin: 2px 0 0;
}

.empty {
  color: var(--text-muted);
  padding: 16px 0;
}

/* Buttons */

.btn {
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 14px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}

.btn:hover {
  border-color: var(--text-muted);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.btn-primary:hover {
  background: #0756a8;
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
}

.btn-danger:hover {
  background: #a40e26;
}

.btn-danger:disabled {
  background: var(--unknown);
  border-color: var(--unknown);
  cursor: not-allowed;
}

.btn-small {
  padding: 4px 10px;
  font-size: 13px;
}

/* Image grid */

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.image-item {
  margin: 0;
}

.image-item img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.image-item figcaption {
  margin-top: 6px;
  text-align: center;
}

/* Dropzone */

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: 2px dashed var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text-muted);
  padding: 28px 16px;
  text-align: center;
  cursor: pointer;
}

.dropzone.dragover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, var(--bg));
  color: var(--text);
}

.dropzone input[type="file"] {
  display: none;
}

.dropzone .link {
  color: var(--accent);
  font-weight: 600;
}

.upload-count {
  color: var(--ok);
  font-weight: 600;
}

/* Scan annotation */

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

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  align-items: center;
  margin: 0 0 16px;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-muted);
}

.swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 6px;
  border-radius: 3px;
  vertical-align: -1px;
}

.swatch.lvl-sku-own {
  background: var(--own);
}

.swatch.lvl-sku-comp {
  background: var(--competitor);
}

.swatch.lvl-brand {
  background: var(--brand);
}

.swatch.lvl-own {
  background: var(--own-only);
}

.swatch.lvl-unknown {
  background: var(--unknown);
}

.scan-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
  align-items: start;
}

@media (max-width: 900px) {
  .scan-layout {
    grid-template-columns: 1fr;
  }
}

.scan-figure {
  position: relative;
  line-height: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.scan-figure img {
  display: block;
  width: 100%;
  height: auto;
}

.scan-figure svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.det {
  fill: transparent;
  cursor: pointer;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.det.lvl-sku-own {
  stroke: var(--own);
}

.det.lvl-sku-comp {
  stroke: var(--competitor);
}

.det.lvl-brand {
  stroke: var(--brand);
}

.det.lvl-own {
  stroke: var(--own-only);
}

.det.lvl-unknown {
  stroke: var(--unknown);
}

.det.selected,
.det:focus-visible {
  stroke-width: 3.5;
  outline: none;
}

.scan-figure.hide-unknown .det.lvl-unknown {
  display: none;
}

.scan-panel {
  position: sticky;
  top: 16px;
}

.scan-panel h2 {
  margin: 12px 0 4px;
}

.scan-panel h3 {
  font-size: 13px;
  color: var(--text-muted);
  margin: 12px 0 4px;
}

#crop-preview {
  display: block;
  width: 120px;
  height: 120px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  object-fit: cover;
}

.facts {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 8px 0;
}

.facts .fact {
  display: flex;
  gap: 8px;
  align-items: baseline;
}

.facts dt {
  flex: 0 0 64px;
  color: var(--text-muted);
  font-size: 13px;
}

.facts dd {
  margin: 0;
  font-weight: 600;
}

.candidates {
  list-style: none;
  margin: 0;
  padding: 0;
}

.candidates li {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 6px 0;
  border-top: 1px solid var(--border);
  font-size: 13px;
}

.candidates img,
.candidates .cand-noimg {
  width: 32px;
  height: 32px;
  border-radius: 4px;
  object-fit: cover;
  background: var(--bg);
}

.candidates .cand-noimg {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  flex: 0 0 32px;
}

.candidates .cand-name {
  flex: 1;
  min-width: 0;
}

.candidates .cand-score {
  color: var(--text-muted);
  font-weight: 600;
}

.history-time {
  white-space: nowrap;
}

/* Idle banners and footer */

.banner {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  font-weight: 500;
}

.banner[hidden] {
  display: none;
}

.banner-warn {
  background: #fff8c5;
  border-bottom: 1px solid #d4a72c;
  color: #6b4e00;
}

.banner-offline {
  background: #eaeef2;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  text-align: center;
}

.footer {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px 32px;
  color: var(--text-muted);
  font-size: 13px;
}

.job-status {
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 8px;
}
