:root {
  --bg: #0e1015;
  --surface: #171a22;
  --surface-2: #202531;
  --line: #343a48;
  --text: #f2f4f8;
  --muted: #9da6b8;
  --accent: #d9ff62;
  --accent-dark: #a8cc35;
  --danger: #ff7272;
  --shadow: 0 18px 60px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }
html { color-scheme: dark; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 8% -10%, rgba(217,255,98,.13), transparent 30%),
    radial-gradient(circle at 100% 20%, rgba(96,111,255,.12), transparent 28%),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.topbar {
  width: min(1480px, calc(100% - 40px));
  margin: 0 auto;
  padding: 34px 0 22px;
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 28px;
}

.eyebrow { color: var(--accent); font-size: .72rem; font-weight: 850; letter-spacing: .19em; margin: 0 0 8px; }
h1 { font-size: clamp(2rem, 4vw, 3.5rem); line-height: .98; margin: 0; letter-spacing: -.055em; }
.subtitle { color: var(--muted); margin: 12px 0 0; }
nav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

main { width: min(1480px, calc(100% - 40px)); margin: 0 auto 70px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 8px 0 18px; }
.stats article { background: rgba(23,26,34,.76); border: 1px solid var(--line); border-radius: 16px; padding: 18px 20px; box-shadow: var(--shadow); }
.stats span { display: block; font-size: 1.45rem; font-weight: 800; letter-spacing: -.03em; }
.stats small { color: var(--muted); }

.panel { background: rgba(23,26,34,.84); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow); overflow: hidden; }
.scanner-panel { padding: 22px; background: linear-gradient(110deg, rgba(217,255,98,.09), rgba(255,255,255,.01)); border-bottom: 1px solid var(--line); }
.scanner-panel > label { font-weight: 800; display: block; margin-bottom: 8px; }
.scanner-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.instruction { color: var(--muted); margin: 12px 0 0; }
.instruction strong { color: var(--accent); }

input, textarea, select {
  width: 100%;
  color: var(--text);
  background: #10131a;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 11px 12px;
  outline: none;
  transition: border-color .18s, box-shadow .18s;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent-dark); box-shadow: 0 0 0 3px rgba(217,255,98,.11); }
input[readonly] { color: #bbc2cf; background: #151820; }
textarea { resize: vertical; }
label { color: #cbd1dc; font-size: .86rem; font-weight: 700; }
label input, label textarea, label select { margin-top: 6px; font-weight: 450; }

.button, .tab {
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 10px 14px;
  cursor: pointer;
  text-decoration: none;
  font-weight: 780;
  transition: transform .14s, background .14s, border-color .14s;
}
.button:hover, .tab:hover { transform: translateY(-1px); }
.primary { background: var(--accent); color: #171b0b; border-color: var(--accent); }
.secondary, .tab { background: var(--surface-2); color: var(--text); }
.danger { background: transparent; color: var(--danger); border-color: rgba(255,114,114,.42); }
.tab.active { background: var(--text); color: #11141a; border-color: var(--text); }

.empty-state { min-height: 420px; display: grid; place-content: center; text-align: center; padding: 50px 20px; color: var(--muted); }
.empty-state h2 { color: var(--text); margin-bottom: 4px; }
.barcode-art { font-family: monospace; color: var(--accent); letter-spacing: .2em; font-size: 2rem; transform: skewY(-4deg); }

.book-editor { display: grid; grid-template-columns: 300px 1fr; gap: 28px; padding: 28px; }
.cover-column { min-width: 0; }
.cover-frame { aspect-ratio: 2 / 3; background: #0a0c10; border: 1px solid var(--line); border-radius: 16px; overflow: hidden; display: grid; place-items: center; position: sticky; top: 16px; }
.cover-frame img { width: 100%; height: 100%; object-fit: contain; display: none; }
#cover-placeholder { color: var(--muted); }
.cover-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0 16px; }
.fields-column { display: grid; gap: 14px; min-width: 0; }
.form-status { display: flex; justify-content: space-between; align-items: center; gap: 15px; }
.badge { display: inline-flex; width: fit-content; background: rgba(217,255,98,.12); color: var(--accent); border: 1px solid rgba(217,255,98,.24); border-radius: 999px; padding: 7px 10px; font-size: .78rem; font-weight: 850; }
.grid { display: grid; gap: 12px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; padding-top: 8px; }
.muted { color: var(--muted); font-size: .86rem; }

.library-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 24px; border-bottom: 1px solid var(--line); }
.library-toolbar h2 { margin: 0 0 3px; }
.library-toolbar p { margin: 0; }
.library-toolbar input { max-width: 420px; }
.library-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 18px; padding: 24px; }
.book-card { background: #11141b; border: 1px solid var(--line); border-radius: 15px; overflow: hidden; cursor: pointer; transition: transform .16s, border-color .16s; }
.book-card:hover { transform: translateY(-3px); border-color: #626c80; }
.book-card-cover { aspect-ratio: 2 / 3; background: #0a0c10; display: grid; place-items: center; color: var(--muted); overflow: hidden; }
.book-card-cover img { width: 100%; height: 100%; object-fit: contain; }
.book-card-body { padding: 13px; }
.book-card h3 { margin: 0 0 6px; font-size: .98rem; line-height: 1.25; }
.book-card p { margin: 0; color: var(--muted); font-size: .82rem; }
.book-card .category { color: var(--accent); margin-top: 9px; }

.toast { position: fixed; right: 22px; bottom: 22px; background: #eef5db; color: #172006; border-radius: 12px; padding: 13px 17px; font-weight: 760; box-shadow: var(--shadow); transform: translateY(140%); opacity: 0; transition: .25s; z-index: 30; max-width: 420px; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { background: #ffd8d8; color: #461010; }
.loading { position: fixed; inset: 0; background: rgba(7,8,11,.72); backdrop-filter: blur(5px); display: grid; place-content: center; text-align: center; z-index: 25; }
.loading span { width: 42px; height: 42px; margin: auto; border: 4px solid #434a58; border-top-color: var(--accent); border-radius: 50%; animation: spin .75s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.hidden { display: none !important; }

@media (max-width: 900px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  nav { justify-content: flex-start; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .book-editor { grid-template-columns: 1fr; }
  .cover-frame { position: static; max-width: 300px; margin: auto; }
  .grid.three { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .topbar, main { width: min(100% - 22px, 1480px); }
  .stats { grid-template-columns: 1fr 1fr; }
  .stats article { padding: 14px; }
  .stats span { font-size: 1.08rem; }
  .scanner-row, .grid.two { grid-template-columns: 1fr; }
  .book-editor { padding: 16px; }
  .library-toolbar { align-items: stretch; flex-direction: column; }
  .library-toolbar input { max-width: none; }
}

.version { color: var(--accent); font-size: .76rem; font-weight: 850; margin-left: 8px; }
.scanner-tools { margin-top: 14px; display: flex; gap: 8px; flex-wrap: wrap; }
.button.compact { padding: 7px 10px; font-size: .78rem; }
.lookup-report {
  margin: 18px 22px 0;
  padding: 20px;
  border: 1px solid rgba(255, 190, 92, .45);
  background: rgba(255, 174, 74, .07);
  border-radius: 16px;
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
}
.lookup-report h2 { margin: 0 0 12px; font-size: 1.08rem; line-height: 1.35; }
.lookup-report .eyebrow { margin-bottom: 6px; color: #ffc66d; }
.lookup-report ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.lookup-report li { display: grid; grid-template-columns: minmax(150px, .5fr) 1fr; gap: 12px; padding-top: 8px; border-top: 1px solid rgba(255,255,255,.08); font-size: .84rem; }
.lookup-report li span { color: var(--muted); overflow-wrap: anywhere; }
.lookup-report .report-ok strong { color: var(--accent); }
.lookup-report .report-warn strong { color: #ffc66d; }
.lookup-report .report-error strong { color: var(--danger); }
.report-actions { display: flex; gap: 8px; flex-wrap: wrap; flex: 0 0 auto; }

@media (max-width: 760px) {
  .lookup-report { flex-direction: column; }
  .lookup-report li { grid-template-columns: 1fr; gap: 3px; }
}
