/* ============================
   Form Elements
   ============================ */
input, select {
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  background: var(--c-background);
  color: var(--c-text-primary);
  font-size: 0.9rem;
  transition: all 0.2s ease;
  width: -webkit-fill-available;
  user-select: none;
}

input:hover, select:hover {
  border-color: var(--c-border-hover);
}

input:focus, select:focus {
  outline: none;
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px var(--c-primary-ring);
}

/* Primary Buttons */
button, .button {
  background: var(--c-surface-hover);
  color: #fff;
  border: 1px solid transparent;
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  box-shadow: var(--shadow-sm);
  user-select: none;
}

button:hover, .button:hover {
  background: var(--c-primary-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-glow);
}

button:active, .button:active {
  background: var(--c-primary-active);
  transform: translateY(0);
}

/* Disabled States */
button[disabled="true"], .button[disabled="true"], #loginAction[inactive="true"], i[disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  filter: grayscale(1);
  pointer-events: none;
}

div.button {
  font-size: 1.3rem;
  padding: 0.5rem 1rem;
}

/* ============================
   Tabs
   ============================ */
#tabsList {
  user-select: none;
}

#tabsList li {
  gap: 1rem;

}

#leftSide #tabsList {
  display: flex;
  padding: var(--space-sm);
  gap: var(--space-sm);
  border-bottom: 1px solid var(--c-border);
  background: var(--c-surface);
}

#leftSide #tabsList li {
  flex: 1;
  list-style: none;
  padding: 0.5rem;
  text-align: center;
  cursor: pointer;
  border-radius: var(--radius-sm);
  color: var(--c-text-secondary);
  font-weight: 500;
  font-size: 0.9rem;
  transition: all 0.2s;
}

#leftSide #tabsList li:hover {
  background-color: var(--c-surface-hover);
  color: var(--c-text-primary);
}

#leftSide #tabsList li.active {
  background-color: var(--c-primary-dark);
  color: var(--c-primary-hover);
  font-weight: 600;
}

.tabContent { display: none; width: 100%; height: 100%; }
.tabContent.active { 
  display: flex;
  flex-direction: column;
}

/* ============================
   Controls & Icons
   ============================ */
.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-sm);
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  border-top: 1px solid var(--c-border);
  gap: 0.5rem;
}

.controls i {
  background: var(--c-surface-hover);
  color: var(--c-text-primary);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 1rem;
}

.controls i:hover {
  background: var(--c-primary);
  color: #fff;
}

.buttons {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.buttons .fa-brands {
  font-size: 1.8rem;
  color: var(--c-text-secondary);
  transition: color 0.2s;
}
.buttons .fa-brands:hover { color: var(--c-primary-hover); }

/* ============================
   Slots (Draggable Items)
   ============================ */
#image-slots {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    padding: var(--space-sm);
    height: calc(100% - 78px);
    flex: none;
    align-content: start;
}

#image-slots > * {
    flex: 1 1 120px; /* grow, shrink, minimum width */
    min-width: 120px;
    height: min-content;
}

.slot {
  width: 100%;
  height: auto;
  aspect-ratio: 2/3;
  background: var(--c-background);
  border-radius: var(--radius-md);
  border: 2px dashed var(--c-border);
  position: relative;
  overflow: hidden;
  transition: all 0.2s ease;
}

/* Logic to detect if image is loaded would be in JS, 
   but assuming .preview has src, we can style the slot */
.slot:has(.preview[src^="http"]), .slot:has(.preview[src^="data"]) {
  border-style: solid;
  border-color: transparent;
}

.slot:hover {
  border-color: var(--c-primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.slot.dragover {
  border-color: var(--c-success);
  background: var(--c-success-bg);
}

/* Slot Controls overlay */
.slot .bottomButtons, .slot .topButtons {
  position: absolute;
  width: 100%;
  padding: 0.5rem;
  display: flex;
  justify-content: space-between;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none; /* Enable only on hover */
}

.slot:hover .bottomButtons, .slot:hover .topButtons {
  opacity: 1;
  pointer-events: auto;
}

.slot .topButtons {
  top: 0;
  background: linear-gradient(to bottom, rgba(0,0,0,0.8), transparent);
}
.slot .bottomButtons {
  bottom: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);
}

.slot i {
  font-size: 0.85rem;
  color: var(--c-text-primary);
  background: rgba(255,255,255,0.1);
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  backdrop-filter: blur(4px);
  cursor: pointer;
}
.slot i:hover {
  background: var(--c-primary);
  color: #fff;
}

i.delete:hover { background: var(--c-danger); }

.preview {
  width: 100%; height: 100%;
  object-fit: cover;
  user-select: none;
}
.preview[src=""] { visibility: hidden; }

/* ============================
   Jellyfin Library Items
   ============================ */
#jellyfinimages {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    padding: var(--space-sm);
    height: calc(100% - 110px); /* subtract controls height */
}

#jellyfinimages > * {
    flex: 1 1 140px; /* fluid like minmax(140px, 1fr) */
    min-width: 140px;
    height: min-content;
}

#jellyfinimages > .library {
  /* The libraries should use the fill available width */
  flex: 1 1 200px; /* fluid like minmax(140px, 1fr) */
  /* min-width: 100%; */
}


#jellyfinContent .library, #jellyfinContent .poster {
  position: relative;
  background: var(--c-surface-hover);
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid transparent;
  transition: all 0.2s;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  /* ENSURE THAT IT KEEPS THE IMAGE SCALE */

}

#jellyfinContent .library img, #jellyfinContent .poster img {
  width: 100%; height: 100%;
  object-fit: cover;
}

#jellyfinContent .library:hover, #jellyfinContent .poster:hover {
  border-color: var(--c-primary);
  transform: scale(1.02);
  box-shadow: var(--shadow-lg);
}

/* Labels for items */
#jellyfinContent span {
  position: absolute;
  bottom: 0;
  width: 100%;
  padding: 0.5rem;
  background: rgba(0,0,0,0.8);
  color: white;
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  user-select: none;
}

/* ============================
   Floating Windows (Modals)
   ============================ */
.floatWindow {
  position: absolute;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  display: flex;
  flex-direction: column;
  z-index: 1;
  overflow: hidden;
  animation: fadeIn 0.2s ease-out;
}

.floatWindow .windowBar {
  padding: 1rem;
  background: var(--c-surface-hover);
  border-bottom: 1px solid var(--c-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: grab;
}

.floatWindow .windowBar h2 { margin: 0; font-size: 1rem; }
.floatWindow .windowBar .closeBtn {
  background: transparent; border: none; color: var(--c-text-secondary);
  font-size: 1.5rem; padding: 0; box-shadow: none; width: auto;
}
.floatWindow .windowBar .closeBtn:hover { color: var(--c-danger); background: transparent; transform: none; box-shadow: none;}

.floatWindow .content {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-height: calc(-6rem + 100vh);
}

/* ============================
   Accordion / Expandables
   ============================ */
.expand-label {
  position: relative;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: left;
  background: var(--c-surface-hover);
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  margin-bottom: 0.25rem;
  user-select: none;
  transition: background 0.2s;
}

.expand-label:hover { 
  background: var(--c-primary); 
}

.expand-checkbox:checked + .expand-label {
  background: var(--c-surface-active); 
}

.expand-checkbox:checked + .expand-label:hover { 
  background: var(--c-primary); 
}

.expand-content {
  position: relative;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.1s cubic-bezier(0, 1, 0, 1);
  padding: 0 0.5rem;
  border: 1px solid transparent;
  border-radius: 2%;
  background: var(--c-surface);
  overflow: hidden;
}

.expand-checkbox:checked ~ .expand-content {
  max-height: unset; /* Large enough number */
  transition: max-height 0.1s ease-in-out;
  padding-bottom: .1rem;
  overflow-y: scroll;
}

/* Expand Buttons (The floating ones on layout edges) */

.field.checkbox {
  position: relative;
  min-width: 100%
}

.optioncheckbox .effect-param-item .field.text {
  display: flex;
  flex-direction: row-reverse;
  min-width: 100%;
  flex-wrap: nowrap;
  white-space: nowrap;
}

.effect-param-item, .effect-layers-container, #typeSettingsContainer {
  /* disable text selection */
  user-select: none;
}


.expand-btn.expandCenterW, 
.expand-btn.expandCenterH {
  background: var(--c-surface-active);
  border-color: var(--c-border);
  color: var(--c-text-secondary);
  width: 24px; height: 24px;
  border-radius: 50% !important;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem;
  box-shadow: var(--shadow-md);
}
.expand-btn:hover, .add-button:hover, .delete-button:hover, .default-button:hover, .duplicate-button:hover, .toggle-button:hover, .opencomposite-button:hover {
  background: var(--c-primary);
  color: white;
  border-color: var(--c-primary);
}
.expand-checkbox { display: none; }


/* ============================
   Action Buttons
   ============================ */

.toggle-checkbox {
  display: none;
}

.toggle-checkbox:not(:checked) ~ .expand-label {
  background: var(--c-surface);
}

.toggle-checkbox:checked ~ .toggle-button::before {
  content: "\f06e"; /* fa-eye */
}

.toggle-checkbox:not(:checked) ~ .toggle-button::before {
  content: "\f070"; /* fa-eye-slash */
}

.add-button, .delete-button, .default-button, .duplicate-button, .toggle-button, .opencomposite-button {
  position: absolute;
  right: 0;
  top: 0;
  z-index: 1;
  overflow: visible;
  padding: .98rem;
  padding-left: .5rem;
  padding-right: .5rem;
  cursor: pointer;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.default-button {
  right: 1.7rem;
  border-radius: 0;
}

.duplicate-button {
  right: 3.4rem;
  border-radius: 0;
}

.toggle-button {
  right: 5.1rem;
  border-radius: 0;  
}

#openTextComposite {
  right: 1.8rem;
  border-radius: 0;  
}

/* if fontSelect-input value is "Add New Font..." then font-custom-options-container display block */
.font-custom-options-container {
  display: none;
}

.font-custom-options-container.show {
  display: block;
  margin-top: 0.5rem;
}



/* ============================
   Search & Misc
   ============================ */

#searchInput {
  position: relative;
  flex-grow: 1;
  background: var(--c-background);
  border: 1px solid var(--c-border);
}

.field.image {
  display: flex;
  flex-wrap: wrap;
}

.field.image > * {
  flex-grow: 1;
}

/* Settings Fields */

.settings span {
  display: block;
  margin-bottom: 0.25rem;
  color: var(--c-text-secondary);
  font-size: 0.85rem;
}

/* Export Buttons */
.canvasBars {
  position: relative;
  background: rgba(24, 24, 27, 0.9);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--c-border);
  display: flex;
  z-index: 1;
  width: 100%;
  min-height: var(--canvasBarsH);
  max-height: var(--canvasBarsH);
  overflow: hidden;
  justify-content: center;
  gap: .5rem;
  padding: .35rem;
}
.canvasBars button {
  border-radius: var(--radius-full);
  white-space: nowrap;
}

#toast-container {
  position: fixed;
  top: var(--space-lg);
  right: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  z-index: 1;
  pointer-events: none;
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============================
   Gallery Contribute Banner
   ============================ */
.gallery-contribute {
  position: absolute;
  display: block;
  margin-bottom: 0.75rem;
}
.gallery-contribute a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: linear-gradient(90deg, var(--c-primary-dark), var(--c-primary));
  color: #fff;
  border-radius: var(--radius-md);
  text-decoration: none;
  box-shadow: var(--shadow-sm);
}
.gallery-contribute a .fa-github {
  font-size: 1.1rem;
}
.gallery-contribute a .contribute-text {
  font-weight: 700;
}
.gallery-contribute a .contribute-sub {
  font-size: 0.8rem;
  opacity: 0.95;
}
.gallery-contribute a:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

@media (max-width: 640px) {
  .gallery-contribute a { flex-direction: column; align-items: flex-start; }
  .gallery-contribute a .contribute-sub { font-size: 0.85rem; }
}

/* Gallery search */
.gallery-controls {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding-bottom: 0.5rem;
}
.gallery-search {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}
.gallery-search input {
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--c-border);
  background: var(--c-background);
  color: var(--c-text-primary);
  width: 280px;
}
.gallery-search input:focus {
  outline: none;
  border-color: var(--c-primary);
}
.gallery-search .icon-button {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--c-text-secondary);
  font-size: 0.9rem;
  padding: 0.25rem;
}
.gallery-search .icon-button:hover { color: var(--c-primary); }
.no-results { text-align: center; color: var(--c-text-secondary); padding: 1rem; }

@media (max-width: 640px) {
  .gallery-search input { width: 100%; }
  .gallery-controls { justify-content: stretch; }
}