/* ── Reset & base ── */
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: system-ui, sans-serif; background: #f5f5f5; color: #222; }

/* ── Nav ── */
nav {
  background: #1a1a2e; color: white;
  padding: 10px 16px;
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 8px;
}
.nav-brand { color: white; text-decoration: none; font-weight: 700; font-size: 1rem; }
.nav-links { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
.nav-links a { color: #aaa; text-decoration: none; padding: 4px 8px; border-radius: 4px; font-size: .9rem; }
.nav-links a:hover { color: white; }

/* ── Layout ── */
main { max-width: 960px; margin: 20px auto; padding: 0 16px; }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-wrap: wrap; gap: 10px; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; margin-bottom: 12px; }

/* ── Buttons ── */
.btn { padding: 8px 16px; border-radius: 6px; border: none; cursor: pointer; text-decoration: none; font-size: .9rem; display: inline-block; }
.btn-primary { background: #3498db; color: white; }
.btn-danger { background: #e74c3c; color: white; }

/* ── Product table (desktop) ── */
.product-table { width: 100%; border-collapse: collapse; background: white; border-radius: 8px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.product-table th { background: #f8f9fb; padding: 10px 12px; text-align: left; font-size: .78rem; color: #6b7280; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.product-table td { padding: 10px 12px; border-top: 1px solid #f0f0f0; font-size: .88rem; vertical-align: middle; }
.product-table tr:hover td { background: #fafbff; }
.product-table a { color: #3498db; text-decoration: none; }
.product-table a:hover { text-decoration: underline; }

/* ── Product cards (mobile) ── */
@media (max-width: 640px) {
  main { margin: 12px auto; padding: 0 10px; }
  h1 { font-size: 1.15rem; }

  /* Stack as cards */
  .product-table thead { display: none; }
  .product-table, .product-table tbody, .product-table tr, .product-table td { display: block; width: 100%; }
  .product-table tr {
    background: white;
    border-radius: 12px;
    margin-bottom: 10px;
    box-shadow: 0 1px 4px rgba(0,0,0,.08);
    padding: 14px 14px 12px;
    border: 1px solid #f0f0f0;
  }
  .product-table td { padding: 2px 0; border: none; font-size: .88rem; }

  /* Name is the card title */
  .product-table td[data-label="Name"] {
    font-weight: 700;
    font-size: .98rem;
    color: #111;
    margin-bottom: 6px;
    padding-bottom: 6px;
    border-bottom: 1px solid #f0f0f0;
  }
  .product-table td[data-label="Name"]::before { display: none; }

  /* Inline meta row: brand, category, status, badge */
  .product-table td[data-label="Brand"],
  .product-table td[data-label="Category"],
  .product-table td[data-label="Status"],
  .product-table td[data-label="Latest"] {
    display: inline-block;
    width: auto;
    margin-right: 6px;
    padding: 2px 0;
  }
  .product-table td[data-label="Brand"] { color: #777; font-size: .82rem; }
  .product-table td[data-label="Brand"]::before,
  .product-table td[data-label="Category"]::before,
  .product-table td[data-label="Status"]::before,
  .product-table td[data-label="Latest"]::before { display: none; }

  /* Last checked row */
  .product-table td[data-label="Last Checked"] {
    display: block;
    color: #9ca3af;
    font-size: .78rem;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid #f5f5f5;
  }
  .product-table td[data-label="Last Checked"]::before {
    content: "Last checked: ";
    font-size: .75rem;
    color: #bbb;
    font-weight: 600;
    text-transform: uppercase;
  }

  /* Action buttons row — no absolute positioning */
  .product-table td[data-label=""] {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #f0f0f0;
    position: static;
  }
  .product-table td[data-label=""] .btn-check-now {
    font-size: .85rem;
    background: #f0f7ff;
    border: 1px solid #bfdbfe;
    border-radius: 6px;
    padding: 4px 10px;
    color: #2563eb;
    opacity: 1;
  }
  .product-table td[data-label=""] a {
    font-size: .85rem;
    color: #6b7280;
    text-decoration: none;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 4px 10px;
  }
}

/* ── Tags & badges ── */
.tag { background: #eee; border-radius: 4px; padding: 2px 8px; font-size: .78rem; }
.tag-owned { background: #d5f5e3; color: #1e8449; }
.tag-seeking { background: #d6eaf8; color: #1a5276; }
.badge { padding: 2px 8px; border-radius: 4px; font-size: .74rem; font-weight: 700; color: white; }
.badge-alert { background: #c0392b; }
.badge-warning { background: #e67e22; }
.badge-info { background: #27ae60; }

/* ── Flash messages ── */
.flash { padding: 12px 16px; border-radius: 6px; margin-bottom: 16px; }
.flash-success { background: #d5f5e3; color: #1e8449; }
.flash-error { background: #fadbd8; color: #c0392b; }
.empty-state { color: #888; padding: 40px 0; text-align: center; }

/* ── Reports ── */
.report-list { list-style: none; }
.report-list li { margin-bottom: 8px; }
.report-list a { color: #3498db; }

/* ── Forms ── */
form .field { margin-bottom: 16px; }
form label { display: block; font-size: .9rem; margin-bottom: 4px; color: #555; }
form input, form select, form textarea { width: 100%; padding: 9px 12px; border: 1px solid #ddd; border-radius: 6px; font-size: .95rem; }
form textarea { height: 80px; resize: vertical; }
.form-card { background: white; border-radius: 8px; padding: 20px; box-shadow: 0 1px 3px rgba(0,0,0,.1); }

/* ── History cards ── */
.history-card { background: white; border-radius: 6px; padding: 14px 16px; margin-top: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.history-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.history-date { font-weight: 600; font-size: .9rem; color: #333; }
.history-price { color: #555; font-size: .88rem; margin: 4px 0 8px; }
.history-no-findings { color: #27ae60; font-size: .9rem; margin: 4px 0 0; }
.history-findings { margin: 6px 0 0; padding-left: 20px; }
.history-findings li { margin-bottom: 7px; line-height: 1.45; font-size: .9rem; }
.history-findings a { color: #2980b9; font-size: .85rem; }

/* ── Barcode / scanner ── */
#barcode-region { max-width: 100%; }
#barcode-region video { width: 100%; border-radius: 6px; }

/* ── Candidate cards ── */
.candidates-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
@media (max-width: 480px) { .candidates-grid { grid-template-columns: 1fr; } }
.candidate-card { background: white; border: 1px solid #ddd; border-radius: 8px; padding: 14px; display: flex; flex-direction: column; }
.candidate-source { display: inline-block; font-size: .7rem; font-weight: 700; text-transform: uppercase; background: #e8f0fe; color: #1a4f9c; border-radius: 4px; padding: 2px 6px; margin-bottom: 8px; align-self: flex-start; }
.candidate-source-browse { background: #f0f0f0; color: #666; }
.candidate-source-openlibrary { background: #fef3c7; color: #92400e; }
.candidate-name { font-weight: 600; font-size: .92rem; margin-bottom: 4px; }
.candidate-brand { color: #666; font-size: .82rem; margin-bottom: 4px; }
.candidate-price { color: #27ae60; font-weight: 700; font-size: .88rem; margin-bottom: 8px; }
.candidate-actions { margin-top: auto; padding-top: 10px; }

/* ── Loading spinner (inline) ── */
.inline-spinner { display:inline-block; width:14px; height:14px; border:2px solid #ccc; border-top-color:#3498db; border-radius:50%; animation:spin 0.7s linear infinite; vertical-align:middle; margin-right:6px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Per-product check button ── */
.btn-check-now { background: none; border: none; cursor: pointer; font-size: 1rem; padding: 0; margin-right: 8px; opacity: 0.6; transition: opacity 0.2s; color: #3498db; }
.btn-check-now:hover { opacity: 1; }
.btn-check-now:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-edit-link { font-size: .82rem; color: #6b7280; text-decoration: none; background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 5px; padding: 3px 9px; }
.btn-edit-link:hover { background: #f0f0f0; color: #333; }

/* ── Field tooltips ── */
.field-label-wrap { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.field-label-wrap label { margin-bottom: 0; }
.tip-wrap { position: relative; display: inline-flex; align-items: center; }
.tip-icon { display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; border-radius: 50%; background: #e0e7ff; color: #4f46e5; font-size: .7rem; font-weight: 700; cursor: pointer; user-select: none; flex-shrink: 0; border: none; padding: 0; }
.tip-icon:hover { background: #c7d2fe; }
.tip-box { display: none; position: absolute; left: 50%; bottom: calc(100% + 6px); transform: translateX(-50%); background: #1e293b; color: #f8fafc; border-radius: 6px; padding: 8px 12px; font-size: .78rem; width: 200px; line-height: 1.45; z-index: 200; pointer-events: none; white-space: normal; }
.tip-box::after { content: ''; position: absolute; top: 100%; left: 50%; transform: translateX(-50%); border: 5px solid transparent; border-top-color: #1e293b; }
.tip-icon:hover + .tip-box,
.tip-icon.open + .tip-box { display: block; }
