.qd-drive {
  max-width: 1200px;
  margin: auto;
  background: #865B9D;
  padding: 50px 40px;
  border-radius: 18px;
  font-family: Inter, Roboto, sans-serif;
  min-height: 600px;
  box-sizing: border-box;
}

/* LOGO HEADER */
.qd-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.qd-logo {
  width: 32px;
  height: 32px;
  object-fit: contain;
  flex-shrink: 0;
}

.qd-header h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  word-break: break-word;
}

/* ACTION BUTTONS */
.qd-actions {
  display: flex;
  gap: 12px;
  margin-bottom: 15px;
  flex-wrap: wrap;
  width: 100%;
}

.qd-actions button {
  background: #7c3aed;
  color: #fff;
  padding: 14px 28px;
  border-radius: 20px;
  border: none;
  cursor: pointer;
  font-size: 16px;
  font-weight: 500;
  transition: all 0.3s ease;
  white-space: nowrap;
  box-sizing: border-box;
}

.qd-actions button:hover {
  background: #6d28d9;
}

/* SEARCH */
.qd-search {
  margin-bottom: 20px;
}

#qd-search-input {
  width: 100%;
  padding: 14px 18px;
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,0.3);
  font-size: 16px;
  outline: none;
  box-sizing: border-box;
  background: rgba(255,255,255,0.9);
}

#qd-search-input:focus {
  border-color: #fff;
  background: #fff;
}

/* FILE GRID - 4 COLUMNS */
#qd-files,
.qd-modal-files {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  justify-items: center;
}

/* FILE CARD */
.qd-file {
  background: #fff;
  padding: 20px;
  border-radius: 16px;
  position: relative;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border: 1px solid #e5e7eb;
  box-shadow: 0 4px 10px rgba(124,58,237,.08);
  transition: transform .2s ease, box-shadow .2s ease;
  width: 100%;
  max-width: 100%;
}

.qd-file:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(124,58,237,.15);
}

/* PREVIEW */
.qd-preview {
  width: 100%;
  height: 100px;
  padding: 10px;
  border-radius: 14px;
  background: #f3f0ff;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-sizing: border-box;
}

/* Ensure any direct child inside preview is centered */
.qd-preview > * {
  margin: auto;
}

.qd-preview img,
.qd-preview iframe,
.qd-preview video {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
  margin: auto;
  border-radius: 10px;
  background: #fff;
  border: none;
}

.qd-preview iframe {
  pointer-events: none;
}

/* PDF ICON */
.qd-pdf-icon {
  width: 64px;
  height: 64px;
  background: #ff5757;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 20px;
  font-weight: 700;
}

/* FILE ICON */
.qd-file-icon {
  width: 64px;
  height: 64px;
  background: #7c3aed;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 16px;
  font-weight: 700;
}

/* FILE NAME */
.qd-file > a,
.qd-file > span {
  width: 100%;
  font-size: 14px;
  font-weight: 500;
  color: #202124;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
  text-align: center;
  margin-top: auto;
}

.qd-file a {
  text-decoration: none;
}

/* FOLDER */
.qd-file[data-dir="true"] {
  align-items: center;
}

.qd-file[data-dir="true"] .qd-preview {
  height: 80px;
  width: 80px;
  background: #f3f0ff;
  border: 1px dashed #dcdcdc;
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
}

.qd-folder-icon {
  width: 48px;
  height: 48px;
  object-fit: contain;
  display: block;
}

/* MODAL */
.qd-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 20px;
  box-sizing: border-box;
}

.qd-modal.active {
  display: flex;
}

.qd-modal-content {
  background: #865B9D;
  width: 100%;
  max-width: 1200px;
  max-height: 90vh;
  /* default visible height even when folder is empty */
  min-height: 80vh;
  /* let inner content (files grid) scroll instead of the whole modal */
  overflow: visible;
  border-radius: 20px;
  padding: 30px;
  position: relative;
  box-sizing: border-box;
}

/* Modal files grid: show a 4x4 viewport and become scrollable when content exceeds it */
.qd-modal-files {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  justify-items: center;
  /* each row height approximates the card height so 4 rows are visible */
  grid-auto-rows: 160px;
  /* cap to 4 rows, but also respect the modal's default height */
  max-height: min(calc(160px * 4 + 20px * 3), calc(60vh - 160px));
  overflow-y: auto;
  box-sizing: border-box;
  padding-right: 6px; /* give room for scrollbar */
}

.qd-close {
  float: right;
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
  padding: 5px;
  color: #fff;
}

/* MODAL CONTROLS */
#qd-modal-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 14px 0 24px;
  flex-wrap: wrap;
}

#qd-modal-search-input {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.3);
  outline: none;
  box-sizing: border-box;
  font-size: 15px;
  background: rgba(255,255,255,0.9);
}

#qd-modal-search-input:focus {
  border-color: #fff;
  background: #fff;
}

/* TITLE CENTER ALIGN */
#qd-folder-title {
  text-align: center;
  margin-bottom: 20px;
  color: #fff;
}

/* =========================
   RESPONSIVE BREAKPOINTS
========================= */

/* Tablets and smaller desktops - 3 columns */
@media (max-width: 1024px) {
  .qd-drive {
    padding: 35px 28px;
  }

  #qd-files,
  .qd-modal-files {
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
  }
}

/* Tablets portrait - 2 columns */
@media (max-width: 768px) {
  .qd-drive {
    padding: 28px 20px;
    border-radius: 12px;
  }

  .qd-header h2 {
    font-size: 20px;
  }

  .qd-actions {
    gap: 10px;
  }

  .qd-actions button {
    padding: 12px 20px;
    font-size: 15px;
  }

  #qd-files,
  .qd-modal-files {
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
  }

  .qd-preview {
    height: 90px;
  }

  .qd-file[data-dir="true"] .qd-preview {
    height: 70px;
    width: 70px;
  }

  .qd-modal-content {
    padding: 24px;
    border-radius: 16px;
  }
}

/* Mobile landscape and larger phones - 2 columns */
@media (max-width: 640px) {
  .qd-actions {
    flex-direction: column;
  }
  
  .qd-actions button {
    width: 100%;
    flex: 1 1 100%;
    max-width: 100%;
  }

  #qd-files,
  .qd-modal-files {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  /* Modal controls responsive */
  #qd-modal-controls {
    flex-direction: column;
    gap: 10px;
  }
  
  #qd-modal-search-input {
    width: 100%;
    flex: 1 1 100%;
  }
  
  /* Modal action buttons */
  .qd-modal .qd-actions {
    flex-direction: column;
  }
  
  .qd-modal .qd-actions button {
    width: 100%;
    flex: 1 1 100%;
  }
}

/* Small mobile devices - 2 columns */
@media (max-width: 480px) {
  .qd-drive {
    padding: 20px 16px;
    border-radius: 8px;
    min-height: auto;
  }

  .qd-header {
    gap: 8px;
    margin-bottom: 16px;
  }

  .qd-logo {
    width: 28px;
    height: 28px;
  }

  .qd-header h2 {
    font-size: 18px;
  }

  .qd-actions {
    margin-bottom: 12px;
    gap: 8px;
  }

  .qd-actions button {
    padding: 12px 18px;
    font-size: 14px;
    border-radius: 16px;
  }

  .qd-search {
    margin-bottom: 16px;
  }

  #qd-search-input {
    padding: 12px 14px;
    font-size: 15px;
    border-radius: 12px;
  }

  #qd-files,
  .qd-modal-files {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .qd-file {
    padding: 16px;
    gap: 10px;
    border-radius: 12px;
  }

  .qd-preview {
    height: 80px;
    padding: 8px;
    border-radius: 10px;
  }

  .qd-file[data-dir="true"] .qd-preview {
    height: 60px;
    width: 60px;
  }

  .qd-folder-icon {
    width: 36px;
    height: 36px;
  }

  .qd-file > a,
  .qd-file > span {
    font-size: 13px;
  }

  .qd-modal {
    padding: 10px;
  }

  .qd-modal-content {
    width: 100%;
    max-height: 92vh;
    padding: 20px 16px;
    border-radius: 12px;
  }

  .qd-close {
    font-size: 22px;
  }

  #qd-modal-search-input {
    padding: 10px 12px;
    font-size: 14px;
  }

  .qd-pdf-icon,
  .qd-file-icon {
    width: 48px;
    height: 48px;
    font-size: 14px;
  }
}

/* Very small devices - 2 columns */
@media (max-width: 360px) {
  .qd-drive {
    padding: 16px 12px;
  }

  #qd-files,
  .qd-modal-files {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .qd-actions button {
    padding: 10px 16px;
    font-size: 13px;
  }
}