/* Styl graficzny 1:1 ze stream_agent: ciemny motyw, bursztynowy akcent,
   zaokrąglone kafle. Sekcje specyficzne dla książek dochodzą etapami. */

:root {
  --bg: #0b0d12;
  --bg-elev: #141822;
  --bg-elev-2: #1b2130;
  --line: #262d3d;
  --text: #eef1f7;
  --muted: #8b94a8;
  --accent: #f2b544;
  --accent-ink: #1a1305;
  --danger: #ef5b5b;
  --ok: #4ade80;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* Atrybut [hidden] to w arkuszu przeglądarki zwykłe `display: none`, więc
   przegrywa z każdą własną regułą `display` (np. `.gate { display: grid }`).
   Bez tego elementy chowane z JavaScriptu zostawałyby na ekranie. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: radial-gradient(1200px 600px at 80% -10%, #1d2537 0%, var(--bg) 55%) fixed;
  color: var(--text);
  font: 15px/1.5 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1.05rem; }
.muted { color: var(--muted); margin: 2px 0 0; font-size: .82rem; }

/* ------------------------------- topbar -------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  padding: 14px clamp(16px, 4vw, 36px);
  background: rgba(11, 13, 18, .82);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; gap: 12px; align-items: center; }
.brand-mark { font-size: 28px; }

.topbar-actions { display: flex; gap: 10px; align-items: center; flex: 1 1 320px; justify-content: flex-end; }

.search { position: relative; flex: 1 1 260px; max-width: 420px; }
.search input {
  width: 100%;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text);
  font-size: .92rem;
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 30;
}

.result {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px;
  border-radius: 10px;
}
.result:hover { background: var(--bg-elev-2); }
.result img, .result .thumb-fallback { width: 40px; height: 58px; border-radius: 6px; object-fit: cover; }
.result strong { display: block; font-size: .9rem; }
.result small { color: var(--muted); }

/* -------------------------------- layout ------------------------------- */
main {
  max-width: 1680px;
  margin: 0 auto;
  /* env(safe-area-inset-*) — margines na „notch” i pasek gestów w telefonie. */
  padding: 24px max(clamp(16px, 3vw, 32px), env(safe-area-inset-left)) 64px;
  display: grid;
  gap: 20px;
}

.panel {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
}

.panel-head {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.badge {
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: .78rem;
  font-weight: 700;
}

/* -------------------------------- buttons ------------------------------ */
.btn {
  border: 1px solid var(--line);
  background: var(--bg-elev-2);
  color: var(--text);
  border-radius: 999px;
  padding: 9px 16px;
  font-size: .87rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform .08s ease, background .15s ease, border-color .15s ease;
}
.btn:hover { background: #232b3c; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #ffc75a; }
.btn-ghost { background: transparent; }
.btn-small { padding: 6px 12px; font-size: .8rem; }
.btn[disabled] { opacity: .55; cursor: progress; }

.chip {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: .84rem;
  cursor: pointer;
}
.chip.is-active { background: var(--text); color: #0b0d12; border-color: var(--text); font-weight: 650; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }

.empty { color: var(--muted); font-size: .88rem; padding: 10px 0; }

.thumb-fallback {
  display: grid;
  place-items: center;
  background: linear-gradient(150deg, #2b3346, #3d4a63);
  color: var(--muted);
  font-size: 1.1rem;
  font-weight: 700;
}

/* --------------------------- plansza główna ----------------------------- */
.stack { display: grid; gap: 20px; }

.board-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

/* ------------------------- zarządzanie półkami --------------------------- */
.shelves-head { grid-template-columns: 1fr; }

.shelf-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: center;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-elev-2);
  margin-bottom: 8px;
}
.shelf-row strong { font-size: .9rem; }
.shelf-row small { color: var(--muted); font-size: .76rem; display: block; }

.shelf-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.shelf-form input {
  width: 100%;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-elev-2);
  color: var(--text);
  font: inherit;
}
.shelf-form input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 10px;
}

.card {
  position: relative;
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 11px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-elev-2);
  cursor: pointer;
  text-align: left;
  width: 100%;
  font: inherit;
  color: inherit;
  transition: border-color .15s ease, background .15s ease;
}
.card:hover { background: #232b3c; border-color: #38425a; }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.card .thumb, .card .thumb-fallback { width: 48px; height: 70px; border-radius: 8px; object-fit: cover; }
.card h3 { font-size: .95rem; }
.card .sub { color: var(--muted); font-size: .78rem; margin: 2px 0 6px; }

.shelf-tag {
  display: inline-block;
  padding: 2px 8px;
  margin: 0 4px 4px 0;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
  background: rgba(242, 181, 68, .16);
  color: var(--accent);
  border: 1px solid rgba(242, 181, 68, .3);
}

/* ------------------------- dialog szczegółów ----------------------------- */
.detail-hero {
  position: relative;
  display: grid;
  grid-template-columns: 116px 1fr;
  gap: 16px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}
.detail-hero img, .detail-hero .thumb-fallback { width: 116px; height: 170px; border-radius: 12px; object-fit: cover; }
.detail-title { min-width: 0; }
.detail-title h2 { font-size: 1.15rem; padding-right: 40px; }
.detail-original { color: var(--muted); font-size: .84rem; margin: 3px 0 0; }

.detail-section { padding: 16px 18px; border-bottom: 1px solid var(--line); }
.detail-section:last-child { border-bottom: 0; }
.detail-section h3 {
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin-bottom: 8px;
}
.detail-overview { margin: 0; font-size: .9rem; line-height: 1.6; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; padding: 14px 18px; }

.shelf-checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px; }
.shelf-checks label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-elev-2);
  font-size: .86rem;
  cursor: pointer;
}
.shelf-checks label:has(input:checked) { border-color: var(--accent); color: var(--accent); }
.shelf-checks input { accent-color: var(--accent); }

.detail-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.detail-fact { background: var(--bg-elev-2); border: 1px solid var(--line); border-radius: 12px; padding: 9px 11px; }
.detail-fact dt { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; }
.detail-fact dd { margin: 3px 0 0; font-size: .88rem; font-weight: 600; }

/* ------------------------- widok „Przeczytane” --------------------------- */
.read-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 14px;
}

.read-tile {
  display: grid;
  gap: 7px;
  align-content: start;
  cursor: pointer;
  border: 0;
  background: none;
  padding: 0;
  font: inherit;
  color: inherit;
  text-align: left;
}
.read-tile img, .read-tile .thumb-fallback {
  width: 100%;
  aspect-ratio: 2 / 3;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid var(--line);
}
.read-tile:hover img, .read-tile:hover .thumb-fallback { outline: 2px solid var(--accent); outline-offset: 1px; }
.read-tile strong { font-size: .8rem; line-height: 1.3; }
.read-tile small { color: var(--muted); font-size: .72rem; }

/* ------------------------- brama logowania ------------------------------ */
.gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: radial-gradient(900px 500px at 50% 0%, #1d2537 0%, var(--bg) 60%);
}
body.is-locked { overflow: hidden; }

.gate-card {
  width: min(400px, 100%);
  display: grid;
  gap: 12px;
  padding: 26px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
}
.gate-brand { display: flex; align-items: center; gap: 10px; }
.gate-card .muted { margin: 0 0 4px; }

.field { display: grid; gap: 5px; }
.field span { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.field input, .admin-form input, .admin-form select, .admin-user select {
  width: 100%;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-elev-2);
  color: var(--text);
  font: inherit;
}
.field input:focus, .admin-form input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.gate-error {
  margin: 0;
  padding: 9px 11px;
  border-radius: 10px;
  background: rgba(239, 91, 91, .12);
  border: 1px solid rgba(239, 91, 91, .35);
  color: var(--danger);
  font-size: .85rem;
}

/* --------------------------- panel kont --------------------------------- */
.admin-user {
  display: grid;
  grid-template-columns: 1fr auto auto auto auto;
  gap: 8px;
  align-items: center;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-elev-2);
  margin-bottom: 8px;
}
.admin-user.is-off { opacity: .55; }
.admin-who { min-width: 0; }
.admin-who strong { display: block; font-size: .9rem; }
.admin-who small { color: var(--muted); font-size: .76rem; }
.admin-user select { width: auto; padding: 6px 8px; font-size: .8rem; }

.admin-form { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.admin-form button { grid-column: 1 / -1; }

@media (max-width: 700px) {
  .admin-user { grid-template-columns: 1fr 1fr; }
  .admin-who { grid-column: 1 / -1; }
}

/* --------------------------------- toast ------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: 999px;
  padding: 10px 20px;
  font-size: .88rem;
  z-index: 50;
}

/* ------------------------------ modale --------------------------------- */
.modal {
  width: min(680px, calc(100vw - 32px));
  max-height: min(86vh, 900px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--bg-elev);
  color: var(--text);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.modal::backdrop { background: rgba(4, 6, 10, .72); backdrop-filter: blur(4px); }
.modal-body { max-height: inherit; overflow-y: auto; overscroll-behavior: contain; }

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, .35);
  color: var(--text);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
}
.modal-close:hover { background: var(--bg-elev-2); }

/* ------------------------------ responsywność --------------------------- */
@media (max-width: 700px) {
  main { gap: 16px; padding-top: 16px; }
  .topbar { flex-direction: column; align-items: stretch; gap: 10px; }
  /* flex-basis 320px z układu poziomego staje się w kolumnie bazą WYSOKOŚCI
     i wybija pustą dziurę na pół ekranu — w pionie liczy się tylko treść. */
  .topbar-actions { flex: 0 0 auto; justify-content: flex-start; flex-wrap: wrap; }
  .search { max-width: none; flex: 1 1 100%; }
  .modal { width: 100vw; max-width: 100vw; max-height: 92vh; border-radius: 18px 18px 0 0; margin-bottom: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
