/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.5;
  color: #1a1a1a;
  background: #f5f5f5;
  min-height: 100vh;
}

#app {
  max-width: 600px;
  margin: 0 auto;
  padding: 1rem;
}

/* ── Footer ───────────────────────────────────────────────────────────────── */
.site-footer {
  max-width: 600px;
  margin: 0 auto;
  padding: 1rem 1rem 2rem;
  text-align: center;
  font-size: 0.875rem;
  color: #595959; /* 7:1 on #f5f5f5 */
}

/* ── Touch targets ────────────────────────────────────────────────────────── */
button, a, [role="button"] {
  min-height: 44px;
  min-width: 44px;
  cursor: pointer;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 0.375rem;
  font-size: 1rem;
  font-weight: 500;
  transition: opacity 0.15s;
}

button:active { opacity: 0.8; }

.btn-primary {
  background: #2563eb;
  color: #fff;
}

.btn-secondary {
  background: #e5e7eb;
  color: #1a1a1a;
}

.btn-danger {
  background: #dc2626;
  color: #fff;
}

/* ── Inputs ───────────────────────────────────────────────────────────────── */
input[type="text"],
input[type="search"] {
  width: 100%;
  padding: 0.625rem 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: 0.375rem;
  font-size: 1rem;
}

input[type="search"]:focus,
input[type="text"]:focus {
  outline: 2px solid #2563eb;
  outline-offset: 1px;
}

input[aria-invalid="true"] {
  border-color: #dc2626;
}

/* ── Utility ──────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Warning banner (8.7) ─────────────────────────────────────────────────── */
.warning-banner {
  background: #fef3c7;
  border: 1px solid #f59e0b;
  border-radius: 0.375rem;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  color: #92400e;
}

/* ── App header ───────────────────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.app-header h1 {
  font-size: 1.25rem;
  font-weight: 700;
}

/* ── Placeholder ──────────────────────────────────────────────────────────── */
.placeholder {
  text-align: center;
  color: #6b7280;
  padding: 3rem 1rem;
  font-size: 1rem;
}

/* ── List toolbar (search + export) ───────────────────────────────────────── */
.list-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.list-toolbar__search { flex: 1; min-width: 0; }

.list-toolbar__export { flex-shrink: 0; }

/* ── Sort bar ─────────────────────────────────────────────────────────────── */
.sort-bar {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.sort-bar__label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-right: 0.25rem;
}

.sort-bar__btn {
  padding: 0.25rem 0.625rem;
  font-size: 0.8rem;
  min-height: 32px;
  background: #e5e7eb;
  color: #374151;
  border-radius: 999px;
}

.sort-bar__btn--active {
  background: #2563eb;
  color: #fff;
}

/* ── Book spine stack ─────────────────────────────────────────────────────── */
.book-stack-section {
  margin-bottom: 1.5rem;
}

.book-stack {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.book-spine {
  position: relative;
  border-radius: 3px 6px 6px 3px;
  box-shadow: 2px 2px 6px rgba(0,0,0,0.18), inset -3px 0 6px rgba(0,0,0,0.12);
  overflow: hidden;
  transition: transform 0.12s, box-shadow 0.12s;
}

.book-spine:hover {
  transform: translateX(4px);
  box-shadow: 4px 3px 10px rgba(0,0,0,0.22), inset -3px 0 6px rgba(0,0,0,0.12);
}

.book-spine__btn {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  height: 100%;
  padding: 0 3.75rem 0 0.625rem;
  background: transparent;
  color: rgba(0,0,0,0.75);
  text-align: left;
  border-radius: 0;
  min-height: unset;
  overflow: hidden;
}

.book-spine__title {
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  line-height: 1.2;
}

.book-spine__author {
  font-size: 0.7rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0.7;
  flex-shrink: 0;
  max-width: 35%;
}

.book-spine__delete {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 28px;
  min-width: unset;
  min-height: unset;
  background: rgba(0,0,0,0.15);
  color: rgba(0,0,0,0.5);
  border-radius: 0;
  font-size: 0.7rem;
  padding: 0;
  opacity: 0;
  transition: opacity 0.15s;
}

.book-spine:hover .book-spine__delete { opacity: 1; }
.book-spine__delete:hover { background: rgba(220,38,38,0.7); color: #fff; }

/* Read status eye — always visible on a dark chip (≥ 3:1 against every pastel
   spine colour); unread = greyed eye + white strike line, not dimmed. */
.book-spine__read {
  position: absolute;
  right: 28px;
  top: 0;
  bottom: 0;
  width: 28px;
  min-width: unset;
  min-height: unset;
  padding: 0;
  background: radial-gradient(circle, #1f2937 0 10px, transparent 10.5px);
  color: #fff;
  border-radius: 0;
  font-size: 0.8rem;
  line-height: 1;
}

.book-spine__read:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: -2px;
}

.book-spine__read--unread { filter: grayscale(1); }

.book-spine__read--unread::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 18px;
  height: 2px;
  background: #fff;
  box-shadow: 0 0 0 1px #1f2937;
  transform: translate(-50%, -50%) rotate(-45deg);
  pointer-events: none;
}

@media (hover: none), (pointer: coarse) {
  .book-spine__delete {
    opacity: 1;
    background: rgba(0,0,0,0.25);
    color: rgba(0,0,0,0.6);
  }
}

/* ── Detail list (8.2) ────────────────────────────────────────────────────── */
.detail-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.375rem 1rem;
}

.detail-list dt {
  font-weight: 600;
  color: #6b7280;
  font-size: 0.875rem;
  white-space: nowrap;
}

.detail-list dd {
  font-size: 0.9375rem;
  word-break: break-word;
}

/* ── Viewfinder (8.3) ─────────────────────────────────────────────────────── */
.viewfinder {
  position: relative;
  background: #000;
  border-radius: 0.5rem;
  overflow: hidden;
  aspect-ratio: 4/3;
  margin-bottom: 1rem;
}

.viewfinder__video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.scanner-fallback {
  padding: 0.5rem 0;
}

.scanner-fallback__msg {
  color: #6b7280;
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}

/* ── Manual entry form (8.4) ──────────────────────────────────────────────── */
.manual-entry-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1.25rem;
}

.manual-entry-form label {
  font-size: 0.9rem;
  font-weight: 500;
  color: #374151;
}

.field-error {
  font-size: 0.8rem;
  color: #dc2626;
}

/* ── Dialog actions (8.5, 8.6) ────────────────────────────────────────────── */
.dialog-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.25rem;
  flex-wrap: wrap;
}

.dialog-actions button { flex: 1; }

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 0;
}

@media (min-width: 480px) {
  .modal-overlay { align-items: center; padding: 1rem; }
}

.modal {
  background: #fff;
  border-radius: 1rem 1rem 0 0;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.25rem 1rem 2rem;
}

@media (min-width: 480px) {
  .modal { border-radius: 0.75rem; padding: 1.5rem; }
}

/* Fullscreen modal — mobile scanner & edit */
.modal-overlay--fullscreen {
  align-items: stretch;
  padding: 0;
  background: #000;
}

.modal--fullscreen {
  border-radius: 0;
  max-width: 100%;
  max-height: 100%;
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
  padding: 0;
}

.modal--fullscreen .modal__header {
  padding: 0.75rem 1rem;
  background: #111;
  color: #fff;
  flex-shrink: 0;
}

.modal--fullscreen .modal__header h2 { color: #fff; }
.modal--fullscreen .modal__close { color: #9ca3af; }
.modal--fullscreen .modal__close:hover { color: #fff; }

.modal--fullscreen .modal__body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  background: #fff;
}

.modal--fullscreen .viewfinder {
  border-radius: 0;
  aspect-ratio: unset;
  flex: 1;
  min-height: 0;
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.modal__header h2 { font-size: 1.125rem; font-weight: 700; }

.modal__close {
  background: transparent;
  color: #6b7280;
  font-size: 1rem;
  min-width: 44px;
  min-height: 44px;
}

.modal__close:hover { color: #1a1a1a; }

/* ── Toast notifications ──────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 200;
  pointer-events: none;
  width: min(90vw, 360px);
}

.toast {
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  animation: toast-in 0.2s ease;
}

.toast--info    { background: #1e40af; color: #fff; }
.toast--success { background: #15803d; color: #fff; }
.toast--error   { background: #dc2626; color: #fff; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Scan controls (continuous + duplicate) ───────────────────────────────── */
.scan-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.scan-controls__toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  cursor: pointer;
  min-height: 44px;
  padding: 0 0.25rem;
  font-size: 1.1rem;
  user-select: none;
}

.scan-controls__toggle input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  cursor: pointer;
}

.scan-controls__dup-select {
  height: 44px;
  padding: 0 0.5rem;
  border: 1px solid #d1d5db;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  background: #fff;
  cursor: pointer;
}

/* Flash effect when a code is detected in continuous mode */
.viewfinder--detected::after {
  content: '';
  position: absolute;
  inset: 0;
  border: 3px solid #22c55e;
  border-radius: 0.5rem;
  animation: detected-flash 1.5s ease forwards;
  pointer-events: none;
}

@keyframes detected-flash {
  0%   { opacity: 1; }
  100% { opacity: 0; }
}

/* ── Scan result card (shown in viewfinder after detection) ───────────────── */
.scan-result-card {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  color: #fff;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 1.25rem 1rem;
  text-align: center;
  gap: 0.375rem;
  border-radius: 0.5rem;
  animation: card-in 0.2s ease;
  z-index: 10;
}

@keyframes card-in {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1); }
}

.scan-result-card--loading {
  font-size: 1rem;
  color: #d1d5db;
}

.scan-result-card__title {
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.3;
}

.scan-result-card__authors {
  font-size: 0.9rem;
  color: #d1d5db;
}

.scan-result-card__meta {
  font-size: 0.8rem;
  color: #9ca3af;
}

.scan-result-card__dup-label {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: #fbbf24;
  font-weight: 600;
}

.scan-result-card__actions {
  display: flex;
  gap: 0.625rem;
  margin-top: 0.75rem;
  width: 100%;
  justify-content: center;
}

.scan-result-card__actions button {
  flex: 1;
  max-width: 140px;
  font-size: 0.9rem;
}


.manual-section {
  margin-top: 2rem;
  padding-top: 1.25rem;
  border-top: 1px solid #e5e7eb;
}

.manual-section__heading {
  font-size: 0.9rem;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.75rem;
}

/* ── Edit form ────────────────────────────────────────────────────────────── */
.edit-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.edit-form__label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: #374151;
}

.edit-form__input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: 0.375rem;
  font-size: 1rem;
  background: #fff;
}

.edit-form__input--readonly {
  background: #f3f4f6;
  color: #6b7280;
  cursor: default;
}

select.edit-form__input {
  height: 44px;
  cursor: pointer;
}

.edit-form__dims {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  border: none;
  padding: 0;
  margin: 0;
}

.edit-form__dims .field-error { grid-column: 1 / -1; }

.edit-form__dims legend {
  font-size: 0.875rem;
  font-weight: 500;
  color: #374151;
  margin-bottom: 0.25rem;
}

.edit-form__checkbox {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  min-height: 44px;
  font-size: 0.9375rem;
  font-weight: 500;
  color: #374151;
  cursor: pointer;
}

.edit-form__checkbox input[type="checkbox"] {
  width: 1.25rem;
  height: 1.25rem;
  cursor: pointer;
}
