/* ==========================================================================
   Trechos & Croissants - Estilos Principais
   Design Limpo, Aconchegante, Literário e Mobile-First
   ========================================================================== */

/* Google Fonts Import */
@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,500;0,600;0,700;1,400&family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap');

:root {
  /* Paleta de Cores Aconchegante / Croissant & Café */
  --bg-main: #fbf8f3;
  --bg-card: #ffffff;
  --bg-subtle: #f3ece1;
  --text-main: #2b221b;
  --text-muted: #6e5e54;
  --text-light: #948275;
  
  --accent-primary: #c86b3c;       /* Terracota / Croissant dourado */
  --accent-hover: #b05629;
  --accent-light: #f7eae1;
  --accent-border: #e9cfbe;
  
  --border-color: #e9e0d4;
  --border-focus: #c86b3c;
  
  --danger-color: #d94f4f;
  --danger-hover: #b83a3a;
  --success-color: #3b8a5a;
  
  /* Tipografia */
  --font-serif: 'Playfair Display', Georgia, serif;
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  
  /* Sombras e Raios */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 2px 8px rgba(43, 34, 27, 0.04);
  --shadow-md: 0 8px 24px rgba(43, 34, 27, 0.07);
  --shadow-hover: 0 12px 32px rgba(200, 107, 60, 0.12);
  
  --transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Tema escuro — roxo profundo */
[data-theme="dark"] {
  --bg-main: #1a1225;
  --bg-card: #251a35;
  --bg-subtle: #2e2042;
  --text-main: #ede8f5;
  --text-muted: #b8a8cc;
  --text-light: #8f7da8;

  --accent-primary: #a78bfa;
  --accent-hover: #8b5cf6;
  --accent-light: #3b2a5c;
  --accent-border: #4c3570;

  --border-color: #3d2d55;
  --border-focus: #a78bfa;

  --danger-color: #f87171;
  --danger-hover: #ef4444;
  --success-color: #4ade80;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-hover: 0 12px 32px rgba(139, 92, 246, 0.18);
}

/* Reset básico */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-main);
  color: var(--text-main);
  font-family: var(--font-sans);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* Layout Container */
.container {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* Cabeçalho */
.site-header {
  background-color: rgba(251, 248, 243, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 1.25rem 0;
}

[data-theme="dark"] .site-header {
  background-color: rgba(26, 18, 37, 0.92);
}

.header-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  text-align: center;
}

@media (min-width: 640px) {
  .header-content {
    flex-direction: row;
    justify-content: space-between;
    text-align: left;
  }
}

.brand {
  text-decoration: none;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-icon {
  width: 42px;
  height: 42px;
  background-color: var(--accent-light);
  border: 1px solid var(--accent-border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  color: var(--accent-primary);
  flex-shrink: 0;
}

.site-title {
  font-family: var(--font-serif);
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-main);
}

.site-tagline {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-style: italic;
}

.header-nav {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.theme-toggle-btn {
  cursor: pointer;
  font-family: inherit;
}

.nav-link {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background-color: var(--bg-subtle);
  border: 1px solid transparent;
}

.nav-link:hover {
  color: var(--accent-primary);
  background-color: var(--accent-light);
  border-color: var(--accent-border);
}

.btn-pwa {
  background-color: var(--accent-primary);
  color: #ffffff !important;
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}

.btn-pwa:hover {
  background-color: var(--accent-hover) !important;
  box-shadow: 0 4px 12px rgba(200, 107, 60, 0.25);
}


/* Principal / Hero */
main {
  flex: 1;
  padding: 2rem 0 3rem 0;
}

.hero-section {
  text-align: center;
  margin-bottom: 2.5rem;
  padding: 1.5rem 1rem;
  background: linear-gradient(180deg, rgba(247, 234, 225, 0.4) 0%, rgba(251, 248, 243, 0) 100%);
  border-radius: var(--radius-lg);
}

[data-theme="dark"] .hero-section {
  background: linear-gradient(180deg, rgba(59, 42, 92, 0.5) 0%, rgba(26, 18, 37, 0) 100%);
}

.hero-title {
  font-family: var(--font-serif);
  font-size: 2rem;
  color: var(--text-main);
  margin-bottom: 0.75rem;
  line-height: 1.2;
}

@media (min-width: 640px) {
  .hero-title {
    font-size: 2.6rem;
  }
}

.hero-subtitle {
  font-size: 1rem;
  color: var(--text-muted);
  max-width: 540px;
  margin: 0 auto 1.5rem auto;
}

/* Barra de Busca */
.search-container {
  max-width: 520px;
  margin: 0 auto;
  position: relative;
}

.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 1rem;
  color: var(--text-muted);
  font-size: 1.1rem;
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 0.9rem 1rem 0.9rem 2.8rem;
  font-size: 0.95rem;
  font-family: var(--font-sans);
  color: var(--text-main);
  background-color: var(--bg-card);
  border: 1.5px solid var(--border-color);
  border-radius: 50px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  outline: none;
}

.search-input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 4px var(--accent-light);
}

.clear-search-btn {
  position: absolute;
  right: 0.75rem;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  font-size: 1rem;
  display: none;
  border-radius: 50%;
}

.clear-search-btn:hover {
  color: var(--text-main);
}

/* Grid de Livros (Mobile-first) */
.books-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.75rem;
  margin-bottom: 2.5rem;
}

@media (min-width: 540px) {
  .books-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 840px) {
  .books-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 1080px) {
  .books-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* Card do Livro */
.book-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  display: flex;
  flex-direction: column;
}

.book-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-hover);
  border-color: var(--accent-border);
}

.card-image-container {
  width: 100%;
  aspect-ratio: 3 / 4;
  background-color: var(--bg-subtle);
  position: relative;
  overflow: hidden;
}

.card-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.4s ease;
}

.book-card:hover .card-image {
  transform: scale(1.04);
}

.category-badge {
  position: absolute;
  top: 0.75rem;
  left: 0.75rem;
  background-color: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(4px);
  color: var(--accent-primary);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.3rem 0.65rem;
  border-radius: 50px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  border: 1px solid var(--accent-border);
}

[data-theme="dark"] .category-badge {
  background-color: rgba(37, 26, 53, 0.92);
}

.card-body {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.book-title {
  font-family: var(--font-serif);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 0.5rem;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.book-synopsis {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 1.25rem;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  flex: 1;
}

.card-footer-action {
  margin-top: auto;
}

/* Botões */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  font-size: 0.9rem;
  font-weight: 600;
  font-family: var(--font-sans);
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  width: 100%;
}

.btn-primary {
  background-color: var(--accent-primary);
  color: #ffffff;
}

.btn-primary:hover {
  background-color: var(--accent-hover);
  box-shadow: 0 4px 12px rgba(200, 107, 60, 0.25);
}

.btn-secondary {
  background-color: var(--bg-subtle);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover:not(:disabled) {
  background-color: var(--accent-light);
  color: var(--accent-primary);
  border-color: var(--accent-border);
}

.btn-secondary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-danger {
  background-color: var(--danger-color);
  color: #ffffff;
}

.btn-danger:hover {
  background-color: var(--danger-hover);
}

.btn-sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.82rem;
  width: auto;
}

/* Paginação */
.pagination-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px dashed var(--border-color);
}

@media (min-width: 500px) {
  .pagination-container {
    flex-direction: row;
    justify-content: space-between;
  }
}

.pagination-info {
  font-size: 0.9rem;
  color: var(--text-muted);
  font-weight: 500;
}

.pagination-controls {
  display: flex;
  gap: 0.75rem;
}

/* Estados de Carregamento e Vazio */
.loading-state, .empty-state, .error-state {
  text-align: center;
  padding: 4rem 1.5rem;
  background-color: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  grid-column: 1 / -1;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3.5px solid var(--accent-light);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 1rem auto;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.state-icon {
  font-size: 2.5rem;
  margin-bottom: 1rem;
  color: var(--text-muted);
}

.empty-state h3, .error-state h3 {
  font-family: var(--font-serif);
  font-size: 1.3rem;
  margin-bottom: 0.5rem;
}

/* Admin Dashboard & Auth */
.auth-card {
  max-width: 440px;
  margin: 2rem auto;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-md);
}

.auth-header {
  text-align: center;
  margin-bottom: 1.75rem;
}

.auth-title {
  font-family: var(--font-serif);
  font-size: 1.75rem;
  color: var(--text-main);
  margin-bottom: 0.4rem;
}

.form-group {
  margin-bottom: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-main);
}

.form-input, .form-textarea {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 0.92rem;
  font-family: var(--font-sans);
  color: var(--text-main);
  background-color: var(--bg-main);
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.form-input:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--accent-primary);
  background-color: var(--bg-card);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.form-textarea {
  resize: vertical;
  min-height: 100px;
}

.file-input-wrapper {
  background-color: var(--bg-subtle);
  border: 1.5px dashed var(--accent-border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
}

.file-input-wrapper:hover {
  background-color: var(--accent-light);
}

.admin-header-bar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem 1.5rem;
  margin-bottom: 2rem;
}

@media (min-width: 640px) {
  .admin-header-bar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

.user-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-avatar {
  width: 40px;
  height: 40px;
  background-color: var(--accent-primary);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2rem;
}

.stat-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 1rem;
}

.stat-icon-wrapper {
  width: 48px;
  height: 48px;
  background-color: var(--accent-light);
  color: var(--accent-primary);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1;
}

.stat-label {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

.admin-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
}

@media (min-width: 900px) {
  .admin-grid {
    grid-template-columns: 420px 1fr;
  }
}

.admin-panel {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.panel-title {
  font-family: var(--font-serif);
  font-size: 1.35rem;
  color: var(--text-main);
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Tabela e Lista no Admin */
.admin-books-list {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.admin-book-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem;
  background-color: var(--bg-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.admin-book-item:hover {
  border-color: var(--accent-border);
}

.admin-book-thumb {
  width: 48px;
  height: 64px;
  object-fit: cover;
  border-radius: 4px;
  background-color: var(--bg-subtle);
  flex-shrink: 0;
}

.admin-book-info {
  flex: 1;
  min-width: 0;
}

.admin-book-title {
  font-family: var(--font-serif);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.admin-book-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Mensagens de Alerta */
.alert {
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.alert-danger {
  background-color: #fde8e8;
  color: var(--danger-color);
  border: 1px solid #f8b4b4;
}

[data-theme="dark"] .alert-danger {
  background-color: rgba(248, 113, 113, 0.12);
  border-color: rgba(248, 113, 113, 0.35);
}

.alert-success {
  background-color: #eaf5ed;
  color: var(--success-color);
  border: 1px solid #b7e1c2;
}

[data-theme="dark"] .alert-success {
  background-color: rgba(74, 222, 128, 0.12);
  border-color: rgba(74, 222, 128, 0.35);
}

/* Rodapé */
.site-footer {
  background-color: var(--bg-card);
  border-top: 1px solid var(--border-color);
  padding: 2rem 0;
  margin-top: auto;
  text-align: center;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.footer-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}
