/* ── Variables ─────────────────────────────────────────────────────────── */
:root {
  --green-dark:   #1a6b3c;
  --green:        #2d9060;
  --green-light:  #e8f5ee;
  --amber:        #d97706;
  --amber-light:  #fef3c7;
  --blue:         #2563eb;
  --blue-light:   #dbeafe;
  --red:          #dc2626;
  --red-light:    #fee2e2;
  --gray-dark:    #374151;
  --gray:         #6b7280;
  --gray-light:   #f3f4f6;
  --border:       #e5e7eb;
  --bg:           #f8fafc;
  --card:         #ffffff;
  --text:         #111827;
  --radius:       10px;
  --radius-sm:    6px;
  --shadow:       0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:    0 4px 12px rgba(0,0,0,.10);
}

/* ── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--green-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }

/* ── Header ─────────────────────────────────────────────────────────────── */
.site-header {
  background: var(--green-dark);
  color: white;
  padding: .9rem 1.5rem;
}
.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}
.site-logo {
  font-size: 1.45rem;
  font-weight: 700;
  color: white;
  display: flex;
  align-items: center;
  gap: .45rem;
  letter-spacing: -.3px;
}
.site-logo:hover { text-decoration: none; opacity: .9; }
.logo-icon { font-size: 1.6rem; }
.site-tagline {
  font-size: .85rem;
  opacity: .75;
  margin-left: auto;
}

/* ── Main + footer ──────────────────────────────────────────────────────── */
.site-main {
  flex: 1;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}
.site-footer {
  background: var(--gray-light);
  border-top: 1px solid var(--border);
  text-align: center;
  padding: 1rem;
  font-size: .8rem;
  color: var(--gray);
}
.site-footer a { color: var(--gray); }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem 1.1rem;
  border-radius: var(--radius-sm);
  border: none;
  font-size: .9rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity .15s, box-shadow .15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { opacity: .88; text-decoration: none; }
.btn-primary  { background: var(--green-dark);  color: white; }
.btn-secondary{ background: var(--gray-dark);   color: white; }
.btn-ghost    { background: transparent; color: var(--gray); border: 1px solid var(--border); }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  font-size: .72rem;
  font-weight: 600;
  padding: .2em .6em;
  border-radius: 999px;
  line-height: 1.4;
  text-transform: capitalize;
  letter-spacing: .02em;
}
.badge-material  { background: var(--blue-light);  color: var(--blue); }
.badge-category  { background: var(--green-light); color: var(--green-dark); }
.badge-condition { background: var(--gray-light);  color: var(--gray-dark); }
.badge-pending   { background: var(--amber-light); color: var(--amber); }

/* Description source badges */
.badge-src-pending { background: var(--amber-light); color: var(--amber); }
.badge-src-ai      { background: var(--blue-light);  color: var(--blue); }
.badge-src-human   { background: var(--green-light); color: var(--green-dark); }

/* Status badges (item detail header) */
.status-badge {
  font-size: .82rem;
  font-weight: 700;
  padding: .3em .9em;
  border-radius: 999px;
  text-transform: capitalize;
  letter-spacing: .04em;
}
.status-available { background: var(--green-light); color: var(--green-dark); }
.status-reserved  { background: var(--amber-light); color: var(--amber); }
.status-taken     { background: var(--gray-light);  color: var(--gray); }
.status-removed   { background: var(--red-light);   color: var(--red); }

/* Transaction action badges */
.badge-action-added    { background: var(--green-light); color: var(--green-dark); }
.badge-action-reserved { background: var(--amber-light); color: var(--amber); }
.badge-action-taken    { background: var(--gray-light);  color: var(--gray); }
.badge-action-returned { background: var(--blue-light);  color: var(--blue); }
.badge-action-removed  { background: var(--red-light);   color: var(--red); }

/* ── Filter bar ──────────────────────────────────────────────────────────── */
.filter-bar {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
}
.filter-form {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
  align-items: center;
}
.search-wrap { flex: 1 1 220px; }
.search-input {
  width: 100%;
  padding: .5rem .8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .9rem;
  background: var(--bg);
  transition: border-color .15s;
}
.search-input:focus { outline: none; border-color: var(--green); }
.filter-select {
  padding: .5rem .7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .87rem;
  background: var(--bg);
  cursor: pointer;
}
.filter-select:focus { outline: none; border-color: var(--green); }

.results-count {
  font-size: .88rem;
  color: var(--gray);
  margin-bottom: 1rem;
}

/* ── Item grid + cards ───────────────────────────────────────────────────── */
.item-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1.1rem;
}
.item-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  transition: box-shadow .18s, transform .18s;
  color: var(--text);
  text-decoration: none;
}
.item-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  text-decoration: none;
}
.card-photo {
  width: 100%;
  aspect-ratio: 4/3;
  overflow: hidden;
  background: var(--gray-light);
}
.card-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform .25s;
}
.item-card:hover .card-photo img { transform: scale(1.03); }
.photo-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  color: var(--gray);
  background: var(--gray-light);
}
.card-body {
  padding: .9rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  flex: 1;
}
.card-name {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.35;
  display: flex;
  align-items: center;
  gap: .4rem;
  flex-wrap: wrap;
}
.card-badges { display: flex; flex-wrap: wrap; gap: .3rem; }
.card-desc {
  font-size: .84rem;
  color: var(--gray);
  line-height: 1.5;
  flex: 1;
}
.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  margin-top: auto;
}
.meta-chip {
  font-size: .76rem;
  color: var(--gray);
  background: var(--gray-light);
  padding: .18em .55em;
  border-radius: 999px;
}

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 5rem 2rem;
  color: var(--gray);
}
.empty-icon { font-size: 4rem; margin-bottom: .75rem; }
.empty-state h2 { font-size: 1.4rem; margin-bottom: .4rem; color: var(--text); }

/* ── Item detail page ────────────────────────────────────────────────────── */
.detail-page { max-width: 960px; }

.back-link {
  display: inline-block;
  margin-bottom: 1.1rem;
  font-size: .88rem;
  color: var(--gray);
}
.back-link:hover { color: var(--green-dark); }

.detail-header { margin-bottom: 1.4rem; }
.detail-title-row {
  display: flex;
  align-items: center;
  gap: .8rem;
  flex-wrap: wrap;
  margin-bottom: .25rem;
}
.detail-title { font-size: 1.7rem; font-weight: 700; }
.detail-dates { font-size: .83rem; color: var(--gray); }

.detail-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 2rem;
  align-items: start;
}
@media (max-width: 680px) {
  .detail-layout { grid-template-columns: 1fr; }
}

.detail-photo-wrap {
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--gray-light);
  aspect-ratio: 4/3;
}
.detail-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.detail-photo-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  font-size: 3rem;
  color: var(--gray);
}

.detail-info { display: flex; flex-direction: column; gap: 1.2rem; }

.detail-dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: .35rem .9rem;
  font-size: .9rem;
}
.detail-dl dt { font-weight: 600; color: var(--gray-dark); white-space: nowrap; }
.detail-dl dd { color: var(--text); }

.detail-description h3 { font-size: .95rem; margin-bottom: .35rem; }
.detail-description p { font-size: .9rem; color: var(--gray-dark); line-height: 1.7; }

/* Reserve box */
.reserve-box {
  background: var(--green-light);
  border: 1px solid #a7d9be;
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}
.reserve-box h3 { font-size: .95rem; margin-bottom: .6rem; color: var(--green-dark); }
.reserve-form { display: flex; gap: .5rem; flex-wrap: wrap; }
.reserve-form .form-input { flex: 1 1 180px; }

.status-notice {
  border-radius: var(--radius);
  padding: .8rem 1rem;
  font-size: .88rem;
}
.status-notice-reserved { background: var(--amber-light); color: var(--amber); }
.status-notice-taken    { background: var(--gray-light);  color: var(--gray); }

/* ── Admin section ───────────────────────────────────────────────────────── */
.admin-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 2rem;
  background: var(--card);
}
.admin-toggle {
  padding: .8rem 1.1rem;
  cursor: pointer;
  font-weight: 600;
  font-size: .92rem;
  color: var(--gray-dark);
  user-select: none;
  list-style: none;
}
.admin-toggle::-webkit-details-marker { display: none; }
.admin-section[open] .admin-toggle { border-bottom: 1px solid var(--border); }
.admin-body { padding: 1.25rem 1.3rem; }
.admin-hint { font-size: .83rem; color: var(--gray); margin-bottom: 1rem; }

.admin-form { display: flex; flex-direction: column; gap: .75rem; }
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .65rem;
}
.form-row-inline { grid-template-columns: unset; display: flex; flex-wrap: wrap; }
@media (max-width: 540px) { .form-row { grid-template-columns: 1fr; } }

label { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; font-weight: 500; }
.form-input {
  padding: .48rem .7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .88rem;
  background: var(--bg);
  font-family: inherit;
  width: 100%;
  transition: border-color .15s;
}
.form-input:focus { outline: none; border-color: var(--green); }
textarea.form-input { resize: vertical; }

/* ── History table ───────────────────────────────────────────────────────── */
.history-section { margin-top: 1rem; }
.history-section h2 { font-size: 1.1rem; margin-bottom: .75rem; }
.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .87rem;
}
.history-table th, .history-table td {
  text-align: left;
  padding: .55rem .8rem;
  border-bottom: 1px solid var(--border);
}
.history-table th {
  font-weight: 600;
  background: var(--gray-light);
  color: var(--gray-dark);
}
.history-table tr:last-child td { border-bottom: none; }
.history-table tr:hover td { background: var(--green-light); }

/* ── AI Material Finder widget ───────────────────────────────────────────── */

/* Button inside the filter bar */
.btn-ai {
  background: var(--green-dark);
  color: white;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn-ai:hover  { opacity: .88; }
.btn-ai-active { background: var(--gray-dark); }

/* Expandable section below the filter form */
.ai-expand {
  border-top: 1px solid var(--border);
  padding: .9rem 1.2rem .85rem;
  display: flex;
  flex-direction: column;
  gap: .65rem;
}
.ai-expand[hidden] { display: none; }

.ai-expand-row {
  display: grid;
  grid-template-columns: 1fr 190px;
  gap: .75rem;
  align-items: start;
}

.ai-expand-input { display: flex; flex-direction: column; }

.ai-expand-side {
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.ai-rate-info {
  font-size: .78rem;
  background: var(--gray-light);
  border-radius: var(--radius-sm);
  padding: .4rem .7rem;
  color: var(--gray);
  line-height: 1.5;
}

.ai-textarea { resize: none; font-size: .87rem; }

.ai-char-count {
  text-align: right;
  font-size: .73rem;
  color: var(--gray);
  margin-top: .2rem;
}

.ai-response {
  background: var(--green-light);
  border: 1px solid #a7d9be;
  border-radius: var(--radius-sm);
  padding: .75rem .9rem;
}
.ai-response-text {
  font-size: .87rem;
  color: var(--gray-dark);
  line-height: 1.65;
  margin: 0;
  white-space: pre-wrap;
}

@media (max-width: 600px) {
  .ai-expand-row { grid-template-columns: 1fr; }
}
