/* Editor de carátulas y datos. Hoja separada para evitar estilos antiguos en caché. */
.metadata-dialog,
.metadata-dialog * { box-sizing: border-box; }

.metadata-dialog {
  position: fixed;
  inset: 12px;
  width: calc(100vw - 24px);
  max-width: 1120px;
  height: calc(100vh - 24px);
  height: calc(100dvh - 24px);
  max-height: none;
  margin: auto;
  padding: 0;
  overflow: hidden;
  color: #fff;
  background: #252525;
  border: 1px solid #50505a;
  border-radius: 12px;
  box-shadow: 0 32px 110px rgba(0, 0, 0, .9);
}

.metadata-dialog::backdrop { background: rgba(4, 4, 10, .88); }
.metadata-dialog[open] { display: block; }
.metadata-dialog form { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; width: 100%; height: 100%; margin: 0; }

.metadata-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  min-height: 78px;
  padding: 18px 24px;
  background: #343434;
  border-bottom: 1px solid #151515;
}
.metadata-header h2 { margin: 5px 0 0; font: 600 22px Outfit, Arial, sans-serif; }
.metadata-header .modal-close { flex: 0 0 auto; color: #bbb; }

.metadata-layout { display: grid; grid-template-columns: 185px minmax(0, 1fr); min-height: 0; overflow: hidden; }
.metadata-tabs { min-height: 0; padding: 14px 0; overflow-y: auto; background: #1c1c1c; border-right: 1px solid #111; }
.metadata-tab {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 13px 19px;
  color: #aaa;
  background: transparent;
  border: 0;
  border-left: 3px solid transparent;
  text-align: left;
  font-size: 13px;
}
.metadata-tab span { width: 18px; color: #999; }
.metadata-tab:hover { color: #fff; background: rgba(255, 255, 255, .05); }
.metadata-tab.active { color: #ffd000; background: #2b2b2b; border-left-color: #ffd000; }
.metadata-tab.active span { color: #ffd000; }

.metadata-panels { min-width: 0; min-height: 0; padding: 25px 28px 34px; overflow-y: auto; overscroll-behavior: contain; background: #282828; }
.metadata-panel { display: grid; gap: 18px; }
.metadata-panel.hidden { display: none !important; }
.metadata-panel label,
.online-search-box label,
.image-editor label { display: grid; gap: 7px; min-width: 0; color: #c7c7c7; font-size: 12px; font-weight: 600; }
.metadata-panel input:not([type="file"]),
.metadata-panel textarea,
.metadata-panel select,
.online-search-box input,
.online-search-box select,
.image-editor input:not([type="file"]) {
  display: block;
  width: 100%;
  min-width: 0;
  padding: 11px 12px;
  color: #fff;
  background: #3a3a3a;
  border: 1px solid #555;
  border-radius: 5px;
  font: 13px 'DM Sans', Arial, sans-serif;
}
.metadata-panel textarea { resize: vertical; }
.metadata-panel input:focus,
.metadata-panel textarea:focus,
.online-search-box input:focus,
.image-editor input:focus { border-color: #ffd000; outline: 2px solid rgba(255, 208, 0, .2); }

.metadata-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.metadata-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.metadata-episode-fields { display: grid; gap: 14px; padding: 18px; background: #202020; border: 1px solid #48444d; border-radius: 7px; }
.metadata-episode-fields h3 { margin: 0; font: 700 15px Outfit, Arial, sans-serif; }
.metadata-episode-fields p { margin: 0; color: #bbb; font-size: 12px; line-height: 1.55; }
.metadata-episode-fields .tool-button { justify-self: start; color: #dce6ff; background: #283247; border-color: #52688f; }
.metadata-episode-fields .tool-button:hover { background: #394966; border-color: #91a9d2; }
.metadata-episode-fields .sync-error { color: #ff8fa0; }
.metadata-episode-fields small,
.metadata-hint { margin: 0; color: #999; font-size: 11px; line-height: 1.55; }

.metadata-footer { display: flex; justify-content: flex-end; gap: 10px; min-height: 64px; padding: 12px 20px; background: #343434; border-top: 1px solid #161616; }
.metadata-footer button { align-self: center; }
.metadata-footer .primary-btn { padding: 11px 17px; }

.online-search-box { display: grid; gap: 14px; padding: 17px; background: linear-gradient(120deg, #35301f, #222 68%); border: 1px solid #554e39; border-radius: 8px; }
.online-search-box h3 { margin: 4px 0; font: 700 18px Outfit, Arial, sans-serif; }
.online-search-box p { margin: 0; color: #aaa; font-size: 11px; line-height: 1.5; }
.online-search-row { display: grid; grid-template-columns: 185px minmax(0, 1fr) auto; gap: 8px; }
.online-search-row .primary-btn { justify-content: center; padding: 10px 16px; }
.online-search-box a { color: #ffd762; }
.metadata-search-results { display: grid; gap: 8px; max-height: 310px; overflow-y: auto; }
.metadata-result { display: grid; grid-template-columns: 54px minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 9px; background: rgba(29, 29, 29, .92); border: 1px solid #454545; border-radius: 6px; }
.metadata-result-image { display: grid; place-items: center; width: 54px; height: 74px; overflow: hidden; color: #aaa; background: #3b3b3b; border-radius: 3px; }
.metadata-result-image img { width: 100%; height: 100%; object-fit: cover; }
.metadata-result-info { display: grid; gap: 4px; min-width: 0; }
.metadata-result-info strong { font-size: 13px; }
.metadata-result-info small { color: #d6b943; font-size: 10px; }
.metadata-result-info p { display: -webkit-box; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.metadata-result .primary-btn { padding: 9px 12px; font-size: 11px; }
.metadata-no-results { padding: 16px !important; text-align: center; border: 1px dashed #555; }
.tmdb-credit { padding-top: 4px; color: #858585 !important; }
.tmdb-credit strong { color: #69b5e8; }

.image-editor { display: grid; grid-template-columns: 220px minmax(0, 1fr); align-items: start; gap: 22px; padding: 19px; background: #212121; border: 1px solid #474747; border-radius: 8px; }
.image-editor > div:last-child { display: grid; gap: 14px; min-width: 0; }
.image-preview { display: grid; place-items: center; overflow: hidden; color: #858585; background: #151515; border: 1px dashed #595959; border-radius: 6px; font-size: 12px; }
.poster-preview { aspect-ratio: 2 / 3; }
.background-preview { aspect-ratio: 16 / 9; }
.image-preview img { width: 100%; height: 100%; object-fit: cover; }
.background-editor { grid-template-columns: minmax(300px, 1.4fr) minmax(0, 1fr); }
.image-editor input[type="file"] { max-width: 100%; color: #aaa; font-size: 11px; }
.image-editor input::file-selector-button { margin-right: 8px; padding: 8px 10px; color: #fff; background: #494949; border: 0; border-radius: 4px; cursor: pointer; }

@media (max-width: 760px) {
  .metadata-dialog { inset: 5px; width: calc(100vw - 10px); height: calc(100vh - 10px); height: calc(100dvh - 10px); border-radius: 8px; }
  .metadata-header { min-height: 68px; padding: 14px 16px; }
  .metadata-header h2 { max-width: 260px; font-size: 18px; }
  .metadata-layout { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .metadata-tabs { display: flex; min-height: auto; padding: 0; overflow-x: auto; overflow-y: hidden; border-right: 0; border-bottom: 1px solid #111; }
  .metadata-tab { flex: 0 0 auto; width: auto; padding: 11px 13px; border-left: 0; border-bottom: 3px solid transparent; }
  .metadata-tab.active { border-left: 0; border-bottom-color: #ffd000; }
  .metadata-panels { padding: 19px 15px 25px; }
  .metadata-grid,
  .metadata-grid-3 { grid-template-columns: 1fr; }
  .online-search-row { grid-template-columns: 1fr; }
  .metadata-result { grid-template-columns: 45px minmax(0, 1fr); }
  .metadata-result-image { width: 45px; height: 62px; }
  .metadata-result .primary-btn { grid-column: 1 / -1; justify-content: center; }
  .image-editor,
  .background-editor { grid-template-columns: 1fr; }
  .poster-preview { width: min(210px, 100%); margin: auto; }
  .metadata-footer { min-height: 58px; padding: 9px 11px; }
  .metadata-footer button { flex: 1; }
}

@media (max-height: 600px) and (min-width: 761px) {
  .metadata-dialog { inset: 6px; width: calc(100vw - 12px); height: calc(100vh - 12px); height: calc(100dvh - 12px); }
  .metadata-header { min-height: 66px; padding: 12px 20px; }
  .metadata-header h2 { font-size: 19px; }
  .metadata-tabs { padding: 8px 0; }
  .metadata-tab { padding-top: 10px; padding-bottom: 10px; }
  .metadata-panels { padding-top: 18px; padding-bottom: 22px; }
  .metadata-footer { min-height: 54px; padding-top: 7px; padding-bottom: 7px; }
}
