/* ═══════════════════════════════════════════════════════════
   Library Management System — Styles
   Design language mirrors the parent portfolio:
     - Inter font, subtle purple/blue accents
     - Clean card surfaces, ample whitespace
     - Full light + dark theme with high contrast
     - Uses CSS custom properties so themes just swap tokens
   ═══════════════════════════════════════════════════════════ */

:root {
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-soft: rgba(99, 102, 241, 0.1);
  --accent: #8b5cf6;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #06b6d4;

  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --surface-hover: #e2e8f0;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;

  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;

  --font: 'Inter', system-ui, -apple-system, sans-serif;
}

html[data-theme="dark"] {
  --primary: #818cf8;
  --primary-hover: #a5b4fc;
  --primary-soft: rgba(129, 140, 248, 0.15);
  --accent: #a78bfa;

  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #1f2937;
  --surface-hover: #374151;
  --border: #1f2937;
  --border-strong: #374151;

  --text: #f3f4f6;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.4);
  --shadow-lg: 0 20px 25px -5px rgb(0 0 0 / 0.5);
}

/* Honor OS preference when no explicit theme has been set */
@media (prefers-color-scheme: dark) {
  html:not([data-theme]) {
    --primary: #818cf8;
    --primary-hover: #a5b4fc;
    --primary-soft: rgba(129, 140, 248, 0.15);
    --accent: #a78bfa;
    --bg: #0b1120;
    --surface: #111827;
    --surface-2: #1f2937;
    --surface-hover: #374151;
    --border: #1f2937;
    --border-strong: #374151;
    --text: #f3f4f6;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.2s ease, color 0.2s ease;
}

/* ── Top bar ─────────────────────────────────────────────── */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}
.topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 14px 24px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 24px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}
.brand:hover { background: var(--surface-2); color: var(--text); }
.brand-title {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
  font-size: 18px;
  justify-self: center;
}
.brand-title i { color: var(--primary); }
.topbar-actions { display: inline-flex; gap: 8px; }
.btn-icon {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.15s ease;
}
.btn-icon:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-icon-text { display: none; }
@media (min-width: 640px) { .btn-icon-text { display: inline; } }

/* ── Tabs ─────────────────────────────────────────────────── */
.tabs {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px 24px 0;
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 10px 16px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* ── Content ──────────────────────────────────────────────── */
.content { max-width: 1400px; margin: 0 auto; padding: 24px; }
.panel { display: none; animation: fadeIn 0.2s ease; }
.panel.active { display: block; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
h1 { margin: 0 0 6px; font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
h2 { margin: 0; font-size: 16px; font-weight: 600; }
.section-lead {
  color: var(--text-secondary);
  margin: 0 0 24px;
  font-size: 15px;
}

/* ── Stat cards ───────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: var(--border-strong);
}
.stat-icon-wrap {
  width: 48px; height: 48px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center; justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.stat-icon-books { background: rgba(99, 102, 241, 0.12); color: #6366f1; }
.stat-icon-copies { background: rgba(139, 92, 246, 0.12); color: #8b5cf6; }
.stat-icon-loans { background: rgba(6, 182, 212, 0.12); color: #06b6d4; }
.stat-icon-overdue { background: rgba(239, 68, 68, 0.12); color: #ef4444; }
.stat-icon-members { background: rgba(16, 185, 129, 0.12); color: #10b981; }
.stat-icon-branches { background: rgba(245, 158, 11, 0.12); color: #f59e0b; }
.stat-info { min-width: 0; }
.stat-label {
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
  margin-top: 2px;
}

/* ── Cards / dashboards ───────────────────────────────────── */
.dashboard-grid, .reports-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.card-header h2 {
  display: inline-flex; align-items: center; gap: 10px;
}
.card-header h2 i { color: var(--primary); }
.card-body { padding: 16px 20px; }
.badge {
  padding: 3px 10px;
  background: var(--primary-soft);
  color: var(--primary);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ── Bar chart (dashboard: loans by branch) ───────────────── */
.bar-row {
  display: grid;
  grid-template-columns: 120px 1fr auto;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.bar-row:last-child { margin-bottom: 0; }
.bar-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bar-track {
  height: 24px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: var(--radius-sm);
  transition: width 0.5s ease;
}
.bar-value {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  min-width: 32px;
  text-align: right;
}

/* ── Activity feed ────────────────────────────────────────── */
.activity-item {
  display: flex;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.activity-item:last-child { border-bottom: none; }
.activity-icon {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center; justify-content: center;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 12px;
  flex-shrink: 0;
}
.activity-text { flex: 1; color: var(--text-secondary); }
.activity-text strong { color: var(--text); font-weight: 600; }
.activity-time { color: var(--text-muted); font-size: 12px; }

/* ── Toolbars ─────────────────────────────────────────────── */
.toolbar {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  align-items: center;
  flex-wrap: wrap;
}
.search-wrap {
  position: relative;
  flex: 1;
  min-width: 240px;
  max-width: 480px;
}
.search-wrap i {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}
.search-wrap input {
  width: 100%;
  padding: 10px 14px 10px 40px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.search-wrap input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.filter-group {
  display: inline-flex;
  gap: 4px;
  background: var(--surface-2);
  padding: 4px;
  border-radius: var(--radius-sm);
}
.filter-chip {
  padding: 6px 14px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  border-radius: 4px;
  transition: all 0.15s ease;
}
.filter-chip:hover { color: var(--text); }
.filter-chip.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}
.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
}
.btn-primary:active { transform: translateY(0); }
.btn-danger {
  padding: 6px 12px;
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s ease;
}
.btn-danger:hover { background: rgba(239, 68, 68, 0.1); border-color: var(--danger); }
.btn-ghost {
  padding: 6px 12px;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s ease;
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }

/* ── Tables ───────────────────────────────────────────────── */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  overflow-x: auto;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.data-table thead th {
  padding: 12px 20px;
  text-align: left;
  background: var(--surface-2);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table tbody td {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr {
  cursor: pointer;
  transition: background 0.1s ease;
}
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table .id-cell { color: var(--text-muted); font-variant-numeric: tabular-nums; font-size: 13px; }
.data-table .row-actions { display: inline-flex; gap: 6px; }

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
.status-active { background: rgba(6, 182, 212, 0.15); color: #06b6d4; }
.status-overdue { background: rgba(239, 68, 68, 0.15); color: #ef4444; }
.status-available { background: rgba(16, 185, 129, 0.15); color: #10b981; }
.status-low { background: rgba(245, 158, 11, 0.15); color: #f59e0b; }
.status-none { background: rgba(148, 163, 184, 0.15); color: #64748b; }

/* ── Checkout form ────────────────────────────────────────── */
.checkout-form {
  max-width: 640px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
}
.form-row {
  margin-bottom: 20px;
}
.form-row label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}
.form-row input,
.form-row select,
.form-row textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.form-row input:focus,
.form-row select:focus,
.form-row textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.form-row .hint {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-muted);
}
.form-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

/* ── Modal ────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal.open { display: flex; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
}
.modal-panel {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-width: 640px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  animation: modalIn 0.2s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}
.modal-close {
  position: absolute;
  top: 12px; right: 12px;
  width: 32px; height: 32px;
  border: none;
  background: var(--surface-2);
  color: var(--text-secondary);
  border-radius: 50%;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}
.modal-close:hover { background: var(--surface-hover); color: var(--text); }
.modal-content { padding: 28px; }
.modal-content h2 {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 700;
  padding-right: 40px;
}
.modal-content .meta {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 20px;
}
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 20px;
  margin-bottom: 20px;
}
.detail-item .detail-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 2px;
}
.detail-item .detail-value { color: var(--text); font-weight: 500; }
.subheading {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
  margin: 20px 0 10px;
}

/* Empty state */
.empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}
.empty i {
  font-size: 32px;
  color: var(--border-strong);
  margin-bottom: 8px;
  display: block;
}

/* ── Toast ────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  padding: 12px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  transform: translateX(calc(100% + 40px));
  transition: transform 0.3s ease;
  max-width: 400px;
}
.toast.show { transform: translateX(0); }
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }

/* ── Footer ───────────────────────────────────────────────── */
.footer {
  margin-top: 60px;
  padding: 24px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.footer-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  color: var(--text-secondary);
  font-size: 13px;
  text-align: center;
}
.footer a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}
.footer a:hover { text-decoration: underline; }

/* Small-screen niceties */
@media (max-width: 640px) {
  .topbar-inner { grid-template-columns: auto 1fr; gap: 12px; }
  .brand-title { justify-self: end; font-size: 15px; }
  .brand-title span { display: none; }
  .content { padding: 20px 16px; }
  h1 { font-size: 24px; }
  .stat-card { padding: 16px; }
  .stat-icon-wrap { width: 40px; height: 40px; font-size: 16px; }
  .stat-value { font-size: 22px; }
  .data-table thead th,
  .data-table tbody td { padding: 10px 12px; }
  .detail-grid { grid-template-columns: 1fr; }
  .toast { left: 16px; right: 16px; bottom: 16px; }
}


/* ── Sortable table headers ──────────────────────────────── */
.data-table thead th.sortable {
  cursor: pointer;
  user-select: none;
  transition: background 0.1s ease, color 0.1s ease;
  position: relative;
}
.data-table thead th.sortable:hover {
  background: var(--surface-hover);
  color: var(--text);
}
.data-table thead th.sortable .sort-icon {
  margin-left: 6px;
  font-size: 11px;
  opacity: 0.35;
  transition: opacity 0.15s ease, color 0.15s ease;
}
.data-table thead th.sortable:hover .sort-icon {
  opacity: 0.7;
}
.data-table thead th.sortable.sort-asc .sort-icon,
.data-table thead th.sortable.sort-desc .sort-icon {
  opacity: 1;
  color: var(--primary);
}
