/* btrack — book tracker. Vanilla CSS, dark theme matching the other trackers. */

:root {
  --bg: #0f0f10;
  --panel: #1a1a1c;
  --panel-2: #141416;
  --panel-hover: #232325;
  --border: #2a2a2c;
  --text: #e8e8e8;
  --text-dim: #999;
  --muted: #888;
  --accent: #3ec8c0;            /* teal — distinct from rtrack's orange */
  --accent-2: #6fdbd2;
  --success: #6ee2a0;
  --warning: #ffd166;
  --danger: #e66;
  --reading: #5ab9ff;
  --radius: 8px;
}

* { box-sizing: border-box; }

/* Honor the HTML `hidden` attribute even on elements with explicit
   `display:` rules. Without this, .auth-overlay and .auth-form would
   stay visible after login because their display:flex overrides the
   user-agent [hidden]{display:none} rule. */
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.4;
}

body.unauth .container { visibility: hidden; }

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
}

header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0 1rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}
.header-title {
  font-weight: 700;
  font-size: 1.25rem;
  flex: 1;
  letter-spacing: 0.02em;
}
.header-actions { display: flex; gap: 0.5rem; }
.icon-btn {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 1rem;
}
.icon-btn:hover { background: var(--panel-hover); }

.tabs {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}
.tab {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
}
.tab.active {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
  font-weight: 600;
}

.search-bar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.search-bar input[type="search"] {
  flex: 1;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.95rem;
}
.search-bar select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius);
}

.search-bar button {
  background: var(--accent);
  color: #000;
  border: 1px solid var(--accent);
  padding: 0.55rem 0.95rem;
  border-radius: var(--radius);
  font-weight: 600;
  cursor: pointer;
}
.search-bar button:hover { background: var(--accent-2); border-color: var(--accent-2); }

.search-results-wrap {
  margin-bottom: 1rem;
}
.search-results-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 0.4rem;
  font-size: 0.85rem;
  color: var(--text-dim);
}
.search-results {
  display: flex;
  gap: 0.75rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.search-card {
  flex: 0 0 140px;
  background: var(--panel);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.search-card:hover { border-color: var(--text-dim); }
.search-card .cover-wrap {
  width: 100%;
  aspect-ratio: 2 / 3;
  background: var(--panel-hover);
  position: relative;
}
.search-card .cover-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.search-card .no-cover {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-dim);
  font-size: 0.7rem;
  text-align: center;
  padding: 0 0.5rem;
}
.search-card .card-tag {
  position: absolute;
  top: 0.3rem; left: 0.3rem;
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  background: rgba(0,0,0,0.7);
  color: var(--text);
}
.search-card-info { padding: 0.4rem 0.5rem 0.5rem; flex: 1; display: flex; flex-direction: column; gap: 0.25rem; }
.search-card-info .title {
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.2;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.search-card-info .meta {
  font-size: 0.7rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-card-info .add-btn {
  margin-top: auto;
  background: var(--accent);
  color: #000;
  border: 1px solid var(--accent);
  border-radius: 5px;
  padding: 0.3rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}
.search-card-info .add-btn:disabled {
  background: var(--panel-hover);
  color: var(--text-dim);
  border-color: var(--border);
  cursor: default;
}

.view-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.view-btn {
  background: var(--panel-2);
  color: var(--text-dim);
  border: none;
  padding: 0.5rem 0.7rem;
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
}
.view-btn + .view-btn { border-left: 1px solid var(--border); }
.view-btn.active { background: var(--accent); color: #000; }
.view-btn:not(.active):hover { background: var(--panel-hover); color: var(--text); }

.library {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.85rem;
}
.library.list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

/* ── list view rows ───────────────────────────────────────────────── */
.list .book-row {
  display: flex;
  gap: 0.7rem;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.7rem;
  cursor: pointer;
}
.list .book-row:hover { border-color: var(--accent); }
.list .book-row .row-cover {
  flex: 0 0 36px;
  width: 36px;
  height: 54px;
  border-radius: 3px;
  overflow: hidden;
  background: var(--panel-2);
}
.list .book-row .row-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.list .book-row .row-cover .no-cover { width: 100%; height: 100%; }
.list .book-row .row-info { flex: 1; min-width: 0; }
.list .book-row .row-title {
  font-weight: 600;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list .book-row .row-authors {
  font-size: 0.78rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list .book-row .row-tags {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
  margin-top: 0.15rem;
}
.list .book-row .row-actions {
  display: flex;
  gap: 0.3rem;
  flex-shrink: 0;
}
.list .book-row .quick-btn {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 5px;
  padding: 0.35rem 0.55rem;
  cursor: pointer;
  font-size: 0.78rem;
  white-space: nowrap;
}
.list .book-row .quick-btn:hover { color: var(--text); }
.list .book-row .quick-btn.on.q-reading { background: var(--reading); color: #000; border-color: var(--reading); }
.list .book-row .quick-btn.on.q-read    { background: var(--success); color: #000; border-color: var(--success); }

/* ── tag chips ────────────────────────────────────────────────────── */
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  font-size: 0.72rem;
  color: var(--text);
}
.tag-chip .tag-x {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0;
  font-size: 0.95rem;
  line-height: 1;
}
.tag-chip .tag-x:hover { color: var(--danger); }
.tag-input-row {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.35rem;
}
.autocomplete-wrap { position: relative; flex: 1; min-width: 0; }
.autocomplete-wrap input {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 5px;
  padding: 0.35rem 0.5rem;
  font-size: 0.85rem;
}
.suggest-list {
  position: absolute;
  top: 100%; left: 0; right: 0;
  margin: 0.2rem 0 0;
  padding: 0.2rem 0;
  list-style: none;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  max-height: 200px;
  overflow-y: auto;
  z-index: 10;
  box-shadow: 0 6px 12px rgba(0,0,0,0.35);
}
.suggest-list li {
  padding: 0.4rem 0.6rem;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text);
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}
.suggest-list li.active,
.suggest-list li:hover { background: var(--accent); color: #000; }
.suggest-list li.active .muted,
.suggest-list li:hover .muted { color: rgba(0,0,0,0.6); }
.tags-row {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
  align-items: center;
}
.book-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  transition: border-color 0.12s;
}
.book-card:hover { border-color: var(--accent); }
.book-cover {
  width: 100%;
  aspect-ratio: 2 / 3;
  border-radius: 4px;
  overflow: hidden;
  background: var(--panel-2);
}
.book-cover img { width: 100%; height: 100%; object-fit: cover; }
.book-title {
  font-weight: 600;
  font-size: 0.9rem;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.book-authors { font-size: 0.78rem; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badges { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.badge {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 600;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.badge-reading   { background: var(--reading); color: #000; border-color: var(--reading); }
.badge-read      { background: var(--success); color: #000; border-color: var(--success); }
.badge-watchlist { background: var(--warning); color: #000; border-color: var(--warning); }
.badge-owned     { background: var(--accent); color: #000; border-color: var(--accent); }
.badge-graphic   { background: #b07cff; color: #000; border-color: #b07cff; }
.badge-in-library { background: var(--success); color: #000; border-color: var(--success); }

.empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: 3rem 1rem;
  font-size: 0.95rem;
}

/* ── modals ──────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 1rem;
}
.modal {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  width: 100%;
  max-width: 700px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-sm { max-width: 480px; }
.modal-confirm { max-width: 360px; text-align: center; padding: 1.5rem; }
.modal-close {
  position: absolute;
  top: 0.6rem; right: 0.8rem;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}
.modal-title { margin: 0 0 0.6rem; font-size: 1.1rem; }

.detail-header {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
}
.detail-cover {
  flex: 0 0 140px;
  border-radius: 6px;
  overflow: hidden;
}
.detail-cover img { width: 100%; height: auto; display: block; }
.detail-info { flex: 1; min-width: 0; }
.detail-info h2 { margin: 0 0 0.4rem; font-size: 1.2rem; }
.meta-line {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 0.3rem;
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  align-items: center;
}
.meta-line a { color: var(--accent); text-decoration: none; }
.meta-line a:hover { text-decoration: underline; }
.meta-pill {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  font-size: 0.72rem;
}
.overview-wrap { margin-top: 0.6rem; }
.overview {
  font-size: 0.85rem;
  color: var(--text);
  line-height: 1.5;
  white-space: pre-wrap;
}
.overview.clamped {
  max-height: calc(1.5em * 5);
  overflow: hidden;
  position: relative;
}
.overview.clamped::after {
  content: '';
  position: absolute;
  inset: auto 0 0 0;
  height: 2em;
  background: linear-gradient(transparent, var(--panel));
  pointer-events: none;
}
.overview-toggle {
  display: inline-block;
  margin-top: 0.3rem;
  background: transparent;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  font-size: 0.82rem;
}
.overview-toggle:hover { text-decoration: underline; }

.detail-section { margin-top: 0.85rem; }
.form-label {
  display: block;
  font-size: 0.78rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.35rem;
}
.status-row { display: flex; gap: 0.4rem; }
.status-btn {
  flex: 1;
  padding: 0.55rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
}
.status-btn.active { background: var(--accent); color: #000; border-color: var(--accent); font-weight: 600; }

.toggles { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.toggle-pill {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.85rem;
}
.toggle-pill.on { background: var(--accent); color: #000; border-color: var(--accent); }

.rating-row { display: flex; gap: 0.25rem; }
.rating-star {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.rating-star.on { color: var(--warning); }

.date-row { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.date-row label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.78rem; color: var(--text-dim); }
.date-row input[type="date"] {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  font-size: 0.9rem;
}

textarea {
  width: 100%;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem;
  font-family: inherit;
  font-size: 0.9rem;
  resize: vertical;
}

.detail-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: space-between;
  flex-wrap: wrap;
  border-top: 1px solid var(--border);
  padding-top: 0.85rem;
}

/* ── buttons ─────────────────────────────────────────────────────── */
.btn-primary {
  background: var(--accent);
  color: #000;
  border: 1px solid var(--accent);
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
}
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn-primary:disabled { opacity: 0.6; cursor: default; }
.btn-ghost {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
}
.btn-ghost:hover { background: var(--panel-hover); }
.btn-danger {
  background: var(--danger);
  color: #000;
  border: 1px solid var(--danger);
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 600;
}
.btn-link {
  background: transparent;
  border: none;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
  font-size: inherit;
}

.confirm-actions {
  display: flex; gap: 0.5rem; justify-content: center;
  margin-top: 1rem;
}

/* ── auth overlay ────────────────────────────────────────────────── */
.auth-overlay {
  position: fixed; inset: 0;
  background: var(--bg);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.auth-panel {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}
.auth-panel h2 { margin: 0 0 1rem; }
.auth-panel p { margin: 0 0 1rem; color: var(--text-dim); text-align: center; }
.auth-cta {
  display: inline-block;
  text-align: center;
  text-decoration: none;
  width: 100%;
}
.auth-form { display: flex; flex-direction: column; gap: 0.6rem; }
.auth-form label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.8rem; color: var(--text-dim); }
.auth-form input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.55rem;
  border-radius: 6px;
  font-size: 0.95rem;
}
.auth-switch { font-size: 0.8rem; color: var(--text-dim); text-align: center; }
.auth-error { color: var(--danger); font-size: 0.85rem; margin-top: 0.5rem; }

/* ── admin invites ───────────────────────────────────────────────── */
.admin-invites { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.admin-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.5rem; }
.admin-head h3 { margin: 0; font-size: 0.95rem; }
.invite-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.3rem; }
.invite-row {
  display: flex; gap: 0.5rem; align-items: center;
  padding: 0.4rem 0.6rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
}
.invite-row code { font-family: ui-monospace, monospace; flex: 1; word-break: break-all; }
.muted { color: var(--text-dim); font-size: 0.85rem; }

/* ── toast ───────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 1rem; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.55rem 1.05rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { border-color: var(--danger); color: var(--danger); }

/* ── responsive ──────────────────────────────────────────────────── */
@media (max-width: 500px) {
  .library { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 0.5rem; }
  .detail-header { flex-direction: column; }
  .detail-cover { flex: 0 0 auto; max-width: 160px; margin: 0 auto; }
  .search-bar { flex-direction: column; }
  .search-bar select { width: 100%; }
}

/* ── mobile touch handling ───────────────────────────────────────── */
@media (pointer: coarse) {
  body {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    user-select: none;
    -webkit-user-select: none;
  }
  * { touch-action: manipulation; }
  input, textarea, [contenteditable], .overview {
    user-select: text;
    -webkit-user-select: text;
  }
}
