:root {
  --ink: #1a1a1a;
  --accent: #c0121a;
  --bg: #f4f4f5;
  --card-bg: #fff;
  --border: #e2e2e5;
  --text-muted: #6b6b6f;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Segoe UI', 'Tahoma', sans-serif;
  background: var(--bg);
  color: var(--ink);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Faint tiled watermark shown on every page a view-only (seller) account sees — deters
   screenshots/photos of price data leaving the system, not just printed PDFs (print.php
   already carries its own copy of this same watermark for anyone printing). */
body.watermarked {
  background: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%22340%22%20height%3D%22200%22%3E%3Ctext%20x%3D%2210%22%20y%3D%22110%22%20font-family%3D%22Segoe%20UI%2C%20Tahoma%2C%20sans-serif%22%20font-size%3D%2226%22%20fill%3D%22rgba%280%2C0%2C0%2C0.06%29%22%20transform%3D%22rotate%28-28%20170%20100%29%22%3EKV%20Accessories%3C/text%3E%3C/svg%3E") repeat, var(--bg);
}
/* The table's own opaque white background would otherwise hide the watermark exactly where
   the price data is — let the body watermark show through instead. */
body.watermarked table,
body.watermarked th,
body.watermarked .category-card,
body.watermarked .product-detail {
  background: transparent;
}

.site-header {
  background: var(--ink);
  color: #fff;
}
.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { color: #fff; font-weight: 700; font-size: 1.1rem; }
.brand:hover { text-decoration: none; }
.main-nav { display: flex; gap: 18px; flex-wrap: wrap; }
.main-nav a { color: #ddd; }
.main-nav a.active, .main-nav a:hover { color: #fff; }

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.flash { padding: 12px 16px; border-radius: 6px; margin-bottom: 18px; }
.flash-success { background: #e4f7e9; color: #1a7a34; border: 1px solid #b6e6c2; }
.flash-error { background: #fce8e8; color: var(--accent); border: 1px solid #f3c1c1; }

.page-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}
h1 { font-size: 1.4rem; margin: 0; }

.btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 9px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.95rem;
}
.btn:hover { background: #9c0e15; text-decoration: none; }
.btn-secondary { background: #6b6b6f; }
.btn-secondary:hover { background: #55555a; }
.btn-sm { padding: 5px 10px; font-size: 0.85rem; }

.login-wrap {
  max-width: 380px;
  margin: 80px auto;
  background: var(--card-bg);
  padding: 30px;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.login-wrap h1 { text-align: center; margin-bottom: 20px; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 600; font-size: 0.9rem; }
.form-group input[type=text],
.form-group input[type=password],
.form-group input[type=number],
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  font-family: inherit;
}
.form-group textarea { min-height: 100px; resize: vertical; }
.form-actions { display: flex; gap: 10px; margin-top: 20px; }
.form-card {
  background: var(--card-bg);
  padding: 24px;
  border-radius: 10px;
  border: 1px solid var(--border);
  max-width: 640px;
}

.filter-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}
.filter-form input, .filter-form select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.brand-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}
.chip {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--ink);
  font-size: 0.85rem;
}
.chip:hover { border-color: var(--accent); text-decoration: none; }
.chip-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.category-picker p { color: var(--text-muted); margin-bottom: 14px; }
.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
}
.category-card {
  display: block;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 16px;
  text-align: center;
}
.category-card:hover { border-color: var(--accent); text-decoration: none; }
.category-card-name { font-weight: 600; margin-bottom: 4px; }
.category-card-count { font-size: 0.82rem; color: var(--text-muted); }

table { width: 100%; border-collapse: collapse; background: var(--card-bg); border-radius: 8px; overflow: hidden; }
.table-scroll { overflow-x: auto; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; font-size: 0.92rem; }
td.thumb-cell { padding-top: 4px; padding-bottom: 4px; }
th { background: #fafafa; color: var(--text-muted); font-weight: 600; }
tr:last-child td { border-bottom: none; }
.thumb { width: 80px; height: 80px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }
.thumb-group { display: flex; gap: 6px; }
.thumb-natural { max-width: 90px; max-height: 80px; width: auto; height: auto; border-radius: 6px; border: 1px solid var(--border); }
.thumb-natural-lg { max-width: 108px; max-height: 96px; width: auto; height: auto; border-radius: 6px; border: 1px solid var(--border); }
.thumb-car { max-width: 180px; max-height: 160px; width: auto; height: auto; border-radius: 6px; border: 1px solid var(--border); }

tr.brand-divider > td { border-top: 3px solid var(--accent); }
.badge { padding: 2px 8px; border-radius: 10px; font-size: 0.78rem; }
.badge-active { background: #e4f7e9; color: #1a7a34; }
.badge-inactive { background: #f0f0f0; color: var(--text-muted); }
.actions-cell { display: flex; gap: 8px; }

.product-detail { display: flex; gap: 24px; flex-wrap: wrap; background: var(--card-bg); padding: 20px; border-radius: 10px; border: 1px solid var(--border); }
.product-detail img { width: 260px; max-width: 100%; border-radius: 8px; border: 1px solid var(--border); }
.product-photos { display: flex; gap: 12px; flex-wrap: wrap; }
.product-detail .price { font-size: 1.4rem; color: var(--accent); font-weight: 700; margin: 10px 0; }
.empty-state { padding: 40px; text-align: center; color: var(--text-muted); background: var(--card-bg); border-radius: 10px; border: 1px dashed var(--border); }

@media (max-width: 640px) {
  .header-inner { flex-direction: column; align-items: flex-start; }
  .product-detail { flex-direction: column; }

  /* On narrow screens the table scrolls horizontally — pin the edit/delete buttons to the
     right edge so they stay visible alongside whichever row is on screen, instead of being
     scrolled out of view past the price column. */
  .table-scroll td.actions-cell,
  .table-scroll th.actions-col {
    position: sticky;
    right: 0;
    background: var(--card-bg);
    box-shadow: -2px 0 6px rgba(0, 0, 0, 0.12);
  }
  /* border-collapse:collapse paints the row-divider lines on the table's shared grid, which
     doesn't move with a sticky cell during horizontal scroll — the lines stay behind while the
     cell's content (the buttons) scrolls into place, so rows look staggered/misaligned. Giving
     each cell its own border via border-collapse:separate keeps the sticky cell's border-bottom
     moving together with its content. */
  .table-scroll table {
    border-collapse: separate;
    border-spacing: 0;
  }
}

/* Link to the public web (kv-accessories.com) + shop */
.web-fields { border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px 4px; margin: 0 0 16px; }
.web-fields legend { font-weight: 700; padding: 0 6px; }
.sync-box { border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px; margin-top: 16px; font-size: 0.92rem; }
.sync-box h3 { margin: 0 0 8px; font-size: 1rem; }
.sync-box .sync-row { margin-bottom: 4px; }
.sync-box form { margin-top: 10px; }
.sync-pending { color: #a86b00; font-weight: 700; }
.web-badge { display: inline-block; font-size: 0.72rem; padding: 1px 6px; border-radius: 10px; background: #e6f4ea; color: #1e7b34; margin-left: 4px; white-space: nowrap; }
/* Per-row "อัปเดตเว็บ" button in the product list — its own colour so it isn't mistaken for ลบ. */
/* As a real table cell (not flex) so its row border lines up with the rest of the row. */
td.actions-cell { display: table-cell; white-space: nowrap; vertical-align: middle; }
td.actions-cell > * + * { margin-left: 6px; }
.btn-sync { background: #1f6fb2; }
.btn-sync:hover { background: #185a91; }
.btn-sync:disabled { background: #a86b00; cursor: default; }
/* Switched-off products (is_active = 0) — only visible to admins via "แสดงสินค้าที่ปิดการแสดงผล". */
tr.row-inactive > td { opacity: 0.55; }
tr.row-inactive > td.actions-cell { opacity: 1; }
.badge-inactive { background: #eee; color: #555; }
.inactive-toggle { margin: -4px 0 12px; font-size: 0.9rem; }

/* No browser header/footer (URL, date, page no.) on printouts/PDFs: with a zero page margin the
   browser has no room for them; the margin is put back as body padding repeated on every page. */
@page { margin: 0; }
@media print {
    html, body { margin: 0 !important; }
    body { padding: 10mm !important; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
}

/* product page: quick "print QR stickers" form */
.sticker-quick { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 12px 0; padding: 10px 12px; background: #f6f6f8; border: 1px solid var(--border); border-radius: 8px; font-size: 0.9rem; }
.sticker-quick input[type=number] { width: 64px; padding: 5px; border: 1px solid #ccc; border-radius: 6px; font: inherit; }
.sticker-quick select { padding: 5px; border: 1px solid #ccc; border-radius: 6px; font: inherit; }
