/* =========================================
   6. MODALS & LINK LIST
   ========================================= */

.modal {
  background: var(--modal-overlay);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  position: fixed;
  inset: 0;
  z-index: 1000; 
  padding: 20px;
  animation: fadeIn 0.3s ease-out;
}

.modal.hidden {
  display: none;
}

/* --- Z-INDEX STACKING FIX --- */
#room-links-modal { z-index: 1000; }

#edit-room-modal, 
#delete-room-modal, 
#link-form-modal, 
#delete-link-modal,
#signup-modal,
#signin-modal,
#create-room-modal,
#join-room-modal {
  z-index: 1100; 
}

/* Base Modal Content Structure */
.modal-content {
  background: var(--sidebar-bg);
  padding: 0; 
  border-radius: 32px;
  width: 100%;
  max-width: 500px;
  border: 1px solid var(--border);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden; 
  animation: modalPop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* --- FUNCTIONAL SIZES --- */
.modal-action-small {
  max-width: 400px;
  height: auto;
  padding: 2rem !important;
}

.modal-auth-form {
  max-width: 450px;
  height: auto;
  padding: 2rem !important;
}

.modal-confirm-danger {
  max-width: 380px;
  height: auto;
  text-align: center;
  padding: 2rem !important;
}

.modal-room-view {
  max-width: 700px;
  height: 85vh;
  max-height: 800px;
}

/* Header & Inline Styles */
.modal-header-inline {
  padding: 2.5rem 3rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--sidebar-bg);
  gap: 15px;
}

.modal-header-inline h3 {
  margin: 0;
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-main);
  word-break: break-word;
}

/* The "Link List Container" */
#link-list-view {
  background: rgba(255, 255, 255, 0.03); 
  flex: 1;
  padding: 1.5rem 2rem;
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--border);
  overflow: hidden;
}

/* --- LINK LIST ITEMS --- */
#modal-links-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding-right: 12px;
}

#modal-links-list li {
  background: var(--card-bg); 
  border: 1px solid var(--border);
  margin-bottom: 1rem;
  padding: 0.8rem 1.5rem;
  border-radius: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: all 0.25s ease;
  animation: slideInUp 0.4s ease-out backwards;
}

#modal-links-list li:hover {
  border-color: var(--accent);
  transform: scale(1.01) translateX(4px);
  background: var(--input-bg);
}

#modal-links-list li span a {
  color: var(--text-main);
  text-decoration: none;
  font-weight: 500;
  font-size: 1.1rem;
  word-break: break-all;
}

/* --- ICON BUTTONS (Edit/Delete) --- */
.link-options {
  display: flex;
  gap: 12px;
}

.link-options button {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: 0.2s;
}

.edit-link { background: var(--input-bg); color: var(--text-main); }
.edit-link:hover { background: var(--border); }

.delete-link { background: rgba(239, 68, 68, 0.1); color: var(--danger); }
.delete-link:hover { background: var(--danger); color: white; }

/* --- MODAL DROPDOWN (Three Dots) --- */
#modal-room-settings {
  position: relative;
  cursor: pointer;
  padding: 10px;
  color: var(--text-dim);
  font-size: 1.2rem;
  display: flex;
  align-items: center;
}

#modal-room-settings:hover {
  color: var(--text-main);
}

#modal-room-dropdown.show {
  display: block;
}

/* --- FOOTER & BUTTONS --- */
.modal-buttons {
  padding: 1.5rem 0; /* Vertical padding, no side padding to prevent offset */
  display: flex;
  gap: 12px;
  justify-content: center !important; /* Forces center alignment */
  width: 100%;
  background: transparent;
  margin: 0 auto;
}

/* --- MODAL DESIGN ELEMENTS --- */
.modal-design-header {
  text-align: center;
  margin-bottom: 2rem;
}

.design-icon {
  font-size: 2.5rem;
  color: var(--accent);
  margin-bottom: 1.2rem;
  opacity: 0.8;
  animation: iconFloat 3s ease-in-out infinite;
}

/* =========================================
   MOBILE ADAPTATION
   ========================================= */

@media (max-width: 600px) {
  .modal {
    padding: 15px; 
  }

  .modal-content {
    border-radius: 24px;
    width: 94%;
  }

  .modal-room-view {
    height: 80vh; 
  }

  .modal-header-inline {
    padding: 1.2rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0px; 
  }

  .modal-header-inline h3 {
    font-size: 1.2rem;
    flex: 1; 
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis; 
  }

  .modal-header-inline button:not(#modal-room-settings) {
    width: 32px; 
    height: 36px;
    padding: 0 !important;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0; 
    background: transparent !important; 
    box-shadow: none !important;
    border: none;
    cursor: pointer;
    transition: opacity 0.2s;
  }

  .modal-header-inline button:not(#modal-room-settings):active {
    opacity: 0.6;
  }

  .modal-header-inline button:not(#modal-room-settings)::before {
    content: '+';
    font-size: 1.4rem; 
    color: var(--text-main); 
  }

  #modal-room-settings {
    padding: 5px;
    margin-left: -5px; 
  }

  #link-list-view {
    padding: 1rem;
  }

  #modal-links-list li {
    padding: 1rem;
    flex-direction: row; 
  }

  .modal-buttons {
    flex-direction: column-reverse;
    width: 100%;
    padding: 1.5rem; /* Give some breathing room on mobile */
    align-items: center;
  }

  .modal-buttons .btn {
    width: 100%;
  }
}

/* --- ANIMATION KEYFRAMES --- */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

@keyframes modalPop {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

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

@keyframes iconFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

/* Scrollbar Styling */
#modal-links-list::-webkit-scrollbar { width: 6px; }
#modal-links-list::-webkit-scrollbar-track { background: transparent; }
#modal-links-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }