:root {
  --bg: #1c1c1a;
  --bg-2: #232320;
  --card: #26261f;
  --card-2: #2e2e26;
  --line: #3a3a30;
  --text: #ece8df;
  --muted: #9d988a;
  --accent: #c9a35a;
  --accent-2: #d9b878;
  --danger: #c66;
  --green: #7aa86b;
  --blue: #6f93c0;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  font-weight: 300;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, h3 { font-family: "Playfair Display", Georgia, serif; font-weight: 600; margin: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: .85rem; }
.spacer { flex: 1; }
hr { border: none; border-top: 1px solid var(--line); margin: 6px 0; }

/* ---------- Botões ---------- */
.btn {
  font-family: inherit; font-size: .9rem; font-weight: 500;
  background: var(--card-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 14px; cursor: pointer; transition: .15s;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); color: #1c1c1a; border-color: var(--accent); font-weight: 600; }
.btn-primary:hover { background: var(--accent-2); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: rgba(204,102,102,.12); }
.btn-link { background: none; border: none; color: var(--accent); padding: 6px; }
.btn-icon { padding: 8px 11px; line-height: 1; }

input, select, textarea {
  font-family: inherit; font-size: .92rem; font-weight: 300;
  background: var(--bg-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
label { display: flex; flex-direction: column; gap: 6px; font-size: .8rem; color: var(--muted); }

/* ---------- Tela de login ---------- */
.auth-screen { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card {
  width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 32px 28px; box-shadow: var(--shadow);
}
.auth-brand { text-align: center; margin-bottom: 26px; }
.auth-logo { font-size: 2.6rem; }
.auth-brand h1 { font-size: 1.7rem; margin: 8px 0 4px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form .btn-primary { margin-top: 6px; }
.auth-error { color: var(--danger); font-size: .82rem; margin: 0; }
.local-note { text-align: center; margin-top: 18px; line-height: 1.4; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 18px; background: rgba(28,28,26,.85); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding-top: calc(12px + env(safe-area-inset-top));
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.brand { font-family: "Playfair Display", serif; font-weight: 600; font-size: 1.15rem; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.sync-pill { font-size: .7rem; color: var(--muted); }
.sync-pill.ok { color: var(--green); }
.sync-pill.off { color: var(--muted); }
.sync-pill.err { color: var(--danger); }

.menu { position: relative; }
.menu-dropdown {
  position: absolute; right: 0; top: 110%; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow); padding: 6px; min-width: 210px; display: flex; flex-direction: column;
}
.menu-dropdown button { background: none; border: none; color: var(--text); text-align: left; padding: 10px 12px; border-radius: 8px; cursor: pointer; font-size: .9rem; }
.menu-dropdown button:hover { background: var(--card-2); }
.menu-user { padding: 4px 12px; }

/* ---------- Estatísticas ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; padding: 18px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stat .num { font-family: "Playfair Display", serif; font-size: 1.9rem; font-weight: 600; color: var(--accent); }
.stat .lbl { color: var(--muted); font-size: .78rem; margin-top: 2px; }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; gap: 10px; padding: 0 18px 14px; flex-wrap: wrap; align-items: center; }
.toolbar #search { flex: 1; min-width: 200px; }
.toolbar select { width: auto; }
.view-toggle { display: flex; gap: 4px; }
.view-toggle button { background: var(--card-2); border: 1px solid var(--line); color: var(--muted); border-radius: 8px; padding: 8px 11px; cursor: pointer; }
.view-toggle button.active { color: var(--accent); border-color: var(--accent); }

/* ---------- Coleção ---------- */
.collection { padding: 0 18px 60px; }
.collection.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 18px; }
.collection.list { display: flex; flex-direction: column; gap: 10px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; cursor: pointer; transition: .15s; display: flex; flex-direction: column; }
.card:hover { border-color: var(--accent); transform: translateY(-2px); }
.card .cover { aspect-ratio: 2/3; background: var(--card-2); display: grid; place-items: center; overflow: hidden; }
.card .cover img { width: 100%; height: 100%; object-fit: cover; }
.card .cover .ph { color: var(--muted); font-size: .75rem; text-align: center; padding: 10px; }
.card .info { padding: 10px 12px; }
.card .info .t { font-weight: 500; font-size: .9rem; line-height: 1.25; }
.card .info .a { color: var(--muted); font-size: .78rem; margin-top: 3px; }
.card .badges { display: flex; gap: 6px; align-items: center; margin-top: 8px; flex-wrap: wrap; }

.badge { font-size: .68rem; padding: 2px 8px; border-radius: 20px; border: 1px solid var(--line); color: var(--muted); }
.badge.s-lido { color: var(--green); border-color: var(--green); }
.badge.s-lendo { color: var(--blue); border-color: var(--blue); }
.badge.s-quero-ler { color: var(--accent); border-color: var(--accent); }
.badge.s-abandonado { color: var(--danger); border-color: var(--danger); }
.stars { color: var(--accent); font-size: .72rem; }

/* Lista compacta */
.collection.list .card { flex-direction: row; align-items: center; }
.collection.list .card .cover { width: 50px; aspect-ratio: 2/3; flex: none; border-radius: 6px; margin: 8px; }
.collection.list .card .info { flex: 1; }

.empty { text-align: center; color: var(--muted); padding: 60px 20px; display: flex; flex-direction: column; gap: 16px; align-items: center; }

/* ---------- Modais ---------- */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.6); display: grid; place-items: center; padding: 16px; overflow-y: auto; }
.modal-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); width: 100%; max-width: 640px; box-shadow: var(--shadow); margin: auto; }
.modal-card.narrow { max-width: 420px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 1.3rem; }

.isbn-box { display: flex; gap: 8px; padding: 18px 22px 6px; }
.isbn-box input { flex: 1; }
.isbn-msg { padding: 0 22px; min-height: 18px; font-size: .82rem; color: var(--muted); margin: 4px 0; }
.scanner { padding: 0 22px 10px; }
.scanner video { width: 100%; border-radius: 10px; background: #000; max-height: 260px; }

.book-form { padding: 6px 22px 22px; }
.cover-preview { float: left; width: 100px; height: 150px; background: var(--card-2); border-radius: 8px; margin: 0 16px 10px 0; display: grid; place-items: center; overflow: hidden; }
.cover-preview img { width: 100%; height: 100%; object-fit: cover; }
.cover-preview img:not([src]), .cover-preview img[src=""] { display: none; }
#f-cover-fallback { color: var(--muted); font-size: .72rem; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.fields .full { grid-column: 1 / -1; }
.modal-actions { display: flex; gap: 10px; align-items: center; margin-top: 18px; clear: both; }
.report-form { padding: 22px; display: flex; flex-direction: column; gap: 16px; }

/* ---------- Toast ---------- */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--card); border: 1px solid var(--accent); color: var(--text); padding: 12px 20px; border-radius: 10px; box-shadow: var(--shadow); z-index: 100; font-size: .9rem; }

/* ---------- Mobile ---------- */
@media (max-width: 560px) {
  .stats { grid-template-columns: repeat(2, 1fr); padding: 14px; }
  .toolbar { padding: 0 14px 12px; }
  .collection { padding: 0 14px 80px; }
  .collection.grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; }
  .fields { grid-template-columns: 1fr; }
  .brand { font-size: 1rem; }
  .modal { padding: 0; align-items: stretch; }
  .modal-card { max-width: 100%; border-radius: 0; min-height: 100vh; }
}
