:root {
  --primary-color: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --border-color: #e2e8f0;
  --border-focus: #3b82f6;

  /* Status Colors */
  --status-borrowing-bg: #fffbeb;
  --status-borrowing-border: #fef3c7;
  --status-borrowing-text: #b45309;
  --status-borrowing-color: #d97706; /* Vàng cam */

  --status-returned-bg: #f0fdf4;
  --status-returned-border: #bbf7d0;
  --status-returned-text: #15803d;
  --status-returned-color: #16a34a; /* Xanh lá */

  --status-overdue-bg: #fef2f2;
  --status-overdue-border: #fecaca;
  --status-overdue-text: #b91c1c;
  --status-overdue-color: #dc2626; /* Đỏ cảnh báo quá hạn */

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

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

body {
  font-family: 'Be Vietnam Pro', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Header */
.app-header {
  background: #ffffff;
  border-bottom: 1px solid var(--border-color);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background-color: #f1f5f9;
  color: #334155;
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
  border: 1px solid #e2e8f0;
}

.btn-back:hover {
  background-color: #e2e8f0;
  color: #0f172a;
}

.header-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #0284c7, #0369a1);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 10px rgba(2, 132, 199, 0.28);
}

.app-header h1 {
  font-size: 18px;
  font-weight: 800;
  color: #0f172a;
  letter-spacing: -0.3px;
}

.app-header .subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 1px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s ease;
}

.btn-primary {
  background: #2563eb;
  color: #ffffff;
  border: none;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary:hover {
  background: #1d4ed8;
}

.btn-secondary {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  color: #334155;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: #f1f5f9;
  border-color: #94a3b8;
}

.btn-sample {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #166534;
}

.btn-sample:hover {
  background: #dcfce7;
}

.btn-backup {
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  color: #334155;
}

.btn-backup:hover {
  background: #e2e8f0;
}

.btn-restore {
  background: #fefce8;
  border: 1px solid #fef08a;
  color: #854d0e;
}

.btn-restore:hover {
  background: #fef9c3;
}

/* App Container */
.app-container {
  max-width: 1380px;
  margin: 0 auto;
  padding: 20px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
}

/* School Info Bar */
.school-bar {
  padding: 12px 18px;
  background: #ffffff;
}

.school-bar-grid {
  display: grid;
  grid-template-columns: 1.5fr 1.5fr 1fr 1.5fr;
  gap: 16px;
  align-items: center;
}

.form-group-inline {
  display: flex;
  align-items: center;
  gap: 8px;
}

.form-group-inline label {
  font-size: 13px;
  font-weight: 600;
  color: #475569;
  white-space: nowrap;
}

.form-control-sm {
  width: 100%;
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: #0f172a;
  outline: none;
  transition: border-color 0.15s;
}

.form-control-sm:focus {
  border-color: var(--border-focus);
}

/* KPI Dashboard */
.kpi-dashboard {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.kpi-card {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  gap: 14px;
  align-items: center;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s, box-shadow 0.2s;
}

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.kpi-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.card-total .kpi-icon {
  background: #eff6ff;
  color: #2563eb;
}

.card-borrowing .kpi-icon {
  background: #fffbeb;
  color: #d97706;
}

.card-monthly .kpi-icon {
  background: #f5f3ff;
  color: #7c3aed;
}

.card-rate .kpi-icon {
  background: #f0fdf4;
  color: #16a34a;
}

.kpi-content {
  overflow: hidden;
}

.kpi-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.kpi-value {
  font-size: 20px;
  font-weight: 800;
  color: #0f172a;
  margin-top: 2px;
  line-height: 1.2;
}

.kpi-unit {
  font-size: 13px;
  font-weight: 500;
  color: #64748b;
}

.kpi-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 3px;
}

.badge-overdue-count {
  display: inline-block;
  padding: 1px 6px;
  font-size: 11px;
  font-weight: 700;
  background: #fee2e2;
  color: #dc2626;
  border-radius: 10px;
}

/* Tabs Navigation */
.tabs-nav {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  border-bottom: 2px solid var(--border-color);
  padding-bottom: 8px;
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 700;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
}

.tab-btn:hover {
  color: var(--primary-color);
  background: #eff6ff;
}

.tab-btn.active {
  background: #ffffff;
  color: var(--primary-color);
  border-color: var(--border-color);
  box-shadow: var(--shadow-sm);
}

.badge-tab {
  background: #e2e8f0;
  color: #475569;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 12px;
  font-weight: 700;
}

.tab-btn.active .badge-tab {
  background: #2563eb;
  color: #ffffff;
}

/* Toolbar Card */
.toolbar-card {
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  flex-wrap: wrap;
}

.search-box {
  position: relative;
  min-width: 280px;
  flex: 1;
  max-width: 450px;
}

.search-box svg {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: #94a3b8;
}

.search-box input {
  width: 100%;
  padding: 8px 12px 8px 34px;
  font-size: 13px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  outline: none;
  background: #f8fafc;
}

.search-box input:focus {
  border-color: var(--border-focus);
  background: #ffffff;
}

.filter-group {
  display: flex;
  gap: 8px;
}

.form-select {
  padding: 8px 12px;
  font-size: 13px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background-color: #ffffff;
  color: #334155;
  outline: none;
  font-weight: 500;
  cursor: pointer;
}

.form-select:focus {
  border-color: var(--border-focus);
}

/* Alert Banner */
.alert-banner {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  animation: pulseLight 2s infinite ease-in-out;
}

@keyframes pulseLight {
  0%, 100% { background: #fef2f2; }
  50% { background: #fee2e2; }
}

.alert-icon {
  color: #dc2626;
  flex-shrink: 0;
  display: flex;
}

.alert-content {
  font-size: 13px;
  flex: 1;
}

.btn-xs {
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 4px;
  cursor: pointer;
}

.btn-outline-danger {
  background: transparent;
  border: 1px solid #dc2626;
  color: #dc2626;
}

.btn-outline-danger:hover {
  background: #dc2626;
  color: #ffffff;
}

/* Tables */
.table-card {
  padding: 0;
  overflow: hidden;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  text-align: left;
}

.data-table thead th {
  background: #f8fafc;
  color: #475569;
  font-weight: 700;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.data-table tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid #f1f5f9;
  color: #334155;
  vertical-align: middle;
}

.data-table tbody tr:hover {
  background-color: #f8fafc;
}

.data-table tr.row-overdue {
  background-color: #fff5f5;
}

.data-table tr.row-overdue:hover {
  background-color: #fee2e2;
}

.text-center {
  text-align: center;
}

/* Badges */
.badge-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.status-borrowing {
  background: var(--status-borrowing-bg);
  color: var(--status-borrowing-text);
  border: 1px solid var(--status-borrowing-border);
}

.status-returned {
  background: var(--status-returned-bg);
  color: var(--status-returned-text);
  border: 1px solid var(--status-returned-border);
}

.status-overdue {
  background: var(--status-overdue-bg);
  color: var(--status-overdue-text);
  border: 1px solid var(--status-overdue-border);
  animation: blinkRed 1.8s infinite;
}

@keyframes blinkRed {
  0%, 100% { border-color: #fecaca; }
  50% { border-color: #dc2626; box-shadow: 0 0 6px rgba(220, 38, 38, 0.3); }
}

.badge-category {
  display: inline-block;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 4px;
  background: #f1f5f9;
  color: #334155;
}

.badge-cat-van-hoc { background: #fdf2f8; color: #be185d; }
.badge-cat-khoa-hoc { background: #ecfeff; color: #0e7490; }
.badge-cat-lich-su { background: #fef3c7; color: #b45309; }
.badge-cat-ky-nang-song { background: #ecfdf5; color: #047857; }
.badge-cat-truyen-tranh { background: #faf5ff; color: #7e22ce; }
.badge-cat-tieng-anh { background: #eff6ff; color: #1d4ed8; }

.badge-stock {
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 12px;
}
.stock-available { background: #dcfce7; color: #15803d; }
.stock-out { background: #fee2e2; color: #b91c1c; }

/* Table Action Buttons */
.row-actions {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.btn-icon {
  width: 30px;
  height: 30px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid #cbd5e1;
  color: #475569;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-icon:hover {
  background: #f1f5f9;
  color: #0f172a;
}

.btn-icon-return {
  color: #16a34a;
  border-color: #bbf7d0;
  background: #f0fdf4;
}
.btn-icon-return:hover {
  background: #16a34a;
  color: #ffffff;
}

.btn-icon-delete:hover {
  background: #dc2626;
  border-color: #dc2626;
  color: #ffffff;
}

/* Empty State */
.empty-state {
  padding: 50px 20px;
  text-align: center;
  color: #94a3b8;
}

.empty-state svg {
  margin-bottom: 12px;
  stroke: #cbd5e1;
}

.empty-state p {
  font-size: 14px;
  margin-bottom: 14px;
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
  backdrop-filter: blur(2px);
}

.modal-dialog {
  background: #ffffff;
  border-radius: var(--radius-lg);
  max-width: 620px;
  width: 100%;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2);
  overflow: hidden;
  animation: modalFadeIn 0.2s ease-out;
}

@keyframes modalFadeIn {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

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

.modal-header h3 {
  font-size: 16px;
  font-weight: 700;
  color: #0f172a;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: #64748b;
  cursor: pointer;
  line-height: 1;
}

.modal-close:hover {
  color: #0f172a;
}

.modal-body {
  padding: 20px;
  max-height: 75vh;
  overflow-y: auto;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: #f8fafc;
}

.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #334155;
  margin-bottom: 5px;
}

.req {
  color: #dc2626;
}

.form-row {
  display: flex;
  gap: 12px;
}

.col-3 { flex: 3; }
.col-4 { flex: 4; }
.col-5 { flex: 5; }
.col-6 { flex: 6; }
.col-8 { flex: 8; }
.col-12 { flex: 12; width: 100%; }

.form-control {
  width: 100%;
  padding: 9px 12px;
  font-size: 13px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  outline: none;
  background: #ffffff;
  color: #1e293b;
}

.form-control:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.due-date-helper {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.quick-days {
  display: flex;
  gap: 4px;
}

.btn-badge {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 4px;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: #475569;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-badge:hover {
  background: #2563eb;
  color: #ffffff;
  border-color: #2563eb;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background: #1e293b;
  color: #ffffff;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideToast 0.25s ease-out;
}

.toast.toast-success {
  background: #15803d;
}

.toast.toast-danger {
  background: #b91c1c;
}

@keyframes slideToast {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Print Stylesheet */
.print-only {
  display: none !important;
}

@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
    font-size: 11pt !important;
  }

  .no-print {
    display: none !important;
  }

  .print-only {
    display: block !important;
  }

  .app-container {
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .card {
    border: none !important;
    box-shadow: none !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .print-header-block {
    margin-bottom: 20px;
  }

  .print-header-top {
    display: flex;
    justify-content: space-between;
    margin-bottom: 14px;
  }

  .print-school-info h3 {
    font-size: 12pt;
    font-weight: bold;
    text-transform: uppercase;
  }

  .print-school-info p {
    font-size: 11pt;
    font-weight: 600;
  }

  .print-doc-meta {
    text-align: center;
  }

  .print-doc-meta p {
    font-size: 10pt;
    margin-bottom: 2px;
  }

  .print-title {
    text-align: center;
    font-size: 14pt;
    font-weight: bold;
    text-transform: uppercase;
    margin: 15px 0;
  }

  .data-table {
    border: 1px solid #000000 !important;
  }

  .data-table th, .data-table td {
    border: 1px solid #000000 !important;
    padding: 6px 8px !important;
    color: #000000 !important;
  }

  .data-table thead th {
    background: #f2f2f2 !important;
  }

  .badge-status {
    border: none !important;
    font-weight: bold !important;
    color: #000000 !important;
    background: transparent !important;
    padding: 0 !important;
  }

  .print-footer-block {
    display: flex;
    justify-content: space-between;
    margin-top: 30px;
    page-break-inside: avoid;
  }

  .print-sig-col {
    text-align: center;
    width: 45%;
  }

  .sig-note {
    font-size: 9pt;
    font-style: italic;
    margin-top: 2px;
  }

  .sig-name {
    margin-top: 60px;
    font-weight: bold;
  }
}

/* Responsive */
@media (max-width: 992px) {
  .kpi-dashboard {
    grid-template-columns: repeat(2, 1fr);
  }
  .school-bar-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 640px) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .header-actions {
    width: 100%;
    justify-content: flex-start;
  }
  .kpi-dashboard {
    grid-template-columns: 1fr;
  }
  .school-bar-grid {
    grid-template-columns: 1fr;
  }
  .toolbar-card {
    flex-direction: column;
    align-items: stretch;
  }
}

.btn-danger-outline {
  background: #fff1f2;
  border: 1px solid #fecdd3;
  color: #e11d48;
}

.btn-danger-outline:hover {
  background: #ffe4e6;
  border-color: #fda4af;
}

/* Welcome / First Time Banner */
.welcome-sample-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: linear-gradient(135deg, #eff6ff 0%, #e0e7ff 100%);
  border: 1px solid #bfdbfe;
  border-left: 5px solid #2563eb;
  padding: 16px 20px;
  border-radius: var(--radius-md);
  margin-bottom: 24px;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.08);
  animation: fadeIn 0.3s ease-in-out;
}

.welcome-banner-content {
  display: flex;
  align-items: center;
  gap: 14px;
}

.welcome-banner-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #ffffff;
  color: #2563eb;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.15);
  flex-shrink: 0;
}

.welcome-banner-title {
  font-size: 15px;
  font-weight: 700;
  color: #1e3a8a;
  margin-bottom: 2px;
}

.welcome-banner-desc {
  font-size: 13.5px;
  color: #334155;
  margin: 0;
}

.welcome-banner-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.btn-banner-empty {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  background: #ffffff;
  border: 1px solid #cbd5e1;
  color: #475569;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-banner-empty:hover {
  background: #f1f5f9;
  color: #0f172a;
}

.btn-banner-sample {
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 700;
  border-radius: var(--radius-sm);
  background: #2563eb;
  border: 1px solid #1d4ed8;
  color: #ffffff;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.25);
  transition: all 0.2s ease;
}

.btn-banner-sample:hover {
  background: #1d4ed8;
}

@media (max-width: 768px) {
  .welcome-sample-banner {
    flex-direction: column;
    align-items: flex-start;
  }
  .welcome-banner-actions {
    width: 100%;
    justify-content: flex-end;
  }
}

