/* =========================================================
   Katalo — Main Stylesheet
   Clean, modern, lightweight
   Grid: 6 kolom desktop / 2 kolom mobile
   ========================================================= */

:root {
  --color-bg: #f8fafc;
  --color-surface: #ffffff;
  --color-text: #0f172a;
  --color-text-muted: #64748b;
  --color-border: #e2e8f0;
  --color-primary: #0f172a;
  --color-accent: #0369a1;
  --color-accent-soft: #e0f2fe;
  --color-success: #15803d;
  --color-danger: #b91c1c;
  --color-warning: #a16207;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --header-h: 64px;
  --max-w: 1280px;
}

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

html {
  scroll-behavior: smooth;
  overflow-x: hidden;          /* cegah geser samping */
  max-width: 100%;
}

body {
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;          /* cegah geser samping */
  max-width: 100%;
  width: 100%;
}

a {
  color: var(--color-accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

/* ---------- Header ---------- */
.site-header {
  background: var(--color-primary);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 100;
  min-height: var(--header-h);
  display: flex;
  align-items: center;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

.site-header .inner {
  width: 100%;
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0.6rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  min-width: 0;                /* penting agar flex child bisa menyusut */
}

.logo {
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  text-decoration: none;
  letter-spacing: -0.02em;
  white-space: nowrap;
  flex-shrink: 0;
  max-width: 40%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.logo:hover {
  text-decoration: none;
  opacity: 0.9;
}
.logo span {
  color: #7dd3fc;
}

/* Search form in header */
.search-form {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;                /* kunci: boleh menyusut di bawah content size */
  max-width: 420px;
  margin: 0;
}

.search-form input {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  padding: 0.45rem 0.7rem;
  border: none;
  border-radius: var(--radius) 0 0 var(--radius);
  font-size: 0.85rem;
  outline: none;
  background: #1e293b;
  color: #fff;
}
.search-form input::placeholder {
  color: #94a3b8;
}
.search-form input:focus {
  background: #334155;
}

.search-form button {
  flex-shrink: 0;
  padding: 0.45rem 0.75rem;
  background: #0369a1;
  color: #fff;
  border: none;
  border-radius: 0 var(--radius) var(--radius) 0;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
}
.search-form button:hover {
  background: #0284c7;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}
.header-actions a {
  color: #94a3b8;
  font-size: 0.8rem;
  text-decoration: none;
  white-space: nowrap;
}
.header-actions a:hover {
  color: #fff;
}

/* ---------- Main ---------- */
.main {
  flex: 1;
  width: 100%;
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 1.25rem 1rem 2.5rem;
  min-width: 0;
  overflow-x: hidden;
}

/* ---------- Toolbar (filter + result count) ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin-bottom: 1.25rem;
  min-width: 0;
  max-width: 100%;
}

.toolbar h1 {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-right: auto;
  min-width: 0;
  word-break: break-word;
}

.result-count {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

/* Category chips */
.category-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.chip {
  display: inline-block;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 500;
  background: var(--color-surface);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  text-decoration: none;
  transition: all 0.15s ease;
  max-width: 100%;
}
.chip:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
  text-decoration: none;
}
.chip.active {
  background: var(--color-accent);
  color: #fff;
  border-color: var(--color-accent);
}
.chip.active:hover {
  background: #0284c7;
  color: #fff;
}

/* ---------- Book Grid ---------- */
.book-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr)); /* minmax(0) cegah overflow */
  gap: 0.75rem;
  width: 100%;
  max-width: 100%;
}

@media (min-width: 640px) {
  .book-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1rem;
  }
}

@media (min-width: 900px) {
  .book-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1.15rem;
  }
}

@media (min-width: 1100px) {
  .book-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 1.25rem;
  }
}

/* ---------- Book Card ---------- */
.book-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.2s ease, transform 0.15s ease;
  text-decoration: none;
  color: inherit;
  min-width: 0;                /* kunci grid overflow */
  max-width: 100%;
}
.book-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  text-decoration: none;
  color: inherit;
}

.book-card .cover {
  aspect-ratio: 3 / 4;
  background: #e2e8f0;
  overflow: hidden;
  position: relative;
  width: 100%;
}
.book-card .cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.book-card .body {
  padding: 0.6rem 0.65rem 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  flex: 1;
  min-width: 0;
}

.book-card .title {
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.book-card .author {
  font-size: 0.72rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-card .meta {
  margin-top: auto;
  padding-top: 0.4rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.25rem;
  min-width: 0;
  flex-wrap: wrap;
}

.book-card .price {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--color-primary);
  min-width: 0;
}

.book-card .stock {
  font-size: 0.68rem;
  font-weight: 500;
  padding: 0.12rem 0.35rem;
  border-radius: 4px;
  white-space: nowrap;
  flex-shrink: 0;
}
.stock.in {
  background: #dcfce7;
  color: var(--color-success);
}
.stock.low {
  background: #fef9c3;
  color: var(--color-warning);
}
.stock.out {
  background: #fee2e2;
  color: var(--color-danger);
}

/* ---------- Empty state ---------- */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 3rem 1rem;
  color: var(--color-text-muted);
}
.empty-state p {
  margin-bottom: 0.75rem;
}
.empty-state a {
  font-weight: 500;
}

/* ---------- Footer ---------- */
.site-footer {
  background: var(--color-primary);
  color: #94a3b8;
  padding: 1.25rem 1rem;
  text-align: center;
  font-size: 0.8rem;
  width: 100%;
  max-width: 100%;
}
.site-footer a {
  color: #7dd3fc;
}

/* ---------- Utility ---------- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* ---------- Mobile header tweaks ---------- */
@media (max-width: 480px) {
  .site-header .inner {
    padding: 0.5rem 0.75rem;
    gap: 0.35rem;
  }
  .logo {
    font-size: 0.95rem;
    max-width: 30%;
  }
  .search-form {
    max-width: none;
  }
  .search-form input {
    font-size: 0.8rem;
    padding: 0.4rem 0.55rem;
  }
  .search-form button {
    padding: 0.4rem 0.55rem;
    font-size: 0.8rem;
  }
  .header-actions a {
    font-size: 0.75rem;
  }
  /* Sembunyikan teks Admin di layar sangat kecil, tetap bisa diakses via URL */
  .main {
    padding: 1rem 0.75rem 2rem;
  }
  .book-grid {
    gap: 0.6rem;
  }
  .book-card .body {
    padding: 0.5rem 0.5rem 0.65rem;
  }
  .book-card .title {
    font-size: 0.78rem;
  }
  .book-card .price {
    font-size: 0.78rem;
  }
}

/* =========================================================
   Dark Mode
   ========================================================= */
[data-theme="dark"] {
  --color-bg: #0f172a;
  --color-surface: #1e293b;
  --color-text: #f1f5f9;
  --color-text-muted: #94a3b8;
  --color-border: #334155;
  --color-primary: #e2e8f0;
  --color-accent: #38bdf8;
  --color-accent-soft: #0c4a6e;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .site-header {
  background: #020617;
}
[data-theme="dark"] .search-form input {
  background: #1e293b;
  color: #f1f5f9;
}
[data-theme="dark"] .search-form input:focus {
  background: #334155;
}
[data-theme="dark"] .chip {
  background: #1e293b;
  border-color: #334155;
  color: #94a3b8;
}
[data-theme="dark"] .chip.active {
  background: #0369a1;
  color: #fff;
  border-color: #0369a1;
}
[data-theme="dark"] .book-card .cover {
  background: #334155;
}
[data-theme="dark"] .site-footer {
  background: #020617;
}

/* Theme toggle button */
.theme-toggle {
  background: transparent;
  border: 1px solid #475569;
  color: #94a3b8;
  border-radius: 6px;
  padding: 0.25rem 0.45rem;
  cursor: pointer;
  font-size: 0.8rem;
  line-height: 1;
  flex-shrink: 0;
}
.theme-toggle:hover {
  color: #fff;
  border-color: #94a3b8;
}
