/* ===================================================================
   Shelfie — Stylesheet
   Aesthetic: Dark library / aged paper / warm amber accents
   Font: Bitter (serif headings) + DM Sans (body)
   =================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Bitter:wght@400;600;700&family=DM+Sans:wght@300;400;500;600&display=swap');

/* --- Variables ---------------------------------------------------- */
:root {
  --bg:           #0f1117;
  --bg2:          #181c26;
  --bg3:          #1f2433;
  --border:       #2a3045;
  --border-light: #3a4260;
  --text:         #dde2f0;
  --text-muted:   #7a8299;
  --text-dim:     #4a5270;
  --gold:         #c8a96e;
  --gold-dim:     #8a7048;
  --gold-bright:  #e4c488;
  --red:          #d05a5a;
  --red-dim:      #7a2020;
  --green:        #5aaf7a;
  --green-dim:    #1e4a30;
  --blue:         #5a90d0;
  --blue-dim:     #1e3a5a;
  --radius:       8px;
  --radius-lg:    14px;
  --shadow:       0 4px 20px rgba(0,0,0,0.4);
  --shadow-sm:    0 2px 8px rgba(0,0,0,0.3);
  --transition:   0.18s ease;
  --header-h:     56px;
  --nav-h:        60px;
}

/* --- Reset -------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--gold); text-decoration: none; }
a:hover { color: var(--gold-bright); }
img { max-width: 100%; display: block; }
button { cursor: pointer; border: none; background: none; font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* --- Layout ------------------------------------------------------- */
#app { display: flex; flex-direction: column; min-height: 100vh; }

header.app-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--header-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
}
.app-header .logo {
  font-family: 'Bitter', serif;
  font-size: 1.4rem; font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.02em;
  flex: 1;
}
.app-header .logo span { color: var(--text-muted); font-weight: 400; font-size: 0.75rem; }

.header-user {
  font-size: 0.8rem; color: var(--text-muted);
  display: flex; align-items: center; gap: 8px;
}

nav.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  height: var(--nav-h);
  background: var(--bg2);
  border-top: 1px solid var(--border);
  display: flex; align-items: stretch;
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px;
  color: var(--text-dim); font-size: 0.65rem; font-weight: 500;
  letter-spacing: 0.04em; text-transform: uppercase;
  transition: color var(--transition);
  border-right: 1px solid var(--border);
  padding-bottom: 4px;
}
.nav-btn:last-child { border-right: none; }
.nav-btn svg { width: 22px; height: 22px; }
.nav-btn.active { color: var(--gold); }
.nav-btn:active { background: var(--bg3); }

main.content {
  flex: 1;
  padding-top: calc(var(--header-h) + 12px);
  padding-bottom: calc(var(--nav-h) + 12px);
  padding-left: 16px; padding-right: 16px;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

/* --- Pages (SPA) -------------------------------------------------- */
.page { display: none; }
.page.active { display: block; }

/* --- Cards -------------------------------------------------------- */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 12px;
}
.card-row {
  display: flex; gap: 12px; align-items: flex-start;
}
.card-cover {
  width: 56px; height: 80px;
  background: var(--bg3);
  border-radius: 4px;
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid var(--border);
}
.card-cover-placeholder {
  width: 56px; height: 80px;
  background: var(--bg3);
  border-radius: 4px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.card-body { flex: 1; min-width: 0; }
.card-title {
  font-family: 'Bitter', serif;
  font-size: 1rem; font-weight: 600;
  color: var(--text); line-height: 1.3;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card-sub { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }
.card-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

/* --- Badges ------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 20px;
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.04em;
  text-transform: uppercase;
}
.badge-in     { background: var(--green-dim); color: var(--green); }
.badge-loaned { background: var(--red-dim);   color: var(--red); }
.badge-missing{ background: #3a2a10;          color: #c8883e; }
.badge-book   { background: var(--blue-dim);  color: var(--blue); }
.badge-game   { background: #2a1a4a;          color: #9a70d8; }
.badge-dvd    { background: #1a2a1a;          color: var(--green); }
.badge-loc    { background: var(--bg3);       color: var(--text-muted); }

/* --- Buttons ------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 20px; border-radius: var(--radius);
  font-size: 0.9rem; font-weight: 600;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn-primary   { background: var(--gold); color: #0f1117; }
.btn-primary:hover { background: var(--gold-bright); }
.btn-danger    { background: var(--red-dim); color: var(--red); border: 1px solid var(--red-dim); }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-ghost     { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { border-color: var(--border-light); color: var(--text); }
.btn-sm { padding: 6px 14px; font-size: 0.8rem; }
.btn-icon { padding: 8px; border-radius: var(--radius); }
.btn-full { width: 100%; }

/* --- Forms -------------------------------------------------------- */
.form-group { margin-bottom: 14px; }
.form-label {
  display: block; font-size: 0.78rem; font-weight: 600;
  color: var(--text-muted); letter-spacing: 0.06em;
  text-transform: uppercase; margin-bottom: 5px;
}
.form-control {
  width: 100%; padding: 10px 12px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  font-size: 0.95rem; transition: border-color var(--transition);
}
.form-control:focus {
  outline: none; border-color: var(--gold);
}
.form-control::placeholder { color: var(--text-dim); }
select.form-control option { background: var(--bg3); }
textarea.form-control { resize: vertical; min-height: 80px; }

/* --- Search bar --------------------------------------------------- */
.search-bar {
  position: relative; margin-bottom: 16px;
}
.search-bar input {
  width: 100%; padding: 11px 12px 11px 40px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius-lg); color: var(--text); font-size: 0.95rem;
}
.search-bar input:focus { outline: none; border-color: var(--gold); }
.search-bar .search-icon {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--text-dim); pointer-events: none;
}
.search-bar .scan-btn {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  padding: 5px 8px; background: var(--gold); border-radius: 6px;
  color: #0f1117;
}

/* --- Section headers ---------------------------------------------- */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px; margin-top: 8px;
}
.section-title {
  font-family: 'Bitter', serif;
  font-size: 1.1rem; font-weight: 700; color: var(--gold);
}

/* --- Filters ------------------------------------------------------ */
.filter-bar {
  display: flex; gap: 8px; overflow-x: auto;
  scrollbar-width: none; margin-bottom: 14px;
  padding-bottom: 2px;
}
.filter-bar::-webkit-scrollbar { display: none; }
.filter-chip {
  flex-shrink: 0; padding: 5px 14px;
  border-radius: 20px; font-size: 0.78rem; font-weight: 600;
  border: 1px solid var(--border); color: var(--text-muted);
  background: var(--bg2); transition: all var(--transition);
}
.filter-chip.active { background: var(--gold); color: #0f1117; border-color: var(--gold); }

/* --- Scanner overlay ---------------------------------------------- */
#scanner-overlay {
  display: none; position: fixed; inset: 0; z-index: 200;
  background: #000; flex-direction: column;
}
#scanner-overlay.open { display: flex; }
#scanner-video {
  width: 100%; flex: 1; object-fit: cover;
}
.scanner-ui {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  pointer-events: none;
}
.scanner-frame {
  width: 260px; height: 160px;
  border: 2px solid var(--gold);
  border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.55);
  position: relative;
}
.scanner-line {
  position: absolute; left: 0; right: 0; top: 50%;
  height: 2px; background: var(--gold);
  animation: scan-line 1.8s ease-in-out infinite;
}
@keyframes scan-line {
  0%   { top: 10%; opacity: 1; }
  50%  { top: 90%; opacity: 1; }
  100% { top: 10%; opacity: 1; }
}
.scanner-label {
  margin-top: 24px; color: #fff; font-size: 0.9rem;
  text-shadow: 0 1px 4px #000;
}
.scanner-controls {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 20px; display: flex; flex-direction: column; gap: 12px;
  background: linear-gradient(transparent, rgba(0,0,0,0.8));
  pointer-events: all;
}
#scanner-manual {
  display: none;
  animation: slide-up 0.25s ease;
}
#scanner-manual.visible { display: block; }
@keyframes slide-up {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
#scanner-isbn-input {
  flex: 1; padding: 10px 12px;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: var(--radius); color: #fff;
  font-size: 1rem; font-family: inherit;
}
#scanner-isbn-input::placeholder { color: rgba(255,255,255,0.4); }
#scanner-isbn-input:focus { outline: none; border-color: var(--gold); }

/* --- Modal -------------------------------------------------------- */
.modal-backdrop {
  display: none; position: fixed; inset: 0; z-index: 150;
  background: rgba(0,0,0,0.7); align-items: flex-end;
}
.modal-backdrop.open { display: flex; }
@media (min-width: 600px) {
  .modal-backdrop { align-items: center; justify-content: center; }
}
.modal {
  background: var(--bg2); border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 20px; width: 100%; max-height: 90vh; overflow-y: auto;
  border-top: 1px solid var(--border);
}
@media (min-width: 600px) {
  .modal { border-radius: var(--radius-lg); max-width: 520px; }
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px;
}
.modal-title {
  font-family: 'Bitter', serif; font-size: 1.1rem;
  font-weight: 700; color: var(--gold);
}

/* --- Item detail --------------------------------------------------- */
.detail-cover {
  width: 100%; max-width: 180px; border-radius: var(--radius);
  border: 1px solid var(--border); margin: 0 auto 16px;
}
.detail-section { margin-bottom: 20px; }
.detail-field { margin-bottom: 10px; }
.detail-field-label {
  font-size: 0.72rem; font-weight: 600; color: var(--text-dim);
  letter-spacing: 0.07em; text-transform: uppercase; margin-bottom: 2px;
}
.detail-field-value { font-size: 0.92rem; color: var(--text); }

/* --- Login screen -------------------------------------------------- */
#login-screen {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 100vh; padding: 32px 24px;
  background: var(--bg);
}
.login-logo {
  font-family: 'Bitter', serif;
  font-size: 3rem; font-weight: 700; color: var(--gold);
  margin-bottom: 6px;
}
.login-tagline { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 40px; }
.login-box {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 28px 24px;
  width: 100%; max-width: 380px;
}

/* --- Toast notifications ------------------------------------------ */
#toast-container {
  position: fixed; bottom: calc(var(--nav-h) + 12px); left: 50%;
  transform: translateX(-50%); z-index: 300;
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none;
}
.toast {
  padding: 10px 20px; border-radius: 20px;
  font-size: 0.85rem; font-weight: 600;
  animation: toast-in 0.2s ease, toast-out 0.3s ease 2.7s forwards;
  white-space: nowrap;
}
.toast-success { background: var(--green);     color: #fff; }
.toast-error   { background: var(--red);       color: #fff; }
.toast-info    { background: var(--gold);      color: #0f1117; }
@keyframes toast-in  { from { opacity:0; transform: translateY(10px); } to { opacity:1; transform: translateY(0); } }
@keyframes toast-out { from { opacity:1; } to { opacity:0; } }

/* --- Loan card ---------------------------------------------------- */
.loan-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 14px;
  margin-bottom: 10px; display: flex; gap: 12px; align-items: center;
}
.loan-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--bg3); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-family: 'Bitter', serif; font-size: 1rem; color: var(--gold);
  flex-shrink: 0; font-weight: 700;
}

/* --- Empty state --------------------------------------------------- */
.empty-state {
  text-align: center; padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state svg { color: var(--text-dim); margin: 0 auto 16px; }
.empty-state h3 {
  font-family: 'Bitter', serif; font-size: 1.1rem;
  color: var(--text-muted); margin-bottom: 8px;
}

/* --- Loading spinner ---------------------------------------------- */
.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 32px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Admin page --------------------------------------------------- */
.admin-section { margin-bottom: 28px; }
.user-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; border-radius: var(--radius);
  background: var(--bg3); margin-bottom: 8px;
}
.user-row-name { flex: 1; font-weight: 500; }
.user-row-badge { font-size: 0.7rem; color: var(--gold); }

/* --- Responsive --------------------------------------------------- */
@media (min-width: 600px) {
  .items-grid {
    display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px;
  }
  .items-grid .card { margin-bottom: 0; }
}

/* --- Utility ------------------------------------------------------ */
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.flex { display: flex; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 12px; }
.flex-1 { flex: 1; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.82rem; }
.text-center { text-align: center; }
.hidden { display: none !important; }
.divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
