:root {
  --primary: #2c6e49;
  --primary-dark: #1f4d34;
  --border: #d8dee2;
  --bg: #f6f8f7;
  --text: #1c2521;
  font-family: -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

.sticky-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg);
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: white;
  border-bottom: 1px solid var(--border);
}

.topbar h1 { margin: 0; font-size: 20px; }
.claim-info { font-size: 13px; color: #567; margin-top: 4px; }
.topbar-actions { display: flex; gap: 16px; align-items: center; }

.grand-total { text-align: right; padding-right: 4px; }
.grand-total-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: #789; }
.grand-total-value { font-size: 22px; font-weight: 700; color: var(--primary-dark); }

.toolbar {
  display: flex;
  gap: 8px;
  padding: 12px 24px;
  align-items: center;
  flex-wrap: wrap;
}

.toolbar input[type="search"] {
  flex: 1;
  min-width: 240px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.toolbar select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.result-count { color: #666; font-size: 13px; margin-left: auto; }

.columns-menu { position: relative; }
.columns-panel {
  position: absolute; top: calc(100% + 6px); right: 0; background: white;
  border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  padding: 10px 14px; z-index: 20; min-width: 160px;
}
.columns-panel.hidden { display: none; }
.columns-panel-row {
  display: flex; align-items: center; gap: 8px; padding: 5px 0; font-size: 14px; cursor: pointer;
}

main { padding: 0 24px 24px; }

table { width: 100%; border-collapse: collapse; background: white; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.06); }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { background: #eef3f0; position: sticky; top: var(--sticky-offset, 0px); z-index: 15; }
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { background: #e2ebe6; }
tbody tr:hover { background: #f1f7f3; cursor: pointer; }

tbody tr.row-verified { background: #eafaf0; }
tbody tr.row-verified:hover { background: #ddf4e6; }
.verified-check { width: 18px; height: 18px; cursor: pointer; accent-color: var(--primary); }

.thumb { width: 100px; height: 100px; object-fit: cover; border-radius: 4px; border: 1px solid var(--border); display: block; }
.thumb-placeholder { width: 100px; height: 100px; border-radius: 4px; background: #e5eae7; }

.qty-input {
  width: 56px; padding: 6px 6px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px;
}
.condition-select {
  padding: 6px 6px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; max-width: 130px;
}
.category-select {
  padding: 6px 6px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; max-width: 150px;
}
.category-select.just-saved { animation: field-saved 900ms ease-out; }
.price-input {
  width: 80px; padding: 6px 6px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px;
}
.purchase-date {
  padding: 6px 6px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px;
}
.purchase-date.just-saved { animation: field-saved 900ms ease-out; }
.line-total { font-weight: 600; white-space: nowrap; }

.row-actions { text-align: center; }
.row-delete {
  border: none; background: none; cursor: pointer; font-size: 16px; line-height: 1;
  padding: 4px 6px; border-radius: 6px; opacity: 0.55; filter: grayscale(1);
}
.row-delete:hover { opacity: 1; filter: none; background: #fdecea; }
.row-delete:disabled { opacity: 0.3; cursor: default; }
.row-restore, .row-purge {
  border: none; background: none; cursor: pointer; font-size: 15px; line-height: 1;
  padding: 4px 6px; border-radius: 6px;
}
.row-restore { color: var(--primary); }
.row-restore:hover { background: #d9f2e3; }
.row-purge { color: #b3261e; }
.row-purge:hover { background: #fdecea; }
.btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.dup-cell {
  max-width: 260px; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #555;
}
.dup-cell.dup-high { color: #b3261e; font-weight: 600; }
.price-basis {
  max-width: 260px; font-size: 12px; color: #667;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.qty-input.just-saved, .price-input.just-saved {
  animation: field-saved 900ms ease-out;
}
@keyframes field-saved {
  0% { background-color: #d9f2e3; border-color: var(--primary); }
  100% { background-color: transparent; border-color: var(--border); }
}

.pagination { display: flex; align-items: center; gap: 12px; justify-content: center; padding: 16px 0; }

.btn {
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 14px;
}
.btn.primary { background: var(--primary); color: white; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.secondary { background: white; border-color: var(--border); }
.btn.secondary:hover { background: #eef3f0; }
.btn.danger { background: #fff0f0; color: #b3261e; border-color: #f3c9c6; }
.btn.danger:hover { background: #fde3e2; }

.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; overflow-y: auto; z-index: 50;
}
.modal.hidden { display: none; }
.modal-content {
  background: white; border-radius: 10px; padding: 24px; width: 100%; max-width: 480px;
  position: relative;
}
.modal-content.wide { max-width: 760px; }
.modal-close {
  position: absolute; top: 12px; right: 14px; border: none; background: none;
  font-size: 22px; cursor: pointer; color: #888;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 16px;
  margin: 12px 0;
}
.form-grid label { display: flex; flex-direction: column; font-size: 13px; color: #444; gap: 4px; }
.form-grid label.full { grid-column: 1 / -1; }
.form-grid input, .form-grid select, .form-grid textarea {
  padding: 7px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; font-family: inherit;
}

.photo-upload-row { display: flex; gap: 8px; align-items: center; margin: 10px 0; }
.photo-gallery { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.photo-item { position: relative; width: 96px; }
.photo-item img { width: 96px; height: 96px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); cursor: zoom-in; }
.photo-item .photo-type-label { font-size: 11px; color: #666; text-align: center; }
.photo-item .photo-remove {
  position: absolute; top: -6px; right: -6px; background: #b3261e; color: white; border: none;
  border-radius: 50%; width: 20px; height: 20px; cursor: pointer; font-size: 12px; line-height: 1;
}

.modal-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 16px; }

.fields-list-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.fields-list-row .field-meta { font-size: 12px; color: #777; }
.add-field-form { display: flex; gap: 8px; margin-top: 14px; }
.add-field-form input { flex: 1; padding: 7px 8px; border: 1px solid var(--border); border-radius: 6px; }
.add-field-form select { padding: 7px 8px; border: 1px solid var(--border); border-radius: 6px; }

.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,0.85);
  display: flex; align-items: center; justify-content: center; z-index: 100; cursor: zoom-out;
}
.lightbox.hidden { display: none; }
.lightbox img { max-width: 92vw; max-height: 92vh; border-radius: 6px; }

/* ---- Photo add button (all screens) ---- */
.photo-add-btn { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.photo-add-btn.disabled { opacity: 0.5; pointer-events: none; }
.photo-add-btn.uploading { opacity: 0.7; pointer-events: none; }
.photo-hint { font-size: 12px; color: #789; margin: 6px 0 10px; }

/* ---- Bulk selection ---- */
.col-select { text-align: center; width: 34px; }
.row-select, #selectAll { width: 18px; height: 18px; cursor: pointer; accent-color: var(--primary); }
tbody tr[data-selected] { background: #eaf1ff; }
tbody tr.row-verified[data-selected] { background: #e2f0ea; }

.bulk-bar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 18px;
  display: flex; align-items: center; gap: 16px;
  background: white; border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 6px 22px rgba(0,0,0,0.18); padding: 10px 16px; z-index: 60; max-width: 94vw;
}
.bulk-bar.hidden { display: none; }
.bulk-info { display: flex; flex-direction: column; gap: 2px; }
.bulk-actions { display: flex; gap: 8px; }
.linklike { background: none; border: none; color: var(--primary); cursor: pointer; font-size: 12px; padding: 0; text-decoration: underline; text-align: left; }
.linklike.hidden { display: none; }

/* ============ MOBILE (phones/tablets) ============ */
@media (max-width: 820px) {
  .sticky-header { position: static; box-shadow: none; }
  .topbar { flex-wrap: wrap; gap: 10px; padding: 12px 14px; }
  .topbar h1 { font-size: 18px; }
  .topbar-actions { width: 100%; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
  .grand-total { text-align: left; padding-right: 0; }
  .grand-total-value { font-size: 20px; }
  .topbar-actions .btn { flex: 1 1 46%; min-height: 44px; }

  .toolbar { padding: 10px 12px; gap: 8px; }
  .toolbar input[type="search"] { flex: 1 1 100%; min-width: 0; font-size: 16px; }
  .toolbar select { flex: 1 1 46%; min-width: 0; font-size: 16px; }
  .result-count { flex: 1 1 100%; margin-left: 0; order: 5; }
  #dupesToggle, #removedToggle, .columns-menu { flex: 1 1 46%; }
  #dupesToggle, #removedToggle, #columnsBtn { width: 100%; min-height: 44px; }

  main { padding: 0 8px 28px; }

  /* table -> stacked cards */
  table { box-shadow: none; background: transparent; }
  thead { display: none; }
  tbody tr {
    display: flex; flex-direction: column; gap: 4px;
    background: white; border: 1px solid var(--border); border-radius: 12px;
    margin: 12px 0; padding: 12px 14px; box-shadow: 0 1px 3px rgba(0,0,0,0.07);
  }
  tbody tr:hover { background: white; }
  tbody tr.row-verified { background: #eafaf0; }
  tbody td { display: flex; align-items: center; gap: 10px; padding: 3px 0; border: none; font-size: 15px; }

  /* field labels from the column key */
  td[data-col]::before { font-weight: 600; color: #789; font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; min-width: 88px; flex-shrink: 0; }
  td[data-col="room"]::before { content: "Room"; }
  td[data-col="brand"]::before { content: "Brand"; }
  td[data-col="category"]::before { content: "Category"; }
  td[data-col="condition"]::before { content: "Condition"; }
  td[data-col="qty"]::before { content: "Qty"; }
  td[data-col="purchase_date"]::before { content: "Purchased"; }
  td[data-col="price"]::before { content: "Price"; }
  td[data-col="total"]::before { content: "Total"; }
  td[data-col="verified"]::before { content: "Verified"; }

  /* prominent bits: photo + description on top; no labels */
  td[data-col="photo"] { order: -2; justify-content: center; }
  td[data-col="photo"]::before, td[data-col="description"]::before { content: none; }
  td[data-col="photo"] .thumb, td[data-col="photo"] .thumb-placeholder { width: 150px; height: 150px; }
  td[data-col="description"] { order: -1; font-size: 16px; font-weight: 600; line-height: 1.3; display: block; }
  td[data-col="verified"] { order: -3; }

  /* hide clutter on phones */
  td[data-col="disposition"], td[data-col="price_source"], td[data-col="duplicate_of"] { display: none; }

  /* touch-friendly inline controls */
  .category-select, .condition-select, .qty-input, .price-input, .purchase-date {
    font-size: 16px; padding: 9px 8px; flex: 1; max-width: none; width: auto;
  }
  .verified-check { width: 24px; height: 24px; }

  /* delete button as a clear full-width action */
  .row-actions { order: 100; margin-top: 6px; }
  .row-delete, .row-restore, .row-purge {
    opacity: 1; filter: none; font-size: 16px; min-height: 42px; border: 1px solid var(--border);
    border-radius: 8px; flex: 1;
  }
  .row-delete::after { content: " Remove"; }
  .row-restore::after { content: " Restore"; }
  .row-purge::after { content: " Delete"; }

  .pagination { gap: 20px; }
  .pagination .btn { min-height: 44px; padding: 8px 20px; }

  /* full-screen modal editor */
  .modal { padding: 0; align-items: flex-start; }
  .modal-content, .modal-content.wide { max-width: 100%; min-height: 100vh; border-radius: 0; padding: 16px; }
  .form-grid { grid-template-columns: 1fr; gap: 12px; }
  .form-grid input, .form-grid select, .form-grid textarea { font-size: 16px; padding: 10px; }
  .photo-add-btn { min-height: 46px; font-size: 16px; padding: 10px 16px; }
  .photo-item, .photo-item img { width: 100px; height: 100px; }
  .modal-actions { flex-direction: column-reverse; align-items: stretch; gap: 10px; }
  .modal-actions > div { display: flex; gap: 10px; }
  .modal-actions .btn { flex: 1; min-height: 46px; font-size: 16px; }
  .modal-close { font-size: 30px; padding: 8px; top: 8px; right: 10px; }

  /* selection checkbox at top of each card */
  td.col-select { order: -4; }
  td.col-select::before { content: "Select"; font-weight: 600; color: #789; font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; min-width: 88px; }
  .row-select { width: 24px; height: 24px; }

  /* bulk bar spans the bottom on phones */
  .bulk-bar { left: 8px; right: 8px; bottom: 10px; transform: none; max-width: none; flex-direction: column; align-items: stretch; gap: 10px; }
  .bulk-actions { }
  .bulk-actions .btn { flex: 1; min-height: 46px; font-size: 16px; }
}
