/* ============================================
   BOOKISH PUBLIC LIBRARY - STYLES
   Warm brown color scheme, adapted from Bookish v2
   ============================================ */

/* ============================================
   CSS VARIABLES
   ============================================ */
:root {
  /* Colors */
  --primary: #7b4b2a;
  --primary-dark: #5c3820;
  --primary-light: #b0723c;
  --bg-main: #fdf7ec;
  --bg-card: #fff9ec;
  --bg-filter: #fbf0dd;
  --bg-hover: #f8e7d0;
  --border-light: #ead4b4;
  --border-medium: #d4b48d;
  --text-dark: #3b2b23;
  --text-medium: #6b4b32;
  --text-light: #a88a69;
  --shadow: rgba(109, 76, 48, 0.25);
  --shadow-heavy: rgba(0, 0, 0, 0.45);

  /* Spacing */
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  --spacing-xl: 2rem;

  /* Border Radius */
  --radius-sm: 0.25rem;
  --radius-md: 0.5rem;
  --radius-lg: 1rem;

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-serif: Georgia, "Times New Roman", serif;
}

/* ============================================
   RESET & BASE
   ============================================ */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-main);
  color: var(--text-dark);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app {
  min-height: 100vh;
  padding-bottom: 4rem;
}

/* ============================================
   HEADER
   ============================================ */
.app-header {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fefaf3;
  padding: var(--spacing-md);
  padding-top: calc(var(--spacing-md) + env(safe-area-inset-top));
  box-shadow: 0 2px 8px var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--spacing-md);
}

.header-left h1 {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  letter-spacing: 0.02em;
  font-weight: 600;
  margin: 0;
}

.header-left p {
  margin: 0.25rem 0 0;
  font-size: 0.85rem;
  opacity: 0.9;
}

.header-badge {
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: white;
  padding: var(--spacing-xs) var(--spacing-md);
  border-radius: 2rem;
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

/* ============================================
   FILTERS SECTION
   ============================================ */
.filters-section {
  background: var(--bg-filter);
  padding: var(--spacing-md);
  border-bottom: 1px solid var(--border-medium);
}

.filters-inner {
  max-width: 1200px;
  margin: 0 auto;
}

.filter-row {
  margin-bottom: var(--spacing-md);
}

.filter-row:last-child {
  margin-bottom: 0;
}

.search-input {
  width: 100%;
  padding: var(--spacing-sm) var(--spacing-md);
  border: 2px solid var(--border-medium);
  border-radius: var(--radius-md);
  font-size: 1rem;
  background: white;
  color: var(--text-dark);
  transition: border-color 0.2s;
}

.search-input:focus {
  outline: none;
  border-color: var(--primary);
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: var(--spacing-sm);
}

.filter-select {
  padding: var(--spacing-sm) var(--spacing-md);
  border: 2px solid var(--border-medium);
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  background: white;
  color: var(--text-dark);
  cursor: pointer;
  transition: border-color 0.2s;
}

.filter-select:focus {
  outline: none;
  border-color: var(--primary);
}

.format-checkboxes {
  display: flex;
  gap: var(--spacing-md);
  flex-wrap: wrap;
}

.format-checkboxes label {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  cursor: pointer;
  font-size: 0.9rem;
  user-select: none;
  min-height: 44px;
}

.format-checkboxes input[type="checkbox"] {
  width: 20px;
  height: 20px;
  cursor: pointer;
}

.results-count {
  text-align: center;
  font-size: 0.9rem;
  color: var(--text-medium);
  padding-top: var(--spacing-sm);
  border-top: 1px solid var(--border-light);
}

/* ============================================
   BOOKS TABLE
   ============================================ */
.table-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--spacing-md);
  overflow-x: auto;
}

.books-table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: 0 2px 8px var(--shadow);
}

.books-table thead {
  background: var(--bg-filter);
}

.books-table th {
  padding: var(--spacing-md);
  text-align: left;
  font-weight: 600;
  color: var(--text-dark);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 2px solid var(--border-medium);
}

.books-table th.sortable {
  cursor: pointer;
  user-select: none;
  transition: background 0.2s;
}

.books-table th.sortable:hover {
  background: var(--bg-hover);
}

.sort-indicator {
  margin-left: var(--spacing-xs);
  color: var(--text-light);
  font-size: 0.8rem;
}

.books-table tbody tr {
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  transition: background 0.2s;
}

.books-table tbody tr:hover {
  background: var(--bg-hover);
}

.books-table tbody tr:last-child {
  border-bottom: none;
}

.books-table td {
  padding: var(--spacing-md);
  font-size: 0.9rem;
}

.books-table td:first-child {
  font-weight: 500;
  color: var(--text-dark);
}

.format-badge {
  display: inline-block;
  padding: 2px 8px;
  margin-right: 4px;
  background: var(--bg-filter);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

/* ============================================
   LOADING STATE
   ============================================ */
.loading-state {
  text-align: center;
  padding: 3rem var(--spacing-md);
  color: var(--text-light);
  font-size: 1rem;
}

.loading-spinner {
  display: inline-block;
  width: 2rem;
  height: 2rem;
  border: 3px solid var(--border-medium);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: var(--spacing-md);
}

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

/* ============================================
   DETAIL SHEET (Bottom Sheet)
   ============================================ */
.detail-sheet {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1000;
  display: none;
}

.detail-sheet.active {
  display: block;
}

.detail-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  animation: fadeIn 0.3s;
}

.detail-content {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 85vh;
  background: white;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: 0 -4px 20px var(--shadow-heavy);
  animation: slideUp 0.3s;
  overflow-y: auto;
  padding-bottom: env(safe-area-inset-bottom);
}

.detail-close {
  position: absolute;
  top: var(--spacing-md);
  right: var(--spacing-md);
  width: 32px;
  height: 32px;
  border: none;
  background: var(--bg-filter);
  border-radius: 50%;
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-medium);
  z-index: 10;
}

.detail-cover {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  background: var(--bg-filter);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  display: block;
}

.detail-body {
  padding: var(--spacing-xl) var(--spacing-md) var(--spacing-md);
}

.detail-body h2 {
  font-family: var(--font-serif);
  font-size: 1.75rem;
  color: var(--text-dark);
  margin-bottom: var(--spacing-sm);
  line-height: 1.3;
}

.detail-author {
  font-size: 1.1rem;
  color: var(--text-medium);
  margin-bottom: var(--spacing-md);
}

.detail-meta {
  font-size: 0.9rem;
  color: var(--text-light);
  margin-bottom: var(--spacing-md);
}

.detail-formats {
  display: flex;
  gap: var(--spacing-sm);
  flex-wrap: wrap;
  margin-bottom: var(--spacing-md);
}

.detail-notes {
  background: var(--bg-filter);
  padding: var(--spacing-md);
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  line-height: 1.6;
  margin-bottom: var(--spacing-md);
}

.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-md);
}

.tag {
  padding: var(--spacing-xs) var(--spacing-sm);
  background: var(--primary);
  color: white;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

.detail-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--spacing-sm);
  padding: var(--spacing-md);
  border-top: 1px solid var(--border-light);
}

.action-btn {
  padding: var(--spacing-md);
  border: 2px solid var(--border-medium);
  background: white;
  color: var(--text-dark);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.2s;
  min-height: 48px;
}

.action-btn:hover {
  background: var(--bg-hover);
  border-color: var(--primary);
}

/* ============================================
   FOOTER
   ============================================ */
.app-footer {
  text-align: center;
  padding: var(--spacing-lg) var(--spacing-md);
  color: var(--text-light);
  font-size: 0.8rem;
  border-top: 1px solid var(--border-light);
  margin-top: var(--spacing-xl);
}

.app-footer a {
  color: var(--primary);
  text-decoration: none;
}

.app-footer a:hover {
  text-decoration: underline;
}

/* ============================================
   TOAST NOTIFICATIONS
   ============================================ */
.toast-container {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
  pointer-events: none;
}

.toast {
  background: var(--text-dark);
  color: white;
  padding: var(--spacing-md) var(--spacing-lg);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 12px var(--shadow-heavy);
  animation: slideUp 0.3s;
  pointer-events: all;
  max-width: 90vw;
  text-align: center;
}

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

/* ============================================
   RESPONSIVE - Mobile (375px)
   ============================================ */
@media (max-width: 425px) {
  .filter-grid {
    grid-template-columns: 1fr;
  }

  .books-table {
    font-size: 0.85rem;
  }

  .books-table th,
  .books-table td {
    padding: var(--spacing-sm);
  }

  .detail-actions {
    grid-template-columns: 1fr;
  }

  .header-badge {
    display: none;
  }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */
.hidden {
  display: none !important;
}
