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

:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #e0e7ff;
  --success: #16a34a;
  --success-light: #dcfce7;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --gray: #6b7280;
  --gray-light: #f3f4f6;
  --border: #e5e7eb;
  --dark: #1f2937;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: #f0f2f5;
  color: var(--dark);
  min-height: 100vh;
}

/* Header */
header {
  background: white;
  border-bottom: 3px solid var(--primary);
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 15px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-img {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  object-fit: contain;
}

.logo h1 {
  font-size: 22px;
  color: var(--dark);
  font-weight: 700;
}

.subtitle {
  font-size: 13px;
  color: var(--gray);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: nowrap;
}

nav {
  display: flex;
  gap: 4px;
  flex-wrap: nowrap;
}

#authArea {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  border-left: 1px solid var(--border);
  padding-left: 12px;
}

.nav-btn {
  padding: 8px 12px;
  border: none;
  background: transparent;
  color: var(--gray);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.2s;
  white-space: nowrap;
}

.nav-btn:hover {
  background: var(--primary-light);
  color: var(--primary);
}

.nav-btn.active {
  background: var(--primary);
  color: white;
}

/* Main */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

.tab-content {
  display: none;
  animation: fadeIn 0.2s ease;
}

.tab-content.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 15px;
  margin-bottom: 20px;
}

.stat-card {
  background: white;
  padding: 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
  transition: transform 0.2s;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.stat-card .stat-icon {
  font-size: 28px;
  margin-bottom: 8px;
}

.stat-card .stat-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--dark);
}

.stat-card .stat-label {
  font-size: 13px;
  color: var(--gray);
  margin-top: 4px;
}

.stat-card.overdue .stat-value { color: var(--danger); }
.stat-card.issued .stat-value { color: var(--warning); }
.stat-card.available .stat-value { color: var(--success); }

/* Dashboard Row */
.dashboard-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
  margin-bottom: 20px;
}

@media (max-width: 768px) {
  .dashboard-row { grid-template-columns: 1fr; }
}

/* Card */
.card {
  background: white;
  padding: 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 15px;
}

.card h3 {
  font-size: 16px;
  margin-bottom: 15px;
  color: var(--dark);
}

/* Toolbar */
.toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 15px;
  flex-wrap: wrap;
}

.toolbar input, .toolbar select {
  flex: 1;
  min-width: 200px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.toolbar input:focus, .toolbar select:focus {
  border-color: var(--primary);
}

/* Buttons */
.btn {
  padding: 10px 18px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover { background: var(--primary-dark); }

.btn-success {
  background: var(--success);
  color: white;
}

.btn-success:hover { background: #15803d; }

.btn-warning {
  background: var(--warning);
  color: white;
}

.btn-warning:hover { background: #d97706; }

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

.btn-danger:hover { background: #b91c1c; }

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
}

.btn-outline {
  background: white;
  border: 1px solid var(--border);
  color: var(--gray);
}

.btn-outline:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* Table-like list */
.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 15px;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

.list-item:hover {
  background: var(--gray-light);
}

.list-item:last-child {
  border-bottom: none;
}

.list-item-info {
  flex: 1;
}

.list-item-title {
  font-weight: 600;
  font-size: 15px;
  color: var(--dark);
}

.list-item-sub {
  font-size: 13px;
  color: var(--gray);
  margin-top: 2px;
}

.list-item-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: #92400e; }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-info { background: var(--primary-light); color: var(--primary); }
.badge-gray { background: var(--gray-light); color: var(--gray); }

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: white;
  border-radius: 14px;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 18px;
  color: var(--dark);
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--gray);
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
}

.modal-close:hover {
  background: var(--gray-light);
}

.modal-body {
  padding: 20px;
}

/* Forms */
.form-group {
  margin-bottom: 15px;
}

.form-group label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 5px;
  color: var(--dark);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--primary);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
}

.form-grid .form-actions {
  grid-column: 1 / -1;
}

@media (max-width: 500px) {
  .form-grid { grid-template-columns: 1fr; }
}

.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 10px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--dark);
  color: white;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s;
  z-index: 2000;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* Books Grid */
.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.book-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  display: flex;
  flex-direction: column;
}

.book-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.12);
}

.book-cover {
  height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gray-light);
  overflow: hidden;
  padding: 8px;
}

.book-cover img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.book-cover-placeholder {
  font-size: 48px;
  color: var(--gray);
}

.book-cover-placeholder.large {
  font-size: 64px;
}

.book-info {
  padding: 12px 14px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.book-title {
  font-weight: 700;
  font-size: 14px;
  color: var(--dark);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.book-author {
  font-size: 12px;
  color: var(--gray);
}

.book-meta {
  margin: 4px 0;
}

.book-meta .badge {
  font-size: 10px;
  padding: 2px 8px;
}

.book-availability {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: auto;
}

.book-copies {
  font-size: 11px;
  color: var(--gray);
}

.book-actions {
  padding: 8px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

/* Book Detail Modal */
.book-detail {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.book-detail-cover {
  width: 180px;
  min-height: 260px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--gray-light);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.book-detail-cover img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.book-detail-info {
  flex: 1;
  min-width: 200px;
}

.book-detail-info h3 {
  font-size: 20px;
  margin-bottom: 4px;
}

.detail-author {
  color: var(--gray);
  font-size: 14px;
  margin-bottom: 16px;
}

.detail-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.detail-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.detail-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--gray);
  letter-spacing: 0.5px;
}

.detail-value {
  font-size: 14px;
  color: var(--dark);
}

.detail-status {
  display: flex;
  align-items: center;
  gap: 12px;
}

@media (max-width: 500px) {
  .detail-fields { grid-template-columns: 1fr; }
  .book-detail-cover { width: 100%; max-width: 200px; margin: 0 auto; }
  .book-detail { flex-direction: column; }
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--gray);
}

.empty-state .empty-icon {
  font-size: 48px;
  margin-bottom: 10px;
}

.empty-state .empty-text {
  font-size: 15px;
}

/* Responsive */
@media (max-width: 768px) {
  .header-content {
    flex-direction: column;
    align-items: flex-start;
  }
  .header-right {
    width: 100%;
    flex-wrap: wrap;
  }
  nav { width: 100%; overflow-x: auto; }
  #authArea { border-left: none; padding-left: 0; }
  .toolbar { flex-direction: column; }
  .toolbar input, .toolbar select { width: 100%; }
  .list-item { flex-direction: column; align-items: flex-start; gap: 8px; }
  .list-item-actions { width: 100%; }
}