:root {
  --bg: #f7f5f0;
  --panel: #ffffff;
  --text: #2a2a2a;
  --muted: #6b6b6b;
  --accent: #7a3b2e;
  --accent-dark: #5c2b21;
  --border: #e2ddd3;
  --warning-bg: #fff3cd;
  --warning-text: #7a5c00;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: bold;
  font-size: 1.2rem;
  color: var(--accent);
  text-decoration: none;
}

.cart-link {
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
}

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

.flash-messages { margin-bottom: 1rem; }
.flash {
  padding: 0.6rem 1rem;
  border-radius: 6px;
  margin-bottom: 0.5rem;
}
.flash-success { background: #e3f3e3; color: #1f5c1f; }
.flash-error { background: #fbe4e2; color: #8a2c22; }

.intro {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
}
.intro h1 {
  margin: 0 0 0.6rem;
  font-size: 1.3rem;
  color: var(--accent);
}
.intro p { margin: 0.5rem 0; line-height: 1.5; }
.intro-howto {
  background: var(--bg);
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
  font-size: 0.92rem;
}

.filters {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.filters input, .filters select {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
}

#search-box { flex: 1 1 260px; }

.empty-state { color: var(--muted); }

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1.25rem;
}

.book-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.book-card-toggle {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  text-align: left;
  display: flex;
  flex-direction: column;
  width: 100%;
  font: inherit;
  color: inherit;
}

.book-cover {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  background: #eee;
}

.book-summary { padding: 0.6rem 0.75rem; }
.book-title { font-weight: 600; font-size: 0.95rem; }
.book-author { color: var(--muted); font-size: 0.85rem; }
.book-category { color: var(--accent); font-size: 0.75rem; margin-top: 0.2rem; }

/* Phones: 180px-minimum cards left room for exactly one column on most
   handsets. Shrink the grid unit (and trim padding/gaps/type around it) so
   2-3 columns and at least two rows fit without the page feeling cramped. */
@media (max-width: 640px) {
  .site-header { padding: 0.75rem 1rem; }
  .brand { font-size: 1.05rem; }

  .container { padding: 1rem 0.75rem 3rem; }

  .intro { padding: 1rem; margin-bottom: 1rem; }
  .intro h1 { font-size: 1.1rem; }
  .intro p { font-size: 0.88rem; }
  .intro-howto { font-size: 0.84rem; }

  .filters { gap: 0.5rem; margin-bottom: 1rem; }
  .filters input, .filters select { flex: 1 1 47%; font-size: 0.85rem; padding: 0.45rem 0.6rem; }
  #search-box { flex: 1 1 100%; }

  .book-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 0.6rem; }

  .book-summary { padding: 0.4rem 0.5rem; }
  .book-title { font-size: 0.8rem; line-height: 1.25; }
  .book-author { font-size: 0.72rem; }
  .book-category { font-size: 0.65rem; }

  .book-details { padding: 0 0.5rem 0.5rem; }
  .book-details p { font-size: 0.78rem; }
  .book-meta { font-size: 0.72rem; }
  .btn-take { padding: 0.4rem 0.75rem; font-size: 0.82rem; }
}

.book-details {
  padding: 0 0.75rem 0.75rem;
  border-top: 1px solid var(--border);
}
.book-details p { font-size: 0.85rem; color: var(--muted); }
.book-meta { list-style: none; padding: 0; margin: 0.5rem 0; font-size: 0.8rem; color: var(--muted); }

.btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  background: var(--border);
  color: var(--text);
  text-decoration: none;
}

.btn-take, .btn-primary {
  background: var(--accent);
  color: white;
  width: 100%;
}
.btn-take:hover, .btn-primary:hover { background: var(--accent-dark); }
.btn-take:disabled { background: #a9a9a9; cursor: default; }

.btn-remove { background: #eee; font-size: 0.8rem; padding: 0.3rem 0.6rem; }
.btn-danger { background: #b3382c; color: white; }

.cart-items { list-style: none; padding: 0; }
.cart-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
}
.cart-item-cover { width: 40px; height: 60px; object-fit: cover; border-radius: 3px; }
.cart-item-title { flex: 1; }

.badge { padding: 0.15rem 0.5rem; border-radius: 4px; font-size: 0.75rem; }
.badge-warning { background: var(--warning-bg); color: var(--warning-text); }

.form-row { margin: 1rem 0; }
.form-row label { display: block; font-weight: 600; margin-bottom: 0.3rem; }
.form-row input, .form-row select, .form-row textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
  font-family: inherit;
}

table { width: 100%; border-collapse: collapse; margin-top: 1rem; }
th, td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
th { color: var(--muted); font-weight: 600; }
th a { color: inherit; text-decoration: none; }
th a:hover { color: var(--text); text-decoration: underline; }

.status-pill {
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
  font-size: 0.75rem;
  text-transform: capitalize;
}
.status-available { background: #e3f3e3; color: #1f5c1f; }
.status-reserved { background: #fff3cd; color: #7a5c00; }
.status-gone { background: #eee; color: #666; }
.status-not_collected { background: #fbe4e2; color: #8a2c22; }
.status-pending { background: #fff3cd; color: #7a5c00; }
.status-partially_collected { background: #dce7f7; color: #1c4a8a; }
.status-completed { background: #e3f3e3; color: #1f5c1f; }

.admin-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.thumb { width: 36px; height: 54px; object-fit: cover; border-radius: 3px; }

.order-block {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1rem;
}
.order-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}
