:root {
  --brand: #1f4e5f;
  --brand-dark: #14343f;
  --bg: #f5f3ee;
  --card-bg: #ffffff;
  --text: #222;
  --error: #b3261e;
  --success: #2e7d32;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button, .download-btn { background: var(--brand); color: white; border: none; padding: 10px 18px; border-radius: 8px; font-size: 1rem; cursor: pointer; text-decoration: none; display: inline-block; }
button:hover, .download-btn:hover { background: var(--brand-dark); }

/* ---------- Viewer pubblico ---------- */
.viewer-header {
  text-align: center;
  padding: 24px 16px 8px;
}
.viewer-header h1 { font-size: 1.6rem; margin: 0; color: var(--brand-dark); }

.viewer-layout {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 20px;
  padding: 16px;
  max-width: 1300px;
  margin: 0 auto;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--card-bg);
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.06);
  padding: 18px;
  max-height: 80vh;
  overflow-y: auto;
}
.sidebar h2 {
  font-size: 1rem;
  margin: 0 0 12px;
  color: var(--brand-dark);
}

.index-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.index-list button {
  width: 100%;
  text-align: left;
  background: none;
  color: var(--text);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 0.9rem;
}
.index-list button:hover:not(:disabled) { background: #eef4f2; color: var(--brand-dark); }
.index-list button.active { background: var(--brand); color: white; }
.index-list button:disabled { color: #bbb; cursor: not-allowed; }

.index-toggle {
  display: none;
  margin: 0 16px;
}

.viewer-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  flex: 1;
  min-width: 0;
}

.loading {
  padding: 60px 20px;
  color: #666;
  font-size: 1rem;
}

.flipbook { margin: 0 auto; }
.flipbook .page {
  background: white;
  box-shadow: 0 0 10px rgba(0,0,0,0.15);
}
.flipbook .page img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.controls {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
}
.controls button {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  font-size: 1.1rem;
  padding: 0;
}
#pageIndicator { font-size: 0.9rem; color: #555; min-width: 60px; text-align: center; }

.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: #666;
}

@media (max-width: 600px) {
  .viewer-header h1 { font-size: 1.3rem; }
}

/* ---------- Indice: mobile ---------- */
@media (max-width: 800px) {
  .viewer-layout { flex-direction: column; align-items: stretch; padding: 8px; }
  .index-toggle { display: block; margin: 0 auto; }
  .sidebar { display: none; width: 100%; max-height: 50vh; }
  .sidebar.open { display: block; }
}
