/* CSS Custom Properties for better maintainability */
:root {
  --gold-border: rgb(255, 183, 0);
  --silver-border: rgb(151, 151, 151);
  --sidebar-width: 255px;
  --border-radius-small: 10px;
  --border-radius-medium: 15px;
  --border-radius-large: 20px;
  --font-family-main: "Source Code Pro", monospace;
  --color-white: #ffffff;
  --color-black: #000000;
  --color-gray-light: rgba(228, 228, 228, 0.492);
  --color-gray-medium: rgba(165, 163, 163, 0.492);
  --color-gray-dark: rgba(1, 10, 18, 0.692);
  --color-shadow: rgba(0, 0, 0, 0.1);
  --color-modal-overlay: rgba(0, 0, 0, 0.478);

  /* House Colors */
  --color-gryffindor: #801717;
  --color-hufflepuff: rgb(31, 31, 31);
  --color-ravenclaw: #222f5b;
  --color-slytherin: rgb(17, 66, 17);
}

.filtering {
  margin: 0;
  position: sticky;
  grid-column: 1/2;
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
  justify-content: center;
}

aside {
  margin: 0;
  position: sticky;
  width: var(--sidebar-width);
  height: 100vh;
  top: 0;
  box-sizing: border-box;
  background-color: var(--color-gray-light);
}

#houseCrest {
  width: 108px;
  height: 113px;
  border-radius: var(--border-radius-medium);
  margin-top: 2rem;
}

[data-action="filter"] {
  padding-left: 1rem;
  line-height: 0.3rem;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

[data-action="filter"]:hover {
  background-color: rgba(255, 255, 255, 0.1);
  border-radius: 5px;
}

body {
  font-family: var(--font-family-main);
  background-color: var(--color-gray-dark);
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  margin: 0;
  min-height: 100vh;
}

.hidden {
  visibility: hidden;
}

.head {
  top: 0;
  position: sticky;
  background-color: var(--color-gray-medium);
  padding: 10px;
  box-shadow: 0px 2px 5px var(--color-shadow);
  z-index: 1;
}

#search {
  width: 98%;
  padding: 0.5rem;
  border: 1px solid #ddd;
  border-radius: var(--border-radius-small);
  font-family: var(--font-family-main);
}

.sort_by {
  grid-column: 1/3;
  display: flex;
  justify-content: space-around;
  padding-bottom: 1rem;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.sort_by button {
  background-color: rgb(230, 230, 230);
  border: 1px solid rgb(209, 209, 209);
  font-family: var(--font-family-main);
  padding: 0.7rem;
  min-width: 120px;
  flex: 1;
  border-radius: var(--border-radius-small);
  cursor: pointer;
  transition: all 0.2s ease;
}

.sort_by button:hover {
  background-color: rgb(220, 220, 220);
  transform: translateY(-1px);
}

tbody {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  align-items: center;
  gap: 1rem;
  padding: 1rem;
}

tbody tr {
  cursor: pointer;
  width: 100%;
  align-items: center;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--border-radius-small);
  transition: all 0.2s ease;
  background-color: rgba(255, 255, 255, 0.05);
}

tbody tr:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  border-color: rgba(255, 255, 255, 0.3);
}

tbody tr td {
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

table {
  table-layout: fixed;
  width: 100%;
}

tbody tr td img {
  width: 60%;
  border-radius: var(--border-radius-small);
  transition: transform 0.2s ease;
}

tbody tr td img:hover {
  transform: scale(1.05);
}

.image-placeholder {
  width: 60% !important;
  aspect-ratio: 1 !important;
  background-color: #f0f0f0 !important;
  border: 2px dashed #ccc !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  font-size: 12px !important;
  color: #666 !important;
  border-radius: var(--border-radius-small) !important;
  margin: 0 auto !important;
  cursor: pointer !important;
  transition: all 0.2s ease !important;
  font-family: var(--font-family-main) !important;
  font-weight: 500 !important;
}

.image-placeholder:hover {
  background-color: #e8e8e8 !important;
  transform: scale(1.05) !important;
}

#popupBox {
  position: relative;
  padding: 2rem;
  width: 450px;
  max-width: 90vw;
  border-radius: var(--border-radius-large);
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  line-height: 0.5rem;
  background-color: var(--color-white);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.inq {
  line-height: 1.2rem;
}

#crest_image {
  grid-column: 1/2;
}

#popup_details {
  background-color: var(--color-white);
  padding: 1rem;
  grid-row: 1/3;
  grid-column: 2/4;
  border-radius: var(--border-radius-medium);
}

.info {
  display: flex;
  border-bottom: 1px solid var(--color-black);
  justify-content: space-between;
  padding: 0.25rem 0;
}

.closebutton {
  position: absolute;
  right: -1em;
  top: -0.5em;
  width: 3em;
  height: 3em;
  border-radius: 50%;
  border: 1px solid rgb(175, 175, 175);
  cursor: pointer;
  background-color: var(--color-white);
  font-weight: bold;
  transition: all 0.2s ease;
}

.closebutton:hover {
  background-color: #f0f0f0;
  transform: scale(1.1);
}

.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: var(--color-modal-overlay);
  z-index: 99;
  backdrop-filter: blur(2px);
}

#popupButtons {
  padding-top: 2rem;
  grid-column: 1/4;
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

#popupButtons button {
  padding: 0.4rem 0.8rem;
  border-radius: var(--border-radius-small);
  border: 1px solid #ddd;
  background-color: #f8f9fa;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--font-family-main);
  font-size: 0.9rem;
}

#popupButtons button:hover {
  background-color: #e9ecef;
  transform: translateY(-1px);
}

td[data-field="firstName"],
td[data-field="lastName"] {
  color: var(--color-white);
  font-weight: bold;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.7);
}

/* House-specific styles using CSS variables instead of !important */
.ravenclaw {
  background-color: var(--color-ravenclaw);
  border: 4px solid var(--gold-border);
}

.gryffindor {
  background-color: var(--color-gryffindor);
  border: 4px solid var(--gold-border);
}

.hufflepuff {
  background-color: var(--color-hufflepuff);
  border: 4px solid var(--gold-border);
}

.slytherin {
  background-color: var(--color-slytherin);
  border: 4px solid var(--silver-border);
}

#alertModal {
  display: none;
  position: fixed;
  z-index: 100;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(2px);
}

.modal-content {
  background-color: #fefefe;
  margin: 15% auto;
  padding: 20px;
  border: 1px solid #888;
  width: min(400px, 80vw);
  position: relative;
  border-radius: var(--border-radius-medium);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(-50px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.close-button {
  position: absolute;
  top: -0.8rem;
  right: -0.5rem;
  border: 1px solid rgb(175, 175, 175);
  border-radius: 50%;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #fefefe;
  color: #aaa;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s ease;
}

.close-button:hover,
.close-button:focus {
  color: var(--color-black);
  background-color: #f0f0f0;
  transform: scale(1.1);
}

/* Responsive Design */
@media (max-width: 768px) {
  body {
    grid-template-columns: 1fr;
  }

  aside {
    width: 100%;
    height: auto;
    position: relative;
  }

  .sort_by {
    flex-direction: column;
    gap: 0.5rem;
  }

  .sort_by button {
    width: 100%;
    min-width: unset;
  }

  #popupBox {
    width: 95vw;
    padding: 1rem;
    grid-template-columns: 1fr;
  }

  #popup_details {
    grid-column: 1;
    grid-row: 2;
  }

  #popupButtons {
    flex-direction: column;
    gap: 0.5rem;
  }
}

/* Loading state for better UX */
.loading {
  position: relative;
}

.loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid #f3f3f3;
  border-top: 2px solid #3498db;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}
