/* Shelfward — warm, paper-and-spine palette. Mobile-first. */
:root {
  --paper: #f6f1e7;
  --paper-2: #efe7d7;
  --ink: #2c2420;
  --ink-soft: #6b5f56;
  --spine: #3b2f2a;
  --accent: #9c5a3c;      /* worn leather / brick */
  --accent-2: #c07a4e;
  --line: #dcd0bd;
  --keep: #4a7c59;
  --sell: #b07c2e;
  --donate: #7c6f9c;
  --danger: #b23a3a;
  --shadow: 0 2px 10px rgba(60,40,20,0.12);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: ui-rounded, "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--paper);
  color: var(--ink);
  overscroll-behavior-y: none;
}

/* Views */
.view { display: none; min-height: 100dvh; flex-direction: column; padding-bottom: env(safe-area-inset-bottom); }
.view.active { display: flex; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  background: var(--spine); color: var(--paper);
  box-shadow: var(--shadow);
}
.brand { font-size: 1.35rem; font-weight: 800; letter-spacing: 0.02em; }
.brand-sm { font-size: 1.05rem; font-weight: 700; flex: 1; text-align: center; }
.icon-btn { background: rgba(255,255,255,0.12); color: var(--paper); border: none; width: 38px; height: 38px; border-radius: 10px; font-size: 1.2rem; cursor: pointer; }
.text-btn { background: none; border: none; color: var(--paper); font-size: 1rem; font-weight: 600; cursor: pointer; padding: 6px 4px; }
.text-btn.primary { color: var(--accent-2); font-weight: 800; }

/* Toolbar */
.toolbar { padding: 12px 16px 4px; display: flex; flex-direction: column; gap: 10px; }
.search {
  width: 100%; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 12px;
  font-size: 1rem; background: #fff; color: var(--ink); outline: none;
}
.search:focus { border-color: var(--accent); }
.filters { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.chip {
  flex: 0 0 auto; padding: 7px 14px; border-radius: 20px; border: 1.5px solid var(--line);
  background: #fff; color: var(--ink-soft); font-size: 0.85rem; font-weight: 600; cursor: pointer;
}
.chip.active { background: var(--spine); color: var(--paper); border-color: var(--spine); }

.count-line { padding: 4px 16px 8px; color: var(--ink-soft); font-size: 0.82rem; }

/* Grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; padding: 8px 16px 120px; }
.card { background: #fff; border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); cursor: pointer; display: flex; flex-direction: column; }
.card-img-wrap { aspect-ratio: 2 / 3; background: var(--paper-2); position: relative; overflow: hidden; }
.card-img-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-noimg { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; color: var(--ink-soft); font-size: 2rem; }
.card-tri { position: absolute; top: 8px; left: 8px; font-size: 0.65rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em; padding: 3px 7px; border-radius: 6px; color: #fff; }
.tri-keep { background: var(--keep); } .tri-sell { background: var(--sell); } .tri-donate { background: var(--donate); } .tri-undecided { background: #a89a88; }
.card-body { padding: 9px 10px 11px; }
.card-title { font-size: 0.85rem; font-weight: 700; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-author { font-size: 0.75rem; color: var(--ink-soft); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Empty state */
.empty { display: none; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 60px 30px; color: var(--ink-soft); flex: 1; }
.empty.show { display: flex; }
.empty-emoji { font-size: 3.5rem; margin-bottom: 12px; }
.empty-title { font-size: 1.2rem; font-weight: 700; color: var(--ink); }
.empty-sub { margin-top: 6px; font-size: 0.95rem; }

/* FAB */
.fab {
  position: fixed; right: 20px; bottom: calc(env(safe-area-inset-bottom) + 22px); z-index: 30;
  width: 60px; height: 60px; border-radius: 50%; border: none;
  background: var(--accent); color: #fff; font-size: 2rem; line-height: 1; cursor: pointer;
  box-shadow: 0 6px 18px rgba(120,60,30,0.4);
}
.fab:active { transform: scale(0.94); }
#view-edit .fab, #view-detail .fab { display: none; }

/* Edit form */
.form-scroll { flex: 1; overflow-y: auto; padding: 16px; }
.photo-drop { display: block; width: 100%; border: 2px dashed var(--line); border-radius: 16px; background: #fff; overflow: hidden; cursor: pointer; margin-bottom: 14px; }
.photo-placeholder { padding: 42px 20px; text-align: center; color: var(--ink-soft); }
.cam-emoji { font-size: 2.6rem; }
.photo-hint { font-weight: 700; color: var(--ink); margin-top: 8px; font-size: 1.02rem; }
.photo-subhint { font-size: 0.85rem; margin-top: 3px; }
.photo-preview { width: 100%; max-height: 340px; object-fit: contain; background: var(--paper-2); display: block; }
.remove-photo-btn { display: block; margin: -6px 0 12px auto; padding: 7px 14px; border: 1.5px solid var(--line); background: #fff; color: var(--danger); border-radius: 10px; font-size: 0.85rem; font-weight: 700; cursor: pointer; }
.remove-photo-btn:active { background: var(--paper-2); }
.scan-status { margin: -6px 0 14px; padding: 9px 12px; border-radius: 10px; font-size: 0.85rem; font-weight: 600; text-align: center; }
.scan-status.working { background: #fff4e2; color: #8a5a1e; }
.scan-status.found { background: #e7f2ea; color: #2f6b45; }
.scan-status.none { background: var(--paper-2); color: var(--ink-soft); }

.lookup { display: flex; gap: 8px; margin-bottom: 8px; }
.lookup-input { flex: 1; padding: 11px 13px; border: 1.5px solid var(--line); border-radius: 11px; font-size: 0.95rem; background: #fff; color: var(--ink); outline: none; }
.lookup-input:focus { border-color: var(--accent); }
.lookup-btn { padding: 0 16px; border: none; border-radius: 11px; background: var(--spine); color: var(--paper); font-weight: 700; cursor: pointer; }
.lookup-results { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.lr { display: flex; gap: 10px; padding: 8px; background: #fff; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; align-items: center; }
.lr:active { background: var(--paper-2); }
.lr img { width: 38px; height: 56px; object-fit: cover; border-radius: 4px; background: var(--paper-2); flex: 0 0 auto; }
.lr-noimg { width: 38px; height: 56px; border-radius: 4px; background: var(--paper-2); display: flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.lr-txt { min-width: 0; }
.lr-title { font-size: 0.88rem; font-weight: 700; line-height: 1.2; }
.lr-meta { font-size: 0.78rem; color: var(--ink-soft); margin-top: 2px; }

.field { margin-bottom: 13px; display: flex; flex-direction: column; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; min-width: 0; }
.field label { font-size: 0.8rem; font-weight: 700; color: var(--ink-soft); margin-bottom: 5px; }
.field input, .field textarea { padding: 11px 13px; border: 1.5px solid var(--line); border-radius: 11px; font-size: 1rem; background: #fff; color: var(--ink); outline: none; font-family: inherit; }
.field input:focus, .field textarea:focus { border-color: var(--accent); }
.checkbox-field { justify-content: flex-end; }
.checkbox-label { display: flex; align-items: center; gap: 8px; font-size: 0.95rem !important; font-weight: 600 !important; color: var(--ink) !important; cursor: pointer; padding: 10px 0; }
.checkbox-label input { width: 20px; height: 20px; accent-color: var(--accent); }

.triage-picker { display: flex; gap: 8px; }
.tri { flex: 1; padding: 11px 4px; border-radius: 11px; border: 1.5px solid var(--line); background: #fff; color: var(--ink-soft); font-weight: 700; font-size: 0.85rem; cursor: pointer; }
.tri.active[data-v="keep"] { background: var(--keep); color: #fff; border-color: var(--keep); }
.tri.active[data-v="sell"] { background: var(--sell); color: #fff; border-color: var(--sell); }
.tri.active[data-v="donate"] { background: var(--donate); color: #fff; border-color: var(--donate); }
.tri.active[data-v="undecided"] { background: #a89a88; color: #fff; border-color: #a89a88; }

.delete-btn { width: 100%; margin-top: 8px; padding: 13px; border: 1.5px solid var(--danger); background: #fff; color: var(--danger); border-radius: 12px; font-weight: 700; cursor: pointer; }
.form-footer-space { height: 40px; }

/* Detail */
.detail-body { flex: 1; overflow-y: auto; padding: 0 0 120px; }
.detail-hero { width: 100%; max-height: 60vh; object-fit: contain; background: var(--spine); display: block; }
.detail-hero-empty { width: 100%; height: 240px; background: var(--paper-2); display: flex; align-items: center; justify-content: center; font-size: 4rem; color: var(--ink-soft); }
.detail-content { padding: 18px 18px; }
.detail-title { font-size: 1.5rem; font-weight: 800; line-height: 1.2; }
.detail-author { font-size: 1.05rem; color: var(--ink-soft); margin-top: 4px; }
.detail-tri { display: inline-block; margin-top: 12px; font-size: 0.72rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; padding: 5px 11px; border-radius: 7px; color: #fff; }
.detail-rows { margin-top: 18px; border-top: 1px solid var(--line); }
.drow { display: flex; padding: 11px 2px; border-bottom: 1px solid var(--line); font-size: 0.95rem; }
.drow-k { width: 120px; flex: 0 0 auto; color: var(--ink-soft); font-weight: 600; }
.drow-v { flex: 1; font-weight: 600; }
.detail-notes { margin-top: 16px; padding: 14px; background: #fff; border-radius: 12px; border: 1px solid var(--line); font-size: 0.95rem; line-height: 1.5; white-space: pre-wrap; }
.detail-value-hint { margin-top: 16px; padding: 14px; background: #fff4e2; border-radius: 12px; font-size: 0.9rem; line-height: 1.5; }
.detail-value-hint a { color: var(--accent); font-weight: 700; }

.toast { position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%); background: var(--spine); color: var(--paper); padding: 11px 20px; border-radius: 30px; font-size: 0.9rem; font-weight: 600; z-index: 100; box-shadow: var(--shadow); opacity: 0; transition: opacity 0.25s; pointer-events: none; }
.toast.show { opacity: 1; }
