*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f9f8f6;
  --surface: #ffffff;
  --border: #e5e3de;
  --border-strong: #ccc9c2;
  --text: #1a1917;
  --text-muted: #6b6860;
  --text-faint: #9e9b94;
  --accent: #1a1917;
  --accent-fg: #ffffff;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --success: #15803d;
  --success-bg: #f0fdf4;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
}

a { color: inherit; }

/* Layout */
.page-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1.25rem 1.5rem;
}
.page-header-inner {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  align-items: baseline;
  gap: 1rem;
}
.site-title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.site-subtitle {
  font-size: 14px;
  color: var(--text-muted);
}

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* Controls bar */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1.5rem;
}
.controls select,
.controls input[type="text"] {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
}
.controls label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--text-muted);
  cursor: pointer;
}
.controls-right { margin-left: auto; }

/* List view */
.items-grid {
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.item-card {
  display: grid;
  grid-template-columns: 90px 1fr auto;
  column-gap: 1.5rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}

.item-img-wrap {
  align-self: stretch;
  overflow: hidden;
  border-radius: var(--radius) 0 0 var(--radius);
  flex-shrink: 0;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: -1rem 0 -1rem -1.25rem;
  max-height: 120px;
}
.item-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
}
.item-img-placeholder {
  font-size: 11px;
  color: var(--text-faint);
  text-align: center;
  line-height: 1.4;
  padding: 0.5rem;
}
.item-card:last-child { border-bottom: none; }
.item-card:hover { background: var(--bg); }
.item-card.purchased { opacity: 0.45; }

.item-card-left {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.item-name {
  font-size: 15px;
  font-weight: 500;
  line-height: 1.4;
}
.item-notes {
  font-size: 13px;
  color: var(--text-faint);
}

.item-card-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  gap: 0.4rem;
  white-space: nowrap;
}
.item-price {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
}

.item-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 100px;
  border: 1px solid var(--border);
  color: var(--text-muted);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: opacity 0.1s, background 0.1s;
  white-space: nowrap;
}
.btn:active { opacity: 0.8; }
.btn-primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}
.btn-primary:hover { opacity: 0.85; }
.btn-outline {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text);
}
.btn-outline:hover { background: var(--bg); }
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
  padding: 8px 8px;
}
.btn-ghost:hover { color: var(--text); background: var(--bg); }
.btn-danger {
  background: var(--danger-bg);
  border-color: #fca5a5;
  color: var(--danger);
}
.btn-danger:hover { background: #fee2e2; }
.btn-sm { padding: 5px 10px; font-size: 13px; }

.amazon-link {
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.amazon-link:hover { color: var(--text); }

/* Purchased state on card */
.purchased-note {
  font-size: 13px;
  color: var(--success);
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Modal */
.dialog-layer {
  display: none;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(0,0,0,0.35);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.dialog-layer.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.75rem;
  width: 100%;
  max-width: 420px;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}
.modal h2 { font-size: 17px; font-weight: 600; margin-bottom: 0.5rem; }
.modal p  { font-size: 14px; color: var(--text-muted); margin-bottom: 1rem; }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1.25rem; }

/* Forms */
.form-group { display: flex; flex-direction: column; gap: 4px; margin-bottom: 1rem; }
.form-group label { font-size: 13px; font-weight: 500; color: var(--text-muted); }
.form-group input,
.form-group select,
.form-group textarea {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 16px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  transition: border-color 0.15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--border-strong);
  box-shadow: 0 0 0 3px rgba(0,0,0,0.06);
}
.form-group textarea { resize: vertical; min-height: 80px; }

/* Admin-specific */
.admin-bar {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-bottom: 1.5rem;
}
.admin-bar-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.items-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.items-table th {
  text-align: left;
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
}
.items-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.items-table tr:last-child td { border-bottom: none; }
.items-table tbody tr:hover { background: var(--bg); }
.items-table tr.row-has-details:hover + tr.details-row,
.items-table tr.row-has-details:has(+ tr.details-row:hover) {
  background: var(--bg);
}
.items-table .row-purchased td { opacity: 0.5; }
.items-table tr.row-has-details td { border-bottom: none; }
.admin-col-mobile { display: none; }

.admin-detail {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 0 0.75rem 0.75rem;
}
.admin-detail-img {
  width: 72px;
  height: 72px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #ffffff;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
}
.admin-detail-img img { width: 100%; height: 100%; object-fit: cover; object-position: center; display: block; }
.admin-detail-links { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.admin-detail-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-size: 13px;
  color: var(--text-muted);
}
.admin-detail-price { font-size: 14px; font-weight: 500; color: var(--text-muted); }
.admin-detail-actions { margin-left: auto; }
.btn-buy {
  background: #2563eb;
  border-color: #2563eb;
  color: #ffffff;
}
.btn-buy:hover { opacity: 0.85; }
.btn-buy-amazon {
  background: #d9c9a3;
  border-color: #d9c9a3;
  color: #3f3620;
}
.btn-buy-amazon:hover { opacity: 0.85; }
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.table-actions { display: flex; gap: 4px; }

/* Login page */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow);
}
.login-card h1 { font-size: 20px; font-weight: 600; margin-bottom: 1.5rem; }
.error-msg { font-size: 13px; color: var(--danger); margin-bottom: 1rem; }

/* Responsive */
@media (max-width: 560px) {
  .container { padding: 0.75rem; }

  .page-header { padding: 1rem 0.75rem; }

  .controls {
    gap: 0.5rem;
    flex-wrap: wrap;
  }
  .controls select,
  .controls input[type="search"] {
    font-size: 13px;
    flex: 1 1 calc(50% - 0.25rem);
    min-width: 0;
  }
  .controls label { font-size: 13px; }

  .items-grid {
    border: none;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    gap: 0.75rem;
  }
  .item-card {
    grid-template-columns: 70px 1fr auto;
    padding: 0.75rem 0.75rem 0.75rem 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    background: var(--surface);
    overflow: hidden;
  }
  .item-card:last-child { border-bottom: 1px solid var(--border); }
  .item-img-wrap { margin: -0.75rem 0 -0.75rem -0.75rem; border-radius: var(--radius) 0 0 var(--radius); overflow: hidden; }
  .item-card-left { gap: 0.4rem; }
  .item-card-right { justify-content: flex-start; white-space: normal; gap: 0.3rem; }
  .item-card-right .item-meta { flex-direction: column; align-items: flex-end; }

  .modal { padding: 1.25rem; }
  .modal h2 { font-size: 15px; }

  /* Admin table → cards on mobile */
  .table-wrap { border-radius: var(--radius); overflow: hidden; }
  .items-table thead { display: none; }
  .items-table, .items-table tbody, .items-table tr, .items-table td { display: block; width: 100%; }
  .items-table tr {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    position: relative;
  }
  .items-table tr:last-child { border-bottom: none; }
  .items-table .row-purchased { opacity: 0.5; }
  .items-table tr.row-has-details { border-bottom: none; padding-bottom: 0; }
  .items-table tr.details-row { padding: 0 1rem 0.75rem; }
  .items-table td {
    padding: 0;
    border: none;
    font-size: 14px;
  }
  .admin-detail { padding: 0.5rem 0 0; }
  .items-table td[data-label="name"] { font-weight: 500; margin-bottom: 0.3rem; }
  .items-table td[data-label="status"] { font-size: 13px; margin-bottom: 0.5rem; }
  .items-table td[data-label="actions"] .table-actions { flex-wrap: wrap; gap: 4px; }
  .admin-col-desktop { display: none; }
  .admin-col-mobile { display: block; margin-bottom: 0.3rem; }
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}
.empty-state p { font-size: 15px; }

/* Utility */
.text-muted { color: var(--text-muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
