:root {
  --bg: #0f1015;
  --panel: #16171f;
  --card: #1c1e28;
  --border: #2a2c38;
  --text: #eceef2;
  --muted: #8a8d9a;
  --accent: #6691ff;
  --accent-dark: #4a6fd6;
  --good: #52cc74;
  --warn: #fada33;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 1.2rem 1rem;
}

.sidebar h1 {
  font-size: 1.1rem;
  margin: 0 0 1.5rem;
}

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.nav-link {
  text-align: left;
  background: none;
  color: var(--muted);
  padding: 0.6rem 0.8rem;
  border-radius: 6px;
  font-weight: 500;
  font-size: 0.9rem;
}

.nav-link:hover { background: #1f212c; color: var(--text); }
.nav-link.active { background: var(--accent); color: #10121a; }

main {
  flex: 1;
  padding: 1.5rem 2rem;
  min-width: 0;
}

.view { display: none; }
.view.active { display: block; }

.toolbar {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 1.2rem;
}

.toolbar h2 {
  margin: 0;
  font-size: 1.1rem;
  flex: 1;
}

input, select, textarea {
  padding: 0.5rem 0.7rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #12141c;
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
}

input#filter-q { min-width: 220px; flex: 1; }

button {
  padding: 0.55rem 1rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #1f212c;
  color: var(--text);
  font-weight: 500;
  font-size: 0.85rem;
  cursor: pointer;
}

button:hover { border-color: var(--accent); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #10121a;
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent-dark); }

.btn-danger { color: #ff7f66; border-color: #ff7f66; background: none; }

.hidden { display: none !important; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
}

.card:hover { transform: translateY(-3px); border-color: var(--accent); }

.card img {
  width: 100%;
  aspect-ratio: 2/3;
  object-fit: cover;
  background: #24262f;
  display: block;
}

.card-body { padding: 0.7rem; }

.card-title {
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta { font-size: 0.75rem; color: var(--muted); margin-top: 0.3rem; }

.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 0.5rem;
  overflow: hidden;
}
.progress-bar > div { height: 100%; background: var(--good); }

.tag {
  display: inline-block;
  background: #262836;
  color: var(--muted);
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.68rem;
  margin: 0.2rem 0.2rem 0 0;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 3rem 1rem;
  z-index: 100;
  overflow-y: auto;
}

.modal-content {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 640px;
  width: 100%;
  padding: 1.6rem;
  position: relative;
}
.modal-content.wide { max-width: 860px; }

.modal-close {
  position: absolute;
  top: 0.6rem;
  right: 0.8rem;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.4rem;
  line-height: 1;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.7rem;
  margin: 1rem 0;
}
.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: var(--muted);
}
.form-grid .span-2 { grid-column: span 2; }
.form-grid input, .form-grid select, .form-grid textarea { width: 100%; }

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

.serie-header {
  display: flex;
  gap: 1.2rem;
  align-items: flex-start;
}
.serie-header img { width: 130px; border-radius: 8px; flex-shrink: 0; }
.serie-header h2 { margin: 0 0 0.3rem; }

.tomes-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
  font-size: 0.85rem;
}
.tomes-table th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.75rem;
  text-transform: uppercase;
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--border);
}
.tomes-table td {
  padding: 0.5rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.tomes-table tr:hover { background: #1a1c26; }
.tomes-table td.actions { text-align: right; white-space: nowrap; }

table.entity-table-inner {
  width: 100%;
  border-collapse: collapse;
}
table.entity-table-inner th {
  text-align: left;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  padding: 0.5rem;
  border-bottom: 1px solid var(--border);
}
table.entity-table-inner td {
  padding: 0.6rem 0.5rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}
table.entity-table-inner td.actions { text-align: right; white-space: nowrap; }

.empty-state {
  color: var(--muted);
  padding: 2rem 0;
  text-align: center;
}

.isbn-lookup {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.8rem;
}
.isbn-lookup input { flex: 1; }

#camera-wrap { margin-top: 0.8rem; }
#scan-video {
  display: none;
  width: 100%;
  max-height: 320px;
  border-radius: 8px;
  background: #000;
  object-fit: cover;
}
#scan-video.active { display: block; margin-bottom: 0.6rem; }
#btn-camera-toggle { width: 100%; }

@media (max-width: 720px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: span 1; }
}
