:root {
  --color-primary:    #2c5f2e;
  --color-primary-light: #4a8f4d;
  --color-surface:    #ffffff;
  --color-bg:         #f5f5f5;
  --color-text:       #1a1a1a;
  --color-text-muted: #6b7280;
  --color-border:     #e5e7eb;
  --color-error:      #dc2626;
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --nav-height: 60px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100dvh;
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0; right: 0;
  height: calc(var(--nav-height) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 100;
}

.nav-item {
  display: flex; flex-direction: column; align-items: center;
  gap: 2px; padding: var(--space-sm);
  min-width: 44px; min-height: 44px;
  text-decoration: none; color: var(--color-text-muted);
  font-size: 12px;
}
.nav-item.active { color: var(--color-primary); }

#main-content {
  padding: var(--space-md);
  padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + var(--space-md));
  min-height: 100dvh;
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-md);
}
@media (min-width: 640px) {
  .book-grid { grid-template-columns: repeat(4, 1fr); }
}

.book-card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.book-card:active { transform: scale(0.97); }

.book-cover {
  width: 100%; aspect-ratio: 2/3;
  object-fit: cover; background: var(--color-border);
}
.book-cover-placeholder {
  width: 100%; aspect-ratio: 2/3;
  background: linear-gradient(135deg, #e5e7eb, #d1d5db);
  display: flex; align-items: center; justify-content: center;
  font-size: 32px;
}

.book-info { padding: var(--space-sm); }
.book-title { font-weight: 600; font-size: 13px; line-height: 1.3; }
.book-author { font-size: 12px; color: var(--color-text-muted); margin-top: 2px; }
.book-location { font-size: 11px; color: var(--color-text-muted); margin-top: 4px; }

.read-badge {
  position: absolute; top: 4px; right: 4px;
  background: var(--color-primary);
  color: white; border-radius: 50%;
  width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px;
}

.search-bar {
  display: flex; gap: var(--space-sm); margin-bottom: var(--space-md);
}
.search-input {
  flex: 1; padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--color-border); border-radius: var(--radius-md);
  font-size: 16px;
  background: var(--color-surface);
}

.fab {
  position: fixed; bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + 16px);
  right: var(--space-md);
  width: 56px; height: 56px;
  background: var(--color-primary); color: white;
  border: none; border-radius: 50%;
  font-size: 24px; cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  display: flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5); z-index: 200;
}
.modal-overlay.hidden { display: none; }

.bottom-sheet {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--color-surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: var(--space-lg) var(--space-md);
  padding-bottom: calc(var(--space-lg) + env(safe-area-inset-bottom));
  max-height: 90dvh; overflow-y: auto;
  z-index: 300;
}

.form-group { margin-bottom: var(--space-md); }
.form-label { display: block; font-size: 14px; font-weight: 500; margin-bottom: var(--space-xs); }
.form-input, .form-select, .form-textarea {
  width: 100%; padding: 12px var(--space-md);
  border: 1px solid var(--color-border); border-radius: var(--radius-sm);
  font-size: 16px; background: var(--color-surface);
  -webkit-appearance: none;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none; border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(44,95,46,0.1);
}

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 12px var(--space-lg);
  border: none; border-radius: var(--radius-sm);
  font-size: 16px; font-weight: 600; cursor: pointer;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary { background: var(--color-primary); color: white; }
.btn-secondary { background: var(--color-bg); color: var(--color-text); border: 1px solid var(--color-border); }
.btn-danger { background: var(--color-error); color: white; }

.toast {
  position: fixed; bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + 80px);
  left: 50%; transform: translateX(-50%);
  background: #1a1a1a; color: white;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md); font-size: 14px;
  z-index: 400; white-space: nowrap;
  animation: slideUp 0.2s ease;
}
@keyframes slideUp {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.stat-bar-container { margin: var(--space-sm) 0; }
.stat-bar-label { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.stat-bar-track { background: var(--color-border); border-radius: 4px; height: 8px; }
.stat-bar-fill { background: var(--color-primary); border-radius: 4px; height: 8px; transition: width 0.3s; }

.stat-card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  text-align: center;
  margin-bottom: var(--space-sm);
}
.stat-number { font-size: 32px; font-weight: 700; color: var(--color-primary); }
.stat-label { font-size: 13px; color: var(--color-text-muted); margin-top: 4px; }

.empty-state {
  text-align: center;
  padding: var(--space-xl);
  color: var(--color-text-muted);
}

.location-tree { padding: var(--space-sm) 0; }
.location-item { padding: var(--space-sm) 0; border-bottom: 1px solid var(--color-border); }
.location-header { display: flex; justify-content: space-between; align-items: center; }
.location-name { font-weight: 600; font-size: 14px; }
.location-count { font-size: 12px; color: var(--color-text-muted); background: var(--color-bg); padding: 2px 8px; border-radius: 10px; }
.location-children { margin-left: var(--space-md); margin-top: var(--space-sm); }
.location-actions { display: flex; gap: var(--space-sm); }

h2 { font-size: 20px; margin-bottom: var(--space-md); }
h3 { font-size: 16px; margin: var(--space-md) 0 var(--space-sm); color: var(--color-text-muted); }

.book-detail { max-width: 500px; margin: 0 auto; }
.book-detail-cover { width: 100%; max-width: 300px; margin: 0 auto var(--space-md); display: block; border-radius: var(--radius-md); }
.book-detail-title { font-size: 24px; font-weight: 700; text-align: center; margin-bottom: var(--space-xs); }
.book-detail-author { font-size: 16px; color: var(--color-text-muted); text-align: center; margin-bottom: var(--space-md); }
.book-detail-row { display: flex; justify-content: space-between; padding: var(--space-sm) 0; border-bottom: 1px solid var(--color-border); font-size: 14px; }
.book-detail-actions { display: flex; gap: var(--space-sm); margin-top: var(--space-lg); }

.scanner-container { text-align: center; }
.scanner-video { width: 100%; max-width: 400px; border-radius: var(--radius-md); margin: var(--space-md) auto; display: block; }
.scanner-status { font-size: 14px; color: var(--color-text-muted); margin-top: var(--space-sm); }
