:root {
  color-scheme: dark;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: #e0e7ff;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(160deg, #0a1628 0%, #0f172a 45%, #1e3a5f 100%);
  line-height: 1.5;
}

/* ===== LOGIN ===== */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #0a1628 0%, #0f172a 45%, #1e3a5f 100%);
  padding: 1rem;
}
.login-overlay.hidden { display: none; }
.login-card {
  width: min(400px, 100%);
  padding: 2rem 1.75rem;
  border-radius: 1.4rem;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid #1e3a5f;
  box-shadow: 0 24px 48px rgba(0,0,0,0.45);
  text-align: center;
}
.login-card .school-title { margin-bottom: 0.25rem; }
.login-card .school-name { margin: 0.25rem 0 0; }
.login-card .app-title { margin: 0.4rem 0 1.2rem; }
.login-hint { margin: 0 0 1rem; color: #94a3b8; font-size: 0.95rem; }
.login-form { text-align: left; }
.login-form .field-row { margin-bottom: 1rem; }
.login-btn { width: 100%; margin-top: 0.5rem; }
.login-error {
  color: #fca5a5;
  font-size: 0.88rem;
  margin: 0 0 0.75rem;
  text-align: center;
}
.login-note {
  margin: 1.25rem 0 0;
  font-size: 0.78rem;
  color: #64748b;
}
.app-content.hidden { display: none; }

.school-header {
  text-align: center;
  padding: 2.2rem 1rem 1.5rem;
  background: rgba(10, 22, 40, 0.7);
  border-bottom: 1px solid #1e3a5f;
}
.header-top {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 1.5rem;
  position: relative;
  max-width: 1400px;
  margin: 0 auto;
}
.header-top > div { flex: 1; }
.header-actions {
  position: absolute;
  right: 1rem;
  top: 0.5rem;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.header-actions .btn-secondary { margin-left: 0; }
.school-title {
  margin: 0;
  font-size: clamp(1.8rem, 5vw, 2.8rem);
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #f8fafc;
}
.school-name {
  margin: 0.35rem 0 0;
  font-size: clamp(1.3rem, 3.5vw, 1.9rem);
  font-weight: 700;
  color: #c7d2fe;
}
.app-title {
  margin: 0.5rem 0 0;
  font-size: clamp(1.1rem, 2.8vw, 1.45rem);
  font-weight: 700;
  color: #a5b4fc;
}
.container {
  width: min(1400px, 100%);
  padding: 1.5rem 1rem 3rem;
  margin: auto;
}
.library-grid {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: minmax(300px, 1fr) minmax(420px, 2fr);
}
@media (max-width: 900px) {
  .library-grid { grid-template-columns: 1fr; }
  .header-actions { position: static; margin-top: 0.75rem; justify-content: center; }
  .header-top { flex-direction: column; align-items: center; }
}
.resource-form,
.resource-panel {
  padding: 1.25rem 1.35rem;
  border-radius: 1.4rem;
  background: rgba(15, 23, 42, 0.88);
  border: 1px solid #1e3a5f;
  box-shadow: 0 18px 40px rgba(0,0,0,0.35);
}
.form-header h3 { margin: 0 0 0.3rem; color: #e0e7ff; }
.form-hint { margin: 0 0 1rem; font-size: 0.88rem; color: #94a3b8; }
.field-row { display: grid; gap: 0.3rem; margin-bottom: 0.8rem; }
.field-row label { font-weight: 600; color: #cbd5e1; font-size: 0.92rem; }
.field-row input,
.field-row select {
  width: 100%;
  padding: 0.8rem 1rem;
  border-radius: 0.85rem;
  border: 1px solid #334155;
  background: #0f172a;
  color: #e0e7ff;
  font: inherit;
}
.field-row input:focus,
.field-row select:focus {
  outline: none;
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99,102,241,0.25);
}
.btn-primary {
  padding: 0.9rem 1.6rem;
  border-radius: 999px;
  border: none;
  background: linear-gradient(135deg, #4f46e5, #3730a3);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}
.btn-primary:hover { background: #4338ca; }
.btn-secondary {
  padding: 0.65rem 1.1rem;
  border-radius: 999px;
  border: none;
  background: #334155;
  color: #e0e7ff;
  font-weight: 600;
  cursor: pointer;
  margin-left: 0.5rem;
}
.hidden { display: none !important; }
.row-hidden { display: none !important; }
.progressive-form .form-step {
  opacity: 0;
  max-height: 0;
  overflow: hidden;
  transform: translateY(10px);
  transition: all 0.35s ease;
  margin-bottom: 0;
  pointer-events: none;
}
.progressive-form .form-step.active {
  opacity: 1;
  max-height: 900px;
  transform: translateY(0);
  margin-bottom: 0.9rem;
  pointer-events: auto;
}
.borrower-details-block {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid #334155;
}
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  margin-bottom: 1.1rem;
}
.view-button {
  padding: 0.6rem 1rem;
  border-radius: 999px;
  border: 1px solid #334155;
  background: #1e293b;
  color: #e0e7ff;
  font-weight: 700;
  cursor: pointer;
}
.view-button.active,
.view-button:hover {
  background: #4f46e5;
  border-color: #4f46e5;
}
.category-select {
  padding: 0.6rem 1rem;
  border-radius: 999px;
  border: 1px solid #334155;
  background: #1e293b;
  color: #e0e7ff;
  font-weight: 600;
  cursor: pointer;
}
.resource-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 1.1rem;
  margin-bottom: 1rem;
  color: #94a3b8;
  font-size: 0.95rem;
}
.filter-bar {
  gap: 0.4rem;
}
.filter-bar-with-meta {
  align-items: center;
  flex-wrap: wrap;
  row-gap: 0.45rem;
}
.resource-meta.inline-meta {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  margin-bottom: 0;
  margin-left: 0.35rem;
  gap: 0.45rem;
  font-size: 0.8rem;
  white-space: nowrap;
  flex-shrink: 1;
  min-width: 0;
}
.resource-meta.inline-meta > div {
  white-space: nowrap;
  flex-shrink: 0;
}
.filter-bar-with-meta {
  flex-wrap: nowrap;
  gap: 0.35rem;
}
@media (max-width: 900px) {
  .filter-bar-with-meta { flex-wrap: wrap; }
  .resource-meta.inline-meta { flex-wrap: wrap; }
}
.borrowers-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.4rem;
  margin-bottom: 0.65rem;
}
.borrowers-search-inline {
  margin-bottom: 0;
  flex: 1 1 140px;
  min-width: 120px;
  max-width: 220px;
}
.borrowers-search-inline input[type="search"] {
  width: 100%;
  padding: 0.55rem 0.9rem;
  border-radius: 999px;
  border: 1px solid #334155;
  background: #0f172a;
  color: #e0e7ff;
  font: inherit;
  font-size: 0.88rem;
}
.borrowers-search-inline input[type="search"]:focus {
  outline: none;
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25);
}
.borrowers-meta-inline {
  margin-left: 0;
}
.resource-list-table { display: grid; gap: 0.2rem; }
#supplyList.resource-list-table {
  max-height: 420px;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 0.25rem;
  scrollbar-width: thin;
  scrollbar-color: #475569 transparent;
}
#supplyList.resource-list-table::-webkit-scrollbar { width: 6px; }
#supplyList.resource-list-table::-webkit-scrollbar-thumb {
  background: #475569;
  border-radius: 999px;
}
#borrowerCards.borrower-list-view {
  max-height: 360px;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 0.25rem;
  scrollbar-width: thin;
  scrollbar-color: #475569 transparent;
}
#borrowerCards.borrower-list-view::-webkit-scrollbar { width: 6px; }
#borrowerCards.borrower-list-view::-webkit-scrollbar-thumb {
  background: #475569;
  border-radius: 999px;
}
.resource-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem 0.5rem;
  padding: 0.4rem 0.75rem;
  border-radius: 0.5rem;
  background: #1e293b;
  border: 1px solid #334155;
  transition: background 0.15s;
  font-size: 0.85rem;
  cursor: pointer;
  min-height: 2.1rem;
}
.resource-row:hover { background: #273549; }
.resource-row.expanded { background: #273549; border-color: #4f46e5; }
.resource-row.missing-item { border-color: #b91c1c; }
.resource-row.missing-item .name-cell { color: #fca5a5; }
.missing-badge {
  display: inline-block;
  margin-left: 0.45rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: #7f1d1d;
  color: #fecaca;
  font-size: 0.68rem;
  font-weight: 700;
  vertical-align: middle;
}
.missing-label { color: #fca5a5 !important; }
.name-cell {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.item-details,
.borrower-details {
  display: none;
  flex: 1 1 100%;
  flex-direction: column;
  gap: 0.45rem;
  margin-top: 0.35rem;
  font-size: 0.8rem;
  color: #94a3b8;
}
/* Hover shows details */
.resource-row.supply-row:hover .item-details,
.borrower-card:hover .borrower-details {
  display: flex;
}
.resource-row.supply-row:hover,
.borrower-card:hover {
  background: #273549;
  border-color: #4f46e5;
}
.resource-row.expanded .item-details,
.borrower-card.expanded .borrower-details {
  display: flex;
}
.form-step.step-skipped {
  display: none !important;
  max-height: 0 !important;
  opacity: 0 !important;
  pointer-events: none !important;
}
.detail-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.9rem;
}
.detail-grid span { white-space: nowrap; }
.owned-item { color: #c7d2fe; }
.resource-actions {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
}
.resource-actions button {
  border: none;
  border-radius: 999px;
  padding: 0.28rem 0.6rem;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  background: #4f46e5;
  color: #fff;
}
.resource-actions .btn-secondary { background: #475569; }
.resource-actions .lend-btn { background: #059669; }
.resource-actions .return-btn { background: #d97706; }
.group-header {
  background: #1e3a5f !important;
  font-size: 0.9rem;
  margin-top: 0.4rem;
  cursor: pointer;
}
.group-header.group-collapsed .group-items { display: none; }
.group-count {
  margin-left: 0.5rem;
  color: #94a3b8;
  font-weight: 500;
  font-size: 0.82rem;
}
.group-toggle-icon {
  margin-right: 0.35rem;
  color: #94a3b8;
  font-size: 0.75rem;
}
.group-items {
  display: grid;
  gap: 0.2rem;
  margin-left: 0.5rem;
  border-left: 2px solid #334155;
  padding-left: 0.4rem;
}
.group-items.collapsed { display: none; }
.borrower-list-view {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.55rem;
}
.borrower-card {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 0.65rem;
  padding: 0.55rem 0.7rem;
  transition: background 0.15s, border-color 0.15s;
  min-height: 2.4rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.borrower-card:hover { background: #273549; }
.borrower-card.expanded {
  background: #273549;
  border-color: #4f46e5;
}
.borrower-name {
  font-size: 0.88rem;
  color: #e0e7ff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.borrowers-section { position: relative; }
.borrowers-panel {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.35s ease, opacity 0.25s ease, margin 0.25s ease;
  margin-top: 0;
}
.borrowers-panel.open {
  max-height: 480px;
  opacity: 1;
  margin-top: 0.55rem;
}
.resource-panel {
  min-width: 0;
}
.library-grid {
  grid-template-columns: minmax(280px, 0.95fr) minmax(420px, 2.1fr);
}
.borrowers-toggle,
.borrowers-filter {
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  border: 1px solid #334155;
  background: #1e293b;
  color: #e0e7ff;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.82rem;
  margin: 0;
  flex-shrink: 0;
}
.view-button {
  padding: 0.5rem 0.85rem;
  font-size: 0.85rem;
}
.category-select {
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
}
.borrowers-toggle:hover,
.borrowers-filter:hover,
.borrowers-filter.active {
  background: #4f46e5;
  border-color: #4f46e5;
}
.search-row { margin-bottom: 0.85rem; }
.search-row input[type="search"] {
  width: 100%;
  padding: 0.7rem 1rem;
  border-radius: 0.85rem;
  border: 1px solid #334155;
  background: #0f172a;
  color: #e0e7ff;
  font: inherit;
}
.search-row input[type="search"]:focus {
  outline: none;
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25);
}
.empty-state {
  color: #94a3b8;
  font-size: 0.9rem;
  padding: 1rem 0.5rem;
  text-align: center;
}
.section-header h2 {
  margin: 0 0 1rem;
  color: #e0e7ff;
  font-size: 1.35rem;
}
.borrowers { margin-top: 2.5rem; }

/* Footer */
.site-footer {
  margin-top: 2rem;
  padding: 1.75rem 1rem;
  background: rgba(10, 22, 40, 0.85);
  border-top: 1px solid #1e3a5f;
  text-align: center;
}
.footer-content {
  max-width: 800px;
  margin: 0 auto;
  color: #94a3b8;
  font-size: 0.88rem;
  line-height: 1.7;
}
.footer-content p { margin: 0.25rem 0; }
.footer-content a {
  color: #a5b4fc;
  text-decoration: none;
}
.footer-content a:hover { text-decoration: underline; color: #c7d2fe; }
.footer-content strong { color: #e0e7ff; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.65);
  padding: 1rem;
}
.modal-overlay.hidden { display: none; }
.modal-card {
  width: min(400px, 100%);
  padding: 1.75rem;
  border-radius: 1.2rem;
  background: #0f172a;
  border: 1px solid #1e3a5f;
  box-shadow: 0 24px 48px rgba(0,0,0,0.5);
}
.modal-card h3 {
  margin: 0 0 1.25rem;
  color: #e0e7ff;
  text-align: center;
}
.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}
.login-success {
  color: #86efac;
  font-size: 0.88rem;
  margin: 0 0 0.75rem;
  text-align: center;
}
